-
Notifications
You must be signed in to change notification settings - Fork 40
/
result.go
549 lines (501 loc) · 20.4 KB
/
result.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
package rest
import (
sjson "encoding/json"
"strings"
"time"
)
type BaseResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result interface{} `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
}
type Item struct {
Price float64 `json:"price,string"`
Size float64 `json:"size"`
}
type OrderBook struct {
Asks []Item `json:"asks"`
Bids []Item `json:"bids"`
Time time.Time `json:"time"`
}
type RawItem struct {
Symbol string `json:"symbol"`
Price float64 `json:"price,string"`
Size float64 `json:"size"`
Side string `json:"side"` // Buy/Sell
}
type GetOrderBookResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []RawItem `json:"result"`
TimeNow string `json:"time_now"`
}
type OHLC struct {
Symbol string `json:"symbol"`
Interval string `json:"interval"`
OpenTime int64 `json:"open_time"`
Open float64 `json:"open,string"`
High float64 `json:"high,string"`
Low float64 `json:"low,string"`
Close float64 `json:"close,string"`
Volume float64 `json:"volume,string"`
Turnover float64 `json:"turnover,string"`
}
type GetKlineResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []OHLC `json:"result"`
TimeNow string `json:"time_now"`
}
type Ticker struct {
Symbol string `json:"symbol"`
BidPrice float64 `json:"bid_price,string"`
AskPrice float64 `json:"ask_price,string"`
LastPrice float64 `json:"last_price,string"`
LastTickDirection string `json:"last_tick_direction"`
PrevPrice24H float64 `json:"prev_price_24h,string"`
Price24HPcnt float64 `json:"price_24h_pcnt,string"`
HighPrice24H float64 `json:"high_price_24h,string"`
LowPrice24H float64 `json:"low_price_24h,string"`
PrevPrice1H float64 `json:"prev_price_1h,string"`
Price1HPcnt float64 `json:"price_1h_pcnt,string"`
MarkPrice float64 `json:"mark_price,string"`
IndexPrice float64 `json:"index_price,string"`
OpenInterest int `json:"open_interest"`
OpenValue float64 `json:"open_value,string"`
TotalTurnover float64 `json:"total_turnover,string"`
Turnover24H float64 `json:"turnover_24h,string"`
TotalVolume int64 `json:"total_volume"`
Volume24H int64 `json:"volume_24h"`
FundingRate float64 `json:"funding_rate,string"`
PredictedFundingRate float64 `json:"predicted_funding_rate,string"`
NextFundingTime time.Time `json:"next_funding_time"`
CountdownHour int `json:"countdown_hour"`
}
type GetTickersResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []Ticker `json:"result"`
TimeNow string `json:"time_now"`
}
type TradingRecord struct {
ID int `json:"id"`
Symbol string `json:"symbol"`
Price float64 `json:"price"`
Qty int `json:"qty"`
Side string `json:"side"`
Time time.Time `json:"time"`
}
type GetTradingRecordsResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []TradingRecord `json:"result"`
TimeNow string `json:"time_now"`
}
type LeverageFilter struct {
MinLeverage int `json:"min_leverage"`
MaxLeverage int `json:"max_leverage"`
LeverageStep float64 `json:"leverage_step,string"`
}
type PriceFilter struct {
MinPrice float64 `json:"min_price,string"`
MaxPrice float64 `json:"max_price,string"`
TickSize float64 `json:"tick_size,string"`
}
type LotSizeFilter struct {
MaxTradingQty int `json:"max_trading_qty"`
MinTradingQty int `json:"min_trading_qty"`
QtyStep int `json:"qty_step"`
}
type SymbolInfo struct {
Name string `json:"name"`
BaseCurrency string `json:"base_currency"`
QuoteCurrency string `json:"quote_currency"`
PriceScale int `json:"price_scale"`
TakerFee float64 `json:"taker_fee,string"`
MakerFee float64 `json:"maker_fee,string"`
LeverageFilter LeverageFilter `json:"leverage_filter"`
PriceFilter PriceFilter `json:"price_filter"`
LotSizeFilter LotSizeFilter `json:"lot_size_filter"`
}
type GetSymbolsResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []SymbolInfo `json:"result"`
TimeNow string `json:"time_now"`
}
type Balance struct {
Equity float64 `json:"equity"`
AvailableBalance float64 `json:"available_balance"`
UsedMargin float64 `json:"used_margin"`
OrderMargin float64 `json:"order_margin"`
PositionMargin float64 `json:"position_margin"`
OccClosingFee float64 `json:"occ_closing_fee"`
OccFundingFee float64 `json:"occ_funding_fee"`
WalletBalance float64 `json:"wallet_balance"`
RealisedPnl float64 `json:"realised_pnl"`
UnrealisedPnl float64 `json:"unrealised_pnl"`
CumRealisedPnl float64 `json:"cum_realised_pnl"`
GivenCash float64 `json:"given_cash"`
ServiceCash float64 `json:"service_cash"`
}
type GetBalanceResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result GetBalanceResultData `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}
type GetBalanceResultData struct {
BTC Balance `json:"BTC"`
ETH Balance `json:"ETH"`
EOS Balance `json:"EOS"`
XRP Balance `json:"XRP"`
USDT Balance `json:"USDT"`
}
type CreateOrderResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result Order `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
}
type OrderLite struct {
OrderID string `json:"order_id"`
}
type ReplaceOrderResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result OrderLite `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
}
type CancelOrderResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result Order `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
}
type OrderListResultData struct {
Data []Order `json:"data"`
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
}
type OrderListResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result OrderListResultData `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
}
// Order ...
type Order struct {
OrderID string `json:"order_id"`
//StopOrderID string `json:"stop_order_id"`
UserID int `json:"user_id"`
Symbol string `json:"symbol"`
Side string `json:"side"`
OrderType string `json:"order_type"`
Price float64 `json:"price"`
Qty float64 `json:"qty"`
TimeInForce string `json:"time_in_force"`
//StopOrderType string `json:"stop_order_type,omitempty"`
//StopPx sjson.Number `json:"stop_px,omitempty"`
OrderStatus string `json:"order_status"`
//StopOrderStatus string `json:"stop_order_status"`
LastExecTime string `json:"last_exec_time"`
LastExecPrice float64 `json:"last_exec_price"`
LeavesQty float64 `json:"leaves_qty"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue float64 `json:"cum_exec_value"`
CumExecFee float64 `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
OrderLinkID string `json:"order_link_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ExtFields *ExtFields `json:"ext_fields,omitempty"`
}
type ExtFields struct {
ReduceOnly bool `json:"reduce_only"`
OpFrom string `json:"op_from"`
Remark string `json:"remark"`
OReqNum int64 `json:"o_req_num"`
XreqType string `json:"xreq_type"`
CrossStatus string `json:"cross_status,omitempty"`
}
type InExtFields struct {
ReduceOnly bool `json:"reduce_only"`
OpFrom string `json:"op_from"`
Remark string `json:"remark"`
OReqNum int64 `json:"o_req_num"`
XreqType string `json:"xreq_type"`
CrossStatus string `json:"cross_status,omitempty"`
}
func (e *ExtFields) MarshalJSON() ([]byte, error) {
return json.Marshal(e)
}
func (e *ExtFields) UnmarshalJSON(b []byte) error {
s := string(b)
if strings.HasPrefix(s, "[") {
return nil
}
o := InExtFields{}
if err := json.Unmarshal(b, &o); err == nil {
e.ReduceOnly = o.ReduceOnly
e.OpFrom = o.OpFrom
e.Remark = o.Remark
e.OReqNum = o.OReqNum
e.XreqType = o.XreqType
e.CrossStatus = o.CrossStatus
return nil
} else {
return err
}
}
type GetLeverageResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result map[string]LeverageItem `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
}
type LeverageItem struct {
Leverage int `json:"leverage"`
}
type PositionV1 struct {
ID int `json:"id"`
UserID int `json:"user_id"`
RiskID int `json:"risk_id"`
Symbol string `json:"symbol"`
Size float64 `json:"size"`
Side string `json:"side"`
EntryPrice float64 `json:"entry_price"`
LiqPrice float64 `json:"liq_price"`
BustPrice float64 `json:"bust_price"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TrailingStop float64 `json:"trailing_stop"`
PositionValue float64 `json:"position_value"`
Leverage float64 `json:"leverage"`
PositionStatus string `json:"position_status"`
AutoAddMargin float64 `json:"auto_add_margin"`
OrderMargin float64 `json:"order_margin"`
PositionMargin float64 `json:"position_margin"`
OccClosingFee float64 `json:"occ_closing_fee"`
OccFundingFee float64 `json:"occ_funding_fee"`
ExtFields *PositionExtFields `json:"ext_fields"`
WalletBalance float64 `json:"wallet_balance"`
CumRealisedPnl float64 `json:"cum_realised_pnl"`
CumCommission float64 `json:"cum_commission"`
RealisedPnl float64 `json:"realised_pnl"`
DeleverageIndicator float64 `json:"deleverage_indicator"`
OcCalcData string `json:"oc_calc_data"`
CrossSeq float64 `json:"cross_seq"`
PositionSeq float64 `json:"position_seq"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
UnrealisedPnl float64 `json:"unrealised_pnl"`
}
type Position struct {
ID int `json:"id"`
UserID int `json:"user_id"`
RiskID int `json:"risk_id"`
Symbol string `json:"symbol"`
Size float64 `json:"size"`
Side string `json:"side"`
EntryPrice float64 `json:"entry_price,string"`
LiqPrice float64 `json:"liq_price,string"`
BustPrice float64 `json:"bust_price,string"`
TakeProfit float64 `json:"take_profit,string"`
StopLoss float64 `json:"stop_loss,string"`
TrailingStop float64 `json:"trailing_stop,string"`
PositionValue float64 `json:"position_value,string"`
Leverage float64 `json:"leverage,string"`
PositionStatus string `json:"position_status"`
AutoAddMargin float64 `json:"auto_add_margin"`
OrderMargin float64 `json:"order_margin,string"`
PositionMargin float64 `json:"position_margin,string"`
OccClosingFee float64 `json:"occ_closing_fee,string"`
OccFundingFee float64 `json:"occ_funding_fee,string"`
ExtFields *PositionExtFields `json:"ext_fields"`
WalletBalance float64 `json:"wallet_balance,string"`
CumRealisedPnl float64 `json:"cum_realised_pnl,string"`
CumCommission float64 `json:"cum_commission,string"`
RealisedPnl float64 `json:"realised_pnl,string"`
DeleverageIndicator float64 `json:"deleverage_indicator"`
OcCalcData string `json:"oc_calc_data"`
CrossSeq float64 `json:"cross_seq"`
PositionSeq float64 `json:"position_seq"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
UnrealisedPnl float64 `json:"unrealised_pnl"`
}
type PositionExtFields struct {
Remark string `json:"_remark"`
}
type PositionListResult struct {
BaseResult
ExtInfo interface{} `json:"ext_info"`
Result []PositionV1 `json:"result"`
}
type GetPositionResult struct {
BaseResult
ExtInfo interface{} `json:"ext_info"`
Result Position `json:"result"`
}
type OrderV2 struct {
UserID int `json:"user_id"`
OrderID string `json:"order_id"`
Symbol string `json:"symbol"`
Side string `json:"side"`
OrderType string `json:"order_type"`
Price sjson.Number `json:"price"`
Qty float64 `json:"qty"`
TimeInForce string `json:"time_in_force"`
OrderStatus string `json:"order_status"`
LastExecTime sjson.Number `json:"last_exec_time"`
LastExecPrice sjson.Number `json:"last_exec_price"`
LeavesQty float64 `json:"leaves_qty"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue sjson.Number `json:"cum_exec_value"`
CumExecFee sjson.Number `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
OrderLinkID string `json:"order_link_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type CreateOrderV2Result struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result OrderV2 `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}
type CancelOrderV2Result struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result OrderV2 `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}
type CancelAllOrderV2Result struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []OrderV2 `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}
type QueryOrderResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result OrderV2 `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}
type StopOrderV2 struct {
ClOrdID string `json:"clOrdID"`
UserID int64 `json:"user_id"`
Symbol string `json:"symbol"`
Side string `json:"side"`
OrderType string `json:"order_type"`
Price sjson.Number `json:"price"`
Qty float64 `json:"qty"`
TimeInForce string `json:"time_in_force"`
CreateType string `json:"create_type"`
CancelType string `json:"cancel_type"`
OrderStatus string `json:"order_status"`
LeavesQty float64 `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CrossStatus string `json:"cross_status"`
CrossSeq float64 `json:"cross_seq"`
StopOrderType string `json:"stop_order_type"`
TriggerBy string `json:"trigger_by"`
BasePrice sjson.Number `json:"base_price"`
ExpectedDirection string `json:"expected_direction"`
}
type CancelStopOrdersV2Result struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
Result []StopOrderV2 `json:"result"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}
type StopOrder struct {
UserID int64 `json:"user_id"`
StopOrderStatus string `json:"stop_order_status"`
Symbol string `json:"symbol"`
Side string `json:"side"`
OrderType string `json:"order_type"`
Price float64 `json:"price"`
Qty float64 `json:"qty"`
TimeInForce string `json:"time_in_force"`
StopOrderType string `json:"stop_order_type"`
TriggerBy string `json:"trigger_by"`
BasePrice float64 `json:"base_price"`
OrderLinkID string `json:"order_link_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
StopPx float64 `json:"stop_px"`
StopOrderID string `json:"stop_order_id"`
}
type GetStopOrdersResultData struct {
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
Data []StopOrder `json:"data"`
}
type GetStopOrdersResult struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
Result GetStopOrdersResultData `json:"result"`
ExtInfo interface{} `json:"ext_info"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}