/
trades.go
82 lines (72 loc) · 2.24 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
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
79
80
81
82
package conn
import (
"fmt"
"github.com/cryptomkt/cryptomkt-go/args"
)
// Trades structs and methods needed for this sdk
type TradesResponse struct {
Status string
Message string
Pagination Pagination
Data []TradeData
}
type Trades struct {
args map[string]string
pagination Pagination
client *Client
Data []TradeData
}
type TradeData struct {
MarketTaker string `json:"market_taker"`
Price string
Amount string
Tid string
Timestamp string
Market string
}
// GetPrevious lets you go to the previous page if it exists, returns (*Trades, nil) if
// it is successfull and (nil, error) otherwise
func (t *Trades) GetPrevious() (*Trades, error) {
if t.pagination.Previous == nil {
return nil, fmt.Errorf("Previous page does not exist")
}
var newArgs []args.Argument = make([]args.Argument, 0, 5)
// there is always a market and a pagination
newArgs = append(newArgs, args.Market(t.args["market"]))
newArgs = append(newArgs, args.Page(int(t.pagination.Previous.(float64))))
newArgs = append(newArgs, args.Limit(t.pagination.Limit))
if v, ok := t.args["start"]; ok {
newArgs = append(newArgs, args.Start(v))
}
if v, ok := t.args["end"]; ok {
newArgs = append(newArgs, args.Start(v))
}
return t.client.GetTrades(newArgs...)
}
// GetNext lets you go to the next page if it exists, returns (*Trades, nil) if
// it is successfull and (nil, error) otherwise
func (t *Trades) GetNext() (*Trades, error) {
if t.pagination.Next == nil {
return nil, fmt.Errorf("Next page does not exist")
}
var newArgs []args.Argument = make([]args.Argument, 0, 5)
// there is always a market and a pagination
newArgs = append(newArgs, args.Market(t.args["market"]))
newArgs = append(newArgs, args.Page(int(t.pagination.Next.(float64))))
newArgs = append(newArgs, args.Limit(t.pagination.Limit))
if v, ok := t.args["start"]; ok {
newArgs = append(newArgs, args.Start(v))
}
if v, ok := t.args["end"]; ok {
newArgs = append(newArgs, args.End(v))
}
return t.client.GetTrades(newArgs...)
}
// GetPage returns the actual page of the request.
func (t *Trades) GetPage() int {
return t.pagination.Page
}
// GetLimit returns the number of trades per page.
func (t *Trades) GetLimit() int {
return t.pagination.Limit
}