forked from adshao/go-binance
/
exchange_info_service.go
365 lines (334 loc) · 10.6 KB
/
exchange_info_service.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package binance
import (
"context"
"net/http"
"github.com/RandomEstimate/go-binance/v2/common"
)
// ExchangeInfoService exchange info service
type ExchangeInfoService struct {
c *Client
symbol string
symbols []string
permissions []string
}
// Symbol set symbol
func (s *ExchangeInfoService) Symbol(symbol string) *ExchangeInfoService {
s.symbol = symbol
return s
}
// Symbols set symbol
func (s *ExchangeInfoService) Symbols(symbols ...string) *ExchangeInfoService {
s.symbols = symbols
return s
}
// Permissions set permission
func (s *ExchangeInfoService) Permissions(permissions ...string) *ExchangeInfoService {
s.permissions = permissions
return s
}
// Do send request
func (s *ExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (res *ExchangeInfo, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/exchangeInfo",
secType: secTypeNone,
}
m := params{}
if s.symbol != "" {
m["symbol"] = s.symbol
}
if len(s.symbols) != 0 {
m["symbols"] = s.symbols
}
if len(s.permissions) != 0 {
m["permissions"] = s.permissions
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ExchangeInfo)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// ExchangeInfo exchange info
type ExchangeInfo struct {
Timezone string `json:"timezone"`
ServerTime int64 `json:"serverTime"`
RateLimits []RateLimit `json:"rateLimits"`
ExchangeFilters []interface{} `json:"exchangeFilters"`
Symbols []Symbol `json:"symbols"`
}
// RateLimit struct
type RateLimit struct {
RateLimitType string `json:"rateLimitType"`
Interval string `json:"interval"`
IntervalNum int64 `json:"intervalNum"`
Limit int64 `json:"limit"`
}
// Symbol market symbol
type Symbol struct {
Symbol string `json:"symbol"`
Status string `json:"status"`
BaseAsset string `json:"baseAsset"`
BaseAssetPrecision int `json:"baseAssetPrecision"`
QuoteAsset string `json:"quoteAsset"`
QuotePrecision int `json:"quotePrecision"`
QuoteAssetPrecision int `json:"quoteAssetPrecision"`
BaseCommissionPrecision int32 `json:"baseCommissionPrecision"`
QuoteCommissionPrecision int32 `json:"quoteCommissionPrecision"`
OrderTypes []string `json:"orderTypes"`
IcebergAllowed bool `json:"icebergAllowed"`
OcoAllowed bool `json:"ocoAllowed"`
QuoteOrderQtyMarketAllowed bool `json:"quoteOrderQtyMarketAllowed"`
IsSpotTradingAllowed bool `json:"isSpotTradingAllowed"`
IsMarginTradingAllowed bool `json:"isMarginTradingAllowed"`
Filters []map[string]interface{} `json:"filters"`
Permissions []string `json:"permissions"`
}
// LotSizeFilter define lot size filter of symbol
type LotSizeFilter struct {
MaxQuantity string `json:"maxQty"`
MinQuantity string `json:"minQty"`
StepSize string `json:"stepSize"`
}
// PriceFilter define price filter of symbol
type PriceFilter struct {
MaxPrice string `json:"maxPrice"`
MinPrice string `json:"minPrice"`
TickSize string `json:"tickSize"`
}
// PERCENT_PRICE_BY_SIDE define percent price filter of symbol by side
type PercentPriceBySideFilter struct {
AveragePriceMins int `json:"avgPriceMins"`
BidMultiplierUp string `json:"bidMultiplierUp"`
BidMultiplierDown string `json:"bidMultiplierDown"`
AskMultiplierUp string `json:"askMultiplierUp"`
AskMultiplierDown string `json:"askMultiplierDown"`
}
// NotionalFilter define notional filter of symbol
type NotionalFilter struct {
MinNotional string `json:"minNotional"`
ApplyMinToMarket bool `json:"applyMinToMarket"`
MaxNotional string `json:"maxNotional"`
ApplyMaxToMarket bool `json:"applyMaxToMarket"`
AvgPriceMins int `json:"avgPriceMins"`
}
// IcebergPartsFilter define iceberg part filter of symbol
type IcebergPartsFilter struct {
Limit int `json:"limit"`
}
// MarketLotSizeFilter define market lot size filter of symbol
type MarketLotSizeFilter struct {
MaxQuantity string `json:"maxQty"`
MinQuantity string `json:"minQty"`
StepSize string `json:"stepSize"`
}
// Spot trading supports tracking stop orders
// Tracking stop loss sets an automatic trigger price based on market price using a new parameter trailingDelta
type TrailingDeltaFilter struct {
MinTrailingAboveDelta int `json:"minTrailingAboveDelta"`
MaxTrailingAboveDelta int `json:"maxTrailingAboveDelta"`
MinTrailingBelowDelta int `json:"minTrailingBelowDelta"`
MaxTrailingBelowDelta int `json:"maxTrailingBelowDelta"`
}
// The "Algo" order is STOP_ LOSS, STOP_ LOS_ LIMITED, TAKE_ PROFIT and TAKE_ PROFIT_ Limit Stop Loss Order.
// Therefore, orders other than the above types are non conditional(Algo) orders, and MaxNumOrders defines the maximum
// number of orders placed for these types of orders
type MaxNumOrdersFilter struct {
MaxNumOrders int `json:"maxNumOrders"`
}
// MaxNumAlgoOrdersFilter define max num algo orders filter of symbol
type MaxNumAlgoOrdersFilter struct {
MaxNumAlgoOrders int `json:"maxNumAlgoOrders"`
}
// LotSizeFilter return lot size filter of symbol
func (s *Symbol) LotSizeFilter() *LotSizeFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeLotSize) {
f := &LotSizeFilter{}
if i, ok := filter["maxQty"]; ok {
f.MaxQuantity = i.(string)
}
if i, ok := filter["minQty"]; ok {
f.MinQuantity = i.(string)
}
if i, ok := filter["stepSize"]; ok {
f.StepSize = i.(string)
}
return f
}
}
return nil
}
// PriceFilter return price filter of symbol
func (s *Symbol) PriceFilter() *PriceFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypePriceFilter) {
f := &PriceFilter{}
if i, ok := filter["maxPrice"]; ok {
f.MaxPrice = i.(string)
}
if i, ok := filter["minPrice"]; ok {
f.MinPrice = i.(string)
}
if i, ok := filter["tickSize"]; ok {
f.TickSize = i.(string)
}
return f
}
}
return nil
}
// PercentPriceBySideFilter return percent price filter of symbol
func (s *Symbol) PercentPriceBySideFilter() *PercentPriceBySideFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypePercentPriceBySide) {
f := &PercentPriceBySideFilter{}
if i, ok := filter["avgPriceMins"]; ok {
if apm, okk := common.ToInt(i); okk == nil {
f.AveragePriceMins = apm
}
}
if i, ok := filter["bidMultiplierUp"]; ok {
f.BidMultiplierUp = i.(string)
}
if i, ok := filter["bidMultiplierDown"]; ok {
f.BidMultiplierDown = i.(string)
}
if i, ok := filter["askMultiplierUp"]; ok {
f.AskMultiplierUp = i.(string)
}
if i, ok := filter["askMultiplierDown"]; ok {
f.AskMultiplierDown = i.(string)
}
return f
}
}
return nil
}
// NotionalFilter return notional filter of symbol
func (s *Symbol) NotionalFilter() *NotionalFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeNotional) {
f := &NotionalFilter{}
if i, ok := filter["minNotional"]; ok {
f.MinNotional = i.(string)
}
if i, ok := filter["applyMinToMarket"]; ok {
f.ApplyMinToMarket = i.(bool)
}
if i, ok := filter["maxNotional"]; ok {
f.MaxNotional = i.(string)
}
if i, ok := filter["applyMaxToMarket"]; ok {
f.ApplyMaxToMarket = i.(bool)
}
if i, ok := filter["avgPriceMins"]; ok {
if apm, okk := common.ToInt(i); okk == nil {
f.AvgPriceMins = apm
}
}
return f
}
}
return nil
}
// IcebergPartsFilter return iceberg part filter of symbol
func (s *Symbol) IcebergPartsFilter() *IcebergPartsFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeIcebergParts) {
f := &IcebergPartsFilter{}
if i, ok := filter["limit"]; ok {
if limit, okk := common.ToInt(i); okk == nil {
f.Limit = limit
}
}
return f
}
}
return nil
}
// MarketLotSizeFilter return market lot size filter of symbol
func (s *Symbol) MarketLotSizeFilter() *MarketLotSizeFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeMarketLotSize) {
f := &MarketLotSizeFilter{}
if i, ok := filter["maxQty"]; ok {
f.MaxQuantity = i.(string)
}
if i, ok := filter["minQty"]; ok {
f.MinQuantity = i.(string)
}
if i, ok := filter["stepSize"]; ok {
f.StepSize = i.(string)
}
return f
}
}
return nil
}
//For specific meanings, please refer to the type definition MaxNumOrders
func (s *Symbol) MaxNumOrdersFilter() *MaxNumOrdersFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeMaxNumOrders) {
f := &MaxNumOrdersFilter{}
if i, ok := filter["maxNumOrders"]; ok {
if mno, okk := common.ToInt(i); okk == nil {
f.MaxNumOrders = mno
}
}
return f
}
}
return nil
}
// MaxNumAlgoOrdersFilter return max num algo orders filter of symbol
func (s *Symbol) MaxNumAlgoOrdersFilter() *MaxNumAlgoOrdersFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeMaxNumAlgoOrders) {
f := &MaxNumAlgoOrdersFilter{}
if i, ok := filter["maxNumAlgoOrders"]; ok {
if mnao, okk := common.ToInt(i); okk == nil {
f.MaxNumAlgoOrders = mnao
}
}
return f
}
}
return nil
}
// For specific meanings, please refer to the type definition TrailingDeltaFilter
func (s *Symbol) TrailingDeltaFilter() *TrailingDeltaFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeTrailingDelta) {
f := &TrailingDeltaFilter{}
if i, ok := filter["minTrailingAboveDelta"]; ok {
if mtad, okk := common.ToInt(i); okk == nil {
f.MinTrailingAboveDelta = mtad
}
}
if i, ok := filter["maxTrailingAboveDelta"]; ok {
if mtad, okk := common.ToInt(i); okk == nil {
f.MaxTrailingAboveDelta = mtad
}
}
if i, ok := filter["minTrailingBelowDelta"]; ok {
if mtbd, okk := common.ToInt(i); okk == nil {
f.MinTrailingBelowDelta = mtbd
}
}
if i, ok := filter["maxTrailingBelowDelta"]; ok {
if mtbd, okk := common.ToInt(i); okk == nil {
f.MaxTrailingBelowDelta = mtbd
}
}
return f
}
}
return nil
}