This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
market.go
228 lines (197 loc) · 7.56 KB
/
market.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
package kumex
import (
"net/http"
)
// 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 int `json:"sequence"`
Symbol string `json:"symbol"`
Side string `json:"side"`
Size int `json:"size"`
Price string `json:"price"`
BestBidSize int `json:"bestBidSize"`
BestBidPrice string `json:"bestBidPrice"`
BestAskSize int `json:"bestAskSize"`
BestAskPrice string `json:"bestAskPrice"`
TradeId string `json:"tradeId"`
Ts int64 `json:"ts"`
}
// Ticker Get Real-Time Ticker.
func (as *ApiService) Ticker(symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/ticker", map[string]string{"symbol": symbol})
return as.Call(req)
}
// Level2SnapshotModel represents level2 ticker.
type Level2SnapshotModel struct {
Symbol string `json:"symbol"`
Sequence int `json:"sequence"`
Asks [][]float32 `json:"asks"`
Bids [][]float32 `json:"bids"`
}
// Level2Snapshot Get Full Order Book - Level 2.
func (as *ApiService) Level2Snapshot(symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/level2/snapshot", map[string]string{"symbol": symbol})
return as.Call(req)
}
// Level2MessageQueryModel represents level2 ticker message.
type Level2MessageQueryModel struct {
Symbol string `json:"symbol"`
Sequence int `json:"sequence"`
Change string `json:"change"`
}
// Level2MessageQueryListModel the set of *Level2MessageQueryModel.
type Level2MessageQueryListModel []*Level2MessageQueryModel
// Level2MessageQuery Level 2 Pulling Messages.
func (as *ApiService) Level2MessageQuery(symbol string, start, end int64) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/level2/message/query", map[string]string{
"symbol": symbol,
"start": IntToString(start),
"end": IntToString(end),
})
return as.Call(req)
}
// Level3SnapshotModel represents level3 ticker message.
type Level3SnapshotModel struct {
Symbol string `json:"symbol"`
Sequence int `json:"sequence"`
Asks [][]interface{} `json:"asks"`
Bids [][]interface{} `json:"bids"`
}
// Level3Snapshot Get Full Order Book - Level 3.
func (as *ApiService) Level3Snapshot(symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/level3/snapshot", map[string]string{"symbol": symbol})
return as.Call(req)
}
// Level3SnapshotV2Model represents level3 ticker message.
type Level3SnapshotV2Model struct {
Symbol string `json:"symbol"`
Sequence int `json:"sequence"`
Asks [][]interface{} `json:"asks"`
Bids [][]interface{} `json:"bids"`
Ts int64 `json:"ts"`
}
// Level3SnapshotV2 Get Full Order Book - Level 3.
func (as *ApiService) Level3SnapshotV2(symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v2/level3/snapshot", map[string]string{"symbol": symbol})
return as.Call(req)
}
// Level3MessageQueryModel represents level3 ticker message.
type Level3MessageQueryModel struct {
Symbol string `json:"symbol"`
Sequence int `json:"sequence"`
Side string `json:"side"`
OrderTime int64 `json:"orderTime"`
Size int `json:"size"`
OrderId string `json:"orderId"`
Price string `json:"price"`
Type string `json:"type"`
ClientOid string `json:"clientOid"`
Ts int64 `json:"ts"`
}
// Level3MessageQueryListModel is the set of *Level3MessageQueryModel
type Level3MessageQueryListModel []*Level3MessageQueryModel
// Level3MessageQuery Level 3 Pulling Messages.
func (as *ApiService) Level3MessageQuery(symbol string, start, end int64) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/level3/message/query", map[string]string{
"symbol": symbol,
"start": IntToString(start),
"end": IntToString(end),
})
return as.Call(req)
}
// TradeHistoryModel represents a the latest trades for a symbol.
type TradeHistoryModel struct {
Sequence int `json:"sequence"`
TradeId string `json:"tradeId"`
TakerOrderId string `json:"takerOrderId"`
MakerOrderId string `json:"makerOrderId"`
Price string `json:"price"`
Size int `json:"size"`
Side string `json:"side"`
Time int64 `json:"t"`
}
// TradesHistoryModel is the set of *TradeHistoryModel.
type TradesHistoryModel []*TradeHistoryModel
// TradeHistory returns a list the latest trades for a symbol.
func (as *ApiService) TradeHistory(symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/trade/history", map[string]string{"symbol": symbol})
return as.Call(req)
}
// InterestModel is the struct.
type InterestModel struct {
Symbol string `json:"symbol"`
Granularity int `json:"granularity"`
TimePoint int64 `json:"timePoint"`
Value float32 `json:"value"`
}
// InterestsModel is the set of *InterestModel.
type InterestsModel struct {
HasMore bool `json:"hasMore"`
DataList []*InterestModel `json:"dataList"` // delay parsing
}
// InterestQuery Get Interest Rate List .
func (as *ApiService) InterestQuery(params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/interest/query", params)
return as.Call(req)
}
// IndexModel is the struct.
type IndexModel struct {
Symbol string `json:"symbol"`
Granularity int `json:"granularity"`
TimePoint int64 `json:"timePoint"`
Value float32 `json:"value"`
DecomposionList [][]interface{} `json:"decomposionList"`
}
// A IndexQueryModel is the set of *IndexModel.
type IndexQueryModel struct {
HasMore bool `json:"hasMore"`
DataList []*IndexModel `json:"dataList"` // delay parsing
}
// IndexQuery Get Index List.
func (as *ApiService) IndexQuery(params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/interest/query", params)
return as.Call(req)
}
// A MarkPriceModel is the struct.
type MarkPriceModel struct {
Symbol string `json:"symbol"`
Granularity float32 `json:"granularity"`
TimePoint int64 `json:"timePoint"`
Value float32 `json:"value"`
IndexPrice float32 `json:"indexPrice"`
}
// MarkPrice Get Current Mark Price
func (as *ApiService) MarkPrice(Symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/mark-price/"+Symbol+"/current", nil)
return as.Call(req)
}
// A PremiumModel is the struct.
type PremiumModel struct {
Symbol string `json:"symbol"`
Granularity string `json:"granularity"`
TimePoint string `json:"timePoint"`
Value string `json:"value"`
}
// A PremiumsModel is the set of *PremiumModel.
type PremiumsModel struct {
HasMore bool `json:"hasMore"`
DataList []*PremiumModel `json:"dataList"` // delay parsing
}
// PremiumQuery Get Premium Index.
func (as *ApiService) PremiumQuery(params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/premium/query", params)
return as.Call(req)
}
// A FundingRateModel is the struct.
type FundingRateModel struct {
Symbol string `json:"symbol"`
Granularity int64 `json:"granularity"`
TimePoint int64 `json:"timePoint"`
Value float32 `json:"value"`
PredictedValue float32 `json:"predictedValue"`
}
// FundingRate Get Current Funding Rate.
func (as *ApiService) FundingRate(Symbol string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/funding-rate/"+Symbol+"/current", nil)
return as.Call(req)
}