forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange_info_service.go
269 lines (246 loc) · 7.54 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
package binance
import (
"context"
"net/http"
"strings"
)
// ExchangeInfoService exchange info service
type ExchangeInfoService struct {
c *Client
symbol string
symbols 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 {
if len(symbols) == 0 {
s.symbols = "[]"
} else {
s.symbols = "[\"" + strings.Join(symbols, "\",\"") + "\"]"
}
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
}
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"`
}
// PercentPriceFilter define percent price filter of symbol
type PercentPriceFilter struct {
AveragePriceMins int `json:"avgPriceMins"`
MultiplierUp string `json:"multiplierUp"`
MultiplierDown string `json:"multiplierDown"`
}
// MinNotionalFilter define min notional filter of symbol
type MinNotionalFilter struct {
MinNotional string `json:"minNotional"`
AveragePriceMins int `json:"avgPriceMins"`
ApplyToMarket bool `json:"applyToMarket"`
}
// 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"`
}
// 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
}
// PercentPriceFilter return percent price filter of symbol
func (s *Symbol) PercentPriceFilter() *PercentPriceFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypePercentPrice) {
f := &PercentPriceFilter{}
if i, ok := filter["avgPriceMins"]; ok {
f.AveragePriceMins = int(i.(float64))
}
if i, ok := filter["multiplierUp"]; ok {
f.MultiplierUp = i.(string)
}
if i, ok := filter["multiplierDown"]; ok {
f.MultiplierDown = i.(string)
}
return f
}
}
return nil
}
// MinNotionalFilter return min notional filter of symbol
func (s *Symbol) MinNotionalFilter() *MinNotionalFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeMinNotional) {
f := &MinNotionalFilter{}
if i, ok := filter["minNotional"]; ok {
f.MinNotional = i.(string)
}
if i, ok := filter["avgPriceMins"]; ok {
f.AveragePriceMins = int(i.(float64))
}
if i, ok := filter["applyToMarket"]; ok {
f.ApplyToMarket = i.(bool)
}
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 {
f.Limit = int(i.(float64))
}
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
}
// 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 {
f.MaxNumAlgoOrders = int(i.(float64))
}
return f
}
}
return nil
}