forked from aopoltorzhicky/go_kraken
-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.go
128 lines (119 loc) · 3.54 KB
/
methods.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package rest
import (
"fmt"
"net/url"
"strconv"
"strings"
)
// Time - Gets server time. Note: This is to aid in approximating the skew time between the server and client.
func (api *Kraken) Time() (TimeResponse, error) {
response := TimeResponse{}
if err := api.request("Time", false, nil, &response); err != nil {
return response, err
}
return response, nil
}
// Assets - Gets info about assets passed through `assets` arg.
// `assets` - array of needed assets. All by default if empty array passed or `assets` is nil.
func (api *Kraken) Assets(assets ...string) (map[string]Asset, error) {
data := url.Values{}
if len(assets) > 0 {
data.Add("asset", strings.Join(assets, ","))
} else {
data = nil
}
response := make(map[string]Asset)
if err := api.request("Assets", false, data, &response); err != nil {
return response, err
}
return response, nil
}
// AssetPairs - Gets array of pair names and their info passed through `pairs` arg.
// `pairs` - array of needed pairs. All by default if empty array passed or `pairs` is nil.
func (api *Kraken) AssetPairs(pairs ...string) (map[string]AssetPair, error) {
data := url.Values{}
if len(pairs) > 0 {
data.Add("pair", strings.Join(pairs, ","))
} else {
data = nil
}
response := make(map[string]AssetPair)
if err := api.request("AssetPairs", false, data, &response); err != nil {
return nil, err
}
return response, nil
}
// Ticker - Gets array of tickers passed through `pairs` arg.
// `pairs` - array of needed pairs. All by default if empty array passed or `pairs` is nil.
func (api *Kraken) Ticker(pairs ...string) (map[string]Ticker, error) {
var data url.Values
if len(pairs) > 0 {
data = url.Values{
"pair": {strings.Join(pairs, ",")},
}
} else {
return nil, fmt.Errorf("You need to set pairs on Ticker request")
}
response := make(map[string]Ticker)
if err := api.request("Ticker", false, data, &response); err != nil {
return nil, err
}
return response, nil
}
// Candles - Get OHLC data
func (api *Kraken) Candles(pair string, interval int64, since int64) (OHLCResponse, error) {
data := url.Values{
"pair": {pair},
}
if since > 0 {
data.Set("since", strconv.FormatInt(since, 10))
}
if interval > 1 {
data.Set("interval", strconv.FormatInt(interval, 10))
}
response := OHLCResponse{}
if err := api.request("OHLC", false, data, &response); err != nil {
return response, err
}
return response, nil
}
// GetOrderBook - Gets order book for `pair` with `depth`
func (api *Kraken) GetOrderBook(pair string, depth int64) (map[string]OrderBook, error) {
data := url.Values{
"pair": {pair},
"count": {strconv.FormatInt(depth, 10)},
}
response := make(map[string]OrderBook)
if err := api.request("Depth", false, data, &response); err != nil {
return nil, err
}
return response, nil
}
// GetTrades - returns trades on pair from since date
func (api *Kraken) GetTrades(pair string, since int64) (TradeResponse, error) {
data := url.Values{
"pair": {pair},
}
if since > 0 {
data.Add("since", strconv.FormatInt(since, 10))
}
response := TradeResponse{}
if err := api.request("Trades", false, data, &response); err != nil {
return response, err
}
return response, nil
}
// GetSpread - return array of pair name and recent spread data
func (api *Kraken) GetSpread(pair string, since int64) (SpreadResponse, error) {
data := url.Values{
"pair": {pair},
}
if since > 0 {
data.Add("since", strconv.FormatInt(since, 10))
}
response := SpreadResponse{}
if err := api.request("Spread", false, data, &response); err != nil {
return response, err
}
return response, nil
}