-
Notifications
You must be signed in to change notification settings - Fork 0
/
trades.go
50 lines (42 loc) · 1 KB
/
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
package binance
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"time"
"github.com/jaztec/go-binance/model"
)
const (
myTradesPath = "/api/v3/myTrades"
)
func init() {
requireSignature(myTradesPath)
}
// MyTrades returns trades performed by a user in a time window
func (a *api) MyTrades(symbol string, startTime, endTime int64, limit int) (t []model.UserTrade, err error) {
if symbol == "" {
return t, NoSymbolProvided
}
q := NewParameters(5)
q.Set("symbol", symbol)
if startTime != 0 {
q.Set("startTime", strconv.FormatInt(startTime, 10))
}
if endTime != 0 {
q.Set("endTime", strconv.FormatInt(endTime, 10))
}
if limit != 0 {
q.Set("limit", strconv.Itoa(limit))
}
q.Set("timestamp", strconv.FormatInt(time.Now().Unix()*1000, 10))
body, err := a.Request(http.MethodGet, myTradesPath, q)
if err != nil {
return t, err
}
err = json.Unmarshal(body, &t)
if err != nil {
return t, fmt.Errorf("encountered error while unmarshaling '%s' into model.Trade", body)
}
return t, nil
}