/
prices.go
75 lines (64 loc) · 1.87 KB
/
prices.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
package conn
import (
"fmt"
"github.com/cryptomkt/cryptomkt-go/args"
)
// Prices structs and its methods for this sdk
type PricesResponse struct {
Status string
Message string
Pagination Pagination
Data DataPrices
}
type Prices struct {
args map[string]string
pagination Pagination
client *Client
Data DataPrices
}
type DataPrices struct {
Ask []Candle
Bid []Candle
}
type Candle struct {
CandleId int `json:"candle_id"`
OpenPrice string `json:"open_price"`
HightPrice string `json:"hight_price"`
ClosePrice string `json:"close_price"`
LowPrice string `json:"low_price"`
VolumeSum string `json:"volume_sum"`
CandleDate string `json:"candle_date"`
TickCount string `json:"tick_count"`
}
// GetPrevious lets you go to the previous page if it exists, returns (*Prices, nil) if
// it is successfull and (nil, error) otherwise
func (p *Prices) GetPrevious() (*Prices, error) {
if p.pagination.Previous == nil {
return nil, fmt.Errorf("Previous page does not exist")
}
return p.client.GetPrices(
args.Market(p.args["market"]),
args.Type(p.args["timeframe"]),
args.Page(int(p.pagination.Previous.(float64))),
args.Limit(p.pagination.Limit))
}
// GetNext lets you go to the next page if it exists, returns (*Prices, nil) if
// it is successfull and (nil, error) otherwise
func (p *Prices) GetNext() (*Prices, error) {
if p.pagination.Next == nil {
return nil, fmt.Errorf("Next page does not exist")
}
return p.client.GetPrices(
args.Market(p.args["market"]),
args.Type(p.args["timeframe"]),
args.Page(int(p.pagination.Next.(float64))),
args.Limit(p.pagination.Limit))
}
// GetPage returns the page you have
func (p *Prices) GetPage() int {
return p.pagination.Page
}
// GetLimit returns the limit you have provided, but if you have not, it provides the default
func (p *Prices) GetLimit() int {
return p.pagination.Limit
}