Skip to content

Commit

Permalink
mod file update
Browse files Browse the repository at this point in the history
  • Loading branch information
eddddiez committed Mar 13, 2024
1 parent f100f45 commit a1efc93
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 139 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package main
import (
"context"
"fmt"
. "github.com/eddddiez/OKEX_V5SDK_GO/rest"
. "github.com/eddddiez/OKEX_V5SDK_GO/ws"
"log"
"time"
. "v5sdk_go/rest"
. "v5sdk_go/ws"
)

/*
rest API请求
更多示例请查看 rest/rest_test.go
rest API请求
更多示例请查看 rest/rest_test.go
*/
func REST() {
// 设置您的APIKey
Expand Down
28 changes: 14 additions & 14 deletions rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"encoding/json"
"errors"
"fmt"
. "github.com/eddddiez/OKEX_V5SDK_GO/utils"
"io/ioutil"
"net/http"
"strings"
"time"
. "v5sdk_go/utils"
)

type RESTAPI struct {
Expand Down Expand Up @@ -51,9 +51,9 @@ type Okexv5APIResponse struct {
}

/*
endPoint:请求地址
apiKey
isSimulate: 是否为模拟环境
endPoint:请求地址
apiKey
isSimulate: 是否为模拟环境
*/
func NewRESTClient(endPoint string, apiKey *APIKeyInfo, isSimulate bool) *RESTAPI {

Expand Down Expand Up @@ -230,7 +230,7 @@ func (this *RESTAPI) Run(ctx context.Context) (res *RESTAPIResult, err error) {
}

/*
生成请求对应的参数
生成请求对应的参数
*/
func (this *RESTAPI) GenReqInfo() (uri string, body string, err error) {
uri = this.Uri
Expand Down Expand Up @@ -265,14 +265,14 @@ func (this *RESTAPI) GenReqInfo() (uri string, body string, err error) {
}

/*
Set http request headers:
Accept: application/json
Content-Type: application/json; charset=UTF-8 (default)
Cookie: locale=en_US (English)
OK-ACCESS-KEY: (Your setting)
OK-ACCESS-SIGN: (Use your setting, auto sign and add)
OK-ACCESS-TIMESTAMP: (Auto add)
OK-ACCESS-PASSPHRASE: Your setting
Set http request headers:
Accept: application/json
Content-Type: application/json; charset=UTF-8 (default)
Cookie: locale=en_US (English)
OK-ACCESS-KEY: (Your setting)
OK-ACCESS-SIGN: (Use your setting, auto sign and add)
OK-ACCESS-TIMESTAMP: (Auto add)
OK-ACCESS-PASSPHRASE: Your setting
*/
func (this *RESTAPI) SetHeaders(request *http.Request, timestamp string, sign string) (header string) {

Expand Down Expand Up @@ -306,7 +306,7 @@ func (this *RESTAPI) SetHeaders(request *http.Request, timestamp string, sign st
}

/*
打印header信息
打印header信息
*/
func (this *RESTAPI) PrintRequest(request *http.Request, body string, preHash string) {
if this.ApiKeyInfo.SecKey != "" {
Expand Down
4 changes: 2 additions & 2 deletions ws/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package ws

import (
"errors"
. "github.com/eddddiez/OKEX_V5SDK_GO/ws/wImpl"
. "github.com/eddddiez/OKEX_V5SDK_GO/ws/wInterface"
"log"
"runtime/debug"
. "v5sdk_go/ws/wImpl"
. "v5sdk_go/ws/wInterface"
)

// 判断返回结果成功失败
Expand Down
4 changes: 2 additions & 2 deletions ws/wImpl/JRPCData.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
JRPC请求/响应数据
JRPC请求/响应数据
*/
package wImpl

import (
"encoding/json"
. "v5sdk_go/utils"
. "github.com/eddddiez/OKEX_V5SDK_GO/utils"
)

// jrpc请求结构体
Expand Down
2 changes: 1 addition & 1 deletion ws/wImpl/ReqData.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package wImpl

import (
"encoding/json"
. "v5sdk_go/utils"
. "github.com/eddddiez/OKEX_V5SDK_GO/utils"
)

// 客户端请求消息格式
Expand Down
2 changes: 1 addition & 1 deletion ws/wInterface/IParam.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package wInterface

import . "v5sdk_go/ws/wImpl"
import . "github.com/eddddiez/OKEX_V5SDK_GO/ws/wImpl"

// 请求数据
type WSParam interface {
Expand Down
55 changes: 28 additions & 27 deletions ws/ws_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"encoding/json"
"errors"
"fmt"
. "github.com/eddddiez/OKEX_V5SDK_GO/config"
. "github.com/eddddiez/OKEX_V5SDK_GO/utils"
. "github.com/eddddiez/OKEX_V5SDK_GO/ws/wImpl"
"log"
"regexp"
"runtime/debug"
"sync"
"time"
. "v5sdk_go/config"
. "v5sdk_go/utils"
. "v5sdk_go/ws/wImpl"

"github.com/gorilla/websocket"
)
Expand Down Expand Up @@ -55,9 +55,9 @@ type WsClient struct {
}

/*
服务端响应详细信息
Timestamp: 接受到消息的时间
Info: 接受到的消息字符串
服务端响应详细信息
Timestamp: 接受到消息的时间
Info: 接受到的消息字符串
*/
type Msg struct {
Timestamp time.Time `json:"timestamp"`
Expand All @@ -71,7 +71,7 @@ func (this *Msg) Print() {
}

/*
订阅结果封装后的消息结构体
订阅结果封装后的消息结构体
*/
type ProcessDetail struct {
EndPoint string `json:"endPoint"`
Expand Down Expand Up @@ -112,7 +112,7 @@ func NewWsClient(ep string) (r *WsClient, err error) {
}

/*
新增记录深度信息
新增记录深度信息
*/
func (a *WsClient) addDepthDataList(key string, dd DepthDetail) error {
a.DepthDataLock.Lock()
Expand All @@ -122,7 +122,7 @@ func (a *WsClient) addDepthDataList(key string, dd DepthDetail) error {
}

/*
更新记录深度信息(如果没有记录不会更新成功)
更新记录深度信息(如果没有记录不会更新成功)
*/
func (a *WsClient) updateDepthDataList(key string, dd DepthDetail) error {
a.DepthDataLock.Lock()
Expand All @@ -136,7 +136,7 @@ func (a *WsClient) updateDepthDataList(key string, dd DepthDetail) error {
}

/*
删除记录深度信息
删除记录深度信息
*/
func (a *WsClient) deleteDepthDataList(key string) error {
a.DepthDataLock.Lock()
Expand All @@ -146,7 +146,7 @@ func (a *WsClient) deleteDepthDataList(key string) error {
}

/*
设置是否自动深度管理,开启 true,关闭 false
设置是否自动深度管理,开启 true,关闭 false
*/
func (a *WsClient) EnableAutoDepthMgr(b bool) error {
a.DepthDataLock.Lock()
Expand All @@ -162,7 +162,7 @@ func (a *WsClient) EnableAutoDepthMgr(b bool) error {
}

/*
获取当前的深度快照信息(合并后的)
获取当前的深度快照信息(合并后的)
*/
func (a *WsClient) GetSnapshotByChannel(data DepthData) (snapshot *DepthDetail, err error) {
key, err := json.Marshal(data.Arg)
Expand Down Expand Up @@ -309,7 +309,7 @@ func (a *WsClient) work() {
}

/*
处理接受到的消息
处理接受到的消息
*/
func (a *WsClient) receive() {
defer func() {
Expand Down Expand Up @@ -443,7 +443,7 @@ func (a *WsClient) receive() {
}

/*
开启了深度数据管理功能后,系统会自动合并深度信息
开启了深度数据管理功能后,系统会自动合并深度信息
*/
func (a *WsClient) MergeDepth(depData DepthData) (err error) {
if !a.autoDepthMgr {
Expand Down Expand Up @@ -496,7 +496,7 @@ func (a *WsClient) MergeDepth(depData DepthData) (err error) {
}

/*
通过ErrorCode判断事件类型
通过ErrorCode判断事件类型
*/
func GetInfoFromErrCode(data ErrData) Event {
switch data.Code {
Expand Down Expand Up @@ -528,9 +528,10 @@ func GetInfoFromErrCode(data ErrData) Event {
}

/*
从error返回中解析出对应的channel
error信息样例
{"event":"error","msg":"channel:index-tickers,instId:BTC-USDT1 doesn't exist","code":"60018"}
从error返回中解析出对应的channel
error信息样例
{"event":"error","msg":"channel:index-tickers,instId:BTC-USDT1 doesn't exist","code":"60018"}
*/
func GetInfoFromErrMsg(raw string) (channel string) {
reg := regexp.MustCompile(`channel:(.*?),`)
Expand All @@ -547,7 +548,7 @@ func GetInfoFromErrMsg(raw string) (channel string) {
}

/*
解析消息类型
解析消息类型
*/
func (a *WsClient) parseMessage(raw []byte) (evt Event, data interface{}, err error) {
evt = EVENT_UNKNOWN
Expand Down Expand Up @@ -660,7 +661,7 @@ func (a *WsClient) Stop() error {
}

a.isStarted = false

if a.conn != nil {
a.conn.Close()
}
Expand All @@ -678,41 +679,41 @@ func (a *WsClient) Stop() error {
}

/*
添加全局消息处理的回调函数
添加全局消息处理的回调函数
*/
func (a *WsClient) AddMessageHook(fn ReceivedDataCallback) error {
a.onMessageHook = fn
return nil
}

/*
添加订阅消息处理的回调函数
添加订阅消息处理的回调函数
*/
func (a *WsClient) AddBookMsgHook(fn ReceivedMsgDataCallback) error {
a.onBookMsgHook = fn
return nil
}

/*
添加深度消息处理的回调函数
例如:
cli.AddDepthHook(func(ts time.Time, data DepthData) error { return nil })
添加深度消息处理的回调函数
例如:
cli.AddDepthHook(func(ts time.Time, data DepthData) error { return nil })
*/
func (a *WsClient) AddDepthHook(fn ReceivedDepthDataCallback) error {
a.onDepthHook = fn
return nil
}

/*
添加错误类型消息处理的回调函数
添加错误类型消息处理的回调函数
*/
func (a *WsClient) AddErrMsgHook(fn ReceivedDataCallback) error {
a.OnErrorHook = fn
return nil
}

/*
判断连接是否存活
判断连接是否存活
*/
func (a *WsClient) IsAlive() bool {
res := false
Expand Down
Loading

0 comments on commit a1efc93

Please sign in to comment.