module changes

This commit is contained in:
zhangkun9038@dingtalk.com 2024-12-16 11:41:20 +08:00
parent a72a120dd7
commit 1dc006253a
19 changed files with 167 additions and 133 deletions

View File

@ -1,3 +0,0 @@
module v5sdk_go/config
go 1.14

5
go.mod
View File

@ -1,3 +1,8 @@
module github.com/phyer/v5sdkgo module github.com/phyer/v5sdkgo
go 1.15 go 1.15
require (
github.com/gorilla/websocket v1.5.3
github.com/stretchr/testify v1.10.0
)

21
go.sum
View File

@ -0,0 +1,21 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

11
main.go
View File

@ -1,17 +1,18 @@
package main package v5sdkgo
import ( import (
"context" "context"
"fmt" "fmt"
. "github.com/phyer/v5sdkgo/rest"
. "github.com/phyer/v5sdkgo/ws"
"log" "log"
"time" "time"
. "v5sdk_go/rest"
. "v5sdk_go/ws"
) )
/* /*
rest API请求 rest API请求
更多示例请查看 rest/rest_test.go 更多示例请查看 rest/rest_test.go
*/ */
func REST() { func REST() {
// 设置您的APIKey // 设置您的APIKey

View File

View File

@ -6,11 +6,11 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
. "github.com/phyer/v5sdkgo/utils"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
"time" "time"
. "v5sdk_go/utils"
) )
type RESTAPI struct { type RESTAPI struct {
@ -51,9 +51,9 @@ type Okexv5APIResponse struct {
} }
/* /*
endPoint:请求地址 endPoint:请求地址
apiKey apiKey
isSimulate: 是否为模拟环境 isSimulate: 是否为模拟环境
*/ */
func NewRESTClient(endPoint string, apiKey *APIKeyInfo, isSimulate bool) *RESTAPI { func NewRESTClient(endPoint string, apiKey *APIKeyInfo, isSimulate bool) *RESTAPI {
@ -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) { func (this *RESTAPI) GenReqInfo() (uri string, body string, err error) {
uri = this.Uri uri = this.Uri
@ -265,14 +265,14 @@ func (this *RESTAPI) GenReqInfo() (uri string, body string, err error) {
} }
/* /*
Set http request headers: Set http request headers:
Accept: application/json Accept: application/json
Content-Type: application/json; charset=UTF-8 (default) Content-Type: application/json; charset=UTF-8 (default)
Cookie: locale=en_US (English) Cookie: locale=en_US (English)
OK-ACCESS-KEY: (Your setting) OK-ACCESS-KEY: (Your setting)
OK-ACCESS-SIGN: (Use your setting, auto sign and add) OK-ACCESS-SIGN: (Use your setting, auto sign and add)
OK-ACCESS-TIMESTAMP: (Auto add) OK-ACCESS-TIMESTAMP: (Auto add)
OK-ACCESS-PASSPHRASE: Your setting OK-ACCESS-PASSPHRASE: Your setting
*/ */
func (this *RESTAPI) SetHeaders(request *http.Request, timestamp string, sign string) (header string) { func (this *RESTAPI) SetHeaders(request *http.Request, timestamp string, sign string) (header string) {
@ -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) { func (this *RESTAPI) PrintRequest(request *http.Request, body string, preHash string) {
if this.ApiKeyInfo.SecKey != "" { if this.ApiKeyInfo.SecKey != "" {

View File

View File

View File

@ -2,10 +2,10 @@ package ws
import ( import (
"errors" "errors"
. "github.com/phyer/v5sdkgo/ws/wImpl"
. "github.com/phyer/v5sdkgo/ws/wInterface"
"log" "log"
"runtime/debug" "runtime/debug"
. "v5sdk_go/ws/wImpl"
. "v5sdk_go/ws/wInterface"
) )
// 判断返回结果成功失败 // 判断返回结果成功失败

View File

@ -1,11 +1,11 @@
/* /*
JRPC请求/响应数据 JRPC请求/响应数据
*/ */
package wImpl package wImpl
import ( import (
"encoding/json" "encoding/json"
. "v5sdk_go/utils" . "github.com/phyer/v5sdkgo/utils"
) )
// jrpc请求结构体 // jrpc请求结构体

View File

@ -6,7 +6,7 @@ package wImpl
import ( import (
"encoding/json" "encoding/json"
. "v5sdk_go/utils" . "github.com/phyer/v5sdkgo/utils"
) )
// 客户端请求消息格式 // 客户端请求消息格式

View File

@ -1,6 +1,8 @@
package wInterface package wInterface
import . "v5sdk_go/ws/wImpl" import (
. "github.com/phyer/v5sdkgo/ws/wImpl"
)
// 请求数据 // 请求数据
type WSParam interface { type WSParam interface {

View File

@ -5,14 +5,14 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
. "github.com/phyer/v5sdkgo/config"
. "github.com/phyer/v5sdkgo/utils"
. "github.com/phyer/v5sdkgo/ws/wImpl"
"log" "log"
"regexp" "regexp"
"runtime/debug" "runtime/debug"
"sync" "sync"
"time" "time"
. "v5sdk_go/config"
. "v5sdk_go/utils"
. "v5sdk_go/ws/wImpl"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
@ -55,9 +55,9 @@ type WsClient struct {
} }
/* /*
服务端响应详细信息 服务端响应详细信息
Timestamp: 接受到消息的时间 Timestamp: 接受到消息的时间
Info: 接受到的消息字符串 Info: 接受到的消息字符串
*/ */
type Msg struct { type Msg struct {
Timestamp time.Time `json:"timestamp"` Timestamp time.Time `json:"timestamp"`
@ -71,7 +71,7 @@ func (this *Msg) Print() {
} }
/* /*
订阅结果封装后的消息结构体 订阅结果封装后的消息结构体
*/ */
type ProcessDetail struct { type ProcessDetail struct {
EndPoint string `json:"endPoint"` EndPoint string `json:"endPoint"`
@ -112,7 +112,7 @@ func NewWsClient(ep string) (r *WsClient, err error) {
} }
/* /*
新增记录深度信息 新增记录深度信息
*/ */
func (a *WsClient) addDepthDataList(key string, dd DepthDetail) error { func (a *WsClient) addDepthDataList(key string, dd DepthDetail) error {
a.DepthDataLock.Lock() a.DepthDataLock.Lock()
@ -122,7 +122,7 @@ func (a *WsClient) addDepthDataList(key string, dd DepthDetail) error {
} }
/* /*
更新记录深度信息如果没有记录不会更新成功 更新记录深度信息如果没有记录不会更新成功
*/ */
func (a *WsClient) updateDepthDataList(key string, dd DepthDetail) error { func (a *WsClient) updateDepthDataList(key string, dd DepthDetail) error {
a.DepthDataLock.Lock() a.DepthDataLock.Lock()
@ -136,7 +136,7 @@ func (a *WsClient) updateDepthDataList(key string, dd DepthDetail) error {
} }
/* /*
删除记录深度信息 删除记录深度信息
*/ */
func (a *WsClient) deleteDepthDataList(key string) error { func (a *WsClient) deleteDepthDataList(key string) error {
a.DepthDataLock.Lock() a.DepthDataLock.Lock()
@ -146,7 +146,7 @@ func (a *WsClient) deleteDepthDataList(key string) error {
} }
/* /*
设置是否自动深度管理开启 true关闭 false 设置是否自动深度管理开启 true关闭 false
*/ */
func (a *WsClient) EnableAutoDepthMgr(b bool) error { func (a *WsClient) EnableAutoDepthMgr(b bool) error {
a.DepthDataLock.Lock() a.DepthDataLock.Lock()
@ -162,7 +162,7 @@ func (a *WsClient) EnableAutoDepthMgr(b bool) error {
} }
/* /*
获取当前的深度快照信息(合并后的) 获取当前的深度快照信息(合并后的)
*/ */
func (a *WsClient) GetSnapshotByChannel(data DepthData) (snapshot *DepthDetail, err error) { func (a *WsClient) GetSnapshotByChannel(data DepthData) (snapshot *DepthDetail, err error) {
key, err := json.Marshal(data.Arg) key, err := json.Marshal(data.Arg)
@ -310,7 +310,7 @@ func (a *WsClient) work() {
} }
/* /*
处理接受到的消息 处理接受到的消息
*/ */
func (a *WsClient) receive() { func (a *WsClient) receive() {
defer func() { defer func() {
@ -444,7 +444,7 @@ func (a *WsClient) receive() {
} }
/* /*
开启了深度数据管理功能后系统会自动合并深度信息 开启了深度数据管理功能后系统会自动合并深度信息
*/ */
func (a *WsClient) MergeDepth(depData DepthData) (err error) { func (a *WsClient) MergeDepth(depData DepthData) (err error) {
if !a.autoDepthMgr { if !a.autoDepthMgr {
@ -497,7 +497,7 @@ func (a *WsClient) MergeDepth(depData DepthData) (err error) {
} }
/* /*
通过ErrorCode判断事件类型 通过ErrorCode判断事件类型
*/ */
func GetInfoFromErrCode(data ErrData) Event { func GetInfoFromErrCode(data ErrData) Event {
switch data.Code { switch data.Code {
@ -529,9 +529,10 @@ func GetInfoFromErrCode(data ErrData) Event {
} }
/* /*
从error返回中解析出对应的channel 从error返回中解析出对应的channel
error信息样例 error信息样例
{"event":"error","msg":"channel:index-tickers,instId:BTC-USDT1 doesn't exist","code":"60018"}
{"event":"error","msg":"channel:index-tickers,instId:BTC-USDT1 doesn't exist","code":"60018"}
*/ */
func GetInfoFromErrMsg(raw string) (channel string) { func GetInfoFromErrMsg(raw string) (channel string) {
reg := regexp.MustCompile(`channel:(.*?),`) reg := regexp.MustCompile(`channel:(.*?),`)
@ -548,7 +549,7 @@ func GetInfoFromErrMsg(raw string) (channel string) {
} }
/* /*
解析消息类型 解析消息类型
*/ */
func (a *WsClient) parseMessage(raw []byte) (evt Event, data interface{}, err error) { func (a *WsClient) parseMessage(raw []byte) (evt Event, data interface{}, err error) {
evt = EVENT_UNKNOWN evt = EVENT_UNKNOWN
@ -679,7 +680,7 @@ func (a *WsClient) Stop() error {
} }
/* /*
添加全局消息处理的回调函数 添加全局消息处理的回调函数
*/ */
func (a *WsClient) AddMessageHook(fn ReceivedDataCallback) error { func (a *WsClient) AddMessageHook(fn ReceivedDataCallback) error {
a.onMessageHook = fn a.onMessageHook = fn
@ -687,7 +688,7 @@ func (a *WsClient) AddMessageHook(fn ReceivedDataCallback) error {
} }
/* /*
添加订阅消息处理的回调函数 添加订阅消息处理的回调函数
*/ */
func (a *WsClient) AddBookMsgHook(fn ReceivedMsgDataCallback) error { func (a *WsClient) AddBookMsgHook(fn ReceivedMsgDataCallback) error {
a.onBookMsgHook = fn a.onBookMsgHook = fn
@ -695,9 +696,9 @@ func (a *WsClient) AddBookMsgHook(fn ReceivedMsgDataCallback) error {
} }
/* /*
添加深度消息处理的回调函数 添加深度消息处理的回调函数
例如: 例如:
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 { func (a *WsClient) AddDepthHook(fn ReceivedDepthDataCallback) error {
a.onDepthHook = fn a.onDepthHook = fn
@ -705,7 +706,7 @@ func (a *WsClient) AddDepthHook(fn ReceivedDepthDataCallback) error {
} }
/* /*
添加错误类型消息处理的回调函数 添加错误类型消息处理的回调函数
*/ */
func (a *WsClient) AddErrMsgHook(fn ReceivedDataCallback) error { func (a *WsClient) AddErrMsgHook(fn ReceivedDataCallback) error {
a.OnErrorHook = fn a.OnErrorHook = fn
@ -713,7 +714,7 @@ func (a *WsClient) AddErrMsgHook(fn ReceivedDataCallback) error {
} }
/* /*
判断连接是否存活 判断连接是否存活
*/ */
func (a *WsClient) IsAlive() bool { func (a *WsClient) IsAlive() bool {
res := false res := false

View File

@ -2,19 +2,20 @@ package ws
import ( import (
"context" "context"
. "github.com/phyer/v5sdkgo/ws/wImpl"
"log" "log"
"time" "time"
. "v5sdk_go/ws/wImpl"
) )
/* /*
websocket交易 通用请求 websocket交易 通用请求
参数说明 参数说明
evtId封装的事件类型
id: 请求ID evtId封装的事件类型
op: 请求参数op id: 请求ID
params: 请求参数 op: 请求参数op
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) jrpcReq(evtId Event, op string, id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) jrpcReq(evtId Event, op string, id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
res = true res = true
@ -56,11 +57,12 @@ func (a *WsClient) jrpcReq(evtId Event, op string, id string, params []map[strin
} }
/* /*
单个下单 单个下单
参数说明 参数说明
id: 请求ID
params: 请求参数 id: 请求ID
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) PlaceOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) PlaceOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "order" op := "order"
@ -74,11 +76,12 @@ func (a *WsClient) PlaceOrder(id string, param map[string]interface{}, timeOut .
} }
/* /*
批量下单 批量下单
参数说明 参数说明
id: 请求ID
params: 请求参数 id: 请求ID
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) BatchPlaceOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) BatchPlaceOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
@ -89,11 +92,12 @@ func (a *WsClient) BatchPlaceOrders(id string, params []map[string]interface{},
} }
/* /*
单个撤单 单个撤单
参数说明 参数说明
id: 请求ID
params: 请求参数 id: 请求ID
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) CancelOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) CancelOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
@ -108,11 +112,12 @@ func (a *WsClient) CancelOrder(id string, param map[string]interface{}, timeOut
} }
/* /*
批量撤单 批量撤单
参数说明 参数说明
id: 请求ID
params: 请求参数 id: 请求ID
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) BatchCancelOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) BatchCancelOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
@ -123,11 +128,12 @@ func (a *WsClient) BatchCancelOrders(id string, params []map[string]interface{},
} }
/* /*
单个改单 单个改单
参数说明 参数说明
id: 请求ID
params: 请求参数 id: 请求ID
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) AmendOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) AmendOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
@ -142,11 +148,12 @@ func (a *WsClient) AmendOrder(id string, param map[string]interface{}, timeOut .
} }
/* /*
批量改单 批量改单
参数说明 参数说明
id: 请求ID
params: 请求参数 id: 请求ID
timeOut: 超时时间 params: 请求参数
timeOut: 超时时间
*/ */
func (a *WsClient) BatchAmendOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) BatchAmendOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {

View File

@ -2,9 +2,9 @@ package ws
import ( import (
"fmt" "fmt"
. "github.com/phyer/v5sdkgo/ws/wImpl"
"testing" "testing"
"time" "time"
. "v5sdk_go/ws/wImpl"
) )
func PrintDetail(d *ProcessDetail) { func PrintDetail(d *ProcessDetail) {
@ -155,7 +155,7 @@ func (r *WsClient) makeOrder(instId string, tdMode string, side string, ordType
// } // }
/* /*
修改订单 修改订单
*/ */
func TestAmendlOrder(t *testing.T) { func TestAmendlOrder(t *testing.T) {
r := prework_pri(CROSS_ACCOUNT) r := prework_pri(CROSS_ACCOUNT)

View File

@ -3,19 +3,19 @@ package ws
import ( import (
"context" "context"
"errors" "errors"
. "github.com/phyer/v5sdkgo/config"
. "github.com/phyer/v5sdkgo/rest"
. "github.com/phyer/v5sdkgo/utils"
. "github.com/phyer/v5sdkgo/ws/wImpl"
. "github.com/phyer/v5sdkgo/ws/wInterface"
"log" "log"
"sync" "sync"
"time" "time"
. "v5sdk_go/config"
"v5sdk_go/rest"
. "v5sdk_go/utils"
. "v5sdk_go/ws/wImpl"
. "v5sdk_go/ws/wInterface"
) )
/* /*
Ping服务端保持心跳 Ping服务端保持心跳
timeOut:超时时间(毫秒)如果不填默认为5000ms timeOut:超时时间(毫秒)如果不填默认为5000ms
*/ */
func (a *WsClient) Ping(timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) Ping(timeOut ...int) (res bool, detail *ProcessDetail, err error) {
tm := 5000 tm := 5000
@ -54,7 +54,7 @@ func (a *WsClient) Ping(timeOut ...int) (res bool, detail *ProcessDetail, err er
} }
/* /*
登录私有频道 登录私有频道
*/ */
func (a *WsClient) Login(apiKey, secKey, passPhrase string, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) Login(apiKey, secKey, passPhrase string, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
@ -140,7 +140,7 @@ func (a *WsClient) Login(apiKey, secKey, passPhrase string, timeOut ...int) (res
} }
/* /*
等待结果响应 等待结果响应
*/ */
func (a *WsClient) waitForResult(e Event, timeOut int) (data interface{}, err error) { func (a *WsClient) waitForResult(e Event, timeOut int) (data interface{}, err error) {
@ -168,7 +168,7 @@ func (a *WsClient) waitForResult(e Event, timeOut int) (data interface{}, err er
} }
/* /*
发送消息到服务端 发送消息到服务端
*/ */
func (a *WsClient) Send(ctx context.Context, op WSReqData) (err error) { func (a *WsClient) Send(ctx context.Context, op WSReqData) (err error) {
select { select {
@ -293,8 +293,8 @@ func (a *WsClient) process(ctx context.Context, e Event, op WSReqData) (data []*
} }
/* /*
根据args请求参数判断请求类型 根据args请求参数判断请求类型
{"channel": "account","ccy": "BTC"} 类型为 EVENT_BOOK_ACCOUNT {"channel": "account","ccy": "BTC"} 类型为 EVENT_BOOK_ACCOUNT
*/ */
func GetEventByParam(param map[string]string) (evtId Event) { func GetEventByParam(param map[string]string) (evtId Event) {
evtId = EVENT_UNKNOWN evtId = EVENT_UNKNOWN
@ -308,8 +308,8 @@ func GetEventByParam(param map[string]string) (evtId Event) {
} }
/* /*
订阅频道 订阅频道
req请求json字符串 req请求json字符串
*/ */
func (a *WsClient) Subscribe(param map[string]string, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) Subscribe(param map[string]string, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
res = true res = true
@ -359,8 +359,8 @@ func (a *WsClient) Subscribe(param map[string]string, timeOut ...int) (res bool,
} }
/* /*
取消订阅频道 取消订阅频道
req请求json字符串 req请求json字符串
*/ */
func (a *WsClient) UnSubscribe(param map[string]string, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) UnSubscribe(param map[string]string, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
res = true res = true
@ -408,7 +408,7 @@ func (a *WsClient) UnSubscribe(param map[string]string, timeOut ...int) (res boo
} }
/* /*
jrpc请求 jrpc请求
*/ */
func (a *WsClient) Jrpc(id, op string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) { func (a *WsClient) Jrpc(id, op string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
res = true res = true

View File

@ -1,39 +1,39 @@
package ws package ws
import ( import (
. "v5sdk_go/ws/wImpl" . "github.com/phyer/v5sdkgo/ws/wImpl"
) )
/* /*
订阅账户频道 订阅账户频道
*/ */
func (a *WsClient) PrivAccout(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PrivAccout(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
return a.PubChannel(EVENT_BOOK_ACCOUNT, op, params, PERIOD_NONE, timeOut...) return a.PubChannel(EVENT_BOOK_ACCOUNT, op, params, PERIOD_NONE, timeOut...)
} }
/* /*
订阅持仓频道 订阅持仓频道
*/ */
func (a *WsClient) PrivPostion(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PrivPostion(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
return a.PubChannel(EVENT_BOOK_POSTION, op, params, PERIOD_NONE, timeOut...) return a.PubChannel(EVENT_BOOK_POSTION, op, params, PERIOD_NONE, timeOut...)
} }
/* /*
订阅订单频道 订阅订单频道
*/ */
func (a *WsClient) PrivBookOrder(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PrivBookOrder(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
return a.PubChannel(EVENT_BOOK_ORDER, op, params, PERIOD_NONE, timeOut...) return a.PubChannel(EVENT_BOOK_ORDER, op, params, PERIOD_NONE, timeOut...)
} }
/* /*
订阅策略委托订单频道 订阅策略委托订单频道
*/ */
func (a *WsClient) PrivBookAlgoOrder(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PrivBookAlgoOrder(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
return a.PubChannel(EVENT_BOOK_ALG_ORDER, op, params, PERIOD_NONE, timeOut...) return a.PubChannel(EVENT_BOOK_ALG_ORDER, op, params, PERIOD_NONE, timeOut...)
} }
/* /*
订阅账户余额和持仓频道 订阅账户余额和持仓频道
*/ */
func (a *WsClient) PrivBalAndPos(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PrivBalAndPos(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
return a.PubChannel(EVENT_BOOK_B_AND_P, op, params, PERIOD_NONE, timeOut...) return a.PubChannel(EVENT_BOOK_B_AND_P, op, params, PERIOD_NONE, timeOut...)

View File

@ -2,11 +2,11 @@ package ws
import ( import (
"errors" "errors"
. "v5sdk_go/ws/wImpl" . "github.com/phyer/v5sdkgo/ws/wImpl"
) )
/* /*
产品频道 产品频道
*/ */
func (a *WsClient) PubInstruemnts(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubInstruemnts(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -19,7 +19,7 @@ func (a *WsClient) PubStatus(op string, timeOut ...int) (res bool, msg []*Msg, e
} }
/* /*
行情频道 行情频道
*/ */
func (a *WsClient) PubTickers(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubTickers(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -27,14 +27,14 @@ func (a *WsClient) PubTickers(op string, params []map[string]string, timeOut ...
} }
/* /*
持仓总量频道 持仓总量频道
*/ */
func (a *WsClient) PubOpenInsterest(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubOpenInsterest(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
return a.PubChannel(EVENT_BOOK_OPEN_INTEREST, op, params, PERIOD_NONE, timeOut...) return a.PubChannel(EVENT_BOOK_OPEN_INTEREST, op, params, PERIOD_NONE, timeOut...)
} }
/* /*
K线频道 K线频道
*/ */
func (a *WsClient) PubKLine(op string, period Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubKLine(op string, period Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -42,7 +42,7 @@ func (a *WsClient) PubKLine(op string, period Period, params []map[string]string
} }
/* /*
交易频道 交易频道
*/ */
func (a *WsClient) PubTrade(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubTrade(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -50,7 +50,7 @@ func (a *WsClient) PubTrade(op string, params []map[string]string, timeOut ...in
} }
/* /*
预估交割/行权价格频道 预估交割/行权价格频道
*/ */
func (a *WsClient) PubEstDePrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubEstDePrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -59,7 +59,7 @@ func (a *WsClient) PubEstDePrice(op string, params []map[string]string, timeOut
} }
/* /*
标记价格频道 标记价格频道
*/ */
func (a *WsClient) PubMarkPrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubMarkPrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -67,7 +67,7 @@ func (a *WsClient) PubMarkPrice(op string, params []map[string]string, timeOut .
} }
/* /*
标记价格K线频道 标记价格K线频道
*/ */
func (a *WsClient) PubMarkPriceCandle(op string, pd Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubMarkPriceCandle(op string, pd Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -75,7 +75,7 @@ func (a *WsClient) PubMarkPriceCandle(op string, pd Period, params []map[string]
} }
/* /*
限价频道 限价频道
*/ */
func (a *WsClient) PubLimitPrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubLimitPrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -83,7 +83,7 @@ func (a *WsClient) PubLimitPrice(op string, params []map[string]string, timeOut
} }
/* /*
深度频道 深度频道
*/ */
func (a *WsClient) PubOrderBooks(op string, channel string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubOrderBooks(op string, channel string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -109,7 +109,7 @@ func (a *WsClient) PubOrderBooks(op string, channel string, params []map[string]
} }
/* /*
期权定价频道 期权定价频道
*/ */
func (a *WsClient) PubOptionSummary(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubOptionSummary(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -117,7 +117,7 @@ func (a *WsClient) PubOptionSummary(op string, params []map[string]string, timeO
} }
/* /*
资金费率频道 资金费率频道
*/ */
func (a *WsClient) PubFundRate(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubFundRate(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -125,7 +125,7 @@ func (a *WsClient) PubFundRate(op string, params []map[string]string, timeOut ..
} }
/* /*
指数K线频道 指数K线频道
*/ */
func (a *WsClient) PubKLineIndex(op string, pd Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubKLineIndex(op string, pd Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {
@ -133,7 +133,7 @@ func (a *WsClient) PubKLineIndex(op string, pd Period, params []map[string]strin
} }
/* /*
指数行情频道 指数行情频道
*/ */
func (a *WsClient) PubIndexTickers(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) { func (a *WsClient) PubIndexTickers(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error) {

View File

@ -3,11 +3,11 @@ package ws
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
. "github.com/phyer/v5sdkgo/ws/wImpl"
"log" "log"
"strings" "strings"
"testing" "testing"
"time" "time"
. "v5sdk_go/ws/wImpl"
) )
func prework() *WsClient { func prework() *WsClient {