-
Notifications
You must be signed in to change notification settings - Fork 102
/
trade.go
78 lines (72 loc) · 2.15 KB
/
trade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ws
import (
"github.com/amir-the-h/okex"
requests "github.com/amir-the-h/okex/requests/ws/trade"
)
// Trade
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade
type Trade struct {
*ClientWs
}
// NewTrade returns a pointer to a fresh Trade
func NewTrade(c *ClientWs) *Trade {
return &Trade{ClientWs: c}
}
// PlaceOrder
// You can place an order only if you have sufficient funds.
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade-place-order
//
// Place orders in a batch. Maximum 20 orders can be placed at a time
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade-place-multiple-orders
func (c *Trade) PlaceOrder(req ...requests.PlaceOrder) error {
tmpArgs := make([]map[string]string, len(req))
op := okex.OrderOperation
if len(req) > 1 {
op = okex.BatchOrderOperation
}
for i, order := range req {
tmpArgs[i] = okex.S2M(order)
}
return c.Send(true, op, tmpArgs, map[string]string{"id": req[0].ID})
}
// CancelOrder
// Cancel an incomplete order
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade-place-order
//
// Cancel incomplete orders in batches. Maximum 20 orders can be canceled at a time.
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade-cancel-multiple-orders
func (c *Trade) CancelOrder(req ...requests.CancelOrder) error {
tmpArgs := make([]map[string]string, len(req))
op := okex.CancelOrderOperation
if len(req) > 1 {
op = okex.BatchCancelOrderOperation
}
for i, order := range req {
tmpArgs[i] = okex.S2M(order)
}
return c.Send(true, op, tmpArgs, map[string]string{"id": req[0].ID})
}
// AmendOrder
// Amend an incomplete order.
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade-place-order
//
// Amend incomplete orders in batches. Maximum 20 orders can be amended at a time.
//
// https://www.okex.com/docs-v5/en/#websocket-api-trade-amend-multiple-orders
func (c *Trade) AmendOrder(req ...requests.AmendOrder) error {
tmpArgs := make([]map[string]string, len(req))
op := okex.AmendOrderOperation
if len(req) > 1 {
op = okex.BatchAmendOrderOperation
}
for i, order := range req {
tmpArgs[i] = okex.S2M(order)
}
return c.Send(true, op, tmpArgs, map[string]string{"id": req[0].ID})
}