-
Notifications
You must be signed in to change notification settings - Fork 76
/
symbol.go
265 lines (233 loc) · 10.4 KB
/
symbol.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package kucoin
import (
"context"
"fmt"
"net/http"
)
// A SymbolModel represents an available currency pairs for trading.
type SymbolModel struct {
Symbol string `json:"symbol"`
Name string `json:"name"`
BaseCurrency string `json:"baseCurrency"`
QuoteCurrency string `json:"quoteCurrency"`
Market string `json:"market"`
BaseMinSize string `json:"baseMinSize"`
QuoteMinSize string `json:"quoteMinSize"`
BaseMaxSize string `json:"baseMaxSize"`
QuoteMaxSize string `json:"quoteMaxSize"`
BaseIncrement string `json:"baseIncrement"`
QuoteIncrement string `json:"quoteIncrement"`
PriceIncrement string `json:"priceIncrement"`
FeeCurrency string `json:"feeCurrency"`
EnableTrading bool `json:"enableTrading"`
IsMarginEnabled bool `json:"isMarginEnabled"`
PriceLimitRate string `json:"priceLimitRate"`
}
// A SymbolsModel is the set of *SymbolModel.
type SymbolsModel []*SymbolModel
// Symbols returns a list of available currency pairs for trading.
// Deprecated
func (as *ApiService) Symbols(ctx context.Context, market string) (*ApiResponse, error) {
p := map[string]string{}
if market != "" {
p["market"] = market
}
req := NewRequest(http.MethodGet, "/api/v1/symbols", p)
return as.Call(ctx, req)
}
// A TickerLevel1Model represents ticker include only the inside (i.e. best) bid and ask data, last price and last trade size.
type TickerLevel1Model struct {
Sequence string `json:"sequence"`
Price string `json:"price"`
Size string `json:"size"`
BestBid string `json:"bestBid"`
BestBidSize string `json:"bestBidSize"`
BestAsk string `json:"bestAsk"`
BestAskSize string `json:"bestAskSize"`
Time int64 `json:"time"`
}
// TickerLevel1 returns the ticker include only the inside (i.e. best) bid and ask data, last price and last trade size.
func (as *ApiService) TickerLevel1(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/orderbook/level1", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// A TickerModel represents a market ticker for all trading pairs in the market (including 24h volume).
type TickerModel struct {
Symbol string `json:"symbol"`
SymbolName string `json:"symbolName"`
Buy string `json:"buy"`
Sell string `json:"sell"`
ChangeRate string `json:"changeRate"`
ChangePrice string `json:"changePrice"`
High string `json:"high"`
Low string `json:"low"`
Vol string `json:"vol"`
VolValue string `json:"volValue"`
Last string `json:"last"`
AveragePrice string `json:"averagePrice"`
TakerFeeRate string `json:"takerFeeRate"`
MakerFeeRate string `json:"makerFeeRate"`
TakerCoefficient string `json:"takerCoefficient"`
MakerCoefficient string `json:"makerCoefficient"`
}
// A TickersModel is the set of *MarketTickerModel.
type TickersModel []*TickerModel
// TickersResponseModel represents the response model of MarketTickers().
type TickersResponseModel struct {
Time int64 `json:"time"`
Tickers TickersModel `json:"ticker"`
}
// Tickers returns all tickers as TickersResponseModel for all trading pairs in the market (including 24h volume).
func (as *ApiService) Tickers(ctx context.Context) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/allTickers", nil)
return as.Call(ctx, req)
}
// A Stats24hrModel represents 24 hr stats for the symbol.
// Volume is in base currency units.
// Open, high, low are in quote currency units.
type Stats24hrModel struct {
Time int64 `json:"time"`
Symbol string `json:"symbol"`
Buy string `json:"buy"`
Sell string `json:"sell"`
ChangeRate string `json:"changeRate"`
ChangePrice string `json:"changePrice"`
High string `json:"high"`
Low string `json:"low"`
Vol string `json:"vol"`
VolValue string `json:"volValue"`
Last string `json:"last"`
AveragePrice string `json:"averagePrice"`
TakerFeeRate string `json:"takerFeeRate"`
MakerFeeRate string `json:"makerFeeRate"`
TakerCoefficient string `json:"takerCoefficient"`
MakerCoefficient string `json:"makerCoefficient"`
}
// Stats24hr returns 24 hr stats for the symbol. volume is in base currency units. open, high, low are in quote currency units.
func (as *ApiService) Stats24hr(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/stats", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// MarketsModel returns Model of Markets API.
type MarketsModel []string
// Markets returns the transaction currencies for the entire trading market.
func (as *ApiService) Markets(ctx context.Context) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/markets", nil)
return as.Call(ctx, req)
}
// A PartOrderBookModel represents a list of open orders for a symbol, a part of Order Book within 100 depth for each side(ask or bid).
type PartOrderBookModel struct {
Sequence string `json:"sequence"`
Time int64 `json:"time"`
Bids [][]string `json:"bids"`
Asks [][]string `json:"asks"`
}
// AggregatedPartOrderBook returns a list of open orders(aggregated) for a symbol.
func (as *ApiService) AggregatedPartOrderBook(ctx context.Context, symbol string, depth int64) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/orderbook/level2_"+IntToString(depth), map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// A FullOrderBookModel represents a list of open orders for a symbol, with full depth.
type FullOrderBookModel struct {
Sequence string `json:"sequence"`
Time int64 `json:"time"`
Bids [][]string `json:"bids"`
Asks [][]string `json:"asks"`
}
// AggregatedFullOrderBook returns a list of open orders(aggregated) for a symbol.
// Deprecated: Use AggregatedFullOrderBookV3/WebSocket instead.
func (as *ApiService) AggregatedFullOrderBook(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v2/market/orderbook/level2", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// AggregatedFullOrderBookV3 returns a list of open orders(aggregated) for a symbol.
func (as *ApiService) AggregatedFullOrderBookV3(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v3/market/orderbook/level2", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// A FullOrderBookV2Model represents a list of open orders for a symbol, with full depth.
type FullOrderBookV2Model struct {
Sequence int64 `json:"sequence"`
Time int64 `json:"time"`
Bids [][]interface{} `json:"bids"`
Asks [][]interface{} `json:"asks"`
}
// AtomicFullOrderBook returns a list of open orders for a symbol.
// Level-3 order book includes all bids and asks (non-aggregated, each item in Level-3 means a single order).
func (as *ApiService) AtomicFullOrderBook(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/orderbook/level3", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// AtomicFullOrderBookV2 returns a list of open orders for a symbol.
// Level-3 order book includes all bids and asks (non-aggregated, each item in Level-3 means a single order).
func (as *ApiService) AtomicFullOrderBookV2(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v2/market/orderbook/level3", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// A TradeHistoryModel represents the latest trades for a symbol.
type TradeHistoryModel struct {
Sequence string `json:"sequence"`
Price string `json:"price"`
Size string `json:"size"`
Side string `json:"side"`
Time int64 `json:"time"`
}
// A TradeHistoriesModel is the set of *TradeHistoryModel.
type TradeHistoriesModel []*TradeHistoryModel
// TradeHistories returns a list the latest trades for a symbol.
func (as *ApiService) TradeHistories(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/histories", map[string]string{"symbol": symbol})
return as.Call(ctx, req)
}
// KLineModel represents the k lines for a symbol.
// Rates are returned in grouped buckets based on requested type.
type KLineModel []string
// A KLinesModel is the set of *KLineModel.
type KLinesModel []*KLineModel
// KLines returns the k lines for a symbol.
// Data are returned in grouped buckets based on requested type.
// Parameter #2 typo is the type of candlestick patterns.
func (as *ApiService) KLines(ctx context.Context, symbol, typo string, startAt, endAt int64) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/market/candles", map[string]string{
"symbol": symbol,
"type": typo,
"startAt": IntToString(startAt),
"endAt": IntToString(endAt),
})
return as.Call(ctx, req)
}
// SymbolsV2 returns a list of available currency pairs for trading.
func (as *ApiService) SymbolsV2(ctx context.Context, market string) (*ApiResponse, error) {
p := map[string]string{}
if market != "" {
p["market"] = market
}
req := NewRequest(http.MethodGet, "/api/v2/symbols", p)
return as.Call(ctx, req)
}
// SymbolsDetail Request via this endpoint to get detail currency pairs for trading
func (as *ApiService) SymbolsDetail(ctx context.Context, symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, fmt.Sprintf("/api/v2/symbols/%s", symbol), nil)
return as.Call(ctx, req)
}
// A SymbolsModelV2 is the set of *SymbolsModelV2.
type SymbolsModelV2 []*SymbolModelV2
type SymbolModelV2 struct {
Symbol string `json:"symbol"`
Name string `json:"name"`
BaseCurrency string `json:"baseCurrency"`
QuoteCurrency string `json:"quoteCurrency"`
Market string `json:"market"`
BaseMinSize string `json:"baseMinSize"`
QuoteMinSize string `json:"quoteMinSize"`
BaseMaxSize string `json:"baseMaxSize"`
QuoteMaxSize string `json:"quoteMaxSize"`
BaseIncrement string `json:"baseIncrement"`
QuoteIncrement string `json:"quoteIncrement"`
PriceIncrement string `json:"priceIncrement"`
FeeCurrency string `json:"feeCurrency"`
EnableTrading bool `json:"enableTrading"`
IsMarginEnabled bool `json:"isMarginEnabled"`
PriceLimitRate string `json:"priceLimitRate"`
MinFunds string `json:"minFunds"`
}