/
okx_types.go
3213 lines (2902 loc) · 135 KB
/
okx_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 okx
import (
"encoding/json"
"strconv"
"time"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/types"
)
const (
// Trade Modes
// TradeModeCross trade mode, cross
TradeModeCross = "cross"
// TradeModeIsolated trade mode, isolated
TradeModeIsolated = "isolated"
// TradeModeCash trade mode, cash
TradeModeCash = "cash"
// Algo Order Types
// AlgoOrdTypeGrid algo order type,grid
AlgoOrdTypeGrid = "grid"
// AlgoOrdTypeContractGrid algo order type, contract_grid
AlgoOrdTypeContractGrid = "contract_grid"
// Position Side for placing order
positionSideLong = "long"
positionSideShort = "short"
positionSideNet = "net"
)
const (
// OkxOrderLimit Limit order
OkxOrderLimit = "limit"
// OkxOrderMarket Market order
OkxOrderMarket = "market"
// OkxOrderPostOnly POST_ONLY order type
OkxOrderPostOnly = "post_only"
// OkxOrderFOK fill or kill order type
OkxOrderFOK = "fok"
// OkxOrderIOC IOC (immediate or cancel)
OkxOrderIOC = "ioc"
// OkxOrderOptimalLimitIOC OPTIMAL_LIMIT_IOC
OkxOrderOptimalLimitIOC = "optimal_limit_ioc"
// Instrument Types ( Asset Types )
okxInstTypeFutures = "FUTURES" // Okx Instrument Type "futures"
okxInstTypeANY = "ANY" // Okx Instrument Type ""
okxInstTypeSpot = "SPOT" // Okx Instrument Type "spot"
okxInstTypeSwap = "SWAP" // Okx Instrument Type "swap"
okxInstTypeOption = "OPTION" // Okx Instrument Type "option"
okxInstTypeMargin = "MARGIN" // Okx Instrument Type "margin"
okxInstTypeContract = "CONTRACT" // Okx Instrument Type "contract"
operationSubscribe = "subscribe"
operationUnsubscribe = "unsubscribe"
operationLogin = "login"
)
// testNetKey this key is designed for using the testnet endpoints
// setting context.WithValue(ctx, testNetKey("testnet"), useTestNet)
// will ensure the appropriate headers are sent to OKx to use the testnet
type testNetKey string
var testNetVal = testNetKey("testnet")
// Market Data Endpoints
// TickerResponse represents the market data endpoint ticker detail
type TickerResponse struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
LastTradePrice types.Number `json:"last"`
LastTradeSize 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"`
High24H types.Number `json:"high24h"`
Low24H types.Number `json:"low24h"`
VolCcy24H types.Number `json:"volCcy24h"`
Vol24H types.Number `json:"vol24h"`
OpenPriceInUTC0 string `json:"sodUtc0"`
OpenPriceInUTC8 string `json:"sodUtc8"`
TickerDataGenerationTime okxUnixMilliTime `json:"ts"`
}
// IndexTicker represents Index ticker data.
type IndexTicker struct {
InstID string `json:"instId"`
IdxPx types.Number `json:"idxPx"`
High24H types.Number `json:"high24h"`
SodUtc0 types.Number `json:"sodUtc0"`
Open24H types.Number `json:"open24h"`
Low24H types.Number `json:"low24h"`
SodUtc8 types.Number `json:"sodUtc8"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// OrderBookResponse holds the order asks and bids at a specific timestamp
type OrderBookResponse struct {
Asks [][4]string `json:"asks"`
Bids [][4]string `json:"bids"`
GenerationTimeStamp okxUnixMilliTime `json:"ts"`
}
// OrderBookResponseDetail holds the order asks and bids in a struct field with the corresponding order generation timestamp.
type OrderBookResponseDetail struct {
Asks []OrderAsk
Bids []OrderBid
GenerationTimestamp time.Time
}
// OrderAsk represents currencies bid detailed information.
type OrderAsk struct {
DepthPrice float64
NumberOfContracts float64
LiquidationOrders int64
NumberOfOrders int64
}
// OrderBid represents currencies bid detailed information.
type OrderBid struct {
DepthPrice float64
BaseCurrencies float64
LiquidationOrders int64
NumberOfOrders int64
}
// GetOrderBookResponseDetail returns the OrderBookResponseDetail instance from OrderBookResponse object.
func (a *OrderBookResponse) GetOrderBookResponseDetail() (*OrderBookResponseDetail, error) {
asks, er := a.GetAsks()
if er != nil {
return nil, er
}
bids, er := a.GetBids()
if er != nil {
return nil, er
}
return &OrderBookResponseDetail{
Asks: asks,
Bids: bids,
GenerationTimestamp: a.GenerationTimeStamp.Time(),
}, nil
}
// GetAsks returns list of asks from an order book response instance.
func (a *OrderBookResponse) GetAsks() ([]OrderAsk, error) {
asks := make([]OrderAsk, len(a.Asks))
for x := range a.Asks {
depthPrice, er := strconv.ParseFloat(a.Asks[x][0], 64)
if er != nil {
return nil, er
}
contracts, er := strconv.ParseFloat(a.Asks[x][1], 64)
if er != nil {
return nil, er
}
liquidation, er := strconv.ParseInt(a.Asks[x][2], 10, 64)
if er != nil {
return nil, er
}
orders, er := strconv.ParseInt(a.Asks[x][3], 10, 64)
if er != nil {
return nil, er
}
asks[x] = OrderAsk{
DepthPrice: depthPrice,
NumberOfContracts: contracts,
LiquidationOrders: liquidation,
NumberOfOrders: orders,
}
}
return asks, nil
}
// GetBids returns list of order bids instance from list of slice.
func (a *OrderBookResponse) GetBids() ([]OrderBid, error) {
bids := make([]OrderBid, len(a.Bids))
for x := range a.Bids {
depthPrice, er := strconv.ParseFloat(a.Bids[x][0], 64)
if er != nil {
return nil, er
}
currencies, er := strconv.ParseFloat(a.Bids[x][1], 64)
if er != nil {
return nil, er
}
liquidation, er := strconv.ParseInt(a.Bids[x][2], 10, 64)
if er != nil {
return nil, er
}
orders, er := strconv.ParseInt(a.Bids[x][3], 10, 64)
if er != nil {
return nil, er
}
bids[x] = OrderBid{
DepthPrice: depthPrice,
BaseCurrencies: currencies,
LiquidationOrders: liquidation,
NumberOfOrders: orders,
}
}
return bids, nil
}
// CandleStick holds candlestick price data
type CandleStick struct {
OpenTime time.Time
OpenPrice float64
HighestPrice float64
LowestPrice float64
ClosePrice float64
Volume float64
QuoteAssetVolume float64
}
// TradeResponse represents the recent transaction instance.
type TradeResponse struct {
InstrumentID string `json:"instId"`
TradeID string `json:"tradeId"`
Price types.Number `json:"px"`
Quantity types.Number `json:"sz"`
Side order.Side `json:"side"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// TradingVolumeIn24HR response model.
type TradingVolumeIn24HR struct {
BlockVolumeInCNY types.Number `json:"blockVolCny"`
BlockVolumeInUSD types.Number `json:"blockVolUsd"`
TradingVolumeInUSD types.Number `json:"volUsd"`
TradingVolumeInCny types.Number `json:"volCny"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// OracleSmartContractResponse returns the crypto price of signing using Open Oracle smart contract.
type OracleSmartContractResponse struct {
Messages []string `json:"messages"`
Prices map[string]string `json:"prices"`
Signatures []string `json:"signatures"`
Timestamp okxUnixMilliTime `json:"timestamp"`
}
// UsdCnyExchangeRate the exchange rate for converting from USD to CNV
type UsdCnyExchangeRate struct {
UsdCny types.Number `json:"usdCny"`
}
// IndexComponent represents index component data on the market
type IndexComponent struct {
Components []IndexComponentItem `json:"components"`
Last types.Number `json:"last"`
Index string `json:"index"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// IndexComponentItem an item representing the index component item
type IndexComponentItem struct {
Symbol string `json:"symbol"`
SymbolPairPrice string `json:"symbolPx"`
Weights string `json:"wgt"`
ConvertToPrice string `json:"cnvPx"`
ExchangeName string `json:"exch"`
}
// InstrumentsFetchParams request params for requesting list of instruments
type InstrumentsFetchParams struct {
InstrumentType string // Mandatory
Underlying string // Optional
InstrumentID string // Optional
}
// Instrument representing an instrument with open contract.
type Instrument struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
InstrumentFamily string `json:"instFamily"`
Underlying string `json:"uly"`
Category string `json:"category"`
BaseCurrency string `json:"baseCcy"`
QuoteCurrency string `json:"quoteCcy"`
SettlementCurrency string `json:"settleCcy"`
ContractValue types.Number `json:"ctVal"`
ContractMultiplier types.Number `json:"ctMult"`
ContractValueCurrency string `json:"ctValCcy"`
OptionType string `json:"optType"`
StrikePrice string `json:"stk"`
ListTime okxTime `json:"listTime"`
ExpTime okxTime `json:"expTime"`
MaxLeverage types.Number `json:"lever"`
TickSize types.Number `json:"tickSz"`
LotSize types.Number `json:"lotSz"`
MinimumOrderSize types.Number `json:"minSz"`
ContractType string `json:"ctType"`
Alias string `json:"alias"`
State string `json:"state"`
MaxQuantityOfSpotLimitOrder types.Number `json:"maxLmtSz"`
MaxQuantityOfMarketLimitOrder types.Number `json:"maxMktSz"`
MaxQuantityOfSpotTwapLimitOrder types.Number `json:"maxTwapSz"`
MaxSpotIcebergSize types.Number `json:"maxIcebergSz"`
MaxTriggerSize types.Number `json:"maxTriggerSz"`
MaxStopSize types.Number `json:"maxStopSz"`
}
// DeliveryHistoryDetail holds instrument id and delivery price information detail
type DeliveryHistoryDetail struct {
Type string `json:"type"`
InstrumentID string `json:"insId"`
DeliveryPrice types.Number `json:"px"`
}
// DeliveryHistory represents list of delivery history detail items and timestamp information
type DeliveryHistory struct {
Timestamp okxUnixMilliTime `json:"ts"`
Details []DeliveryHistoryDetail `json:"details"`
}
// OpenInterest Retrieve the total open interest for contracts on OKX.
type OpenInterest struct {
InstrumentType asset.Item `json:"instType"`
InstrumentID string `json:"instId"`
OpenInterest types.Number `json:"oi"`
OpenInterestCurrency types.Number `json:"oiCcy"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// FundingRateResponse response data for the Funding Rate for an instruction type
type FundingRateResponse struct {
FundingRate types.Number `json:"fundingRate"`
RealisedRate types.Number `json:"realizedRate"`
FundingTime okxUnixMilliTime `json:"fundingTime"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
NextFundingRate types.Number `json:"nextFundingRate"`
NextFundingTime okxUnixMilliTime `json:"nextFundingTime"`
}
// LimitPriceResponse hold an information for
type LimitPriceResponse struct {
InstrumentType string `json:"instType"`
InstID string `json:"instId"`
BuyLimit types.Number `json:"buyLmt"`
SellLimit types.Number `json:"sellLmt"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// OptionMarketDataResponse holds response data for option market data
type OptionMarketDataResponse struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
Underlying string `json:"uly"`
Delta types.Number `json:"delta"`
Gamma types.Number `json:"gamma"`
Theta types.Number `json:"theta"`
Vega types.Number `json:"vega"`
DeltaBS types.Number `json:"deltaBS"`
GammaBS types.Number `json:"gammaBS"`
ThetaBS types.Number `json:"thetaBS"`
VegaBS types.Number `json:"vegaBS"`
RealVol string `json:"realVol"`
BidVolatility string `json:"bidVol"`
AskVolatility types.Number `json:"askVol"`
MarkVolatility types.Number `json:"markVol"`
Leverage types.Number `json:"lever"`
ForwardPrice string `json:"fwdPx"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// DeliveryEstimatedPrice holds an estimated delivery or exercise price response.
type DeliveryEstimatedPrice struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
EstimatedDeliveryPrice string `json:"settlePx"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// DiscountRate represents the discount rate amount, currency, and other discount related information.
type DiscountRate struct {
Amount string `json:"amt"`
Currency string `json:"ccy"`
DiscountInfo []DiscountRateInfoItem `json:"discountInfo"`
DiscountRateLevel string `json:"discountLv"`
}
// DiscountRateInfoItem represents discount info list item for discount rate response
type DiscountRateInfoItem struct {
DiscountRate string `json:"discountRate"`
MaxAmount types.Number `json:"maxAmt"`
MinAmount types.Number `json:"minAmt"`
}
// ServerTime returning the server time instance.
type ServerTime struct {
Timestamp okxUnixMilliTime `json:"ts"`
}
// LiquidationOrderRequestParams holds information to request liquidation orders
type LiquidationOrderRequestParams struct {
InstrumentType string
MarginMode string // values are either isolated or crossed
InstrumentID string
Currency currency.Code
Underlying string
Alias string
State string
Before time.Time
After time.Time
Limit int64
}
// LiquidationOrder represents liquidation order item detailed information
type LiquidationOrder struct {
Details []LiquidationOrderDetailItem `json:"details"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
TotalLoss string `json:"totalLoss"`
Underlying string `json:"uly"`
}
// LiquidationOrderDetailItem represents the detail information of liquidation order
type LiquidationOrderDetailItem struct {
BankruptcyLoss string `json:"bkLoss"`
BankruptcyPx string `json:"bkPx"`
Currency string `json:"ccy"`
PosSide string `json:"posSide"`
Side string `json:"side"` // May be empty
QuantityOfLiquidation types.Number `json:"sz"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// MarkPrice represents a mark price information for a single instrument id
type MarkPrice struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
MarkPrice string `json:"markPx"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// PositionTiers represents position tier detailed information.
type PositionTiers struct {
BaseMaxLoan string `json:"baseMaxLoan"`
InitialMarginRequirement string `json:"imr"`
InstrumentID string `json:"instId"`
MaximumLeverage string `json:"maxLever"`
MaximumSize types.Number `json:"maxSz"`
MinSize types.Number `json:"minSz"`
MaintenanceMarginRequirement string `json:"mmr"`
OptionalMarginFactor string `json:"optMgnFactor"`
QuoteMaxLoan string `json:"quoteMaxLoan"`
Tier string `json:"tier"`
Underlying string `json:"uly"`
}
// InterestRateLoanQuotaBasic holds the basic Currency, loan,and interest rate information.
type InterestRateLoanQuotaBasic struct {
Currency string `json:"ccy"`
LoanQuota string `json:"quota"`
InterestRate types.Number `json:"rate"`
}
// InterestRateLoanQuotaItem holds the basic Currency, loan,interest rate, and other level and VIP related information.
type InterestRateLoanQuotaItem struct {
InterestRateLoanQuotaBasic
InterestRateDiscount types.Number `json:"0.7"`
LoanQuotaCoefficient types.Number `json:"loanQuotaCoef"`
Level string `json:"level"`
}
// VIPInterestRateAndLoanQuotaInformation holds interest rate and loan quoata information for VIP users.
type VIPInterestRateAndLoanQuotaInformation struct {
InterestRateLoanQuotaBasic
LevelList []struct {
Level string `json:"level"`
LoanQuota types.Number `json:"loanQuota"`
} `json:"levelList"`
}
// InsuranceFundInformationRequestParams insurance fund balance information.
type InsuranceFundInformationRequestParams struct {
InstrumentType string `json:"instType"`
Type string `json:"type"` // Type values allowed are `liquidation_balance_deposit, bankruptcy_loss, and platform_revenue`
Underlying string `json:"uly"`
Currency string `json:"ccy"`
Before time.Time `json:"before"`
After time.Time `json:"after"`
Limit int64 `json:"limit"`
}
// InsuranceFundInformation holds insurance fund information data.
type InsuranceFundInformation struct {
Details []InsuranceFundInformationDetail `json:"details"`
Total types.Number `json:"total"`
}
// InsuranceFundInformationDetail represents an Insurance fund information item for a
// single currency and type
type InsuranceFundInformationDetail struct {
Amount types.Number `json:"amt"`
Balance types.Number `json:"balance"`
Currency string `json:"ccy"`
Timestamp okxUnixMilliTime `json:"ts"`
Type string `json:"type"`
}
// SupportedCoinsData holds information about currencies supported by the trading data endpoints.
type SupportedCoinsData struct {
Contract []string `json:"contract"`
TradingOptions []string `json:"option"`
Spot []string `json:"spot"`
}
// TakerVolume represents taker volume information with creation timestamp
type TakerVolume struct {
Timestamp time.Time `json:"ts"`
SellVolume float64
BuyVolume float64
}
// MarginLendRatioItem represents margin lend ration information and creation timestamp
type MarginLendRatioItem struct {
Timestamp time.Time `json:"ts"`
MarginLendRatio float64 `json:"ratio"`
}
// LongShortRatio represents the ratio of users with net long vs net short positions for futures and perpetual swaps.
type LongShortRatio struct {
Timestamp time.Time `json:"ts"`
MarginLendRatio float64 `json:"ratio"`
}
// OpenInterestVolume represents open interest and trading volume item for currencies of futures and perpetual swaps.
type OpenInterestVolume struct {
Timestamp time.Time `json:"ts"`
OpenInterest float64 `json:"oi"`
Volume float64 `json:"vol"`
}
// OpenInterestVolumeRatio represents open interest and trading volume ratio for currencies of futures and perpetual swaps.
type OpenInterestVolumeRatio struct {
Timestamp time.Time `json:"ts"`
OpenInterestRatio float64 `json:"oiRatio"`
VolumeRatio float64 `json:"volRatio"`
}
// ExpiryOpenInterestAndVolume represents open interest and trading volume of calls and puts for each upcoming expiration.
type ExpiryOpenInterestAndVolume struct {
Timestamp time.Time
ExpiryTime time.Time
CallOpenInterest float64
PutOpenInterest float64
CallVolume float64
PutVolume float64
}
// StrikeOpenInterestAndVolume represents open interest and volume for both buyers and sellers of calls and puts.
type StrikeOpenInterestAndVolume struct {
Timestamp time.Time
Strike int64
CallOpenInterest float64
PutOpenInterest float64
CallVolume float64
PutVolume float64
}
// CurrencyTakerFlow holds the taker volume information for a single currency.
type CurrencyTakerFlow struct {
Timestamp time.Time
CallBuyVolume float64
CallSellVolume float64
PutBuyVolume float64
PutSellVolume float64
CallBlockVolume float64
PutBlockVolume float64
}
// PlaceOrderRequestParam requesting parameter for placing an order.
type PlaceOrderRequestParam struct {
AssetType asset.Item `json:"-"`
InstrumentID string `json:"instId"`
TradeMode string `json:"tdMode,omitempty"` // cash isolated
ClientOrderID string `json:"clOrdId,omitempty"`
Currency string `json:"ccy,omitempty"` // Only applicable to cross MARGIN orders in Single-currency margin.
OrderTag string `json:"tag,omitempty"`
Side string `json:"side,omitempty"`
PositionSide string `json:"posSide,omitempty"`
OrderType string `json:"ordType,omitempty"`
Amount float64 `json:"sz,string,omitempty"`
Price float64 `json:"px,string,omitempty"`
ReduceOnly bool `json:"reduceOnly,string,omitempty"`
QuantityType string `json:"tgtCcy,omitempty"` // values base_ccy and quote_ccy
// Added in the websocket requests
BanAmend bool `json:"banAmend,omitempty"` // Whether the SPOT Market Order size can be amended by the system.
ExpiryTime okxUnixMilliTime `json:"expTime,omitempty"`
}
// OrderData response message for place, cancel, and amend an order requests.
type OrderData struct {
OrderID string `json:"ordId,omitempty"`
RequestID string `json:"reqId,omitempty"`
ClientOrderID string `json:"clOrdId,omitempty"`
Tag string `json:"tag,omitempty"`
SCode string `json:"sCode,omitempty"`
SMessage string `json:"sMsg,omitempty"`
}
// CancelOrderRequestParam represents order parameters to cancel an order.
type CancelOrderRequestParam struct {
InstrumentID string `json:"instId"`
OrderID string `json:"ordId"`
ClientOrderID string `json:"clOrdId,omitempty"`
}
// AmendOrderRequestParams represents amend order requesting parameters.
type AmendOrderRequestParams struct {
InstrumentID string `json:"instId"`
CancelOnFail bool `json:"cxlOnFail,omitempty"`
OrderID string `json:"ordId,omitempty"`
ClientOrderID string `json:"clOrdId,omitempty"`
ClientRequestID string `json:"reqId,omitempty"`
NewQuantity float64 `json:"newSz,string,omitempty"`
NewPrice float64 `json:"newPx,string,omitempty"`
}
// ClosePositionsRequestParams input parameters for close position endpoints
type ClosePositionsRequestParams struct {
InstrumentID string `json:"instId"` // REQUIRED
PositionSide string `json:"posSide"`
MarginMode string `json:"mgnMode"` // cross or isolated
Currency string `json:"ccy"`
AutomaticallyCanceled bool `json:"autoCxl"`
ClientID string `json:"clOrdId,omitempty"`
Tag string `json:"tag,omitempty"`
}
// ClosePositionResponse response data for close position.
type ClosePositionResponse struct {
InstrumentID string `json:"instId"`
PositionSide string `json:"posSide"`
}
// OrderDetailRequestParam payload data to request order detail
type OrderDetailRequestParam struct {
InstrumentID string `json:"instId"`
OrderID string `json:"ordId"`
ClientOrderID string `json:"clOrdId"`
}
// OrderDetail returns a order detail information
type OrderDetail struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
Currency string `json:"ccy"`
OrderID string `json:"ordId"`
ClientOrderID string `json:"clOrdId"`
Tag string `json:"tag"`
ProfitAndLoss string `json:"pnl"`
OrderType string `json:"ordType"`
Side order.Side `json:"side"`
PositionSide string `json:"posSide"`
TradeMode string `json:"tdMode"`
TradeID string `json:"tradeId"`
FillTime time.Time `json:"fillTime"`
Source string `json:"source"`
State string `json:"state"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType"`
StopLossTriggerPriceType string `json:"slTriggerPxType"`
StopLossOrdPx string `json:"slOrdPx"`
RebateCurrency string `json:"rebateCcy"`
QuantityType string `json:"tgtCcy"` // base_ccy and quote_ccy
Category string `json:"category"` // normal, twap, adl, full_liquidation, partial_liquidation, delivery, ddh
AccumulatedFillSize types.Number `json:"accFillSz"`
FillPrice types.Number `json:"fillPx"`
FillSize types.Number `json:"fillSz"`
RebateAmount types.Number `json:"rebate"`
FeeCurrency string `json:"feeCcy"`
TransactionFee types.Number `json:"fee"`
AveragePrice types.Number `json:"avgPx"`
Leverage types.Number `json:"lever"`
Price types.Number `json:"px"`
Size types.Number `json:"sz"`
TakeProfitTriggerPrice types.Number `json:"tpTriggerPx"`
TakeProfitOrderPrice types.Number `json:"tpOrdPx"`
StopLossTriggerPrice types.Number `json:"slTriggerPx"`
UpdateTime time.Time `json:"uTime"`
CreationTime time.Time `json:"cTime"`
}
// OrderListRequestParams represents order list requesting parameters.
type OrderListRequestParams struct {
InstrumentType string `json:"instType"` // SPOT , MARGIN, SWAP, FUTURES , OPTIONS
Underlying string `json:"uly"`
InstrumentID string `json:"instId"`
OrderType string `json:"orderType"`
State string `json:"state"` // live, partially_filled
Before string `json:"before,omitempty"` // used for order IDs
After string `json:"after,omitempty"` // used for order IDs
Start time.Time `json:"begin"`
End time.Time `json:"end"`
Limit int64 `json:"limit,omitempty"`
}
// OrderHistoryRequestParams holds parameters to request order data history of last 7 days.
type OrderHistoryRequestParams struct {
OrderListRequestParams
Category string `json:"category"` // twap, adl, full_liquidation, partial_liquidation, delivery, ddh
}
// PendingOrderItem represents a pending order Item in pending orders list.
type PendingOrderItem struct {
AccumulatedFillSize types.Number `json:"accFillSz"`
AveragePrice types.Number `json:"avgPx"`
CreationTime okxUnixMilliTime `json:"cTime"`
Category string `json:"category"`
Currency string `json:"ccy"`
ClientOrderID string `json:"clOrdId"`
Fee types.Number `json:"fee"`
FeeCurrency currency.Code `json:"feeCcy"`
LastFilledPrice types.Number `json:"fillPx"`
LastFilledSize types.Number `json:"fillSz"`
FillTime okxUnixMilliTime `json:"fillTime"`
InstrumentID string `json:"instId"`
InstrumentType string `json:"instType"`
Leverage types.Number `json:"lever"`
OrderID string `json:"ordId"`
OrderType string `json:"ordType"`
ProfitAndLoss string `json:"pnl"`
PositionSide string `json:"posSide"`
RebateAmount types.Number `json:"rebate"`
RebateCurrency string `json:"rebateCcy"`
Side order.Side `json:"side"`
StopLossOrdPrice types.Number `json:"slOrdPx"`
StopLossTriggerPrice types.Number `json:"slTriggerPx"`
StopLossTriggerPriceType string `json:"slTriggerPxType"`
State string `json:"state"`
Price types.Number `json:"px"`
Size types.Number `json:"sz"`
Tag string `json:"tag"`
SizeType string `json:"tgtCcy"`
TradeMode string `json:"tdMode"`
Source string `json:"source"`
TakeProfitOrdPrice types.Number `json:"tpOrdPx"`
TakeProfitTriggerPrice types.Number `json:"tpTriggerPx"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType"`
TradeID string `json:"tradeId"`
UpdateTime okxUnixMilliTime `json:"uTime"`
}
// TransactionDetailRequestParams retrieve recently-filled transaction details in the last 3 day.
type TransactionDetailRequestParams struct {
InstrumentType string `json:"instType"` // SPOT , MARGIN, SWAP, FUTURES , option
Underlying string `json:"uly"`
InstrumentID string `json:"instId"`
OrderID string `json:"ordId"`
OrderType string `json:"orderType"`
After string `json:"after"` // after billid
Before string `json:"before"` // before billid
Begin time.Time `json:"begin"`
End time.Time `json:"end"`
Limit int64 `json:"limit"`
}
// TransactionDetail holds ecently-filled transaction detail data.
type TransactionDetail struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
TradeID string `json:"tradeId"`
OrderID string `json:"ordId"`
ClientOrderID string `json:"clOrdId"`
BillID string `json:"billId"`
Tag string `json:"tag"`
FillPrice types.Number `json:"fillPx"`
FillSize types.Number `json:"fillSz"`
Side order.Side `json:"side"`
PositionSide string `json:"posSide"`
ExecType string `json:"execType"`
FeeCurrency string `json:"feeCcy"`
Fee string `json:"fee"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// AlgoOrderParams holds algo order information.
type AlgoOrderParams struct {
InstrumentID string `json:"instId"` // Required
TradeMode string `json:"tdMode"` // Required
Currency string `json:"ccy,omitempty"`
Side order.Side `json:"side"` // Required
PositionSide string `json:"posSide,omitempty"`
OrderType string `json:"ordType"` // Required
Size float64 `json:"sz,string"` // Required
ReduceOnly bool `json:"reduceOnly,omitempty"`
OrderTag string `json:"tag,omitempty"`
QuantityType string `json:"tgtCcy,omitempty"`
// Place Stop Order params
TakeProfitTriggerPrice float64 `json:"tpTriggerPx,string,omitempty"`
TakeProfitOrderPrice float64 `json:"tpOrdPx,string,omitempty"`
StopLossTriggerPrice float64 `json:"slTriggerPx,string,omitempty"`
StopLossOrderPrice float64 `json:"slOrdPx,string,omitempty"`
StopLossTriggerPriceType string `json:"slTriggerPxType,omitempty"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType,omitempty"`
// Trigger Price Or TrailingStopOrderRequestParam
CallbackRatio float64 `json:"callbackRatio,omitempty,string"`
ActivePrice float64 `json:"activePx,string,omitempty"`
CallbackSpreadVariance string `json:"callbackSpread,omitempty"`
// trigger algo orders params.
// notice: Trigger orders are not available in the net mode of futures and perpetual swaps
TriggerPrice float64 `json:"triggerPx,string,omitempty"`
OrderPrice float64 `json:"orderPx,string,omitempty"` // if the price i -1, then the order will be executed on the market.
TriggerPriceType string `json:"triggerPxType,omitempty"` // last, index, and mark
PriceVariance string `json:"pxVar,omitempty"` // Optional
PriceSpread string `json:"pxSpread,omitempty"` // Optional
SizeLimit float64 `json:"szLimit,string,omitempty"` // Required
PriceLimit float64 `json:"pxLimit,string,omitempty"` // Required
// TWAPOrder
TimeInterval kline.Interval `json:"interval,omitempty"` // Required
}
// StopOrderParams holds stop order request payload.
type StopOrderParams struct {
AlgoOrderParams
TakeProfitTriggerPrice string `json:"tpTriggerPx"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType"`
TakeProfitOrderType string `json:"tpOrdPx"`
StopLossTriggerPrice string `json:"slTriggerPx"`
StopLossTriggerPriceType string `json:"slTriggerPxType"`
StopLossOrderPrice string `json:"slOrdPx"`
}
// AlgoOrder algo order requests response.
type AlgoOrder struct {
AlgoID string `json:"algoId"`
StatusCode string `json:"sCode"`
StatusMsg string `json:"sMsg"`
}
// AlgoOrderCancelParams algo order request parameter
type AlgoOrderCancelParams struct {
AlgoOrderID string `json:"algoId"`
InstrumentID string `json:"instId"`
}
// AlgoOrderResponse holds algo order information.
type AlgoOrderResponse struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
OrderID string `json:"ordId"`
Currency string `json:"ccy"`
AlgoOrderID string `json:"algoId"`
Quantity string `json:"sz"`
OrderType string `json:"ordType"`
Side order.Side `json:"side"`
PositionSide string `json:"posSide"`
TradeMode string `json:"tdMode"`
QuantityType string `json:"tgtCcy"`
State string `json:"state"`
Lever string `json:"lever"`
TakeProfitTriggerPrice string `json:"tpTriggerPx"`
TakeProfitTriggerPriceType string `json:"tpTriggerPxType"`
TakeProfitOrdPrice string `json:"tpOrdPx"`
StopLossTriggerPriceType string `json:"slTriggerPxType"`
StopLossTriggerPrice string `json:"slTriggerPx"`
TriggerPrice string `json:"triggerPx"`
TriggerPriceType string `json:"triggerPxType"`
OrdPrice string `json:"ordPx"`
ActualSize string `json:"actualSz"`
ActualPrice string `json:"actualPx"`
ActualSide string `json:"actualSide"`
PriceVar string `json:"pxVar"`
PriceSpread string `json:"pxSpread"`
PriceLimit string `json:"pxLimit"`
SizeLimit string `json:"szLimit"`
TimeInterval string `json:"timeInterval"`
TriggerTime okxUnixMilliTime `json:"triggerTime"`
CallbackRatio string `json:"callbackRatio"`
CallbackSpread string `json:"callbackSpread"`
ActivePrice string `json:"activePx"`
MoveTriggerPrice string `json:"moveTriggerPx"`
CreationTime okxUnixMilliTime `json:"cTime"`
}
// CurrencyResponse represents a currency item detail response data.
type CurrencyResponse struct {
CanDeposit bool `json:"canDep"` // Availability to deposit from chain. false: not available true: available
CanInternalTransfer bool `json:"canInternal"` // Availability to internal transfer.
CanWithdraw bool `json:"canWd"` // Availability to withdraw to chain.
Currency string `json:"ccy"` //
Chain string `json:"chain"` //
LogoLink string `json:"logoLink"` // Logo link of currency
MainNet bool `json:"mainNet"` // If current chain is main net then return true, otherwise return false
MaxFee types.Number `json:"maxFee"` // Minimum withdrawal fee
MaxWithdrawal types.Number `json:"maxWd"` // Minimum amount of currency withdrawal in a single transaction
MinFee types.Number `json:"minFee"` // Minimum withdrawal fee
MinWithdrawal string `json:"minWd"` // Minimum amount of currency withdrawal in a single transaction
Name string `json:"name"` // Chinese name of currency
UsedWithdrawalQuota string `json:"usedWdQuota"` // Amount of currency withdrawal used in the past 24 hours, unit in BTC
WithdrawalQuota string `json:"wdQuota"` // Minimum amount of currency withdrawal in a single transaction
WithdrawalTickSize string `json:"wdTickSz"` // Withdrawal precision, indicating the number of digits after the decimal point
}
// AssetBalance represents account owner asset balance
type AssetBalance struct {
AvailBal types.Number `json:"availBal"`
Balance types.Number `json:"bal"`
Currency string `json:"ccy"`
FrozenBalance types.Number `json:"frozenBal"`
}
// AccountAssetValuation represents view account asset valuation data
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 okxUnixMilliTime `json:"ts"`
}
// FundingTransferRequestInput represents funding account request input.
type FundingTransferRequestInput struct {
Currency string `json:"ccy"`
Type int `json:"type,string"`
Amount float64 `json:"amt,string"`
From string `json:"from"` // "6": Funding account, "18": Trading account
To string `json:"to"`
SubAccount string `json:"subAcct"`
LoanTransfer bool `json:"loanTrans,string"`
ClientID string `json:"clientId"` // Client-supplied ID A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
}
// FundingTransferResponse represents funding transfer and trading account transfer response.
type FundingTransferResponse struct {
TransferID string `json:"transId"`
Currency string `json:"ccy"`
ClientID string `json:"clientId"`
From int64 `json:"from,string"`
Amount types.Number `json:"amt"`
To int64 `json:"to,string"`
}
// TransferFundRateResponse represents funcing transfer rate response
type TransferFundRateResponse struct {
Amount types.Number `json:"amt"`
Currency string `json:"ccy"`
ClientID string `json:"clientId"`
From string `json:"from"`
InstrumentID string `json:"instId"`
State string `json:"state"`
SubAccount string `json:"subAcct"`
To string `json:"to"`
ToInstrumentID string `json:"toInstId"`
TransferID string `json:"transId"`
Type int `json:"type,string"`
}
// AssetBillDetail represents the billing record
type AssetBillDetail struct {
BillID string `json:"billId"`
Currency string `json:"ccy"`
ClientID string `json:"clientId"`
BalanceChange string `json:"balChg"`
AccountBalance string `json:"bal"`
Type int `json:"type,string"`
Timestamp okxUnixMilliTime `json:"ts"`
}
// LightningDepositItem for creating an invoice.
type LightningDepositItem struct {
CreationTime okxUnixMilliTime `json:"cTime"`
Invoice string `json:"invoice"`
}
// CurrencyDepositResponseItem represents the deposit address information item.
type CurrencyDepositResponseItem struct {
Tag string `json:"tag"`
Chain string `json:"chain"`
ContractAddress string `json:"ctAddr"`
Currency string `json:"ccy"`
ToBeneficiaryAccount string `json:"to"`
Address string `json:"addr"`
Selected bool `json:"selected"`
Memo string `json:"memo"`
DepositAddressAttachment map[string]string `json:"addrEx"`
PaymentID string `json:"pmtId"`