forked from bitfinexcom/bitfinex-api-go
/
trades.go
51 lines (42 loc) · 894 Bytes
/
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
package bitfinex
import (
"net/url"
"strconv"
"strings"
"time"
)
type TradesService struct {
client *Client
}
type Trade struct {
Price string
Amount string
Exchange string
Type string
Timestamp int64
TradeId int64 `json:"tid,int"`
}
func (el *Trade) Time() *time.Time {
t := time.Unix(el.Timestamp, 0)
return &t
}
func (s *TradesService) All(pair string, timestamp time.Time, limitTrades int) ([]Trade, error) {
pair = strings.ToUpper(pair)
params := url.Values{}
if !time.Time.IsZero(timestamp) {
params.Add("timestamp", strconv.FormatInt(timestamp.Unix(), 10))
}
if limitTrades != 0 {
params.Add("limit_trades", strconv.Itoa(limitTrades))
}
req, err := s.client.newRequest("GET", "trades/"+pair, params)
if err != nil {
return nil, err
}
var v []Trade
_, err = s.client.do(req, &v)
if err != nil {
return nil, err
}
return v, nil
}