-
Notifications
You must be signed in to change notification settings - Fork 789
/
okcoin_types.go
1460 lines (1366 loc) · 59.9 KB
/
okcoin_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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package okcoin
import (
"strconv"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/types"
)
var withdrawalFeeMaps = map[currency.Code]float64{
currency.BTC: 0.00007,
currency.ETH: 0.00096,
currency.USDC: 3.5044432,
currency.DOGE: 4,
currency.ADA: 0.8,
currency.SOL: 0.008,
currency.TRX: 0.8,
currency.MATIC: 7.46726546,
currency.DOT: 0.08,
currency.LTC: 0.001,
currency.SHIB: 290655.61757874,
currency.WBTC: 0.00017668,
currency.UNI: 0.59184286,
currency.AVAX: 0.008,
currency.LINK: 0.5480391,
currency.DAI: 0.5480391,
currency.ATOM: 0.004,
currency.HBAR: 0.8,
currency.ICP: 0.0003,
currency.LDO: 3.46374201,
currency.CRO: 52.74539796,
currency.NEAR: 0.008,
currency.OP: 0.1,
currency.MKR: 0.00463947,
currency.GRT: 34.50290634,
currency.AAVE: 0.07203909,
currency.ALGO: 0.008,
currency.SAND: 4.62930946,
currency.SNX: 1.85469272,
currency.STX: 0.5,
currency.IMX: 7.94166437,
currency.EOS: 0.08,
currency.EGLD: 0.001,
currency.AXS: 0.26108549,
currency.XTZ: 0.08,
currency.APE: 0.8,
currency.MANA: 4.58638989,
currency.FTM: 5,
currency.FTM: 5,
currency.FLOW: 0.008,
currency.CRV: 3.45323741,
currency.CHZ: 16.62405247,
currency.LUNC: 1000,
currency.MINA: 0.4,
currency.COMP: 0.07717078,
currency.DYDX: 2.26134119,
currency.ZIL: 0.16,
currency.AR: 0.01,
currency.FLR: 1,
currency.OneINCH: 5.61490912,
currency.ENJ: 6.98777134,
currency.MASK: 0.98622576,
currency.LRC: 10.02915512,
currency.CELO: 0.0008,
currency.CVX: 0.92875557,
currency.ASTR: 1,
currency.ZEC: 0.0008,
currency.ENS: 1.4,
currency.RVN: 0.8,
currency.YFI: 0.00040394,
currency.ICX: 0.016,
currency.KSM: 0.008,
currency.LUNA: 0.05,
currency.ANT: 1.48614813,
currency.LPT: 0.34101202,
currency.WAXP: 0.01,
currency.USTC: 10,
currency.ONE: 0,
currency.SUSHI: 3.37202198,
currency.SKL: 328,
currency.KDA: 0,
currency.UMA: 2.77,
currency.KNC: 3.2,
currency.API3: 2.13391062,
currency.XNO: 0.1,
currency.NMR: 0.176,
currency.BNT: 8.40922032,
currency.SLP: 770.4,
currency.METIS: 0.13742175,
currency.SPELL: 0.13742175,
currency.PHA: 24.72661591,
currency.AGLD: 10.74779497,
currency.GHST: 3.93441153,
currency.BADGER: 3.93441153,
currency.STORJ: 9.85835481,
currency.PERP: 8.48902141,
currency.LAT: 0.8,
currency.YFII: 0.00393526,
currency.TRB: 0.24234508,
currency.FORTH: 1.13699584,
currency.DIA: 9.74318345,
currency.KP3R: 0.0336,
currency.CLV: 54.8817387,
currency.ZRX: 16.27968018,
currency.BRWL: 879.4987,
currency.BRL: 0,
}
// TickerData stores ticker data
type TickerData struct {
InstType string `json:"instType"`
InstrumentID string `json:"instId"`
LastTradedPrice types.Number `json:"last"`
LastTradedSize types.Number `json:"lastSz"`
BestAskPrice types.Number `json:"askPx"`
BestAskSize types.Number `json:"askSz"`
BestBidPrice types.Number `json:"bidPx"`
BestBidSize types.Number `json:"bidSz"`
Open24H types.Number `json:"open24h"` // Open price in the past 24 hours
High24H types.Number `json:"high24h"` // Highest price in the past 24 hours
Low24H types.Number `json:"low24h"` // Lowest price in the past 24 hours
VolCcy24H types.Number `json:"volCcy24h"` // 24h trading volume, with a unit of currency. The value is the quantity in quote currency.
Vol24H types.Number `json:"vol24h"` // 24h trading volume, with a unit of contract. The value is the quantity in base currency.
Timestamp okcoinTime `json:"ts"`
OpenPriceInUtc0 types.Number `json:"sodUtc0"`
OpenPriceInUtc8 types.Number `json:"sodUtc8"`
}
// GetOrderBookResponse response data
type GetOrderBookResponse struct {
Timestamp okcoinTime `json:"ts"`
Asks [][4]string `json:"asks"` // [[0]: "Price", [1]: "Size", [2]: "Num_orders"], ...
Bids [][4]string `json:"bids"` // [[0]: "Price", [1]: "Size", [2]: "Num_orders"], ...
}
// WebsocketEventRequest contains event data for a websocket channel
type WebsocketEventRequest struct {
Operation string `json:"op"` // 1--subscribe 2--unsubscribe 3--login
Arguments []map[string]string `json:"args"` // args: the value is the channel name, which can be one or more channels
}
// WebsocketEventResponse contains event data for a websocket channel
type WebsocketEventResponse struct {
Event string `json:"event"`
Channel string `json:"channel,omitempty"`
Message string `json:"msg"`
Code string `json:"code"`
}
// WebsocketOrderbookResponse formats orderbook data for a websocket push data
type WebsocketOrderbookResponse struct {
Arg struct {
Channel string `json:"channel"`
InstrumentID string `json:"instId"`
} `json:"arg"`
Action string `json:"action"`
Data []WebsocketOrderBook `json:"data"`
}
// WebsocketOrderBook holds orderbook data
type WebsocketOrderBook struct {
Checksum int64 `json:"checksum"`
Asks [][2]types.Number `json:"asks"` // [ Price, Quantity, depreciated, number of orders at the price ]
Bids [][2]types.Number `json:"bids"` // [ Price, Quantity, depreciated, number of orders at the price ]
Timestamp okcoinTime `json:"ts"`
}
func (a *WebsocketOrderBook) prepareOrderbook() {
asks := [][2]types.Number{}
for x := range a.Asks {
if len(asks) > 0 && asks[len(asks)-1][0].Float64() == a.Asks[x][0].Float64() {
if a.Asks[x][1].Float64() != 0 {
if asks[len(asks)-1][1].Float64() > a.Asks[x][1].Float64() {
asks[len(asks)-1], a.Asks[x] = a.Asks[x], asks[len(asks)-1]
}
} else if a.Asks[x][1] == 0 {
continue
}
}
asks = append(asks, a.Asks[x])
}
a.Asks = asks
bids := [][2]types.Number{}
for x := range a.Bids {
if len(bids) > 0 && bids[len(bids)-1][0].Float64() == a.Bids[x][0].Float64() {
if a.Bids[x][1].Float64() != 0 {
if bids[len(bids)-1][1].Float64() < a.Bids[x][1].Float64() {
bids[len(bids)-1], a.Bids[x] = a.Bids[x], bids[len(bids)-1]
}
} else if a.Bids[x][1] == 0 {
continue
}
}
bids = append(bids, a.Bids[x])
}
a.Bids = bids
}
// WebsocketDataResponse formats all response data for a websocket event
type WebsocketDataResponse struct {
ID string `json:"id"`
Operation string `json:"op"`
Message string `json:"msg"`
Arguments struct {
Channel string `json:"channel"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
} `json:"arg"`
Action string `json:"action"`
Data []interface{} `json:"data"`
}
// WebsocketDataResponseReciever formats all response data for a websocket events and used to unmarshal push data into corresponding instance
type WebsocketDataResponseReciever struct {
Arguments struct {
Channel string `json:"channel"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
} `json:"arg"`
Action string `json:"action"`
Data interface{} `json:"data"`
}
// WebsocketStatus represents a system status response.
type WebsocketStatus struct {
Arg struct {
Channel string `json:"channel"`
} `json:"arg"`
Data []struct {
Title string `json:"title"`
State string `json:"state"`
End okcoinTime `json:"end"`
Begin okcoinTime `json:"begin"`
Href string `json:"href"`
ServiceType int64 `json:"serviceType,string"`
System string `json:"system"`
RescheduleDescription string `json:"scheDesc"`
Time okcoinTime `json:"ts"`
} `json:"data"`
}
// WebsocketAccount represents an account information. Data will be pushed when triggered by events such as placing order, canceling order, transaction execution
type WebsocketAccount struct {
Arg struct {
Channel string `json:"channel"`
UID string `json:"uid"`
} `json:"arg"`
Data []struct {
AdjustedEquity string `json:"adjEq"`
Details []struct {
AvailableBalance types.Number `json:"availBal"`
AvailableEquity types.Number `json:"availEq"`
CashBalance types.Number `json:"cashBal"`
Currency string `json:"ccy"`
CoinUsdPrice types.Number `json:"coinUsdPrice"`
CrossLiab string `json:"crossLiab"`
DiscountEquity string `json:"disEq"`
Equity string `json:"eq"`
EquityUsd string `json:"eqUsd"`
FixedBalance types.Number `json:"fixedBal"`
FrozenBalance types.Number `json:"frozenBal"`
Interest types.Number `json:"interest"`
IsoEquity string `json:"isoEq"`
IsoLiability string `json:"isoLiab"`
IsoUpl string `json:"isoUpl"`
Liability types.Number `json:"liab"`
MaxLoan types.Number `json:"maxLoan"`
MgnRatio types.Number `json:"mgnRatio"`
NotionalLeverage string `json:"notionalLever"`
MarginFrozenOrders string `json:"ordFrozen"`
SpotInUseAmount string `json:"spotInUseAmt"`
StrategyEquity string `json:"stgyEq"`
Twap string `json:"twap"`
UPL string `json:"upl"` // Unrealized profit and loss
UpdateTime okcoinTime `json:"uTime"`
} `json:"details"`
FrozenEquity string `json:"imr"`
IsoEquity string `json:"isoEq"`
MarginRatio string `json:"mgnRatio"`
MaintenanceMarginRequirement string `json:"mmr"`
NotionalUsd types.Number `json:"notionalUsd"`
MarginOrderFrozen string `json:"ordFroz"`
TotalEquity string `json:"totalEq"`
UpdateTime okcoinTime `json:"uTime"`
} `json:"data"`
}
// WebsocketOrder represents and order information. Data will not be pushed when first subscribed.
type WebsocketOrder struct {
Arg struct {
Channel string `json:"channel"`
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
UID string `json:"uid"`
} `json:"arg"`
Data []struct {
AccFillSize types.Number `json:"accFillSz"`
AmendResult string `json:"amendResult"`
AveragePrice types.Number `json:"avgPx"`
CreateTime okcoinTime `json:"cTime"`
Category string `json:"category"`
Currency string `json:"ccy"`
ClientOrdID string `json:"clOrdId"`
Code string `json:"code"`
ExecType string `json:"execType"`
Fee types.Number `json:"fee"`
FeeCurrency string `json:"feeCcy"`
FillFee types.Number `json:"fillFee"`
FillFeeCurrency string `json:"fillFeeCcy"`
FillNotionalUsd types.Number `json:"fillNotionalUsd"`
FillPrice types.Number `json:"fillPx"`
FillSize types.Number `json:"fillSz"`
FillTime okcoinTime `json:"fillTime"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
Leverage types.Number `json:"lever"`
ErrorMessage string `json:"msg"`
NotionalUsd types.Number `json:"notionalUsd"`
OrderID string `json:"ordId"`
OrderType string `json:"ordType"`
ProfitAndLoss types.Number `json:"pnl"`
PositionSide string `json:"posSide"`
Price types.Number `json:"px"`
Rebate string `json:"rebate"`
RebateCurrency string `json:"rebateCcy"`
ReduceOnly bool `json:"reduceOnly,string"`
ClientRequestID string `json:"reqId"`
Side string `json:"side"`
StopLossOrderPrice types.Number `json:"slOrdPx"`
StopLossTriggerPrice types.Number `json:"slTriggerPx"`
StopLossTriggerPriceType string `json:"slTriggerPxType"`
Source string `json:"source"`
State string `json:"state"`
Size types.Number `json:"sz"`
Tag string `json:"tag"`
TradeMode string `json:"tdMode"`
TargetCurrency string `json:"tgtCcy"`
TakeProfitOrdPrice types.Number `json:"tpOrdPx"`
TakeProfitTriggerPrice types.Number `json:"tpTriggerPx"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType"`
TradeID string `json:"tradeId"`
UpdateTime okcoinTime `json:"uTime"`
} `json:"data"`
}
// WebsocketAlgoOrder represents algo orders (includes trigger order, oco order, conditional order).
type WebsocketAlgoOrder struct {
Arg struct {
Channel string `json:"channel"`
UID string `json:"uid"`
InstType string `json:"instType"`
InstrumentID string `json:"instId"`
} `json:"arg"`
Data []struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
OrderID string `json:"ordId"`
Currency string `json:"ccy"`
ClientOrderID string `json:"clOrdId"`
AlgoID string `json:"algoId"`
Price types.Number `json:"px"`
Size types.Number `json:"sz"`
TradeMode string `json:"tdMode"`
TgtCurrency string `json:"tgtCcy"`
NotionalUsd types.Number `json:"notionalUsd"`
OrderType string `json:"ordType"`
Side string `json:"side"`
PositionSide string `json:"posSide"`
State string `json:"state"`
Leverage float64 `json:"lever"`
TakeProfitTriggerPrice types.Number `json:"tpTriggerPx"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType"`
TakeProfitOrdPrice types.Number `json:"tpOrdPx"`
SlTriggerPrice types.Number `json:"slTriggerPx"`
SlTriggerPriceType string `json:"slTriggerPxType"`
TriggerPxType string `json:"triggerPxType"`
TriggerPrice types.Number `json:"triggerPx"`
OrderPrice types.Number `json:"ordPx"`
Tag string `json:"tag"`
ActualSize types.Number `json:"actualSz"`
ActualPrice types.Number `json:"actualPx"`
ActualSide string `json:"actualSide"`
TriggerTime okcoinTime `json:"triggerTime"`
CreateTime okcoinTime `json:"cTime"`
} `json:"data"`
}
// WebsocketAdvancedAlgoOrder represents advance algo orders (including Iceberg order, TWAP order, Trailing order).
type WebsocketAdvancedAlgoOrder struct {
Arg struct {
Channel string `json:"channel"`
UID string `json:"uid"`
InstType string `json:"instType"`
InstrumentID string `json:"instId"`
} `json:"arg"`
Data []struct {
ActualPx types.Number `json:"actualPx"`
ActualSide string `json:"actualSide"`
ActualSz types.Number `json:"actualSz"`
AlgoID string `json:"algoId"`
CreationTime okcoinTime `json:"cTime"`
Ccy string `json:"ccy"`
ClOrdID string `json:"clOrdId"`
Count string `json:"count"`
InstrumentID string `json:"instId"`
InstType string `json:"instType"`
Lever types.Number `json:"lever"`
NotionalUsd types.Number `json:"notionalUsd"`
OrderPrice types.Number `json:"ordPx"`
OrderType string `json:"ordType"`
PushTime okcoinTime `json:"pTime"`
PosSide string `json:"posSide"`
PriceLimit types.Number `json:"pxLimit"`
PriceSpread types.Number `json:"pxSpread"`
PriceVar types.Number `json:"pxVar"`
Side string `json:"side"`
StopLossOrdPrice string `json:"slOrdPx"`
StopLossTriggerPrice string `json:"slTriggerPx"`
State string `json:"state"`
Size types.Number `json:"sz"`
SizeLimit types.Number `json:"szLimit"`
TradeMode string `json:"tdMode"`
TimeInterval string `json:"timeInterval"`
TakeProfitOrdPx types.Number `json:"tpOrdPx"`
TakeProfitTriggerPx types.Number `json:"tpTriggerPx"`
Tag string `json:"tag"`
TriggerPrice types.Number `json:"triggerPx"`
TriggerTime string `json:"triggerTime"`
CallbackRatio string `json:"callbackRatio"`
CallbackSpread string `json:"callbackSpread"`
ActivePrice types.Number `json:"activePx"`
MoveTriggerPrice types.Number `json:"moveTriggerPx"`
} `json:"data"`
}
// WebsocketInstrumentData contains formatted data for instruments related websocket responses
type WebsocketInstrumentData struct {
Alias string `json:"alias"`
BaseCurrency string `json:"baseCcy"`
Category string `json:"category"`
ContractMultiplier string `json:"ctMult"`
ContractType string `json:"ctType"`
ContractValue string `json:"ctVal"`
ContractValueCurrency string `json:"ctValCcy"`
ExpiryTime okcoinTime `json:"expTime"`
InstrumentFamily string `json:"instFamily"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
Leverage types.Number `json:"lever"`
ListTime okcoinTime `json:"listTime"`
LotSize types.Number `json:"lotSz"`
MaxIcebergSize types.Number `json:"maxIcebergSz"`
MaxLimitSize types.Number `json:"maxLmtSz"`
MaxMarketSize types.Number `json:"maxMktSz"`
MaxStopSize types.Number `json:"maxStopSz"`
MaxTriggerSize types.Number `json:"maxTriggerSz"`
MaxTwapSize types.Number `json:"maxTwapSz"`
MinimumOrderSize types.Number `json:"minSz"`
OptionType string `json:"optType"`
QuoteCurrency string `json:"quoteCcy"`
SettleCurrency string `json:"settleCcy"`
State string `json:"state"`
StrikePrice types.Number `json:"stk"`
TickSize types.Number `json:"tickSz"`
Underlying string `json:"uly"`
}
// WsTickerData contains formatted data for ticker related websocket responses
type WsTickerData struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
Last types.Number `json:"last"`
LastSize types.Number `json:"lastSz"`
AskPrice types.Number `json:"askPx"`
AskSize types.Number `json:"askSz"`
BidPrice types.Number `json:"bidPx"`
BidSize types.Number `json:"bidSz"`
Open24H types.Number `json:"open24h"`
High24H types.Number `json:"high24h"`
Low24H types.Number `json:"low24h"`
SodUtc0 string `json:"sodUtc0"`
SodUtc8 string `json:"sodUtc8"`
VolCcy24H types.Number `json:"volCcy24h"`
Vol24H types.Number `json:"vol24h"`
Timestamp okcoinTime `json:"ts"`
}
// WebsocketTradeResponse contains formatted data for trade related websocket responses
type WebsocketTradeResponse struct {
Arg struct {
Channel string `json:"channel"`
InstrumentID string `json:"instId"`
} `json:"arg"`
Data []struct {
InstrumentID string `json:"instId"`
TradeID string `json:"tradeId"`
Price types.Number `json:"px"`
Size types.Number `json:"sz"`
Side string `json:"side"`
Timestamp okcoinTime `json:"ts"`
} `json:"data"`
}
// WebsocketCandlesResponse represents a candlestick response data.
type WebsocketCandlesResponse struct {
Arg struct {
Channel string `json:"channel"`
InstrumentID string `json:"instId"`
} `json:"arg"`
Data [][]string `json:"data"`
}
// WebsocketOrderBooksData is the full websocket response containing orderbook data
type WebsocketOrderBooksData struct {
Table string `json:"table"`
Action string `json:"action"`
Data []WebsocketOrderBook `json:"data"`
}
// WebsocketErrorResponse yo
type WebsocketErrorResponse struct {
Event string `json:"event"`
Message string `json:"message"`
ErrorCode int64 `json:"errorCode"`
}
// List of all websocket channels to subscribe to
const (
okcoinWsRateLimit = 30
allowableIterations = 25
maxConnByteLen = 4096
)
// SystemStatus represents system status
type SystemStatus struct {
Title string `json:"title"`
State string `json:"state"`
Begin okcoinTime `json:"begin"`
End okcoinTime `json:"end"`
Href string `json:"href"`
ServiceType string `json:"serviceType"`
System string `json:"system"`
ScheDesc string `json:"scheDesc"`
}
// Instrument represents an instrument in an open contract.
type Instrument struct {
Alias string `json:"alias"`
BaseCurrency string `json:"baseCcy"`
Category string `json:"category"`
CtMult string `json:"ctMult"`
CtType string `json:"ctType"`
CtVal string `json:"ctVal"`
CtValCurrency string `json:"ctValCcy"`
ExpTime okcoinTime `json:"expTime"`
InstFamily string `json:"instFamily"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
Leverage types.Number `json:"lever"`
ListTime okcoinTime `json:"listTime"`
LotSize types.Number `json:"lotSz"`
MaxIcebergSz types.Number `json:"maxIcebergSz"`
MaxLimitSize types.Number `json:"maxLmtSz"`
MaxMarketSize types.Number `json:"maxMktSz"`
MaxStopSize types.Number `json:"maxStopSz"`
MaxTwapSize types.Number `json:"maxTwapSz"`
MaxTriggerSize types.Number `json:"maxTriggerSz"`
MinSize types.Number `json:"minSz"` // Minimum order size
QuoteCurrency string `json:"quoteCcy"`
OptionType string `json:"optType"`
SettleCurrency string `json:"settleCcy"`
State string `json:"state"`
StrikePrice types.Number `json:"stk"`
TickSize types.Number `json:"tickSz"`
Underlying string `json:"uly"`
}
type candlestickItemResponse [9]string
// CandlestickData represents the candlestick chart
type CandlestickData struct {
Timestamp okcoinTime
OpenPrice float64
HighestPrice float64
LowestPrice float64
ClosePrice float64
TradingVolume float64
QuoteTradingVolume float64
TradingVolumeInQuote float64
Confirm string
}
// SpotTrade represents spot trades
type SpotTrade struct {
InstrumentID string `json:"instId"`
Side string `json:"side"`
TradeSize types.Number `json:"sz"`
TradePrice types.Number `json:"px"`
TradeID string `json:"tradeId"`
Timestamp okcoinTime `json:"ts"`
}
// TradingVolume represents the trading volume of the platform in 24 hours
type TradingVolume struct {
VolCny types.Number `json:"volCny"`
VolUsd types.Number `json:"volUsd"`
Timestamp okcoinTime `json:"ts"`
}
// Oracle represents crypto price of signing using Open Oracle smart contract.
type Oracle []struct {
Messages []string `json:"messages"`
Prices map[string]string `json:"prices"`
Signatures []string `json:"signatures"`
Timestamp okcoinTime `json:"timestamp"`
}
// ExchangeRate represents average exchange rate data
type ExchangeRate struct {
UsdCny string `json:"usdCny"`
}
// ToExtract returns a CandlestickData instance from []string
func (c *candlestickItemResponse) ToExtract() (CandlestickData, error) {
var candle CandlestickData
err := candle.Timestamp.UnmarshalJSON([]byte(c[0]))
if err != nil {
return candle, err
}
candle.OpenPrice, err = strconv.ParseFloat(c[1], 64)
if err != nil {
return candle, err
}
candle.HighestPrice, err = strconv.ParseFloat(c[2], 64)
if err != nil {
return candle, err
}
candle.LowestPrice, err = strconv.ParseFloat(c[3], 64)
if err != nil {
return candle, err
}
candle.ClosePrice, err = strconv.ParseFloat(c[4], 64)
if err != nil {
return candle, err
}
candle.TradingVolume, err = strconv.ParseFloat(c[5], 64)
if err != nil {
return candle, err
}
if c[6] != "" {
candle.QuoteTradingVolume, err = strconv.ParseFloat(c[6], 64)
if err != nil {
return candle, err
}
}
if c[7] != "" {
candle.TradingVolumeInQuote, err = strconv.ParseFloat(c[7], 64)
if err != nil {
return candle, err
}
}
candle.Confirm = c[8]
return candle, nil
}
// ExtractCandlesticks retrieves a list of CandlestickData
func ExtractCandlesticks(candles []candlestickItemResponse) ([]CandlestickData, error) {
candlestickData := make([]CandlestickData, len(candles))
var err error
for x := range candles {
candlestickData[x], err = candles[x].ToExtract()
if err != nil {
return nil, err
}
}
return candlestickData, nil
}
// CurrencyInfo represents a currency instance detailed information
type CurrencyInfo struct {
CanDep bool `json:"canDep"`
CanInternal bool `json:"canInternal"`
CanWd bool `json:"canWd"`
Currency string `json:"ccy"`
Chain string `json:"chain"`
DepQuotaFixed string `json:"depQuotaFixed"`
DepQuoteDailyLayer2 string `json:"depQuoteDailyLayer2"`
LogoLink string `json:"logoLink"`
MainNet bool `json:"mainNet"`
MaxFee types.Number `json:"maxFee"`
MaxWithdrawal types.Number `json:"maxWd"`
MinDeposit types.Number `json:"minDep"`
MinDepArrivalConfirm string `json:"minDepArrivalConfirm"`
MinFee types.Number `json:"minFee"`
MinWithdrawal types.Number `json:"minWd"`
MinWithdrawalUnlockConfirm string `json:"minWdUnlockConfirm"`
Name string `json:"name"`
NeedTag bool `json:"needTag"`
UsedDepQuotaFixed string `json:"usedDepQuotaFixed"`
UsedWdQuota string `json:"usedWdQuota"`
WithdrawalQuota string `json:"wdQuota"`
WithdrawalTickSize types.Number `json:"wdTickSz"`
}
// CurrencyBalance represents a currency balance information.
type CurrencyBalance struct {
AvailableBalance types.Number `json:"availBal"`
Balance types.Number `json:"bal"`
Currency string `json:"ccy"`
FrozenBalance types.Number `json:"frozenBal"`
}
// AccountAssetValuation represents account asset valuation
type AccountAssetValuation struct {
Details struct {
Classic types.Number `json:"classic"`
Earn types.Number `json:"earn"`
Funding types.Number `json:"funding"`
Trading types.Number `json:"trading"`
} `json:"details"`
TotalBalance types.Number `json:"totalBal"`
Timestamp okcoinTime `json:"ts"`
}
// FundingTransferRequest represents a transfer of funds between your funding account and trading account
type FundingTransferRequest struct {
Currency currency.Code `json:"ccy"`
// Transfer type
// 0: transfer within account
// 1: master account to sub-account (Only applicable to APIKey from master account)
// 2: sub-account to master account (Only applicable to APIKey from master account)
// 3: sub-account to master account (Only applicable to APIKey from sub-account)
// The default is 0.
Amount float64 `json:"amt,string"`
From string `json:"from"`
To string `json:"to"`
TransferType int32 `json:"type,string,omitempty"`
SubAccount string `json:"subAcct,omitempty"`
ClientID string `json:"clientId,omitempty"`
}
// FundingTransferItem represents a response for a transfer of funds between your funding account and trading account
type FundingTransferItem struct {
TransferID string `json:"transId"`
Currency string `json:"ccy"`
ClientID string `json:"clientId"`
From string `json:"from"`
Amount types.Number `json:"amt"`
InstrumentID string `json:"instId"`
State string `json:"state"`
SubAcct string `json:"subAcct"`
To string `json:"to"`
ToInstrumentID string `json:"toInstId"`
Type string `json:"type"`
}
// AssetBillDetail represents the billing record.
type AssetBillDetail struct {
BillID string `json:"billId"`
Currency string `json:"ccy"`
ClientID string `json:"clientId"`
BalChange types.Number `json:"balChg"`
Balance types.Number `json:"bal"`
Type string `json:"type"`
Timestamp okcoinTime `json:"ts"`
}
// LightningDepositDetail represents a lightning deposit instance detail
type LightningDepositDetail struct {
CreationTime okcoinTime `json:"cTime"`
Invoice string `json:"invoice"`
}
// DepositAddress represents a currency deposit address detail
type DepositAddress struct {
Chain string `json:"chain"`
ContractAddr string `json:"ctAddr"`
Ccy string `json:"ccy"`
To string `json:"to"`
Address string `json:"addr"`
Selected bool `json:"selected"`
Tag string `json:"tag"`
Memo string `json:"memo"`
DepositPaymentID string `json:"pmtId"`
DepositAddressAttachment string `json:"addrEx"`
}
// DepositHistoryItem represents deposit records according to the currency, deposit status, and time range in reverse chronological order.
type DepositHistoryItem struct {
ActualDepBlkConfirm string `json:"actualDepBlkConfirm"` // ActualDepBlkConfirm actual amount of blockchain confirm in a single deposit
Amount types.Number `json:"amt"`
Currency string `json:"ccy"`
Chain string `json:"chain"`
DepositID string `json:"depId"`
From string `json:"from"`
State string `json:"state"`
To string `json:"to"`
Timestamp okcoinTime `json:"ts"`
TransactionID string `json:"txId"`
}
// WithdrawalRequest represents withdrawal of tokens request.
type WithdrawalRequest struct {
Amount float64 `json:"amt,string,omitempty"`
TransactionFee float64 `json:"fee,string"`
WithdrawalMethod string `json:"dest,omitempty"` // Withdrawal method 3: internal 4: on chain
Ccy currency.Code `json:"ccy,omitempty"`
Chain string `json:"chain,omitempty"`
ClientID string `json:"clientId,omitempty"`
ToAddress string `json:"toAddr,omitempty"`
}
// WithdrawalResponse represents withdrawal of tokens response.
type WithdrawalResponse struct {
Amt types.Number `json:"amt"`
WdID string `json:"wdId"`
Currency string `json:"ccy"`
ClientID string `json:"clientId"`
Chain string `json:"chain"`
}
// LightningWithdrawalsRequest represents lightning withdrawal request params
type LightningWithdrawalsRequest struct {
Ccy currency.Code `json:"ccy"`
Invoice string `json:"invoice"`
Memo string `json:"memo,omitempty"`
}
// LightningWithdrawals the minimum withdrawal amount is approximately 0.000001 BTC. Sub-account does not support withdrawal.
type LightningWithdrawals struct {
WithdrawalID string `json:"wdId"`
CreationTime okcoinTime `json:"cTime"`
}
// WithdrawalCancellation represents a request parameter for withdrawal cancellation
type WithdrawalCancellation struct {
WithdrawalID string `json:"wdId"`
}
// WithdrawalOrderItem represents a withdrawal instance item
type WithdrawalOrderItem struct {
Ccy string `json:"ccy"`
Chain string `json:"chain"`
Amount types.Number `json:"amt"`
Timestamp okcoinTime `json:"ts"`
RemittingAddress string `json:"from"`
ReceivingAddress string `json:"to"`
Tag string `json:"tag"`
PaymentID string `json:"pmtId"`
Memo string `json:"memo"`
WithdrawalAddressAttachment string `json:"addrEx"`
TransactionID string `json:"txId"`
Fee types.Number `json:"fee"`
State string `json:"state"`
WithdrawalID string `json:"wdId"`
ClientID string `json:"clientId"`
}
// AccountBalanceInformation represents currency balance information.
type AccountBalanceInformation struct {
AdjustedEquity string `json:"adjEq"` // Adjusted / Effective equity in USD . Not enabled. Please disregard.
Details []struct {
AvailableBalance types.Number `json:"availBal"`
AvailableEquity types.Number `json:"availEq"`
CashBalance types.Number `json:"cashBal"`
Currency string `json:"ccy"`
CrossLiability string `json:"crossLiab"`
DiscountEquity string `json:"disEq"`
Equity types.Number `json:"eq"`
EquityUsd types.Number `json:"eqUsd"`
FixedBalance types.Number `json:"fixedBal"`
FrozenBalance types.Number `json:"frozenBal"`
Interest types.Number `json:"interest"`
IsolatedEquity types.Number `json:"isoEq"`
IsolatedLiability types.Number `json:"isoLiab"`
IsolatedUpl string `json:"isoUpl"` // Isolated unrealized profit and loss of the currency. Not enabled. Please disregard.
Liability types.Number `json:"liab"`
MaxLoan types.Number `json:"maxLoan"`
MarginRatio types.Number `json:"mgnRatio"`
NotionalLever types.Number `json:"notionalLever"`
OrderFrozen types.Number `json:"ordFrozen"`
SpotInUseAmount types.Number `json:"spotInUseAmt"`
StrategyEquity string `json:"stgyEq"`
Twap string `json:"twap"`
UpdateTime okcoinTime `json:"uTime"`
UnrealizedProfitAndLoss types.Number `json:"upl"`
UnrealizedProfitAndLossLiability string `json:"uplLiab"`
} `json:"details"`
IMR string `json:"imr"` // Frozen equity for open positions and pending orders in USD.
IsolatedEquity string `json:"isoEq"`
MarginRatio types.Number `json:"mgnRatio"`
Mmr string `json:"mmr"` // Maintenance margin requirement in USD.
NotionalUsd types.Number `json:"notionalUsd"`
OrdFroz string `json:"ordFroz"`
TotalEq string `json:"totalEq"`
UpdateTime okcoinTime `json:"uTime"`
}
// BillsDetail represents a bill
type BillsDetail struct {
Balance types.Number `json:"bal"`
BalanceChange types.Number `json:"balChg"`
BillID string `json:"billId"`
Currency string `json:"ccy"`
ExecType string `json:"execType"`
Fee types.Number `json:"fee"`
From string `json:"from"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
MarginMode string `json:"mgnMode"`
Notes string `json:"notes"`
OrderID string `json:"ordId"`
ProfitAndLoss types.Number `json:"pnl"`
PosBalance types.Number `json:"posBal"`
PosBalanceChange types.Number `json:"posBalChg"`
BillSubType string `json:"subType"`
Size types.Number `json:"sz"`
To string `json:"to"`
BillType string `json:"type"`
Timestamp okcoinTime `json:"ts"`
}
// AccountConfiguration represents account configuration information.
type AccountConfiguration struct {
AccountLevel string `json:"acctLv"`
AutoLoan bool `json:"autoLoan"`
ContractIsolatedMode string `json:"ctIsoMode"`
GreeksType string `json:"greeksType"`
Level string `json:"level"`
LevelTemporary string `json:"levelTmp"`
MarginIsolatedMode string `json:"mgnIsoMode"`
PositionMode string `json:"posMode"`
SpotOffsetType string `json:"spotOffsetType"`
UID string `json:"uid"`
}
// MaxBuySellResp represent a maximum buy sell or open amount information.
type MaxBuySellResp struct {
Currency string `json:"ccy"`
InstrumentID string `json:"instId"`
MaxBuy types.Number `json:"maxBuy"`
MaxSell types.Number `json:"maxSell"`
}
// AvailableTradableAmount represents maximum available tradable amount information
type AvailableTradableAmount struct {
AvailableBuy types.Number `json:"availBuy"`
AvailableSell types.Number `json:"availSell"`
InstrumentID string `json:"instId"`
}
// FeeRate represents instrument trading fee information.
type FeeRate struct {
Category string `json:"category"`
Delivery string `json:"delivery"`
Exercise string `json:"exercise"`
InstrumentType string `json:"instType"`
Level string `json:"level"`
MakerFeeRate types.Number `json:"maker"`
MakerU types.Number `json:"makerU"`
MakerUSDC types.Number `json:"makerUSDC"`
TakerFeeRate types.Number `json:"taker"`
TakerU types.Number `json:"takerU"`
TakerUSDC types.Number `json:"takerUSDC"`
Timestamp okcoinTime `json:"ts"`
}
// MaximumWithdrawal represents maximum withdrawal information for currency.
type MaximumWithdrawal struct {
Currency string `json:"ccy"`
MaxWithdrawal string `json:"maxWd"`
MaxWithdrawalEx string `json:"maxWdEx"`
SpotOffsetMaxWd string `json:"spotOffsetMaxWd"`
SpotOffsetMaxWdEx string `json:"spotOffsetMaxWdEx"`
}
// AvailableRFQPair represents list of instruments and
type AvailableRFQPair struct {
Instruments []struct {
BaseCurrency string `json:"baseCcy"`
BaseCurrencyIcon string `json:"baseCcyIcon"`
BaseSingleMin types.Number `json:"baseSingleMin"`
InstrumentID string `json:"instId"`
QuoteCurrency string `json:"quoteCcy"`
QuoteCurrencyIcon string `json:"quoteCcyIcon"`
QuoteSingleMin types.Number `json:"quoteSingleMin"`
} `json:"instruments"`
Timestamp okcoinTime `json:"ts"`
}
// QuoteRequestArg market quotation information
type QuoteRequestArg struct {
BaseCurrency currency.Code `json:"baseCcy"`
QuoteCurrency currency.Code `json:"quoteCcy"`
Side string `json:"side"`
RfqSize float64 `json:"rfqSz,string"` // Amount
RfqSzCurrency currency.Code `json:"rfqSzCcy"` // Token
ClientDefinedQuoteRequestID string `json:"clQReqId,omitempty"`
ClientRequestTimestamp string `json:"clQReqTs,omitempty"`
}