-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy_trades.go
65 lines (54 loc) · 1.62 KB
/
my_trades.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
package binance
import "encoding/json"
type AccountTrade struct {
Id int64 `json:"id"`
OrderId int64 `json:"orderId"`
Price float64 `json:"price,string"`
Quantity float64 `json:"qty,string"`
Commission float64 `json:"commission,string"`
CommissionAsset string `json:"commissionAsset"`
Time int64 `json:"time"`
IsBuyer bool `json:"isBuyer"`
IsMaker bool `json:"isMaker"`
IsBestMatch bool `json:"isBestMatch"`
}
type myTradesQuery struct {
symbol *string
limit *int64
fromId *int64
recvWindow *int64
}
func (r *myTradesQuery) Limit(value int64) *myTradesQuery {
r.limit = &value
return r
}
func (r *myTradesQuery) FromId(value int64) *myTradesQuery {
r.fromId = &value
return r
}
func (r *myTradesQuery) RecvWindow(value int64) *myTradesQuery {
r.recvWindow = &value
return r
}
func NewMyTradesQuery(symbol string) *myTradesQuery {
return &myTradesQuery{symbol: &symbol}
}
func (sdk Sdk) MyTrades(query *myTradesQuery) ([]AccountTrade, error) {
req := newRequest("GET", "/api/v3/myTrades").
StringParam("symbol", query.symbol).
Int64Param("recvWindow", query.recvWindow).
Int64Param("limit", query.limit).
Int64Param("fromId", query.fromId).
Int64Param("timestamp", sdk.clock.Now()).
Sign()
responseContent, err := sdk.client.Do(req)
if err != nil {
return nil, err
}
return parseAccountTradesResponse(responseContent)
}
func parseAccountTradesResponse(jsonContent []byte) ([]AccountTrade, error) {
response := make([]AccountTrade, 0)
err := json.Unmarshal(jsonContent, &response)
return response, err
}