forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchange_info_service.go
143 lines (130 loc) · 4.17 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
package eoptions
import (
"context"
"encoding/json"
"net/http"
)
// ExchangeInfoService exchange info service
type ExchangeInfoService struct {
c *Client
}
// Do send request
func (s *ExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (res *ExchangeInfo, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/eapi/v1/exchangeInfo",
secType: secTypeNone,
}
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"`
OptionContracts []OptionContract `json:"optionContracts"`
OptionAssets []OptionAsset `json:"optionAssets"`
OptionSymbols []OptionSymbol `json:"optionSymbols"`
RateLimits []RateLimit `json:"rateLimits"`
}
// RateLimit struct
type RateLimit struct {
RateLimitType string `json:"rateLimitType"`
Interval string `json:"interval"`
IntervalNum int64 `json:"intervalNum"`
Limit int64 `json:"limit"`
}
// Option Contract
type OptionContract struct {
Id int64 `json:"id"`
BaseAsset string `json:"baseAsset"`
QuoteAsset string `json:"quoteAsset"`
Underlying string `json:"underlying"`
SettleAsset string `json:"settleAsset"`
}
// Option Asset
type OptionAsset struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
// Option Symbol
type OptionSymbol struct {
ContractId int64 `json:"contractId"`
ExpiryDate int64 `json:"expiryDate"`
Filters []map[string]interface{} `json:"filters"`
Id int64 `json:"id"`
Symbol string `json:"symbol"`
Side string `json:"side"`
StrikePrice string `json:"strikePrice"`
Underlying string `json:"underlying"`
Unit int64 `json:"unit"`
MakerFeeRate string `json:"makerFeeRate"`
TakerFeeRate string `json:"takerFeeRate"`
MinQty string `json:"minQty"`
MaxQty string `json:"maxQty"`
InitialMargin string `json:"initialMargin"`
MaintenanceMargin string `json:"maintenanceMargin"`
MinInitialMargin string `json:"minInitialMargin"`
MinMaintenanceMargin string `json:"minMaintenanceMargin"`
PriceScale int `json:"priceScale"`
QuantityScale int `json:"quantityScale"`
QuoteAsset string `json:"quoteAsset"`
}
// 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"`
}
// LotSizeFilter return lot size filter of symbol
func (s *OptionSymbol) 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 *OptionSymbol) PriceFilter() *PriceFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypePrice) {
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
}