1 Star 0 Fork 0

hacker61/okex_v5sdk_go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ws_jrpc.go 3.23 KB
一键复制 编辑 原始数据 按行查看 历史
farawaylu 提交于 4年前 . 名称空间修改
package ws
import (
"context"
"log"
"time"
. "gitee.com/hacker61/okex_v5sdk_go/ws/wImpl"
)
/*
websocket交易 通用请求
参数说明:
evtId:封装的事件类型
id: 请求ID
op: 请求参数op
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) jrpcReq(evtId Event, op string, id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
res = true
tm := 5000
if len(timeOut) != 0 {
tm = timeOut[0]
}
req := &JRPCReq{
Id: id,
Op: op,
Args: params,
}
detail = &ProcessDetail{
EndPoint: a.WsEndPoint,
}
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, time.Duration(tm)*time.Millisecond)
defer cancel()
ctx = context.WithValue(ctx, "detail", detail)
msg, err := a.process(ctx, evtId, req)
if err != nil {
res = false
log.Println("处理请求失败!", req, err)
return
}
detail.Data = msg
res, err = checkResult(req, msg)
if err != nil {
res = false
return
}
return
}
/*
单个下单
参数说明:
id: 请求ID
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) PlaceOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "order"
evtId := EVENT_PLACE_ORDER
var args []map[string]interface{}
args = append(args, param)
return a.jrpcReq(evtId, op, id, args, timeOut...)
}
/*
批量下单
参数说明:
id: 请求ID
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) BatchPlaceOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "batch-orders"
evtId := EVENT_PLACE_BATCH_ORDERS
return a.jrpcReq(evtId, op, id, params, timeOut...)
}
/*
单个撤单
参数说明:
id: 请求ID
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) CancelOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "cancel-order"
evtId := EVENT_CANCEL_ORDER
var args []map[string]interface{}
args = append(args, param)
return a.jrpcReq(evtId, op, id, args, timeOut...)
}
/*
批量撤单
参数说明:
id: 请求ID
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) BatchCancelOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "batch-cancel-orders"
evtId := EVENT_CANCEL_BATCH_ORDERS
return a.jrpcReq(evtId, op, id, params, timeOut...)
}
/*
单个改单
参数说明:
id: 请求ID
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) AmendOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "amend-order"
evtId := EVENT_AMEND_ORDER
var args []map[string]interface{}
args = append(args, param)
return a.jrpcReq(evtId, op, id, args, timeOut...)
}
/*
批量改单
参数说明:
id: 请求ID
params: 请求参数
timeOut: 超时时间
*/
func (a *WsClient) BatchAmendOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error) {
op := "batch-amend-orders"
evtId := EVENT_AMEND_BATCH_ORDERS
return a.jrpcReq(evtId, op, id, params, timeOut...)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hacker61/okex_v5sdk_go.git
git@gitee.com:hacker61/okex_v5sdk_go.git
hacker61
okex_v5sdk_go
okex_v5sdk_go
v1.0.3

搜索帮助