-
Notifications
You must be signed in to change notification settings - Fork 1
/
public.go
206 lines (147 loc) · 3.98 KB
/
public.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package gemini
import (
"encoding/json"
"fmt"
"github.com/claudiocandio/gemini-api/logger"
)
// Symbols
func (api *Api) Symbols() ([]string, error) {
url := api.url + symbols_URI
logger.Debug("func Symbols", fmt.Sprintf("url:%s", url))
var symbols []string
body, err := api.request("GET", url, nil)
if err != nil {
return nil, err
}
if err := json.Unmarshal(body, &symbols); err != nil {
return nil, err
}
logger.Debug("func Symbols: unmarshal",
fmt.Sprintf("symbols:%v", symbols),
)
return symbols, nil
}
// TickerV1
func (api *Api) TickerV1(symbol string) (TickerV1, error) {
url := api.url + ticker_v1_URI + symbol
logger.Debug("func TickerV1", fmt.Sprintf("url:%s", url))
var tickerV1 TickerV1
body, err := api.request("GET", url, nil)
if err != nil {
return tickerV1, err
}
if err := json.Unmarshal(body, &tickerV1); err != nil {
return tickerV1, err
}
logger.Debug("func TickerV1: unmarshal",
fmt.Sprintf("tickerV1:%v", tickerV1),
)
return tickerV1, nil
}
// TickerV2
func (api *Api) TickerV2(symbol string) (TickerV2, error) {
url := api.url + ticker_v2_URI + symbol
logger.Debug("func TickerV2", fmt.Sprintf("url:%s", url))
var tickerV2 TickerV2
body, err := api.request("GET", url, nil)
if err != nil {
return tickerV2, err
}
if err := json.Unmarshal(body, &tickerV2); err != nil {
return tickerV2, err
}
logger.Debug("func TickerV2: unmarshal",
fmt.Sprintf("tickerV2:%v", tickerV2),
)
return tickerV2, nil
}
// Order Book
func (api *Api) OrderBook(symbol string, args Args) (Book, error) {
url := api.url + book_URI + symbol
logger.Debug("func OrderBook", fmt.Sprintf("url:%s", url))
var book Book
body, err := api.request("GET", url, args)
if err != nil {
return book, err
}
if err := json.Unmarshal(body, &book); err != nil {
return book, err
}
logger.Debug("func OrderBook: unmarshal",
fmt.Sprintf("book:%v", book),
)
return book, nil
}
// Trades
func (api *Api) Trades(symbol string, args Args) ([]Trade, error) {
url := api.url + trades_URI + symbol
logger.Debug("func Trades",
fmt.Sprintf("url:%v", url),
fmt.Sprintf("args:%v", args),
)
var trade []Trade
body, err := api.request("GET", url, args)
if err != nil {
return nil, err
}
if err := json.Unmarshal(body, &trade); err != nil {
return nil, err
}
// adding TimestampmsT
for i, r := range trade {
trade[i].TimestampmsT = msToTime(r.Timestampms)
}
logger.Debug("func Trades: unmarshal",
fmt.Sprintf("trade:%v", trade),
)
return trade, nil
}
// Current Auction
func (api *Api) CurrentAuction(symbol string) (CurrentAuction, error) {
url := api.url + auction_URI + symbol
logger.Debug("func CurrentAuction", fmt.Sprintf("url:%s", url))
var currentAuction CurrentAuction
body, err := api.request("GET", url, nil)
if err != nil {
return currentAuction, err
}
if err := json.Unmarshal(body, ¤tAuction); err != nil {
return currentAuction, err
}
// adding TimestampmsT
if currentAuction.NextAuction > 0 {
currentAuction.NextAuctionT = msToTime(currentAuction.NextAuction)
}
if currentAuction.NextUpdate > 0 {
currentAuction.NextUpdateT = msToTime(currentAuction.NextUpdate)
}
logger.Debug("func CurrentAuction: unmarshal",
fmt.Sprintf("currentAuction:%v", currentAuction),
)
return currentAuction, nil
}
// Auction History
// Args{"since": 50, "limit": 0, "includeIndicative": true}
func (api *Api) AuctionHistory(symbol string, args Args) ([]Auction, error) {
url := api.url + auction_URI + symbol + "/history"
logger.Debug("func AuctionHistory",
fmt.Sprintf("url:%v", url),
fmt.Sprintf("args:%v", args),
)
var auction []Auction
body, err := api.request("GET", url, args)
if err != nil {
return nil, err
}
if err := json.Unmarshal(body, &auction); err != nil {
return nil, err
}
// adding TimestampmsT
for i, au := range auction {
auction[i].TimestampmsT = msToTime(au.Timestampms)
}
logger.Debug("func AuctionHistory: unmarshal",
fmt.Sprintf("auction:%v", auction),
)
return auction, nil
}