forked from thrasher-corp/gocryptotrader
/
binance_types.go
928 lines (856 loc) · 31.6 KB
/
binance_types.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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
package binance
import (
"sync"
"time"
"github.com/idoall/gocryptotrader/currency"
"github.com/idoall/gocryptotrader/exchanges/asset"
)
const wsRateLimitMilliseconds = 250
// withdrawals status codes description
const (
EmailSent = iota
Cancelled
AwaitingApproval
Rejected
Processing
Failure
Completed
)
// ExchangeInfo holds the full exchange information type
type ExchangeInfo struct {
Code int `json:"code"`
Msg string `json:"msg"`
Timezone string `json:"timezone"`
Servertime time.Time `json:"serverTime"`
RateLimits []struct {
RateLimitType string `json:"rateLimitType"`
Interval string `json:"interval"`
Limit int `json:"limit"`
} `json:"rateLimits"`
ExchangeFilters interface{} `json:"exchangeFilters"`
Symbols []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"`
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 []struct {
FilterType string `json:"filterType"`
MinPrice float64 `json:"minPrice,string"`
MaxPrice float64 `json:"maxPrice,string"`
TickSize float64 `json:"tickSize,string"`
MultiplierUp float64 `json:"multiplierUp,string"`
MultiplierDown float64 `json:"multiplierDown,string"`
AvgPriceMinutes int64 `json:"avgPriceMins"`
MinQty float64 `json:"minQty,string"`
MaxQty float64 `json:"maxQty,string"`
StepSize float64 `json:"stepSize,string"`
MinNotional float64 `json:"minNotional,string"`
ApplyToMarket bool `json:"applyToMarket"`
Limit int64 `json:"limit"`
MaxNumAlgoOrders int64 `json:"maxNumAlgoOrders"`
MaxNumIcebergOrders int64 `json:"maxNumIcebergOrders"`
MaxNumOrders int64 `json:"maxNumOrders"`
} `json:"filters"`
Permissions []string `json:"permissions"`
} `json:"symbols"`
}
// CoinInfo stores information about all supported coins
type CoinInfo struct {
Coin string `json:"coin"`
DepositAllEnable bool `json:"depositAllEnable"`
WithdrawAllEnable bool `json:"withdrawAllEnable"`
Free float64 `json:"free,string"`
Freeze float64 `json:"freeze,string"`
IPOAble float64 `json:"ipoable,string"`
IPOing float64 `json:"ipoing,string"`
IsLegalMoney bool `json:"isLegalMoney"`
Locked float64 `json:"locked,string"`
Name string `json:"name"`
NetworkList []struct {
AddressRegex string `json:"addressRegex"`
Coin string `json:"coin"`
DepositDescription string `json:"depositDesc"` // shown only when "depositEnable" is false
DepositEnable bool `json:"depositEnable"`
IsDefault bool `json:"isDefault"`
MemoRegex string `json:"memoRegex"`
MinimumConfirmation uint16 `json:"minConfirm"`
Name string `json:"name"`
Network string `json:"network"`
ResetAddressStatus bool `json:"resetAddressStatus"`
SpecialTips string `json:"specialTips"`
UnlockConfirm uint16 `json:"unLockConfirm"`
WithdrawDescription string `json:"withdrawDesc"` // shown only when "withdrawEnable" is false
WithdrawEnable bool `json:"withdrawEnable"`
WithdrawFee float64 `json:"withdrawFee,string"`
WithdrawMinimum float64 `json:"withdrawMin,string"`
WithdrawMaximum float64 `json:"withdrawMax,string"`
} `json:"networkList"`
Storage float64 `json:"storage,string"`
Trading bool `json:"trading"`
Withdrawing float64 `json:"withdrawing,string"`
}
// OrderBookDataRequestParams represents Klines request data.
type OrderBookDataRequestParams struct {
Symbol currency.Pair `json:"symbol"` // Required field; example LTCBTC,BTCUSDT
Limit int `json:"limit"` // Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000]
}
// OrderbookItem stores an individual orderbook item
type OrderbookItem struct {
Price float64
Quantity float64
}
// OrderBookData is resp data from orderbook endpoint
type OrderBookData struct {
Code int `json:"code"`
Msg string `json:"msg"`
LastUpdateID int64 `json:"lastUpdateId"`
Bids [][2]string `json:"bids"`
Asks [][2]string `json:"asks"`
}
// OrderBook actual structured data that can be used for orderbook
type OrderBook struct {
Symbol string
LastUpdateID int64
Code int
Msg string
Bids []OrderbookItem
Asks []OrderbookItem
}
// DepthUpdateParams is used as an embedded type for WebsocketDepthStream
type DepthUpdateParams []struct {
PriceLevel float64
Quantity float64
ingnore []interface{}
}
// WebsocketDepthStream is the difference for the update depth stream
type WebsocketDepthStream struct {
Event string `json:"e"`
Timestamp time.Time `json:"E"`
Pair string `json:"s"`
FirstUpdateID int64 `json:"U"`
LastUpdateID int64 `json:"u"`
UpdateBids [][2]interface{} `json:"b"`
UpdateAsks [][2]interface{} `json:"a"`
}
// RecentTradeRequestParams represents Klines request data.
type RecentTradeRequestParams struct {
Symbol currency.Pair `json:"symbol"` // Required field. example LTCBTC, BTCUSDT
Limit int `json:"limit"` // Default 500; max 500.
}
// RecentTrade holds recent trade data
type RecentTrade struct {
ID int64 `json:"id"`
Price float64 `json:"price,string"`
Quantity float64 `json:"qty,string"`
Time time.Time `json:"time"`
IsBuyerMaker bool `json:"isBuyerMaker"`
IsBestMatch bool `json:"isBestMatch"`
}
// TradeStream holds the trade stream data
type TradeStream struct {
EventType string `json:"e"`
EventTime time.Time `json:"E"`
Symbol string `json:"s"`
TradeID int64 `json:"t"`
Price string `json:"p"`
Quantity string `json:"q"`
BuyerOrderID int64 `json:"b"`
SellerOrderID int64 `json:"a"`
TimeStamp time.Time `json:"T"`
Maker bool `json:"m"`
BestMatchPrice bool `json:"M"`
}
// UFutureKlineStream holds the kline stream data
type UFutureKlineStream struct {
EventType string `json:"e"`
EventTime int64 `json:"E"`
Symbol string `json:"s"`
Kline UFutureKlineStreamData `json:"k"`
}
// UFutureKlineStreamData defines kline streaming data
type UFutureKlineStreamData struct {
StartTime int64 `json:"t"`
CloseTime int64 `json:"T"`
Symbol string `json:"s"`
Interval string `json:"i"`
FirstTradeID int64 `json:"f"`
LastTradeID int64 `json:"L"`
OpenPrice float64 `json:"o,string"`
ClosePrice float64 `json:"c,string"`
HighPrice float64 `json:"h,string"`
LowPrice float64 `json:"l,string"`
Volume float64 `json:"v,string"`
NumberOfTrades int64 `json:"n"`
KlineClosed bool `json:"x"`
Quote float64 `json:"q,string"`
TakerBuyBaseAssetVolume float64 `json:"V,string"`
TakerBuyQuoteAssetVolume float64 `json:"Q,string"`
}
// KlineStream holds the kline stream data
type KlineStream struct {
EventType string `json:"e"`
EventTime time.Time `json:"E"`
Symbol string `json:"s"`
Kline KlineStreamData `json:"k"`
}
// KlineStreamData defines kline streaming data
type KlineStreamData struct {
StartTime time.Time `json:"t"`
CloseTime time.Time `json:"T"`
Symbol string `json:"s"`
Interval string `json:"i"`
FirstTradeID int64 `json:"f"`
LastTradeID int64 `json:"L"`
OpenPrice float64 `json:"o,string"`
ClosePrice float64 `json:"c,string"`
HighPrice float64 `json:"h,string"`
LowPrice float64 `json:"l,string"`
Volume float64 `json:"v,string"`
NumberOfTrades int64 `json:"n"`
KlineClosed bool `json:"x"`
Quote float64 `json:"q,string"`
TakerBuyBaseAssetVolume float64 `json:"V,string"`
TakerBuyQuoteAssetVolume float64 `json:"Q,string"`
}
// TickerStream holds the ticker stream data
type TickerStream struct {
EventType string `json:"e"`
EventTime time.Time `json:"E"`
Symbol string `json:"s"`
PriceChange float64 `json:"p,string"`
PriceChangePercent float64 `json:"P,string"`
WeightedAvgPrice float64 `json:"w,string"`
ClosePrice float64 `json:"x,string"`
LastPrice float64 `json:"c,string"`
LastPriceQuantity float64 `json:"Q,string"`
BestBidPrice float64 `json:"b,string"`
BestBidQuantity float64 `json:"B,string"`
BestAskPrice float64 `json:"a,string"`
BestAskQuantity float64 `json:"A,string"`
OpenPrice float64 `json:"o,string"`
HighPrice float64 `json:"h,string"`
LowPrice float64 `json:"l,string"`
TotalTradedVolume float64 `json:"v,string"`
TotalTradedQuoteVolume float64 `json:"q,string"`
OpenTime time.Time `json:"O"`
CloseTime time.Time `json:"C"`
FirstTradeID int64 `json:"F"`
LastTradeID int64 `json:"L"`
NumberOfTrades int64 `json:"n"`
}
// HistoricalTrade holds recent trade data
type HistoricalTrade struct {
ID int64 `json:"id"`
Price float64 `json:"price,string"`
Quantity float64 `json:"qty,string"`
QuoteQuantity float64 `json:"quoteQty,string"`
Time time.Time `json:"time"`
IsBuyerMaker bool `json:"isBuyerMaker"`
IsBestMatch bool `json:"isBestMatch"`
}
// AggregatedTradeRequestParams holds request params
type AggregatedTradeRequestParams struct {
Symbol currency.Pair // Required field; example LTCBTC, BTCUSDT
// The first trade to retrieve
FromID int64
// The API seems to accept (start and end time) or FromID and no other combinations
StartTime time.Time
EndTime time.Time
// Default 500; max 1000.
Limit int
}
// AggregatedTrade holds aggregated trade information
type AggregatedTrade struct {
ATradeID int64 `json:"a"`
Price float64 `json:"p,string"`
Quantity float64 `json:"q,string"`
FirstTradeID int64 `json:"f"`
LastTradeID int64 `json:"l"`
TimeStamp time.Time `json:"T"`
Maker bool `json:"m"`
BestMatchPrice bool `json:"M"`
}
// IndexMarkPrice stores data for index and mark prices
type IndexMarkPrice struct {
Symbol string `json:"symbol"`
Pair string `json:"pair"`
MarkPrice float64 `json:"markPrice,string"`
IndexPrice float64 `json:"indexPrice,string"`
EstimatedSettlePrice float64 `json:"estimatedSettlePrice,string"`
LastFundingRate string `json:"lastFundingRate"`
NextFundingTime int64 `json:"nextFundingTime"`
Time int64 `json:"time"`
}
// CandleStick holds kline data
type CandleStick struct {
OpenTime time.Time
Open float64
High float64
Low float64
Close float64
Volume float64
CloseTime time.Time
QuoteAssetVolume float64
TradeCount float64
TakerBuyAssetVolume float64
TakerBuyQuoteAssetVolume float64
}
// AveragePrice holds current average symbol price
type AveragePrice struct {
Mins int64 `json:"mins"`
Price float64 `json:"price,string"`
}
// PriceChangeStats contains statistics for the last 24 hours trade
type PriceChangeStats struct {
Symbol string `json:"symbol"`
PriceChange float64 `json:"priceChange,string"`
PriceChangePercent float64 `json:"priceChangePercent,string"`
WeightedAvgPrice float64 `json:"weightedAvgPrice,string"`
PrevClosePrice float64 `json:"prevClosePrice,string"`
LastPrice float64 `json:"lastPrice,string"`
LastQty float64 `json:"lastQty,string"`
BidPrice float64 `json:"bidPrice,string"`
AskPrice float64 `json:"askPrice,string"`
OpenPrice float64 `json:"openPrice,string"`
HighPrice float64 `json:"highPrice,string"`
LowPrice float64 `json:"lowPrice,string"`
Volume float64 `json:"volume,string"`
QuoteVolume float64 `json:"quoteVolume,string"`
OpenTime time.Time `json:"openTime"`
CloseTime time.Time `json:"closeTime"`
FirstID int64 `json:"firstId"`
LastID int64 `json:"lastId"`
Count int64 `json:"count"`
}
// SymbolPrice holds basic symbol price
type SymbolPrice struct {
Symbol string `json:"symbol"`
Price float64 `json:"price,string"`
}
// BestPrice holds best price data
type BestPrice struct {
Symbol string `json:"symbol"`
BidPrice float64 `json:"bidPrice,string"`
BidQty float64 `json:"bidQty,string"`
AskPrice float64 `json:"askPrice,string"`
AskQty float64 `json:"askQty,string"`
}
// NewOrderRequest request type
type NewOrderRequest struct {
// Symbol (currency pair to trade)
Symbol currency.Pair
// Side Buy or Sell
Side string
// TradeType (market or limit order)
TradeType RequestParamsOrderType
// TimeInForce specifies how long the order remains in effect.
// Examples are (Good Till Cancel (GTC), Immediate or Cancel (IOC) and Fill Or Kill (FOK))
TimeInForce RequestParamsTimeForceType
// Quantity is the total base qty spent or received in an order.
Quantity float64
// QuoteOrderQty is the total quote qty spent or received in a MARKET order.
QuoteOrderQty float64
Price float64
NewClientOrderID string
StopPrice float64 // Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
IcebergQty float64 // Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
NewOrderRespType string
}
// NewOrderResponse is the return structured response from the exchange
type NewOrderResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Symbol string `json:"symbol"`
OrderID int64 `json:"orderId"`
ClientOrderID string `json:"clientOrderId"`
TransactionTime time.Time `json:"transactTime"`
Price float64 `json:"price,string"`
OrigQty float64 `json:"origQty,string"`
ExecutedQty float64 `json:"executedQty,string"`
// The cumulative amount of the quote that has been spent (with a BUY order) or received (with a SELL order).
CumulativeQuoteQty float64 `json:"cummulativeQuoteQty,string"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
Type string `json:"type"`
Side string `json:"side"`
Fills []struct {
Price float64 `json:"price,string"`
Qty float64 `json:"qty,string"`
Commission float64 `json:"commission,string"`
CommissionAsset string `json:"commissionAsset"`
} `json:"fills"`
}
// CancelOrderResponse is the return structured response from the exchange
type CancelOrderResponse struct {
Symbol string `json:"symbol"`
OrigClientOrderID string `json:"origClientOrderId"`
OrderID int64 `json:"orderId"`
ClientOrderID string `json:"clientOrderId"`
}
// QueryOrderData holds query order data
type QueryOrderData struct {
Code int `json:"code"`
Msg string `json:"msg"`
Symbol string `json:"symbol"`
OrderID int64 `json:"orderId"`
ClientOrderID string `json:"clientOrderId"`
Price float64 `json:"price,string"`
OrigQty float64 `json:"origQty,string"`
ExecutedQty float64 `json:"executedQty,string"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
Type string `json:"type"`
Side string `json:"side"`
StopPrice float64 `json:"stopPrice,string"`
IcebergQty float64 `json:"icebergQty,string"`
Time time.Time `json:"time"`
IsWorking bool `json:"isWorking"`
CummulativeQuoteQty float64 `json:"cummulativeQuoteQty,string"`
OrderListID int64 `json:"orderListId"`
OrigQuoteOrderQty float64 `json:"origQuoteOrderQty,string"`
UpdateTime time.Time `json:"updateTime"`
}
// Balance holds query order data
type Balance struct {
Asset string `json:"asset"`
Free string `json:"free"`
Locked string `json:"locked"`
}
// Account holds the account data
type Account struct {
MakerCommission int `json:"makerCommission"`
TakerCommission int `json:"takerCommission"`
BuyerCommission int `json:"buyerCommission"`
SellerCommission int `json:"sellerCommission"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
CanDeposit bool `json:"canDeposit"`
UpdateTime time.Time `json:"updateTime"`
Balances []Balance `json:"balances"`
}
// MarginAccount holds the margin account data
type MarginAccount struct {
BorrowEnabled bool `json:"borrowEnabled"`
MarginLevel float64 `json:"marginLevel,string"`
TotalAssetOfBtc float64 `json:"totalAssetOfBtc,string"`
TotalLiabilityOfBtc float64 `json:"totalLiabilityOfBtc,string"`
TotalNetAssetOfBtc float64 `json:"totalNetAssetOfBtc,string"`
TradeEnabled bool `json:"tradeEnabled"`
TransferEnabled bool `json:"transferEnabled"`
UserAssets []MarginAccountAsset `json:"userAssets"`
}
// MarginAccountAsset holds each individual margin account asset
type MarginAccountAsset struct {
Asset string `json:"asset"`
Borrowed float64 `json:"borrowed,string"`
Free float64 `json:"free,string"`
Interest float64 `json:"interest,string"`
Locked float64 `json:"locked,string"`
NetAsset float64 `json:"netAsset,string"`
}
// RequestParamsTimeForceType Time in force
type RequestParamsTimeForceType string
var (
// BinanceRequestParamsTimeGTC GTC
BinanceRequestParamsTimeGTC = RequestParamsTimeForceType("GTC")
// BinanceRequestParamsTimeIOC IOC
BinanceRequestParamsTimeIOC = RequestParamsTimeForceType("IOC")
// BinanceRequestParamsTimeFOK FOK
BinanceRequestParamsTimeFOK = RequestParamsTimeForceType("FOK")
)
// RequestParamsOrderType trade order type
type RequestParamsOrderType string
var (
// BinanceRequestParamsOrderLimit Limit order
BinanceRequestParamsOrderLimit = RequestParamsOrderType("LIMIT")
// BinanceRequestParamsOrderMarket Market order
BinanceRequestParamsOrderMarket = RequestParamsOrderType("MARKET")
// BinanceRequestParamsOrderStopLoss STOP_LOSS
BinanceRequestParamsOrderStopLoss = RequestParamsOrderType("STOP_LOSS")
// BinanceRequestParamsOrderStopLossLimit STOP_LOSS_LIMIT
BinanceRequestParamsOrderStopLossLimit = RequestParamsOrderType("STOP_LOSS_LIMIT")
// BinanceRequestParamsOrderTakeProfit TAKE_PROFIT
BinanceRequestParamsOrderTakeProfit = RequestParamsOrderType("TAKE_PROFIT")
// BinanceRequestParamsOrderTakeProfitLimit TAKE_PROFIT_LIMIT
BinanceRequestParamsOrderTakeProfitLimit = RequestParamsOrderType("TAKE_PROFIT_LIMIT")
// BinanceRequestParamsOrderLimitMarker LIMIT_MAKER
BinanceRequestParamsOrderLimitMarker = RequestParamsOrderType("LIMIT_MAKER")
)
// KlinesRequestParams represents Klines request data.
type KlinesRequestParams struct {
Symbol currency.Pair // Required field; example LTCBTC, BTCUSDT
Interval string // Time interval period
Limit int // Default 500; max 500.
StartTime time.Time
EndTime time.Time
}
// WithdrawalFees the large list of predefined withdrawal fees
// Prone to change
var WithdrawalFees = map[currency.Code]float64{
currency.BNB: 0.13,
currency.BTC: 0.0005,
currency.NEO: 0,
currency.ETH: 0.01,
currency.LTC: 0.001,
currency.QTUM: 0.01,
currency.EOS: 0.1,
currency.SNT: 35,
currency.BNT: 1,
currency.GAS: 0,
currency.BCC: 0.001,
currency.BTM: 5,
currency.USDT: 3.4,
currency.HCC: 0.0005,
currency.OAX: 6.5,
currency.DNT: 54,
currency.MCO: 0.31,
currency.ICN: 3.5,
currency.ZRX: 1.9,
currency.OMG: 0.4,
currency.WTC: 0.5,
currency.LRC: 12.3,
currency.LLT: 67.8,
currency.YOYO: 1,
currency.TRX: 1,
currency.STRAT: 0.1,
currency.SNGLS: 54,
currency.BQX: 3.9,
currency.KNC: 3.5,
currency.SNM: 25,
currency.FUN: 86,
currency.LINK: 4,
currency.XVG: 0.1,
currency.CTR: 35,
currency.SALT: 2.3,
currency.MDA: 2.3,
currency.IOTA: 0.5,
currency.SUB: 11.4,
currency.ETC: 0.01,
currency.MTL: 2,
currency.MTH: 45,
currency.ENG: 2.2,
currency.AST: 14.4,
currency.DASH: 0.002,
currency.BTG: 0.001,
currency.EVX: 2.8,
currency.REQ: 29.9,
currency.VIB: 30,
currency.POWR: 8.2,
currency.ARK: 0.2,
currency.XRP: 0.25,
currency.MOD: 2,
currency.ENJ: 26,
currency.STORJ: 5.1,
currency.KMD: 0.002,
currency.RCN: 47,
currency.NULS: 0.01,
currency.RDN: 2.5,
currency.XMR: 0.04,
currency.DLT: 19.8,
currency.AMB: 8.9,
currency.BAT: 8,
currency.ZEC: 0.005,
currency.BCPT: 14.5,
currency.ARN: 3,
currency.GVT: 0.13,
currency.CDT: 81,
currency.GXS: 0.3,
currency.POE: 134,
currency.QSP: 36,
currency.BTS: 1,
currency.XZC: 0.02,
currency.LSK: 0.1,
currency.TNT: 47,
currency.FUEL: 79,
currency.MANA: 18,
currency.BCD: 0.01,
currency.DGD: 0.04,
currency.ADX: 6.3,
currency.ADA: 1,
currency.PPT: 0.41,
currency.CMT: 12,
currency.XLM: 0.01,
currency.CND: 58,
currency.LEND: 84,
currency.WABI: 6.6,
currency.SBTC: 0.0005,
currency.BCX: 0.5,
currency.WAVES: 0.002,
currency.TNB: 139,
currency.GTO: 20,
currency.ICX: 0.02,
currency.OST: 32,
currency.ELF: 3.9,
currency.AION: 3.2,
currency.CVC: 10.9,
currency.REP: 0.2,
currency.GNT: 8.9,
currency.DATA: 37,
currency.ETF: 1,
currency.BRD: 3.8,
currency.NEBL: 0.01,
currency.VIBE: 17.3,
currency.LUN: 0.36,
currency.CHAT: 60.7,
currency.RLC: 3.4,
currency.INS: 3.5,
currency.IOST: 105.6,
currency.STEEM: 0.01,
currency.NANO: 0.01,
currency.AE: 1.3,
currency.VIA: 0.01,
currency.BLZ: 10.3,
currency.SYS: 1,
currency.NCASH: 247.6,
currency.POA: 0.01,
currency.ONT: 1,
currency.ZIL: 37.2,
currency.STORM: 152,
currency.XEM: 4,
currency.WAN: 0.1,
currency.WPR: 43.4,
currency.QLC: 1,
currency.GRS: 0.2,
currency.CLOAK: 0.02,
currency.LOOM: 11.9,
currency.BCN: 1,
currency.TUSD: 1.35,
currency.ZEN: 0.002,
currency.SKY: 0.01,
currency.THETA: 24,
currency.IOTX: 90.5,
currency.QKC: 24.6,
currency.AGI: 29.81,
currency.NXS: 0.02,
currency.SC: 0.1,
currency.EON: 10,
currency.NPXS: 897,
currency.KEY: 223,
currency.NAS: 0.1,
currency.ADD: 100,
currency.MEETONE: 300,
currency.ATD: 100,
currency.MFT: 175,
currency.EOP: 5,
currency.DENT: 596,
currency.IQ: 50,
currency.ARDR: 2,
currency.HOT: 1210,
currency.VET: 100,
currency.DOCK: 68,
currency.POLY: 7,
currency.VTHO: 21,
currency.ONG: 0.1,
currency.PHX: 1,
currency.HC: 0.005,
currency.GO: 0.01,
currency.PAX: 1.4,
currency.EDO: 1.3,
currency.WINGS: 8.9,
currency.NAV: 0.2,
currency.TRIG: 49.1,
currency.APPC: 12.4,
currency.PIVX: 0.02,
}
// DepositHistory stores deposit history info
type DepositHistory struct {
Amount float64 `json:"amount,string"`
Coin string `json:"coin"`
Network string `json:"network"`
Status uint8 `json:"status"`
Address string `json:"address"`
AddressTag string `json:"adressTag"`
TransactionID string `json:"txId"`
InsertTime float64 `json:"insertTime"`
TransferType uint8 `json:"transferType"`
ConfirmTimes string `json:"confirmTimes"`
}
// WithdrawResponse contains status of withdrawal request
type WithdrawResponse struct {
ID string `json:"id"`
}
// WithdrawStatusResponse defines a withdrawal status response
type WithdrawStatusResponse struct {
Address string `json:"address"`
Amount float64 `json:"amount,string"`
ApplyTime string `json:"applyTime"`
Coin string `json:"coin"`
ID string `json:"id"`
WithdrawOrderID string `json:"withdrawOrderId"`
Network string `json:"network"`
TransferType uint8 `json:"transferType"`
Status int64 `json:"status"`
TransactionFee float64 `json:"transactionFee,string"`
TransactionID string `json:"txId"`
ConfirmNumber int64 `json:"confirmNo"`
}
// DepositAddress stores the deposit address info
type DepositAddress struct {
Address string `json:"address"`
Coin string `json:"coin"`
Tag string `json:"tag"`
URL string `json:"url"`
}
// UserAccountStream contains a key to maintain an authorised
// websocket connection
type UserAccountStream struct {
ListenKey string `json:"listenKey"`
}
type wsAccountInfo struct {
Stream string `json:"stream"`
Data WsAccountInfoData `json:"data"`
}
// WsAccountInfoData defines websocket account info data
type WsAccountInfoData struct {
CanDeposit bool `json:"D"`
CanTrade bool `json:"T"`
CanWithdraw bool `json:"W"`
EventTime time.Time `json:"E"`
LastUpdated time.Time `json:"u"`
BuyerCommission float64 `json:"b"`
MakerCommission float64 `json:"m"`
SellerCommission float64 `json:"s"`
TakerCommission float64 `json:"t"`
EventType string `json:"e"`
Currencies []struct {
Asset string `json:"a"`
Available float64 `json:"f,string"`
Locked float64 `json:"l,string"`
} `json:"B"`
}
type wsAccountPosition struct {
Stream string `json:"stream"`
Data WsAccountPositionData `json:"data"`
}
// WsAccountPositionData defines websocket account position data
type WsAccountPositionData struct {
Currencies []struct {
Asset string `json:"a"`
Available float64 `json:"f,string"`
Locked float64 `json:"l,string"`
} `json:"B"`
EventTime time.Time `json:"E"`
LastUpdated time.Time `json:"u"`
EventType string `json:"e"`
}
type wsBalanceUpdate struct {
Stream string `json:"stream"`
Data WsBalanceUpdateData `json:"data"`
}
// WsBalanceUpdateData defines websocket account balance data
type WsBalanceUpdateData struct {
EventTime time.Time `json:"E"`
ClearTime time.Time `json:"T"`
BalanceDelta float64 `json:"d,string"`
Asset string `json:"a"`
EventType string `json:"e"`
}
type wsOrderUpdate struct {
Stream string `json:"stream"`
Data WsOrderUpdateData `json:"data"`
}
// WsOrderUpdateData defines websocket account order update data
type WsOrderUpdateData struct {
EventType string `json:"e"`
EventTime time.Time `json:"E"`
Symbol string `json:"s"`
ClientOrderID string `json:"c"`
Side string `json:"S"`
OrderType string `json:"o"`
TimeInForce string `json:"f"`
Quantity float64 `json:"q,string"`
Price float64 `json:"p,string"`
StopPrice float64 `json:"P,string"`
IcebergQuantity float64 `json:"F,string"`
OrderListID int64 `json:"g"`
CancelledClientOrderID string `json:"C"`
CurrentExecutionType string `json:"x"`
OrderStatus string `json:"X"`
RejectionReason string `json:"r"`
OrderID int64 `json:"i"`
LastExecutedQuantity float64 `json:"l,string"`
CumulativeFilledQuantity float64 `json:"z,string"`
LastExecutedPrice float64 `json:"L,string"`
Commission float64 `json:"n,string"`
CommissionAsset string `json:"N"`
TransactionTime time.Time `json:"T"`
TradeID int64 `json:"t"`
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'.
IsOnOrderBook bool `json:"w"`
IsMaker bool `json:"m"`
Ignored2 bool `json:"M"` // See the comment for "I".
OrderCreationTime time.Time `json:"O"`
CumulativeQuoteTransactedQuantity float64 `json:"Z,string"`
LastQuoteAssetTransactedQuantity float64 `json:"Y,string"`
QuoteOrderQuantity float64 `json:"Q,string"`
}
type wsListStatus struct {
Stream string `json:"stream"`
Data WsListStatusData `json:"data"`
}
// WsListStatusData defines websocket account listing status data
type WsListStatusData struct {
ListClientOrderID string `json:"C"`
EventTime time.Time `json:"E"`
ListOrderStatus string `json:"L"`
Orders []struct {
ClientOrderID string `json:"c"`
OrderID int64 `json:"i"`
Symbol string `json:"s"`
} `json:"O"`
TransactionTime time.Time `json:"T"`
ContingencyType string `json:"c"`
EventType string `json:"e"`
OrderListID int64 `json:"g"`
ListStatusType string `json:"l"`
RejectionReason string `json:"r"`
Symbol string `json:"s"`
}
// WsPayload defines the payload through the websocket connection
type WsPayload struct {
Method string `json:"method"`
Params []string `json:"params"`
ID int64 `json:"id"`
}
// CrossMarginInterestData stores cross margin data for borrowing
type CrossMarginInterestData struct {
Code int64 `json:"code,string"`
Message string `json:"message"`
MessageDetail string `json:"messageDetail"`
Data []struct {
AssetName string `json:"assetName"`
Specs []struct {
VipLevel string `json:"vipLevel"`
DailyInterestRate string `json:"dailyInterestRate"`
BorrowLimit string `json:"borrowLimit"`
} `json:"specs"`
} `json:"data"`
Success bool `json:"success"`
}
// orderbookManager defines a way of managing and maintaining synchronisation
// across connections and assets.
type orderbookManager struct {
state map[currency.Code]map[currency.Code]map[asset.Item]*update
sync.Mutex
jobs chan job
}
type update struct {
buffer chan *WebsocketDepthStream
fetchingBook bool
initialSync bool
needsFetchingBook bool
lastUpdateID int64
}
// job defines a synchonisation job that tells a go routine to fetch an
// orderbook via the REST protocol
type job struct {
Pair currency.Pair
}