
    E#iS                    <   S SK Jr  S SKJr  S SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  S SK/J0r0  S SK1J2r2  S SK1J3r3  S SK1J4r4  S S	K1J5r5  S S
K1J6r6  S SK1J7r7  S SK1J8r8  S SK1J9r9  S SK1J:r:  S SK1J;r;  S SK1J<r<  S SK1J=r=  S SK1J>r>  S SK1J?r?  S SK1J@r@  S SK1JArA  S SK1JBrB  S SK1JCrC  S SK1JDrD  S SK1JErE  S SK1JFrF  S SK1JGrG  S SK1JHrH  S SK1JIrI  S SK1JJrJ  S SKKJLrL  S S KMJNrN   " S! S"\\5      rOg)#    )Exchange)ImplicitAPIN)(AccountAnyBalancesBorrowInterest
ConversionCrossBorrowRateCrossBorrowRates
CurrenciesCurrencyDepositAddressGreeksIntLedgerEntryLeverageLeverageTierLongShortRatioMarginModificationMarketNumOptionOptionChainOrder	OrderBookOrderRequestCancellationRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesOpenInterestsTradeTradingFeeInterfaceTransactionMarketInterfaceTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)OperationRejected)ManualInteractionNeeded)RestrictedLocation)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)ContractUnavailable)NotSupported)NetworkError)DDoSProtection)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)RequestTimeout)CancelPending)	TICK_SIZE)Precisec                   t  ^  \ rS rSrS\4U 4S jjrS0 S4S\S\S\4U 4S jjjrS r	S	\4S
 jr
SS\S\S\S\S\4
U 4S jjjr0 4S jr0 4S\4S jjr0 4S\\   4S jjrS r0 4S\\   4S jjrS\S\4S jr0 4S jr0 4S\4S jjrS0 4S	\S\S\4S jjrSS\S\S\4S jjr0 4S	\S\4S jjrS0 4S\ S\!4S jjr"0 4S	\S\4S jjr#S0 4S\ S\!4S jjr$SS \S\S\%4S! jjr&SS0 4S	\S"\S\S\\%   4S# jjr'SS\S\(4S$ jjr)S%SS0 4S	\S&\S"\S\S\\(   4
S' jjr*SSS0 4S	\S"\S\4S( jjr+S) r,S* r-S+ r.SS,\S\S\/4S- jjr00 4S	\S\/4S. jjr10 4S\24S/ jjr30 4S	\S0\44S1 jjr50 4S	\S0\44S2 jjr6S0 4S	\S3\7S4\8S5\4S6\94
S7 jjr:S0 4S	\S3\7S4\8S5\4S6\94
S8 jjr;0 4S9\\<   4S: jjr=SS0 4S;\4S< jjr>SS0 4S;\S	\S3\7S4\8S5\9S6\94S= jjr?S0 4S;\S	\4S> jjr@S? rAS0 4S@\\   S	\4SA jjrB0 4S9\\C   4SB jjrD0 4SC\4SD jjrESE\4SF jrFSSG\S\S\G4SH jjrHS0 4S;\S	\4SI jjrISSS0 4S	\S"\S\S\\G   4SJ jjrJSSS0 4S	\S"\S\4SK jjrKSSS0 4S	\S"\S\S\\G   4SL jjrLSSS0 4S	\S"\S\4SM jjrMSSS0 4S;\S	\S"\S\4SN jjrNSSS0 4SO\S"\S\S\\O   4SP jjrPSQ rQSSR\SS\RS\O4ST jjrSSSS\RS\T4SU jjrU0 4SO\S\\T   4SV jjrV0 4SO\S\T4SW jjrWS0 4SO\S5\4SX\SY\S\X4
SZ jjrYSSS0 4SO\S"\S\S\\X   4S[ jjrZS0 4S;\SO\4S\ jjr[SSS0 4SO\S"\S\S\\X   4S] jjr\S0 4S;\SO\4S^ jjr]SE\4S_ jr^SS`\SS\RS\X4Sa jjr_0 4S	\S\`4Sb jjraSSc\S\S\`4Sd jjrb0 4S	\4Se jjrcS0 4S\ S\\d   4Sf jjre0 4S	\4Sg jjrfSSh\S\4Si jjrg0 4SO\S5\4Sj\Sk\S\h4
Sl jjriSSm\SS\RS\h4Sn jjrjSE\S\4So jrkS0 4S;\SO\S\h4Sp jjrlSSS0 4SO\S"\S\S\\h   4Sq jjrmSrSs0 SS4St jrnSS\S\o4Su jjrpSv rq0 4S	\S\o4Sw jjrr0 4S	\S\o4Sx jjrsS0 4S\ S\t4Sy jjruSSS0 4S	\S"\S\4Sz jjrvS0 4Sc\wS	\4S{ jjrxS0 4S	\4S| jjryS0 4S}\zS	\4S~ jjr{S0 4S\S	\4S jjr|0 4S\}4S jjr~0 4SO\S\4S jjrSSS\R4S jjrS rSSS0 4S"\S\4S jjrSS0 4SO\S"\S\4S jjr0 4S	\S\4S jjrSS\S\S\4S jjr0 4S	\S5\4S\4S jjr0 4S	\S5\4S\4S jjr0 4S	\S\\   4S jjrSS\S\\   4S jjrSSSS0 4SO\S	\S"\S\S\\   4
S jjrSS\S\S\4S jjr0 4SO\S5\44S jjr0 4SO\4S jjrSSS\R4S jjr0 4S	\4S jjrS0 4S\ S\4S jjrSSS0 4S	\S"\S\4S jjrSS\4S jjrS\z4U 4S jjrS0 4S\ 4S jjrSS jrSSS0 4S	\S"\S\4S jjrS rS r0 4S jr0 4S	\S\4S jjrS0 4S\ S\\   4S jjrSS\S\S\4S jjrS0 4S	\S4\8S\G4S jjr0 4S	\S\4S jjr0 4SO\S\4S jjrSS\SS\RS\S\4S jjrS0 4S\S\S5\9S\4S jjrS0 4S;\S\S\S5\9S\4
S jjrS0 4S;\SO\S\4S jjrSSS0 4SO\S"\S\S\\   4S jjrSS\S\RS\RS\4S jjr0 4S\4S jjrS\wS\S\S\S\S\4S jrSSSS0 4S	\S3\S"\9S\9S\\   4
S jjrSSS0 4S\ S"\S\S\\d   4S jjrSSSS0 4S	\S&\S"\S\S\\   4
S jjrSS\S\S\4S jjrSrU =r$ )okx)   returnc                 .  > U R                  [        [        U ]  5       0 SS_SS_SSS/_SS	_S
S_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_0 S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_E0 S3S _S4S_S5S_S6S_S7S_S8S _S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_E0 SDS_SES_SFS_SGSH_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_STS_SUS_E0 SVS _SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_SeS_SfS_E0 SgS _ShS_SiS_SjS_SkS_SlS_SmS_SnS_SoS_SpS_SqSH_SrS_SsS_StS_SuS_SvS_SwS_E0 SxS_SyS_SzS_S{S_S|S_S}S_S~S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESSSSSSSSSSSS.E_SSSSSSSSSSSSSSSS._SS_SSSS0SSSSSS.SS0S._SS0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESSSSSSSSSSSSSS.E00 SS_SS_SS_SS_SS_SS_SS_SGS _GSGS _GSS_GSS_GSGS _GSGS _GSGS _GSS_GSS_GS	GS _0 GS
GS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSGS_GSS_GS S_GS!S_GS"S_GS#S_GS$S_GS%S_GS&S_GS'S_GS(S_GS)S_GS*GS+_GS,S_GS-S_GS.S_E0 GS/S_GS0S_GS1S_GS2S_GS3S_GS4S_GS5S_GS6S_GS7S_GS8S_GS9S_GS:S_GS;S_GS<S_GS=S_GS>S_GS?S_E0 GS@S_GSAS_GSBS_GSCS_GSDS_GSES_GSFGS_GSGGS_GSHGSI_GSJS_GSKS_GSLS_GSMS_GSNS_GSOS_GSPS_GSQS_E0 GSRS_GSSS_GSTS_GSUS_GSVS_GSWS_GSXS_GSYS_GSZS_SS_GS[S_GS\S_GS]S_GS^S_GS_S_GS`S_GSaS_E0 GSbS_GScS_GSdS_GSeS_GSfS_GSgS_GShS_GSiS_GSjS_GSkS_GSlS_GSmGSn_GSoS_GSpS_GSqS_GSrS_GSsS_E0 GStS_GSuS_GSvS_GSwS_GSxS_GSyS_GSzS_GS{S_GS|S_GS}S_GS~S_GSS_GSS_GSGS+_GSGS_GSS_GSS_EGSGSSSSGS.E0 GSS_GSS_GSS_GSS_GSGS_SS_GSS_SGS+_GSGS_GSGS_GSS_GSS_SS_GSS_GSS_GSS_GSS_0 GSGS _GSGS_GSGS _GSGS_GSGS _GSGS_GSS_GSGS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSGS_GSS_GSS_GSS_GSS_GS&S_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSDGS+_GSGS_GSGS_GSGS_GSGS_GS/GS_GSS_GSS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_SS_GSS_GSS_GSS_GSS_E0 GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSGSn_GSGSn_GSGSn_GSGS_GSGS_GSGS_E0 GSGS_GSS_GSS_GSS_GSS_GSS_GSS_GSS_GSGS_GSS_GS}GS_GSS_GSS_GSS_GSS_GSGS_GS~S_ESGSSSGSGSGS.EGS.GS._GSU R	                  GS5      U R	                  GS5      GS .U R	                  GS5      U R	                  GS5      GS .U R	                  GS5      U R	                  GS5      GS .U R	                  GS5      U R	                  GS5      GS .GS._GSSSSGS._GS0 GS	[
        _GS
[
        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[
        _GS[        _GS[
        _GS[        _GS[        _0 GS[
        _GS[
        _GS[
        _GS[
        _GS[
        _GS[
        _GS [
        _GS![
        _GS"[
        _GS#[        _GS$[
        _GS%[        _GS&[        _GS'[
        _GS([        _GS)[
        _GS*[
        _E0 GS+[
        _GS,[        _GS-[        _GS.[        _GS/[        _GS0[        _GS1[        _GS2[        _GS3[
        _GS4[
        _GS5[        _GS6[        _GS7[        _GS8[        _GS9[        _GS:[        _GS;[        _E0 GS<[         _GS=[         _GS>[        _GS?["        _GS@["        _GSA["        _GSB["        _GSC[$        _GSD[        _GSE[&        _GSF["        _GSG[         _GSH[         _GSI[         _GSJ["        _GSK[
        _GSL[
        _E0 GSM[
        _GSN["        _GSO[(        _GSP[(        _GSQ[
        _GSR[        _GSS[
        _GST[         _GSU[(        _GSV[(        _GSW[(        _GSX[(        _GSY["        _GSZ["        _GS[["        _GS\["        _GS]["        _E0 GS^["        _GS_["        _GS`["        _GSa["        _GSb["        _GSc["        _GSd["        _GSe["        _GSf["        _GSg["        _GSh["        _GSi["        _GSj["        _GSk["        _GSl["        _GSm["        _GSn["        _E0 GSo["        _GSp["        _GSq["        _GSr["        _GSs["        _GSt[        _GSu["        _GSv[        _GSw["        _GSx["        _GSy["        _GSz["        _GS{[$        _GS|["        _GS}["        _GS~["        _GS["        _E0 GS["        _GS["        _GS[$        _GS["        _GS["        _GS[         _GS[$        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS[*        _GS[        _E0 GS[        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _E0 GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _E0 GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS[        _GS[        _GS["        _GS["        _GS["        _GS["        _GS["        _GS[,        _E0 GS[,        _GS[,        _GS["        _GS["        _GS[
        _GS[
        _GS[        _GS[
        _GS[
        _GS[.        _GS[
        _GS[
        _GS[$        _GS[
        _GS[
        _GS[
        _GS[
        _E0 GS[
        _GS[
        _GS[
        _GS[
        _GS[
        _GS[,        _GS[        _GS[        _GS[        _GS[
        _GS[$        _GS[
        _GS[
        _GS[
        _GS["        _GS["        _GS["        _E0 GS[
        _GS[        _GS[
        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS["        _GS[
        _GS[        _GS[        _GS[
        _GS[        _GS[
        _E0 GS[
        _GS[
        _GS[
        _GS[        _GS[        _GS[
        _GS[
        _GS[
        _GS[
        _GS [
        _GS[
        _GS[
        _GS[
        _GS[
        _GS[
        _GS[
        _GS[
        _E0 GS[
        _GS	[
        _GS
[        _GS[        _GS[        _GS[        _GS[
        _GS[
        _GS[
        _GS[0        _GS[        _GS[
        _GS[
        _GS[0        _GS[
        _GS[
        _GS[
        _E0 GS[
        _GS[
        _GS[        _GS[        _GS[        _GS[        _GS[        _GS [        _GS![$        _GS"[
        _GS#[$        _GS$[
        _GS%[
        _GS&[
        _GS'[
        _GS([
        _GS)[$        _E0 GS*[
        _GS+[
        _GS,[
        _GS-[
        _GS.[$        _GS/[
        _GS0["        _GS1[$        _GS2[$        _GS3[        _GS4[        _GS5[        _GS6[
        _GS7[
        _GS8[
        _GS9[
        _GS:[2        _E0 GS;[$        _GS<[2        _GS=[2        _GS>[        _GS?[
        _GS@[
        _GSA[
        _GSB[
        _GSC[
        _GSD[
        _GSE[
        _GSF[
        _GSG[        _GSH[
        _GSI[
        _GSJ[
        _GSK[
        _E0 GSL[
        _GSM[        _GSN[
        _GSO[
        _GSP[        _GSQ[        _GSR[        _GSS[        _GST[        _GSU[        _GSV[        _GSW[        _GSX[        _GSY[        _GSZ[        _GS[[        _GS\[        _E0 GS][        _GS^[        _GS_[        _GS`[4        _GSa[        _GSb[        _GSc[        _GSd[        _GSe[
        _GSf[&        _GSg[        _GSh[6        _GSi[        _GSj[
        _GSk[        _GSl[8        _GSm[:        _E0 GSn[&        _GSo[&        _GSp[        _GSq[        _GSr[
        _GSs[        _GSt[        _GSu[        _GSv[&        _GSw[        _GSx[        _GSy[        _GSz[        _GS{[        _GS|[        _GS}[        _GS~[        _E[        [        [        [        [        [        [4        [        [        [        [        GS.E[        [        GS.GS._GSGS[        0_GS[<        _0 GSS_GSGS_GSGSGSGSGS._GS0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GS GS_GSGS_GSGS_EGSGSGSGS.E_SeSSSGS	SSSGS	SGS
.0_ScGSGS0_SrGSGS0_S#GS_GSS_S]GS/ GSQ0_GSGS_GSS_GSS_SUGSGS0_SkGSGS0_ShGSGS0_SGSGS0_GSGS0GSGS0S S GS.SSSSSSGS.GSGSGSGSGSGSGSGSGS .GS!GS"GS#.GS$GS%GS&GS'GS'GS(GS$GS%GS&GS'GS(GS).GS*GS+.ESSSSSSGS,.SSSSSSGS,.SGS-.SSSSGS..SSSSSSSGS/.GS0S0SGS1GS+GS2SGS3.SSSSGS4.SGS+SSSGS5.S SGS+GS1GS6S SSSGS7.GSGS+GS+GS8.GS9.	GS:GS;S0GS<.GS=GS:0GS=GS:0GS>.GS=GS:0GS=GS:0GS>.GS?.U R?                  GS@GS@U R	                  GSA5      GSB.5      U R?                  GSCGSCU R	                  GSA5      GSB.5      U R?                  GSDGSDU R	                  GSA5      GSB.5      U R?                  GSEGSEU R	                  GSA5      GSB.5      U R?                  GSFGSFU R	                  GSA5      GSB.5      GSG.GSHGSIGSJ.GSK.E5      $ (L  NidrJ   nameOKX	countriesCNUSversionv5	rateLimitg    [@proT	certifiedhasCORSspotmarginswapfutureoption	addMargincancelAllOrdersFcancelAllOrdersAftercancelOrdercancelOrderscancelOrdersForSymbolscloseAllPositionsclosePositioncreateConvertTradecreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrderfetchAccountsfetchAllGreeksfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLedgerEntryfetchLeveragefetchLeverageTiersfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawalfetchWithdrawals)fetchWithdrawalWhitelistreduceMarginrepayCrossMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw
timeframes1m3m5m15m30m1H2H4H6H12H1D1W1M3M)r   r   r   r   r   1h2h4h6h12h1d1wr   r   hostnamezwww.okx.comurlszdhttps://user-images.githubusercontent.com/1294454/152485636-38b19e4a-bece-4dec-979a-5982859ffc04.jpgrestzhttps://{hostname}zhttps://www.okx.comzhttps://www.okx.com/docs-v5/en/z,https://www.okx.com/pages/products/fees.htmlz https://www.okx.com/join/CCXTCOMg?)urldiscount)logoapiwwwdocfeesreferraltestr   getzmarket/books-full   zmarket/tickers   zmarket/tickerzmarket/index-tickerszmarket/booksg      ?zmarket/books-liteg?zmarket/candleszmarket/history-candleszmarket/index-candleszmarket/history-index-candleszmarket/mark-price-candlesz!market/history-mark-price-candleszmarket/tradeszmarket/history-tradesz&market/option/instrument-family-tradeszmarket/platform-24-volume
   zmarket/open-oracle2   zmarket/exchange-rate   zmarket/index-componentszpublic/market-data-history   zpublic/economic-calendarzmarket/block-tickerszmarket/block-tickerzpublic/block-tradeszpublic/instrumentsz public/delivery-exercise-historyzpublic/open-interestzpublic/funding-ratezpublic/funding-rate-historyzpublic/price-limitzpublic/opt-summaryzpublic/estimated-pricez(public/discount-rate-interest-free-quotazpublic/timezpublic/mark-pricezpublic/position-tierszpublic/interest-rate-loan-quotaz#public/vip-interest-rate-loan-quotazpublic/underlyingzpublic/insurance-fundzpublic/convert-contract-coinzpublic/option-tradeszpublic/instrument-tick-bandsz$rubik/stat/trading-data/support-coinzrubik/stat/taker-volumezrubik/stat/margin/loan-ratioz-rubik/stat/contracts/long-short-account-ratioz6rubik/stat/contracts/long-short-account-ratio-contractz)rubik/stat/contracts/open-interest-volumez&rubik/stat/option/open-interest-volumez,rubik/stat/option/open-interest-volume-ratioz-rubik/stat/option/open-interest-volume-expiryz-rubik/stat/option/open-interest-volume-strikez$rubik/stat/option/taker-block-volumezsystem/statuszsprd/spreadsz
sprd/bookszsprd/tickerzsprd/public-tradeszmarket/sprd-tickerzmarket/sprd-candleszmarket/sprd-history-candlesztradingBot/grid/ai-paramztradingBot/grid/min-investmentz"tradingBot/public/rsi-back-testingzasset/exchange-listz$finance/staking-defi/eth/apy-historyz$finance/staking-defi/sol/apy-historyg
@gUUUUUU?)z$finance/savings/lending-rate-summaryz$finance/savings/lending-rate-historyz!finance/fixed-loan/lending-offersz&finance/fixed-loan/lending-apy-historyz)finance/fixed-loan/pending-lending-volumezfinance/sfp/dcd/productszcopytrading/public-lead-traderszcopytrading/public-weekly-pnlzcopytrading/public-statsz&copytrading/public-preference-currencyz'copytrading/public-current-subpositionsz'copytrading/public-subpositions-historyzsupport/announcements-typeszrfq/counterpartieszrfq/maker-instrument-settingszrfq/mmp-configzrfq/rfqsz
rfq/quotesz
rfq/tradeszrfq/public-tradesz
sprd/ordergUUUUUU?zsprd/orders-pendingzsprd/orders-historyzsprd/orders-history-archivezsprd/tradestrade/orderztrade/orders-pendingztrade/orders-historyztrade/orders-history-archiveztrade/fillsztrade/fills-historyg@ztrade/fills-archivetrade/order-algoztrade/orders-algo-pendingztrade/orders-algo-historyz trade/easy-convert-currency-listztrade/easy-convert-historyz#trade/one-click-repay-currency-listz&trade/one-click-repay-currency-list-v2ztrade/one-click-repay-historyz trade/one-click-repay-history-v2ztrade/account-rate-limitzasset/currencieszasset/balanceszasset/non-tradable-assetszasset/asset-valuationzasset/transfer-statezasset/billszasset/deposit-lightning   zasset/deposit-addresszasset/deposit-historyzasset/withdrawal-historyzasset/deposit-withdraw-statuszasset/convert/currencieszasset/convert/currency-pairzasset/convert/historyzasset/monthly-statementzaccount/instrumentszaccount/balancezaccount/positionszaccount/positions-historyd   zaccount/account-position-riskzaccount/billszaccount/bills-archivezaccount/bills-history-archivezaccount/configzaccount/max-sizezaccount/max-avail-sizezaccount/leverage-infozaccount/adjust-leverage-infozaccount/max-loanzaccount/trade-feezaccount/interest-accruedzaccount/interest-ratezaccount/max-withdrawalzaccount/risk-statez)account/quick-margin-borrow-repay-historyzaccount/borrow-repay-historyzaccount/vip-interest-accruedzaccount/vip-interest-deductedzaccount/vip-loan-order-listzaccount/vip-loan-order-detailzaccount/interest-limitszaccount/greekszaccount/position-tierszaccount/mmp-configz"account/fixed-loan/borrowing-limitz"account/fixed-loan/borrowing-quotez(account/fixed-loan/borrowing-orders-listz account/spot-manual-borrow-repay   zaccount/set-auto-repayz!account/spot-borrow-repay-historyzaccount/move-positions-historyzusers/subaccount/listzaccount/subaccount/balanceszasset/subaccount/balancesz!account/subaccount/max-withdrawalzasset/subaccount/billsz)asset/subaccount/managed-subaccount-billszusers/entrust-subaccount-listz"account/subaccount/interest-limitszusers/subaccount/apikeyz#tradingBot/grid/orders-algo-pendingz#tradingBot/grid/orders-algo-historyz#tradingBot/grid/orders-algo-detailsztradingBot/grid/sub-ordersztradingBot/grid/positionsztradingBot/signal/signalsz%tradingBot/signal/orders-algo-detailsz%tradingBot/signal/orders-algo-historyztradingBot/signal/positionsz#tradingBot/signal/positions-historyztradingBot/signal/sub-ordersztradingBot/signal/event-historyz(tradingBot/recurring/orders-algo-pendingz(tradingBot/recurring/orders-algo-historyz(tradingBot/recurring/orders-algo-detailsztradingBot/recurring/sub-orderszfinance/savings/balancezfinance/savings/lending-historyzfinance/staking-defi/offersz"finance/staking-defi/orders-activez#finance/staking-defi/orders-historyz finance/staking-defi/eth/balancez0finance/staking-defi/eth/purchase-redeem-historyz%finance/staking-defi/eth/product-info   z finance/staking-defi/sol/balancez0finance/staking-defi/sol/purchase-redeem-historyz copytrading/current-subpositionsz copytrading/subpositions-historyzcopytrading/instrumentsz"copytrading/profit-sharing-detailsz copytrading/total-profit-sharingz-copytrading/unrealized-profit-sharing-detailszcopytrading/copy-settingszcopytrading/batch-leverage-infoz copytrading/current-lead-tradersz copytrading/lead-traders-historyzbroker/nd/infozbroker/nd/subaccount-infozbroker/nd/subaccount/apikeyz*asset/broker/nd/subaccount-deposit-addressz*asset/broker/nd/subaccount-deposit-historyz-asset/broker/nd/subaccount-withdrawal-historyzbroker/nd/rebate-dailybroker/nd/rebate-per-orders,  finance/sfp/dcd/orderzfinance/sfp/dcd/orders)broker/fd/rebate-per-orderszbroker/fd/if-rebatezaffiliate/invitee/detailzusers/partner/if-rebatezsupport/announcementszrfq/create-rfqzrfq/cancel-rfqzrfq/cancel-batch-rfqszrfq/cancel-all-rfqszrfq/execute-quote   zrfq/mmp-resetzrfq/create-quoteg?zrfq/cancel-quotezrfq/cancel-batch-quoteszrfq/cancel-all-quoteszsprd/cancel-orderzsprd/mass-cancelzsprd/amend-orderzsprd/cancel-all-aftertrade/batch-ordersg?ztrade/cancel-orderztrade/cancel-batch-ordersztrade/amend-orderztrade/amend-batch-ordersgO贁N{?ztrade/close-positioni  ztrade/cancel-algosztrade/amend-algosztrade/cancel-advance-algosztrade/easy-convertztrade/one-click-repayztrade/one-click-repay-v2ztrade/mass-cancelztrade/cancel-all-afterzasset/transferzasset/withdrawalzasset/withdrawal-lightningzasset/cancel-withdrawalzasset/convert-dust-assetszasset/convert/estimate-quotezasset/convert/tradezaccount/set-position-modezaccount/set-leveragezaccount/position/margin-balancezaccount/set-greekszaccount/set-isolated-modez!account/quick-margin-borrow-repayzaccount/borrow-repayzaccount/simulated_marginzaccount/position-builderzaccount/set-riskOffset-typezaccount/activate-optionzaccount/set-auto-loanzaccount/set-account-levelzaccount/mmp-resetz"account/fixed-loan/borrowing-orderz(account/fixed-loan/amend-borrowing-orderz"account/fixed-loan/manual-reborrowz(account/fixed-loan/repay-borrowing-orderi@ zaccount/move-positionszaccount/set-settle-currencyzusers/subaccount/modify-apikeyzasset/subaccount/transferz!users/subaccount/set-transfer-outz&account/subaccount/set-loan-allocationz"users/subaccount/create-subaccountz"users/subaccount/subaccount-apikeyzusers/subaccount/delete-apikeyztradingBot/grid/order-algoz tradingBot/grid/amend-order-algoztradingBot/grid/stop-order-algoztradingBot/grid/close-positionz"tradingBot/grid/cancel-close-orderz%tradingBot/grid/order-instant-triggerztradingBot/grid/withdraw-incomez&tradingBot/grid/compute-margin-balanceztradingBot/grid/margin-balancez!tradingBot/grid/adjust-investmentztradingBot/signal/create-signalztradingBot/signal/order-algoz!tradingBot/signal/stop-order-algoz tradingBot/signal/margin-balanceztradingBot/signal/amendTPSLz!tradingBot/signal/set-instrumentsz tradingBot/signal/close-positionztradingBot/signal/sub-orderz"tradingBot/signal/cancel-sub-orderztradingBot/recurring/order-algoz%tradingBot/recurring/amend-order-algoz$tradingBot/recurring/stop-order-algoz finance/savings/purchase-redemptz finance/savings/set-lending-ratezfinance/staking-defi/purchasezfinance/staking-defi/redeemzfinance/staking-defi/cancelz!finance/staking-defi/eth/purchasezfinance/staking-defi/eth/redeemz!finance/staking-defi/sol/purchasezfinance/staking-defi/sol/redeemzcopytrading/algo-orderzcopytrading/close-subpositionzcopytrading/set-instrumentszcopytrading/first-copy-settingszcopytrading/amend-copy-settingszcopytrading/stop-copy-tradingzcopytrading/batch-set-leveragezbroker/nd/create-subaccountg      ?zbroker/nd/delete-subaccountz"broker/nd/subaccount/modify-apikeyz"broker/nd/subaccount/delete-apikeyzbroker/nd/set-subaccount-levelz!broker/nd/set-subaccount-fee-ratezbroker/nd/set-subaccount-assetsi  )z1asset/broker/nd/modify-subaccount-deposit-addressr  zfinance/sfp/dcd/quoter  zbroker/nd/report-subaccount-ipr  )r   post)publicprivater   z0.0015z0.0010)takermakerz0.0005z0.0002z0.00050z0.00020)tradingr[   r^   r]   requiredCredentials)apiKeysecretpassword
exceptions1240885000050001500025000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850044500615006250100501015010250103501045010550106501075010850109501105011150112501135011450115510005100151002510035100451005510065100751008510095101051011510125101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315104651047510515107251073510745109051091510925109351094510955109651098510995110051101511025110351104511055110651107511085110951110511115111251113511155111651117511185111951120511215112251124511255112651127511285112951130511315113251133511345113551136511375113851139511555115651159511625116351166511745118551201512025120351204512055125051251512525125351254512555125651257512585125951260512615126251263512645126551267512685126951270512715127251273512745127551276512775127851279512805132151322513235132451325513275132851329513305140051401514025140351404514055140651407514085140951410515005150151502515035150651508515095151051511516005160151602516035173251733517345173551736520005400054001540085400954011540725407354074551005510155102551035510455111551125511358000580015800258003580045800558006580075810058101581025810358104581055810658107581085810958110581115811258114581155811658117581255812658127581285820058201582025820358204582055820658207582085820958210582115821258213582215822258224582275822858229583005835059000590015910059101591025910359104591055910659107591085910959128592005920159216592605926259300593015931359401594105941159412594135941459500595015950259503595045950559506595075950859515595165951759518595195964259643596835968459686600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003263999640006400164002640037001070013700167006070061700627006470065)7006670067100940014002400340044005400640074008)zInternal Server Errorzserver error)exactbroadhttpExceptions429precisionModesandboxModedefaultNetworkERC20defaultNetworksBTCTRC20)ETHr  USDTnetworksBitcoinBTCLN	LightningBTCLIGHTNINGBEP20BSCBRC20CRC20CryptoACAAcalaALGOAlgorandAPTAptosSCROLLScrollARBONEzArbitrum OneAVAXCzAvalanche C-ChainAVAXXzAvalanche X-ChainBASEBaseSUI	ZKSYNCERAz
zkSync EraLINEALineaARArweaveASTRAstarBCHBitcoinCashBSVz
Bitcoin SVADACardanoCSPRCasperCELOXCHChiaATOMCosmosDGBDigibyteDOGEDogecoinEGLDElrondCFXConfluxEOSCOREETCzEthereum ClassicETHWEthereumPowFILFilecoinONEHarmonyHBARHederaICXICONICPDfinityIOSTIOTAMIOTAKLAYKlaytnKSMKusamaLSKLiskLTCLitecoinMETISMetisMINAMinaGLRMMoonbeamMOVR	MoonriverNANONanoNEARNULSOASYSONTOntologyOPTIMISMOptimismLATPlatONDOTPolkadotMATICPolygonRVN	RavencoinXRPRippleSCSiacoinSOLSolanaSTXzl-StacksXLMzStellar LumensXTZTezosTONThetaWaxZilliqa)THETAWAXZIL8H)r   r   8hr   5Mr   r"  r   timezoneUTCmethodprivateGetAccountPositionsprivatePostTradeBatchOrders!createMarketBuyOrderRequiresPricetypesr[   r^   r]   r_   timeDifferencer   adjustForTimeDifferencedefaultTypeprivateGetAccountBillsprivateGetTradeOrderprivateGetTradeOrdersPending!privatePostTradeCancelBatchOrdersprivateGetTradeOrdersHistory)r  pwd)conditionaltriggerocomove_order_stopicebergtwap618)fundingr  r[   r^   futuresr\   r]   r_   r>  r  )r<  r=  SPOTMARGINSWAPFUTURESOPTION)r[   r\   r]   r^   r?  r_   r@  rA  rB  rC  rD  6b9ad766b55dBCDE)r   r   r   algoOrderTypesaccountsByTypeaccountsByIdexchangeTypebrokerId)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricerN  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingr:  leverageselfTradePreventionmarketBuyByCostmarketBuyRequiresPricemaxZ   i'  )rT  daysBacklimit	untilDayssymbolRequired)rT  r7  r\  rf  )rT  rd  r7  r\  rf  gUUUUUU?)rT  rd  rc  daysBackCanceledre  r7  r\  rf  )rd  rL  rM  )	r   rl   rm   r   r   r   r   r   r   defaultr  )extendsr   ri  )linearinverse)rh  r[   r]   r^   USDz0.0001)rN   code	precisionEURAEDGBPAUD)rl  ro  rp  rq  rr  AETWINTOKEN)AEWIN)optionsfeatures
currenciescommonCurrencies) deep_extendsuperrJ   describeparse_numberr.   r7   r4   rC   rE   rB   r2   r/   rA   r0   rD   r5   r;   r9   r1   r=   r8   r<   rF   r:   r6   r?   r@   r3   r>   rG   safe_currency_structure)self	__class__s    P/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/okx.pyr}  okx.describe+   s%:   c4 9 ; m>
%m>
Em>
 $m>
 t	m>

 m>
 4m>
 m>
  CCC $C 	C
 $C $C TC "5C 'C tC C )$C $UC  C %dC  '!C" /#C$ 0%C& t'C( )C* 7+C, &t-C. (/C0 '1C2 &t3C4 (5C6 "47C8 (9C: -d;C< %d=C> T?C@  ACB !$CCD ECF  GCH &tICJ +DKCL )$MCN &tOCP #DQCR $TSCT )$UCV $TWCX $TYCZ +D[C\ ']C^ (_C` "4aCb cCd &teCf (gCh 1$iCj  kCl +EmCn *:oCp +DqCr &tsCt 'uCv (wCx #DyCz *4{C| $T}C~ tC@ "4ACB *5CCD +EECF #EGCH tICJ #DKCL  MCN %eOCP &uQCR -dSCT /UCV +DWCX YCZ !$[C\ !$]C^ "4_C` +EaCb  cCd deCf $TgCh +DiCj %dkCl !$mCn "4oCp tqCr #DsCt duCv !$wCx "5yCz u{C| #D}C~  C@ '
ACB !$CCD *4ECF (GCH %eICJ )%KCL )$MCN tOCP tQCR SCT TUCV tWCX "4YCZ #E[C\ %e]C^ &u_C` 'aCb $UcCd  eCf !$gCh (iCj )%kCl "4mCn #DoCp -2 $$(#"!%#'  ECm>
X Ym>
x ym>
z ~0 -8F > #	 0{m>
^  W+QW(!W (W /	W
 'W ,UW )%W 1!W /W 7W 4QW <QW (W 0W A!W  4R!W" -b#W$ /%W& 21'W( 5a)W* 3B+W, /-W. .q/W0 .q1W2 -a3W4 ;E5W6 /7W8 .q9W: 6q;W< -a=W> -a?W@ 1!AWB CBCWD &qEWF ,QGWH 0IWJ :2KWL >rMWN ,QOWP 0QWR 7SWT /UWV 7WWX ?YWZ 21[W\ 7]W` HaWb QRScWd DQeWf A!gWj GkWl HmWn HoWp ?qWr (sWv 'wWx %eyWz &q{W| -e}W~ -aW@ .qAWB 6qCWD 3AEWF 9!GWH =aIWJ .uKWL ?MWN ?OWP AF@E=CBHEK49;<9:45BCCDCD79mWYvZ,aZ 8Z )!	Z
 #BZ %bZ %aZ ,QZ %eZ .uZ .uZ 6uZ &uZ  &u!Z" /#Z$ /%Z& 7'Z( &u)Z* .s+Z, .q-Z. +A/Z0 4Q1Z2 4Q3Z4 ;B5Z6 5b7Z8 >r9Z: A";Z< 8=Z> ;B?Z@ 3AAZD +EEZF )%GZH 4UIZJ 0KZL /MZN &uOZP 21QZR 0SZT 0UZV 3EWZX 8YZZ 3E[Z\ 6u]Z^ 0_Z` 21aZd .qeZf *1gZh ,QiZj 4SkZl 8mZn (oZp 0qZr 8sZt )!uZv +AwZx 1!yZz 0{Z| 7}Z~ +AZ@ ,QAZB 3ACZD 0EZF 1!GZH -aIZJ DQKZL 7MZN 7OZP 8QZR 6qSZT 8UZV 21WZX )!YZZ 1![Z\ -a]Z^ =a_Z` =aaZb CAcZd ;BeZf 1!gZh <QiZj 9"kZn 0oZp 6vqZr 4VsZt <QuZv 1%wZx DUyZz 8{Z| =a}Z~ 22ZB >qCZD >qEZF >qGZH 5aIZJ 4QKZL 3AMZN 4QOZP @QZR @SZT 6qUZV >qWZX 7YZZ :1[Z\ CA]Z^ CA_Z` CAaZb :1cZf 25gZh :5iZj 6vkZl =fmZn >voZr ;EsZt KEuZv @wZx ;EyZz KE{Z~ ;AZ@ ;AAZB 21CZD =aEZF ;AGZH HIZJ 4QKZL :1MZN ;AOZP ;AQZT )"UZV 4RWZX 6rYZZ Ee[Z\ Ea]Z^ H_Z` 1#aZb 6scZd 0eZf 1!gZh 8;/0453412sZvI(!I )!I 0	I
 .rI ,RI 8I (I )#I +CI +CI 22I 0I %aI  ,Q!I" +A#I$ +A%I& 0'I* &u+I, -f-I. -e/I0 4V1I2 ,U3I4 3G5I6 /7I8 .v9I: +A;I< -a=I> ,Q?I@ 5aAIB -bCID 0EIF 3BGIH ,QIIJ 1"KIN )"OIP +EQIR 5aSIT 25UIV 4RWIX 7YIZ .q[I\ 21]I` 4QaIb /cId :1eIf -agIh 4QiIj <QkIl /mIn 3BoIp 3BqIr 6qsIt 21uIv 0wIx 4QyIz ,Q{I| -c}I~ =aI@ CAAIB =aCID CAEIF 8GIH 1"IIJ 6qKIN 9"OIP 4RQIR <RSIT A!UIV =bWIX =bYIZ 9"[I^ 5a_I` ;AaIb :1cId 9!eIf =agIh @iIj :1kIl A!mIn 9!oIp 9!qIr <QsIt :1uIv 7wIx <QyIz ;A{I| 6q}I~ <QI@ ;AAIB 6qCID =aEIF :1GIH @IIJ ?KIN ;EOIP ;EQIR 8SIT 6qUIV 6qWIZ <Q[I\ :1]I^ <Q_I` :1aId 1!eIf 8gIh 6qiIj :1kIl :1mIn 8oIp 9!qIt 6tuIv 6qwIx 6tyIz =a{I| =a}I~ 9!I@ <QAIB :4CID EaEIF NS7<1313:>7<QIyfwB_m>
d !..x8!..x8
 "..x8!..x8
 "..x8!..x8
 "..y9!..y9em>
H " $Im>
R L L 	L
 3L ZL ]L ZL ^L 1L ZL -L 0L -L ]L  .!L" ]#L$ 1%L& Z'L( ])L* ]+L, ]-L. ]/L0 ]1L2 ]3L4 ]5L6 ]7L8 ]9L: Z;L< ]=L> 1?L@ -ALB ]CLD ZELF ]GLH ]ILL ]MLN 0OLP \QLR 0SLT 0ULV 0WLX 0YLZ 0[L\ ]]L^ ]_L` -aLb 0cLd 0eLf 0gLh 0iLj ZkLn ZoLp YqLr YsLt ZuLv \wLx \yLz \{L| \}L~ .L@ -ALB .CLD \ELF YGLH YILJ YKLL \MLN ]OLP ]QLR ]SLT \ULV 0WLX 0YLZ ][L\ -]L^ ]_L` YaLb 0cLd 0eLf 0gLh 0iLj \kLl \mLn \oLp \qLr \sLt \uLv \wLx \yLz \{L| \}L~ \L@ \ALB \CLD \ELF \GLH \ILJ \KLL \MLN \OLP \QLR \SLT \ULV \WLX \YLZ \[L\ \]L^ \_L` ZaLb \cLd .eLf \gLh \iLj \kLl \mLn .oLp \qLr \sLt \uLv \wLx \yLz \{L| .}L~ \L@ \ALB YCLD .ELF \GLH \ILJ \KLL \MLN \OLP \QLR \SLT \ULV /WLX ZYLZ Z[L\ \]L^ \_L` \aLb \cLd \eLf \gLh \iLj \kLl \mLn \oLp \qLr \sLt \uLv \wLx \yLz \{L| \}L~ \L@ \ALB \CLD \ELF \GLH \ILJ \KLL \MLN \OLP \QLR \SLT \ULV \WLX \YLZ \[L\ \]L^ \_L` \aLb \cLd \eLf \gLh \iLj \kLl \mLn \oLp ZqLr ZsLt \uLv \wLx \yLz \{L| \}L~ ]L@ ]ALB ]CLD \ELF \GLH ]ILJ ]KLL ZMLN ]OLP ]QLR ]SLT ]ULV ]WLX .YLZ ][L\ ]]L^ ]_L` ]aLb ]cLd ]eLf ]gLh ]iLj ]kLl ]mLn 0oLp 0qLr 0sLt ]uLv .wLz ]{L~ ]L@ ]ALB \CLD \ELF \GLH ]ILJ ZKLL ]MLP \QLR \SLT \ULV \WLX \YLZ \[L\ \]L^ \_Lb ]cLd 0eLf -gLh ]iLj -kLl ]mLn ]oLp ]qLr ]sLt -uLv .wLx ]yLz ]{L| ]}L~ ]L@ ]ALB ]CLD ]ELF ]GLH ]ILJ ]KLL ]MLN ]OLP ]QLR ]SLT ZULV ZWLX ZYLZ Z[L\ ]]L^ ]_L` ]aLb ^cLd -eLf ]gLh ]iLj ^kLl ]mLn ]oLp ]qLr ]sLt ]uLv 0wLx ZyLz Z{L| Z}L~ ZL@	 ZA	LB	 .C	LD	 ]E	LF	 .G	LJ	 ]K	LL	 ]M	LN	 ]O	LP	 ]Q	LR	 ]S	LT	 .U	LV	 ]W	LX	 ]Y	LZ	 ][	L\	 ]]	L^	 ._	L`	 ]a	Lb	 \c	Ld	 .e	Lf	 .g	Lh	 Zi	Lj	 -k	Ll	 -m	Ln	 ]o	Lp	 ]q	Lr	 ]s	Lt	 ]u	Lv	 .w	Lx	 .y	Lz	 .{	L|	 .}	L~	 Z	L@
 ]A
LB
 ]C
LD
 ]E
LF
 ]G
LH
 ]I
LJ
 ]K
LL
 ]M
LN
 ]O
LP
 -Q
LR
 ]S
LT
 ]U
LV
 ]W
LX
 ]Y
LZ
 ][
L\
 Z]
L^
 ]_
L`
 ]a
Lb
 Zc
Ld
 Ze
Lh
 0i
Lj
 0k
Ll
 0m
Ln
 0o
Lp
 0q
Lr
 \s
Lt
 0u
Lv
 0w
Lx
 0y
Lz
 0{
L|
 0}
L~
 Z
L@ ZALB .CLD \ELF 1GLH ZILJ ZKLL ZMLN ]OLP .QLR 0SLT ^ULV 0WLX ]YLZ 0[L\ .]L^ \_L` .aLb .cLd 0eLf 0gLh ]iLj ZkLl ZmLn ZoLp .qLr ZsLt ZuLv ZwLx ZyLz Z{L| Z}L~ ZL@ ZALB ('&/&-(0&/-WL\ .B$8]RSm>
x +ym>
~ Ym>
@]u] '] "" #$]  y9y[y #Ky U	y
 Wy Wy Wy Xy 7y Jy 7y hy ny 0y 0y  F!y" 5#y$  %y& W'y( ))y* G+y, =-y. </y0 91y2 H3y4 F5y6 67y: H;y< :=y> J?y@ HAyB 9CyD 5EyF FGyH -IyJ MKyN :OyP 9QyR HSyT 6UyV 9WyX FYyZ G[y\ H]y^ 8_y` 6ayb :cyd Weyf Fgyh Jiyj Kkyl Fmyn Foyp Fqyr Wsyt :uyv 
wyz 8{y| :}y~ Yy@ ;AyB 8CyD )EyF 8GyH :IyJ +KyL 7MyN 5OyP % $Uy]D + """"""""	#-E]\ ]]d !:#e]j <k]l 4Um]n A!o]t !!u]v *5w]x vy]@ 6 A]H 4I]N "<$O]T A!U]\ <( <& !%	 $(#'+# #  ## "#" "	# ##!
 #&"'(&"&"(&! /y]@  $&*(,$($(%)-
 -2)-+/ )-(,)-1
 &*7 $(#'"&#(	( #'$(#'$)/3+/27? $D r% ',$&!$%**/& ',#'$(*.	# ',!$#'$(*/( $(&+!$$&,2%)#'$(*/	* "% #!$#KJX  )!4( "9 "9 	 "9 "9 	ubH 335%^b^o^opx^y4z{335%^b^o^opx^y4z{335%^b^o^opx^y4z{335%^b^o^opx^y4z{335%^b^o^opx^y4z{ !!Q)m>
 m m	    N
methodNamemarketc                    > U R                  US5      nU R                  US5      nU R                  US5      nUc  Ub  XSS'   [        [        U ]  XX45      $ )NinstTypetype)safe_stringomitr|  rJ   handle_market_type_and_params)r  r  r  paramsdefaultValuer  r  r  s          r  r  !okx.handle_market_type_and_params[  s]    ##FJ76:./Lx3%6NS$=jRXggr  c                 `    U R                  U R                  S0 5      nU R                  X!U5      $ )NrI  )	safe_dictrw  r  )r  r  exchangeTypess      r  convert_to_instrument_typeokx.convert_to_instrument_typec  s+    t||^RHT::r  symbolc                    SnUR                  S5      nUR                  S5      nS nUR                  S5      S:  a  U R                  US5      nOU R                  US5      nUnU R                  US5      nU R                  US5      nU R                  US5      n	U R                  U5      n
U R	                  U
5      n0 S	US-   U-   S-   U-   S-   U-   S-   U	-   _S
US-   U-   S-   U-   S-   U-   S-   U-   S-   U	-   _SU_SU_SU_SU_SU_SU_SS_SS_SS _SS _SS_SS_SS_SS_SS_SU R                  S5      UU
U	S:X  a  SOS U R                  U5      S S S!.S S S".S S S".S S S".S#.S S$.	E$ )%Nrl  -/r   r   r  r  rN   r  :basequotesettlebaseIdquoteIdsettleIdactiveFr  r_   rj  rk  r[   r]   r^   Tr\   r  CcallputamountrO  minra  )r  rO  cost)	contractcontractSizeexpiryexpiryDatetime
optionTypestrikern  limitsinfo)splitfindr  convert_expire_date	parse8601r~  )r  r  r  optionParts
symbolBaser  r  r  r  r  datetime	timestamps               r  create_expired_option_market okx.create_expired_option_marketg  sW   ll3'\\#&
;;sb ##J2D##K3D!!+q1!!+q1%%k15
++F3NN8,	+
$*u$s*V3c9FBSH:U+
dSj5(3.7#=FLvUX[[^hh+
 D+
 U	+

 f+
 d+
 u+
 +
 e+
 H+
 d+
 t+
 E+
 E+
 e+
  d!+
" e#+
$  --c2&%/3%6&U''/  
  
   U+
 +	
r  marketId	delimiter
marketTypec                    > US L=(       a/    UR                  S5      S:  =(       d    UR                  S5      S:  nU(       a   XR                  ;  a  U R                  U5      $ [        [        U ]  XX45      $ )Nz-Cr  z-P)r  markets_by_idr  r|  rJ   safe_market)r  r  r  r  r  isOptionr  s         r  r  okx.safe_market  sh    D(hd0Cb0H/ghmm\`NadfNfX););;44X>>S$+HiTTr  c                   #    U R                  U5      I Sh  vN nU R                  US/ 5      n[        U5      nSUS:X  a  SOSSSUS.n[        S[        U5      5       Hw  nX6   nU R	                  US5      nU R                  US5      US	'   U R	                  US
5      US'   US:X  a  SUS'   MP  US:X  a  SUS'   M]  US:X  a  SUS'   Mj  US:X  d  Mr  SUS'   My     U$  N7f)a#  
the latest known information on the availability of the exchange API

https://www.okx.com/docs-v5/en/#status-get-status

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
Ndatar   okmaintenance)updatedstatusetar   r  stateendr  hrefr   ongoingr  	scheduled	completedcanceled)publicGetSystemStatus	safe_listlenranger  safe_integer)	r  r  responser  
dataLengthupdateieventr  s	            r  fetch_statusokx.fetch_status  s     33F;;* ~~h3Y
)Qd]
 q#d)$AGE$$UG4E --eU;F5M ,,UF;F5M	!#0x +%#'x +%#'x *$#'x  % W <s   CCB5CCc                    #    U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  US5      $  N<7f)a9  
fetches the current integer timestamp in milliseconds from the exchange server

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-system-time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
Nr  r   ts)publicGetPublicTimer  r  r  )r  r  r  r  firsts        r  
fetch_timeokx.fetch_time  sX      11&99 ~~h3tQ+  -- :s   AA=Ac           	      $  #    U R                  U5      I Sh  vN nU R                  US/ 5      n/ n[        S[        U5      5       HB  nX5   nU R	                  US5      nU R	                  US5      nUR                  UUSUSS.5        MD     U$  Nv7f)aT  
fetch all the accounts associated with a profile

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
Nr  r   uidacctLv)rN   r  currencyr  rm  )privateGetAccountConfigr  r  r  r  append)	r  r  r  r  resultr  account	accountIdr  s	            r  fetch_accountsokx.fetch_accounts  s      55f==N ~~h3q#d)$AgG((%8I##GX6DMM  	 % i >s   BBA7Bc                 B    U R                  5       U R                  S   -
  $ )Nr-  )millisecondsrw  )r  s    r  nonce	okx.nonce7  s       "T\\2B%CCCr  c                 2  #    U R                   S   (       a  U R                  5       I Sh  vN   / SQnU R                  U R                   S5      nUb  U R                  USU5      nOU R                  U R                   SU5      n/ n/ n[	        S[        U5      5       H&  nUR                  U R                  X&   U5      5        M(     [        R                  " U6 I Sh  vN n[	        S[        U5      5       H  nU R                  XTU   5      nM     U$  N N87f)z
retrieves data on all markets for okx

https://www.okx.com/docs-v5/en/#rest-api-public-data-get-instruments

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r.  Nr,  r   r+  r   )rw  load_time_differencer  r  r  r  r  fetch_markets_by_typeasynciogatherarray_concat)r  r  r+  fetchMarketsOptionpromisesr  r  s          r  fetch_marketsokx.fetch_markets:  s      <<12++---4!^^DLL.I)NN#5wFENN4<<GEq#e*%AOOD66uxHI & 22q#h-(A&&v{;F ) . 3s"   (DDB1DD7DDc                    U R                  US5      nU R                  US5      nUS:X  a  SnUS:H  nUS:H  nUS:H  nUS:H  nU=(       d    U=(       d    UnU R                  USS	5      n	U R                  US
S	5      n
U R                  US5      nU R                  U5      nU R                  US5      nUb<  U(       d5  UR                  S5      nU R                  US5      n	U R                  US5      n
U	S	:X  d  U
S	:X  aO  U(       aH  U R                  USS	5      nUR                  S5      nU R                  US5      n	U R                  US5      n
U R                  U	5      nU R                  U
5      nUS-   U-   nUS	:X  d  US	:X  a  UnS nS nS nU(       a  Ub  US-   U-   nU(       a/  U R	                  US5      nUb  U R                  U5      nUS-   U-   nOoU(       ah  U R	                  US5      nU R                  US5      nU R                  US5      nUb/  U R                  U5      nUS-   U-   S-   U-   S-   U-   nUS:X  a  SOSnU R                  U R                  US0 5      nU R                  USS5      n[        R                  " US5      nU R                  US5      nU R                  US5      nU R                  U0 SU_SU_SU_S U_S!U_S"U	_S#U
_S$U_S%U_SU_S&U=(       a    [        R                  " US5      _SU_SU_SU_S'US(:H  _S)U_S*U(       a  X:H  OS _U(       a  X:H  OS U(       a  U R                  US+5      OS UU R                  U5      U R                  U5      UU R                  US,S-5      U R                  US.5      U R                  US/5      S0.U R                  S5      U R                  U5      S1.U R                  US25      S S1.S S S1.S U(       a  S OUS1.S3.US4.
E5      $ )5NinstIdr  r?  r^   r[   r]   r_   baseCcy quoteCcy	settleCcyulyr  r   r  r  r  expTimestkoptTypePr  r  r  leverr  maxMktSzr  rN   r  r  r  r  r  r  r  r  r\   r  liver  rj  ctValcontTdSwTimelistTimelotSztickSzr  r  minSz)r]  r  rO  r  )
rk  r  r  r  r  r  createdrn  r  r  )r  safe_string_lowersafe_currency_coder  r  yymmddsafe_dict_2r   rH   
string_maxsafe_numberextend	string_gtiso8601r~  safe_integer_2)r  r  rN   r  r[   r^   r]   r_   r  r  r  r  r  
underlyingpartsr  r  r  r  r  strikePricer  ymdr   maxLeveragemaxSpotCostr  s                              r  parse_marketokx.parse_marketT  s   r fh/%%fj99D("("+6+V!!&)R8""6:r:##FK8((2%%fe4
"D$$S)E%%eQ/F&&ua0Gr\w"}4%%fh;FLL%E%%eQ/F&&ua0G&&v.''0e#2:"F
!#.**69=%++f-C#c\C/F**69="..vu=!--fi@
%++f-C#c\C/#5CcIJVF+5+<6J		4B?&&vw<((c:&&vz:!!&'2{{4 0"
"0"
f0"
 D0"
 U	0"

 f0"
 f0"
 w0"
 0"
 D0"
 D0"
 dD 1 1+s C0"
 D0"
 f0"
 f0"
 f&0"
  !0"
" xw*T#0"
$ 08*TAID,,VW=t"ll62''4$**6>:N**67;))&(;  ,,S1,,[9
  ++FG<
  
  #+4$ _0"
 0 0	r  c           	        #    SU R                  U5      0nUS:X  a  U R                  U R                  SSS/5      n/ n[        S[	        U5      5       H:  nXF   nXsS'   UR                  U R                  U R                  X25      5      5        M<     [        R                  " U6 I S h  vN n/ n	[        S[	        U5      5       H9  nU R                  X0 5      n
U R                  U
S/ 5      nU R                  X5      n	M;     U R                  U	5      $ U R                  U R                  X25      5      I S h  vN nU R                  US/ 5      nU R                  U5      $  N N*7f)	Nr  r_   defaultUnderlyingBTC-USDzETH-USDr   r  r  )r  r  rw  r  r  r  publicGetPublicInstrumentsr  r  r  r  r  parse_markets)r  r  r  requestoptionsUnderlyingr  r  r  promisesResultmarketsresrw  r  dataResponses                 r  r  okx.fetch_markets_by_type  sQ    77=
 8 $t||=PS\^gRh iH1c"345.1
!+ ? ?G@\ ]^ 6 $+>>8#<<NG1c.12nn^;..fb9++G= 3 %%g..88W9UVVD ~~h;!!,//U = Ws%   B$E &E'BE 3E4)E E c                   #    U R                  U R                  SS5      nU R                  S5      (       a  U(       a  0 $ U R                  U5      I Sh  vN nU R	                  US/ 5      n0 nU R                  US5      n[        UR                  5       5      n[        S[        U5      5       GH  nXx   n	U R                  U	5      n
U
S   nXi   n0 nSn[        U5      n[        SU5       H  nUU   nU R                  US	S
5      nUS
:X  a  SnUR                  S5      nU R                  US5      nSR                  U5      nU R                  UU
S   5      nUUSU R                  US5      U R                  US5      U R!                  US5      U R#                  U R%                  U R                  US5      5      5      SU R!                  US5      U R!                  US5      S.0US.	UU'   GM     U R'                  US0 5      nU R)                  UUU	U R                  US5      SSSSSSSSS.0UUS.5      X['   GM     U$  GN7f)z
fetches all available currencies on an exchange

https://www.okx.com/docs-v5/en/#rest-api-funding-get-currencies

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
r  FNr  ccyr   rm  cryptochainr   fiatr  r  canDepcanWdfeewdTickSzr   minWdmaxWdr  )	rN   networkr  depositr   r7  rn  r  r  rO   r  )r  rm  rN   rO   r  r<  r   r7  rn  r  r  r  )	safe_boolrw  check_required_credentialsprivateGetAssetCurrenciesr  group_bylistkeysr  r  safe_currencyr  r  array_slicejoinnetwork_id_to_coder  r~  parse_precisionr  r  )r  r  isSandboxModer  r  r  dataByCurrencyIdcurrencyIdsr  
currencyIdr  rm  chainsr  r  chainsLengthjr3  	networkIdidPartsr  	chainPartnetworkCode
firstChains                           r  fetch_currenciesokx.fetch_currencies+  sr     t||]EJ..u55I 77??X ~~h3==u5+0023q#k*+A$J))*5HF#D%1FHDv;L1l+q	 ,,UGR@	?!D#//#.((!4HHUO	"55i&AQR#*"#~~eX> $ug >++E59!%!2!243G3GHXHXY^`jHk3l!m"#'#3#3E7#C#'#3#3E7#C% ")% ,6 26J77 ((V< !## $#9 FLI ,n O @s   AH?H<G)H?rd  c                 *  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nSnU R                  USSS5      u  pcUS:X  a  Uc  SnUc  S	OUnUb  X%S
'   SnUS:X  d  US:  a)  U R                  U R	                  XS5      5      I Sh  vN nO(U R                  U R	                  XS5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      n	U R                  U	S5      n
U R                  XU
5      $  N Ny NR7f)a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-order-book

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.method]: 'publicGetMarketBooksFull' or 'publicGetMarketBooks' default is 'publicGetMarketBooks'
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr  rN   r   r'  publicGetMarketBookspublicGetMarketBooksFulli  r	  szi  r  r   r  )
load_marketsr  handle_option_and_paramsrX  r  rW  r  r  r  parse_order_book)r  r  rd  r  r  r)  r'  r  r  r  r  s              r  fetch_order_bookokx.fetch_order_book  s)     !!!V$fTl
 66v?OQY[qr//EMEE!DM00eck!::4;;w;WXXH!66t{{77STTH, ~~h3tQ+%%eT2	$$UI>>S 	" YTs5   DDA>DD(D>D?ADDDtickerc           
          U R                  US5      nU R                  US5      nU R                  XBS5      nUS   nU R                  US5      nU R                  US5      nU R                  USS5      nU(       a  U R                  US	5      OS n	U R                  US
5      n
U R                  US5      nU R                  US5      nU R	                  0 SU_SU_SU R                  U5      _SU_SU_SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU_SU_SU_SS _SS _SS _SS _U
U	U R                  US 5      U R                  US!5      US".EU5      $ )#Nr  r  r  r  rK  open24hr[   F	volCcy24hvol24hhigh24hlow24hr  r  highlowbidbidPx	bidVolumebidSzaskaskPx	askVolumeaskSzvwapopenclosepreviousClosechange
percentageaveragemarkPxidxPx)
baseVolumequoteVolume	markPrice
indexPricer  )r  r  r  r=  safe_tickerr  )r  r_  r  r  r  r  rK  rq  r[   rz  ry  rf  rg  s                r  parse_tickerokx.parse_ticker  s   L %%fd3	##FH5!!(C8!/	2~~ffe4?Cd&&v{;%%fh7
	2vx0 !
f!
!
 Y/!
 D	!

 3!
 4##FG4!
 ))&':!
 4##FG4!
 ))&':!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&))&(;**67;-!
. / 	r  c                 0  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  US0 5      nU R                  Xs5      $  N{ N=7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-ticker

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr  rN   r  r   )rZ  r  publicGetMarketTickerr  r  r  r~  r  r  r  r  r)  r  r  r  s           r  fetch_tickerokx.fetch_ticker*  s      !!!V$fTl
 33DKK4PQQ6 ~~h3tQ+  //E 	"
 R!   BB?BB<BBsymbolsc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      nSnU R                  SX25      u  pBSU R	                  U5      0nUS:X  aP  U R                  U R                  SS5      nU R                  USSU5      nUc  [        U R                  S	-   5      eXuS'   U R                  U R                  XR5      5      I Sh  vN nU R                  US
/ 5      n	U R                  X5      $  N N*7f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers

:param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r  r_   r%  r&  r  r  zT fetchTickers() requires an underlying uly or marketId parameter for options marketsr  )rZ  market_symbolsget_market_from_symbolsr  r  r  rw  safe_string_2r3   rN   publicGetMarketTickersr  r  parse_tickers
r  r  r  r  r  r)  r%  rK  r  tickerss
             r  fetch_tickersokx.fetch_tickersX  s"     !!!%%g.--g6
!??PV_
77
C
 ! $ 0 0?RT] ^++FE:GXYJ!'  3I  )I  J  J!+44T[[5QRR6 ..626!!'33W 	" Ss"   DDCDD
 )D
Dc                 *  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US5      nU R                  U R                  US5      U5      $  Nx N:7f)a`  
fetches mark price for the market

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr  rN   r  r   )rZ  r  publicGetPublicMarkPricer  r  r~  r  )r  r  r  r  r)  r  r  s          r  fetch_mark_priceokx.fetch_mark_price  s      !!!V$fTl
 66t{{77STT ~~h/  a!8&AA+ 	"
 Us!   BB?BB9BBc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U5      nSnU R                  SX2S5      u  pBSU R	                  U5      0nUS:X  aP  U R                  U R                  SS5      nU R                  USS	U5      nUc  [        U R                  S
-   5      eXuS'   U R                  U R                  XR5      5      I Sh  vN nU R                  US/ 5      n	U R                  X5      $  N N*7f)a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price

:param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r]   r  r_   r%  r&  r  r  zW fetchMarkPrices() requires an underlying uly or marketId parameter for options marketsr  )rZ  r  r  r  r  r  rw  r  r3   rN   r  r  r  r  r  s
             r  fetch_mark_pricesokx.fetch_mark_prices  s"     !!!%%g.--g6
!??PV`fg
77
C
 ! $ 0 0?RT] ^++FE:GXYJ!'  3L  )L  M  M!+66t{{77STT..626!!'33# 	" Us"   DD	C	D D!)DDtradec                 ~   U R                  US5      nU R                  US5      nU R                  XBS5      nUS   nU R                  US5      nU R                  USS5      nU R                  USS	5      nU R                  US
5      n	U R                  US5      n
U R                  US5      nS nUb>  [        R
                  " U5      nU R                  US5      nU R                  U5      nUUS.nU R                  US5      nUS:X  a  SnOUS:X  a  SnU R                  UUU R                  U5      UUU
S UU	UUS US.U5      $ )NtradeIdr  r  r  r  fillPxpxfillSzrY  sideordIdr7  feeCcyr  r  execTypeTr  Mr  )r  r  r  r  rN   orderr  takerOrMakerr  rO  r  r  r7  )	r  r  r  r  rH   
string_negr  
safe_trader  )r  r  r  rN   r  r  r  rO  r  r  orderIdfeeCostStringr7  feeCostSignedfeeCurrencyIdfeeCurrencyCoder  s                    r  parse_tradeokx.parse_trade  sx   d eY/##E84!!(C8!%%eT2	""5(D9##E8T:v.""5'2((6$#..}=M ,,UH=M"55mDO%+C ''z:3"LS "L"Y/( 
  	r  sincec                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX4SSSS5	      I Sh  vN $ U R                  U5      nSUS	   0nSnUS
   (       a)  U R	                  U R                  Xt5      5      I Sh  vN nO|Ub  X7S'   Sn	U R                  USSS5      u  pU	S:X  a)  U R                  U R                  Xt5      5      I Sh  vN nO.U	S:X  a(  U R                  U R                  Xt5      5      I Sh  vN nU R                  US/ 5      n
U R                  XX#5      $  GN0 N N N_ N27f)aU  
get the list of most recent trades for a particular symbol

https://www.okx.com/docs-v5/en/#rest-api-market-data-get-trades
https://www.okx.com/docs-v5/en/#rest-api-public-data-get-option-trades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.method]: 'publicGetMarketTrades' or 'publicGetMarketHistoryTrades' default is 'publicGetMarketTrades'
:param boolean [params.paginate]: *only applies to publicGetMarketHistoryTrades* default False, when True will automatically paginate by calling self endpoint multiple times
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NFr   paginater  afterr	  r  rN   r_   rd  r'  publicGetMarketTradespublicGetMarketHistoryTradesr  )
rZ  r[  fetch_paginated_call_cursorr  publicGetPublicOptionTradesr  r  r  r  parse_trades)r  r  r  rd  r  r  r  r)  r  r'  r  s              r  fetch_tradesokx.fetch_trades'	  sn     !!!88PZ[99-X]gpry{  BE  F  F  FV$fTl
 (!==dkk'>Z[[H #( F!::6=RZ\stNF00!%!;!;DKK<X!YY99!%!B!B4;;wC_!``F ~~h3  u<<q 	" F \ Z`sY   EE<EE	AEE AE-E..EE*E	EEEEc           	         U R                  SUS 5      nUS   nUS:X  a  SOSnU R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US	5      U R                  X5      /$ )
Nr   r   r[   r     r  r   r  r  )r  r  r  )r  ohlcvr  r-  r  volumeIndexs         r  parse_ohlcvokx.parse_ohlcvp	  s     00vtL1v FNaeQ'UA&UA&UA&UA&U0
 	
r  r   	timeframec           	      $  #    U R                  5       I Sh  vN   U R                  U5      nSnU R                  USS5      u  puU(       a  U R                  SXXBUS5      I Sh  vN $ U R	                  US5      nU R                  USS/5      n	U R                  US5      nU R                  U R                  S0 5      n
U R	                  U
S	S
5      nUSL nUc  SnOU	(       a  SOSn[        XM5      nU R                  U5      nU R	                  U R                  X"5      nUS
:X  a  US:  a  XR                  5       -  nUS   UUS.nSnUbg  U R                  5       nUS-  nUSU-  -
  nUU:  a  SnU	(       a  SOSn[        XM5      n[        US-
  S5      nUUS'   U R                  UUU-  5      US'   U R!                  US5      nUb  UUS'   U R                  US5      nU R	                  U
SU5      nU R	                  USU5      nU R                  US5      nUS:H  nSnUS:X  a\  U(       a+  U R#                  U R%                  UU5      5      I Sh  vN nGOU R'                  U R%                  UU5      5      I Sh  vN nOUS:X  af  US   S   US'   U(       a*  U R)                  U R%                  UU5      5      I Sh  vN nOU R+                  U R%                  UU5      5      I Sh  vN nOnU(       a>  U(       a  US:X  a  SnSUS'   U R-                  U R%                  UU5      5      I Sh  vN nO)U R/                  U R%                  UU5      5      I Sh  vN nU R1                  US/ 5      nU R3                  UXbX45      $  GNf GN GN7 GN N N Nd N<7f)aU  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.okx.com/docs-v5/en/#rest-api-market-data-get-candlesticks
https://www.okx.com/docs-v5/en/#rest-api-market-data-get-candlesticks-history
https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks
https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks-history
https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks
https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks-history
https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.price]: "mark" or "index" for mark price and index price candles
:param int [params.until]: timestamp in ms of the latest candle to fetch
:param str [params.type]: "Candles" or "HistoryCandles", default is "Candles" for recent candles, "HistoryCandles" for older candles
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns int[][]: A list of candles ordered, open, high, low, close, volume
NFr   r     rO  rL  rM  r%  r&  r	  r  i`T  rN   )r  barrd  Candles  i  HistoryCandlesr  r   beforer  untilr  r  
instFamilyr  rd  r  )rZ  r  r[  "fetch_paginated_call_deterministicr  in_arrayr  r  rw  r  parse_timeframer   lowerr  ra  sumr  &publicGetMarketHistoryMarkPriceCandlesr  publicGetMarketMarkPriceCandles"publicGetMarketHistoryIndexCandlespublicGetMarketIndexCandlespublicGetMarketHistoryCandlespublicGetMarketCandlesr  parse_ohlcvs)r  r  r  r  rd  r  r  r  	priceTypeisMarkOrIndexrw  r%  limitIsUndefinedmaxLimitdurationr  r)  r/  nowdurationInMillisecondshistoryBorder	startTimer  r  isHistoryCandlesr  r  s                              r  fetch_ohlcvokx.fetch_ohlcv	  s    . !!!V$88zZ@@v^cpvx{|||$$VW5	i&'1BC67+..|R@##GZ?!TM=E+sH(E''	2t	EH$5>>##CTl

  ##%C%-_"H0F#FGM}$."/3SE,EAIq)I )GH#xx/E/MNGG!!&'2$GGYYvw/F&&wD<66* $44!%!L!LT[[Y`bhMi!jj!%!E!EdkkRY[aFb!cc'! &v| <GH!%!H!HU\^dIe!ff!%!A!A$++gW]B^!__##E'*GG$!%!C!CDKKPWY_D`!aa!%!<!<T[[RX=Y!ZZ ~~h3  v%GG_ 	"
 }Z kc g_ bZs   NM<AN"M?#G(NN*N6N7AN8N9)N"N
#AN'N()NN+N?NNNN
NNNc           
      6  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R	                  SXUSUS5      I Sh  vN $ U R                  U5      nSUS	   0nUb  [        US
-
  S5      US'   Ub  X7S'   U R                  U R                  Xt5      5      I Sh  vN n/ n	U R                  US/ 5      n
[        S[        U
5      5       Hn  nX   nU R                  US5      nU	R                  UU R                  U R                  US5      5      U R!                  US5      UU R#                  U5      S.5        Mp     U R%                  U	S5      nU R'                  XS   X#5      $  GN` GN' N7f)aK  
fetches historical funding rate prices

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate-history

:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: timestamp in ms of the earliest funding rate to fetch
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
Nz5 fetchFundingRateHistory() requires a symbol argumentFr   r  r#  r	  r  rN   r  r   r  rd  r  fundingTimerealizedRate)r  r  fundingRater  r  r  r  )r3   rN   rZ  r[  r  r  ra  !publicGetPublicFundingRateHistoryr  r  r  r  r  r  safe_symbolr  r  r  sort_byfilter_by_symbol_since_limit)r  r  r  rd  r  r  r  r)  r  ratesr  r  rater  sorteds                  r  fetch_funding_rate_historyokx.fetch_funding_rate_history	  s     >#DGG.e$eff!!!88AZ\fg@@AZ\bkprvx~  AD  E  E  EV$fTl
  #EAIq 1GH$G??G@\]]. ~~h3q#d)$A7D))$>ILL**4+;+;D(+KL#//nE& LL3  % e[1009I5XXc 	" E ^s5   /FF;F-F.AF	F
CFFFc                 R    US:X  a  U R                  U5      $ U R                  U5      $ )Nr>  )parse_funding_balanceparse_trading_balance)r  r  r  s      r  parse_balance_by_typeokx.parse_balance_by_type4
  s,    9--h77--h77r  c                 T   SU0nU R                  US/ 5      nU R                  US0 5      nU R                  US5      nU R                  US/ 5      n[        S[	        U5      5       H  nXg   nU R                  US5      n	U R                  U	5      n
U R                  5       nU R                  US5      nU R                  US5      nXS	'   Uc+  U R                  US
5      US'   U R                  US5      US'   OXS'   XU
'   M     XRS'   U R                  U5      US'   U R                  U5      $ )Nr  r  r   uTimedetailsr1  eqavailEqtotalavailBalfree	frozenBalusedr  r  )
r  r  r  r  r  r  r  r  r  safe_balance)r  r  r  r  r  r  r  r  balancerK  rm  r  r  r  s                 r  r  okx.parse_trading_balance:
  s6   )~~h3tQ+%%eW5	..	26q#g,'AjG))'59J**:6DllnG!!'40B&&w	:G!G"&"2"27J"G"&"2"27K"H")"4L ( ({!\\)4z  ((r  c                 ~   SU0nU R                  US/ 5      n[        S[        U5      5       H}  nX4   nU R                  US5      nU R	                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US	5      US
'   XU'   M     U R                  U5      $ )Nr  r  r   r1  balr  r  r  r  r  )r  r  r  r  r  r  r  )	r  r  r  r  r  r   rK  rm  r  s	            r  r  okx.parse_funding_balanceS
  s    )~~h3q#d)$AgG))'59J**:6DllnG#//?GG"..w
CGFO"..wDGFO"4L %   ((r  r7  c                    UU R                  S U5      U R                  [        R                  " U R	                  USS5      5      5      U R                  [        R                  " U R	                  USS5      5      5      S S S.$ )Nr  makerUr  takerU)r  r  r  r  ru  	tierBased)r  r~  rH   r  r  )r  r7  r  s      r  parse_trading_feeokx.parse_trading_feeb
  s{     &&tV4&&w'9'9$:L:LSRY[c:d'ef&&w'9'9$:L:LSRY[c:d'ef
 	
r  c                   #    U R                  5       I Sh  vN   U R                  U5      nSU R                  US   5      0nUS   (       a	  US   US'   OHUS   (       d  US   (       d
  US	   (       a  US
   S-   US   -   US'   O[        U R                  S-   5      eU R                  U R                  XB5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $  N N=7f)a1  
fetch the trading fees for a market

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-fee-rates

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
Nr  r  r[   rN   r  r]   r^   r_   r  r  r  r  zE fetchTradingFee() supports spot, swap, future or option markets onlyr  r   )
rZ  r  r  r>   rN   privateGetAccountTradeFeer  r  r  r	  r  s           r  fetch_trading_feeokx.fetch_trading_feez
  s      !!!V$77vG
 &> &tGHF^vh/6(3C#H-3fY6GGGENtww)ppqq77G8TUU& ~~h3tQ+%%e44G 	" Vs"   D C<B)D  C><D >D c                 H  #    U R                  5       I Sh  vN   U R                  SSU5      u  p#0 nSnUS:X  a)  U R                  U R                  XC5      5      I Sh  vN nO(U R	                  U R                  XC5      5      I Sh  vN nU R                  X%5      $  N N@ N7f)a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-balance
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: wallet type, ['funding' or 'trading'] default is 'trading'
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr{   r>  )rZ  r  privateGetAssetBalancesr  privateGetAccountBalancer  )r  r  r  queryr)  r  s         r  fetch_balanceokx.fetch_balance
  s      !!! >>~tU[\

 "!99$++g:UVVH!::4;;w;VWWHN ))*??a 	" WWs4   B"BAB"B(B"B B"B" B"r  c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSSS.nU R	                  USSUSU R                  XS5      5      I Sh  vN $  Ni N7f)	  
create a market buy order by providing the symbol and cost

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr[   z: createMarketBuyOrderWithCost() supports spot markets onlyF	quote_ccyr*  tgtCcyr  buyrZ  r  r>   rN   create_orderr  r  r  r  r  r  reqs         r  !create_market_buy_order_with_cost%okx.create_market_buy_order_with_cost&  s      !!!V$f~tww)eeff16!
 &&vxdDKKX[Ldeee 	" f"   BB A$B;B<BBc                   #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSSS.nU R	                  USSUSU R                  XS5      5      I Sh  vN $  Ni N7f)	r  Nr[   z; createMarketSellOrderWithCost() supports spot markets onlyFr  r  r  sellr  r  s         r  "create_market_sell_order_with_cost&okx.create_market_sell_order_with_cost;  s      !!!V$f~tww)ffgg16!
 &&vxtT[[Y\Mefff 	" gr!  r  r  r  rO  c                 D   U R                  U5      nUS   UUU R                  X5      S.nUS   n	US   n
U R                  U/ SQ5      nU R                  USS5      nU R	                  USS	5      nU R                  US
U5      nU R                  USS5      nU R	                  USS5      nU R                  USU5      nU R                  USS5      nU R                  USS5      nU R                  US5      nUS LnU R                  US5      nUS LnU R                  USS5      nUS LnU R                  USS5      nUS LnUS L=(       d    US:H  nU R                  USS5      nU R                  U R                  SSS5      nU R                  USS5      nSn Ub	  US :w  a  S!n OUnU R                  US"S5      n U	(       aO  U (       a7  US#:X  a  US$   OUS%   n!U R                  US&U!5      n"U R                  U"5      US&'   U (       a  UOS n#U#US'   OU
(       a  US'   (       d
  US(   (       a  S n$U R                  US)S*5      u  n$nU$b  U$US+'   OyS n%U R                  US)S,5      u  n%nU%(       aZ  US#:H  n&US L=(       d    US L=(       d    Un'U'(       a(  U&(       a  S-OS.US+'   U(       a  U R                  US5      nOU&(       a  S.OS-US+'   UUS'   US/:H  n(Sn)U R                  U(US0:H  U5      u  n)nU R                  U/ S1Q5      nUS2:H  =(       d    US3:H  n*US4:H  =(       d    US5:H  n+US L=(       d    US L=(       d    US6:H  n,U(=(       a    U*=(       d    US7:H  n-U R                  U R                  S8S95      n.U R                  US8U.5      n/U
(       d  U (       d  U/US8'   U((       d  U-(       a  S/US:'   U	(       a  US#:X  a  U/S;:X  a  S!n0U R                  US)S<S!5      u  n0nU R                  US=S>5      n1U R                  US=S>/5      nU0(       am  UbN  U1cJ  U R                  U5      n2U R                  U5      n3[        R                   " U2U35      n4U R#                  U45      n1O#U1c  [%        U R&                  S?-   5      eOU1c  UOU1n1U R)                  UU15      US>'   U-(       a  U
(       a  S7US:'   O"U(       d  U,(       d  U R+                  X5      US@'   U)(       a  S0US:'   O U*(       a  U-(       d  S3US:'   OU+(       a  S5US:'   U(       a#  [        R,                  " USA5      n5U5US'   SBUS:'   GO#U(       a  UUS'   SBUS:'   GOU(       d  U(       Ga  0 n6U(       Ga[  U R                  U/ SCQ5      n7U7c  [%        U R&                  SD-   5      eU R+                  UU75      n80 n9U8U9S'   U R                  U/ SEQ5      n:U R                  USF5      n;U;bt  U;SG:H  n<U;S/:H  n=U<(       d  U=(       d  [%        U R&                  SH-   5      eU<(       a1  U:c  [%        U R&                  SI-   5      eU R+                  UU:5      U9S'   O*U;S/:X  a  SJU9S'   OU:b  U R+                  UU:5      U9S'   OSJU9S'   U R                  USKSS5      n>U>b/  U>S:w  a$  U>SL:w  a  U>SM:w  a  [%        U R&                  SN-   5      eU>U9S'   U R/                  U6U95      n6U(       Gad  U R                  U/ SOQ5      n?U?c  [%        U R&                  SP-   5      e0 n@U R+                  UU?5      U@S	'   U R                  U/ SQQ5      nAU R                  USFSR5      nBUBby  WBSG:H  nCUBS/:H  nDUC(       d  WD(       d  [%        U R&                  SS-   5      eWC(       a6  WAc  [%        U R&                  ST-   5      eWBW@SR'   U R+                  UWA5      U@S
'   O/WBS/:X  a  SJW@S
'   O#WAb  SGW@SR'   U R+                  UWA5      U@S
'   OSJW@S
'   U R                  USKSS5      nEUEb/  WES:w  a$  WESL:w  a  WESM:w  a  [%        U R&                  SU-   5      eWEW@S'   U R/                  U6W@5      n6[1        U6R3                  5       5      nF[5        UF5      nGUGSV:  a  U6/USW'   U(       a7  SUS:'   U R+                  X5      USX'   U((       a  SJOU R+                  X5      USY'   OU,(       a  S6US:'   US L=(       a    US LnHUH(       a  SZUS:'   US[:X  a  U R                  US85      nU R                  US5      S :X  a  UUS'   Ub3  U R+                  X5      US	'   SJnIUb  U R+                  X5      nIWIUS
'   XS'   Ub6  U R+                  UU5      US'   SJnJUb  U R+                  UU5      nJWJUS'   UUS'   Uc;  U R                  U R                  S\5      nKUKb  WKU R7                  5       -   US'   UKUS]'   OUUS'   U R                  USS/5      nU R/                  X5      $ )^NrN   )r  r  ordTyperY  r[   r  )rU  	stopPrice	triggerPxrZ  GTCrX  tpTriggerPxtpOrdPxtpTriggerPxTyperK  rW  slTriggerPxslOrdPxslTriggerPxTypeclOrdIdclientOrderIdstopLoss
takeProfittrailingPercentcallbackRatiotrailingPricecallbackSpreadr7  
reduceOnlyFdefaultMarginModerT  crosstdModecashTr\   r  r  r  r1  r]   r^   rl   positionSideposSider[  shortlongr  	post_only)r  r1  rT  rZ  r(  rU  r2  rW  rX  r/  r,  r\   r3  r4  r5  rP  iocrQ  fokr6  optimal_limit_iocr  base_ccyr'  r  r*  r  rY  a   createOrder() requires the price argument with market buy orders to calculate total order cost(amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = False and supply the total cost value in the 'amount' argument or in the 'cost' unified extra parameter or in exchange-specific 'sz' extra parameter(the exchange-specific behaviour)r  100r9  )rU  r(  r.  z createOrder() requires a trigger price in params["stopLoss"]["triggerPrice"], or params["stopLoss"]["stopPrice"], or params["stopLoss"]["slTriggerPx"] for a stop loss order)rO  rW  r/  r  rd  zL createOrder() params["stopLoss"]["type"] must be either "limit" or "market"z createOrder() requires a limit price in params["stopLoss"]["price"] or params["stopLoss"]["slOrdPx"] for a stop loss limit order-1rN  rM  rL  zT createOrder() stop loss trigger price type must be one of "last", "index" or "mark")rU  r(  r+  z createOrder() requires a trigger price in params["takeProfit"]["triggerPrice"], or params["takeProfit"]["stopPrice"], or params["takeProfit"]["tpTriggerPx"] for a take profit order)rO  rX  r,  	tpOrdKindzN createOrder() params["takeProfit"]["type"] must be either "limit" or "market"z createOrder() requires a limit price in params["takeProfit"]["price"] or params["takeProfit"]["tpOrdPx"] for a take profit limit orderzV createOrder() take profit trigger price type must be one of "last", "index" or "mark"r   attachAlgoOrdsr)  orderPxr8  r#  rJ  tag)r  amount_to_precisionsafe_value_nr  safe_value_2
safe_valuer  rw  r=  r  r[  r  handle_post_onlysafe_number_2number_to_stringrH   
string_mulr~  r;   rN   cost_to_precisionprice_to_precision
string_divr  rA  rB  r  uuid16)Lr  r  r  r  r  rO  r  r  r)  r[   r  rU  rZ  rX  r,  r-  rW  r/  r0  r2  r3  stopLossDefinedr4  takeProfitDefinedr5  isTrailingPercentOrderr7  isTrailingPriceOrderr7  isReduceOnlyr:  rT  r\   defaultCurrencyr  	tradeModer>  r[  isBuyisProtectiveisMarketOrderpostOnlyrC  rD  r6  	marketIOCdefaultTgtCcyr  r*  notionalamountStringpriceStringquoteAmountconvertedTrailingPercentattachAlgoOrdstopLossTriggerPricer.  slOrderstopLossLimitPricestopLossOrderTypestopLossLimitOrderTypestopLossMarketOrderTypestopLossTriggerPriceTypetakeProfitTriggerPricetpOrdertakeProfitLimitPricetakeProfitOrderTypetakeProfitLimitOrderTypetakeProfitMarketOrderTypetakeProfitTriggerPriceTypeattachOrdKeysattachOrdLentwoWayCondition
tpOrdPxReq
slOrdPxReqrJ  sL                                                                               r  create_order_requestokx.create_order_requestP  s-   V$Tl  **6:
4 f~*%((1[\&&v}eD++F4E}U//&)U;**63DfM))&/=Q//&)U;**63DfM**69oN??6:6#4/__V\:
't3,,V5FX!0!<**6?DTU,D8t+C1Bv|UC ..t||=PR^`gh''hG
"v)=F*J^^FHe<F6:em&/&QW.++FE?K!%!8!8!B&,
&I )GHf~!1#'+'D'DV]\j'k$f+)5GI&!F%)%B%B6=Zb%cNFF!%(7t(C's^bIb'sgs' =BvGI.+)-6<)H;@gGI. *GH(00@SU[\&6  $s  te#7e#7$D0moT6QmW[_lWl"*sL8K0K	((xL!!&(MB6 &GHI!)GI [(8<5@D@]@]^dfs  vY  [_  A`=5v#11&&$GH!YYv~>F8 ,'//3/D/DV/L.2.C.CE.J.5.@.@{.[+/+<+<[+I%-".tww  :z  0z  #{  { . /7.>6X$($:$:68$LGDMX%8	"k $ 7 7 F!,GI!&GI!&GI!'.'9'9/5'Q$'?GO$!2GI!(5G$%!2GI 1M'+'8'8Co'p$'/&tww  2a  (a  b  b"55f>RS)4&%)%6%6xAf%g"$($4$4Xv$F!$0.?7.J*/@H/L+2=T*477  6D  ,D  E  E/-5".tww  :}  0}  #~  ~151H1HQc1dGI.*h6-1	*'3)-)@)@I[)\GI&)-GI&+/+=+=hHZ\mou+v(+70F:AY]dAd  lD  HN  lN*477  6L  ,L  M  M1IG-. $M7 C )-):)::Gs)t&)1&tww  2i  (i  j  j)-)@)@I_)`&'+'8'8El'm$&*&8&8V[&Y#&20Cw0N,1D1P-4?X*477  6F  ,F  G  G1/7".tww  :C  0C  #D  D3FGK0151H1HQe1fGI.,8-1	*)5+2GK()-)@)@I])^GI&)-GI&-1-?-?
L^`qsy-z*-92f<C]ahCh  pJ  NT  pT*477  6N  ,N  O  O1KG-. $M7 C !3!3!56M}-La-:O()!*GI#'#:#:6#PGK )6D<S<STZ<bGI!.GI /t ;\-W[B[O %*	"v~))GX62f< %/!*)-)@)@)Y&!
&!%!8!8!IJ%/	"-<)*()-)@)@)W&!
&!%!8!8!IJ%/	"-<)* ''jAH#%-%=	"!)!.GIYYv	?'CDF{{7++r  c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  XX4XV5      nU R                  U R                  SS5      n	U R                  US5      n
U
S:X  d$  U
S:X  d  U
S:X  d  US:X  d  US:X  d  US	:X  d  US
:X  a  Sn	U	S:w  a$  U	S:w  a  U	S:w  a  [        U R                  S-   5      eU	S:X  a  U/nSnU	S:X  a  U R                  U5      I Sh  vN nO9U	S:X  a  U R                  U5      I Sh  vN nOU R                  U5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  X5      nX.S'   X>S'   U$  GNS N Nd NL7f)a1	  
create a trade order

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-multiple-orders
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-place-algo-order

:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of currency you want to trade in units of base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.reduceOnly]: a mark to reduce the position size for margin, swap and future orders
:param bool [params.postOnly]: True to place a post only order
:param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
:param float [params.takeProfit.triggerPrice]: take profit trigger price
:param float [params.takeProfit.price]: used for take profit limit orders, not used for take profit market price orders
:param str [params.takeProfit.type]: 'market' or 'limit' used to specify the take profit price type
:param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
:param float [params.stopLoss.triggerPrice]: stop loss trigger price
:param float [params.stopLoss.price]: used for stop loss limit orders, not used for stop loss market price orders
:param str [params.stopLoss.type]: 'market' or 'limit' used to specify the stop loss price type
:param str [params.positionSide]: if position mode is one-way: set to 'net', if position mode is hedge-mode: set to 'long' or 'short'
:param str [params.trailingPercent]: the percent to trail away from the current market price
:param str [params.tpOrdKind]: 'condition' or 'limit', the default is 'condition'
:param bool [params.hedged]: *swap and future only* True for hedged mode, False for one way mode
:param str [params.marginMode]: 'cross' or 'isolated', the default is 'cross'
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nrl   r)  r'  r7  r6  r9  r8  r:  r;  privatePostTradeOrderAlgoprivatePostTradeOrderz createOrder() self.options["createOrder"] must be either privatePostTradeBatchOrders or privatePostTradeOrder or privatePostTradeOrderAlgor  r   r  r  )rZ  r  r  r  rw  r.   rN   r  r  r)  r  r  parse_order)r  r  r  r  r  rO  r  r  r)  r'  requestOrdTyper  r  r  r  s                  r  r  okx.create_orderJ  s    > !!!V$++F$V!!$,,?\]))'9=i'^}-LR`duRu{  DU  |U  [_  ch  [h  nr  v  n  EI  MS  ES0F--F>Y4Y`f  kH  aH  +x  !x  y  y22 iG,,!77@@H22!;;GDDH!==gFFH~~h3tQ+  /ff5 	"  ADFsG   E2E)CE2)E,*E2	E.
E2#E0$AE2,E2.E20E2ordersc           	      F  #    U R                  5       I Sh  vN   / n[        S[        U5      5       H  nX   nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  US5      n	U R	                  US5      n
U R                  US0 5      nU R                  X5      nU R                  XgXX5      nUR                  U5        M     U R                  U5      I Sh  vN nU R                  US	/ 5      nU R                  U5      $  GN N+7f)
a  
create a list of trade orders

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-multiple-orders

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  r  r  r  rO  r  r  )rZ  r  r  r  rP  r  r  r  r  r)  r  parse_orders)r  r  r  ordersRequestsr  rawOrderr  r  r  r  rO  orderParamsextendedParamsorderRequestr  r  s                   r  create_ordersokx.create_orders  s     !!!q#f+&AyH''(;H##Hf5D##Hf5D__Xx8FOOHg6E..8R@K![[=N44XTSXiL!!,/ ' 99.II. ~~h3  &&K 	" Js"   D!DCD!3D4)D!D!rN   c                 8   U R                  U5      nSUS   0n	S n
US:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US:X  a  S	n
U R                  US
S5      nUb  U
(       a  XS'   OXS
'   OU
(       a  XS'   OXS'   U R                  USS5      nU R                  US5      nU R	                  USS5      nU R                  USS5      nU R                  US5      nU R	                  USS5      nU R                  US5      nU R                  US5      nUS LnUS LnU
(       a  Uc  Uc  [        U R                  S-   5      eUbO  Uc  [        U R                  S-   5      eU R                  X,5      U	S'   US:X  a  SOU R                  X-5      U	S'   XS'   UbQ  Uc  [        U R                  S-   5      eU R                  X/5      U	S'   US:X  a  SOU R                  UU5      U	S'   UU	S'   GOaUb4  U R                  X,5      U	S'   US:X  a  SOU R                  X-5      U	S'   XS'   Ub6  U R                  X/5      U	S'   US:X  a  SOU R                  UU5      U	S'   UU	S'   U(       aj  U R                  US5      nU R                  US 5      nU R	                  US!5      nU R                  X,5      U	S'   US:X  a  SOU R                  X-5      U	S'   XS'   U(       ay  U R                  US5      nU R                  US 5      nU R	                  US!5      nUS":X  a  UOS#U	S$'   U R                  X/5      U	S'   US:X  a  SOU R                  UU5      U	S'   UU	S'   Ub  U R                  X%5      U	S%'   U
(       d  Ub  U R                  X&5      U	S&'   U R                  U/ S'Q5      nU R                  X5      $ )(Nr  rN   r7  r6  r9  r8  r:  r;  Tr1  r2  algoClOrdIdalgoIdr  rW  newSlTriggerPx
newSlOrdPxnewSlTriggerPxTyperK  rX  newTpTriggerPx
newTpOrdPxnewTpTriggerPxTyper3  r4  z\ editOrder() requires a stopLossPrice or takeProfitPrice parameter for editing an algo orderzF editOrder() requires a newSlOrdPx parameter for editing an algo orderr  rH  zF editOrder() requires a newTpOrdPx parameter for editing an algo orderrU  rO  r  rd  	conditionnewTpOrdKindnewSznewPx)r1  r2  rX  rW  r3  r4  rc  )r  r  rO  rP  r  r4   rN   rV  rM  r  r  )r  rN   r  r  r  r  rO  r  r  r)  isAlgoOrderr2  rl  rW  rr  rs  rX  ry  r3  r4  rY  rZ  stopLossTypetakeProfitTypes                           r  edit_order_requestokx.edit_order_request  sM   V$fTl
 I4=#8dFW>W]aej]jpt  yB  qB  HL  PV  HVK**69oN$)6&%2	"$&!#% #00JZ[=#'#3#3F<PRX#Y !%!2!26;LN^!_//&,?%)%5%5f>RTZ%["??6:6__V\:
#4/'t3$,3I3Q   ,J  "J  K  K#/ ($TWW/w%wxx,0,C,CF,a()151AH_H_`fHv%0H,-%1"*$TWW/w%wxx,0,C,CF,c()151AH_H_`fhwHx%0J,-#/,0,C,CF,a()151AH_H_`fHv%0H,-%1,0,C,CF,c()151AH_H_`fhwHx%0J,-'+x'P$ $' B#//&A,0,C,CF,a()1=1IPTPgPghnP~%0H,- )-^)T&"&//*g"F!%!1!1*f!E=Kw=V.]h',0,C,CF,c()1?81KRVRiRijp  sB  SC%0J,-#77GGG #'#:#:6#I 6  $J  K{{7++r  c           	        #    U R                  5       I Sh  vN   U R                  U5      nU R                  XX4XVU5      n	Sn
US:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US:X  a  Sn
SnU
(       a)  U R                  U R	                  X5      5      I Sh  vN nO(U R                  U R	                  X5      5      I Sh  vN nU R                  US	/ 5      nU R                  US
0 5      nU R                  X5      nX>S'   XNS'   U$  N Np NI7f)a6	  
edit a trade order

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-amend-order
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-amend-algo-order

:param str id: order id
:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of the currency you want to trade in units of the base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.clientOrderId]: client order id, uses id if not passed
:param float [params.stopLossPrice]: stop loss trigger price
:param float [params.newSlOrdPx]: the stop loss order price, set to stopLossPrice if the type is market
:param str [params.newSlTriggerPxType]: 'last', 'index' or 'mark' used to specify the stop loss trigger price type, default is 'last'
:param float [params.takeProfitPrice]: take profit trigger price
:param float [params.newTpOrdPx]: the take profit order price, set to takeProfitPrice if the type is market
:param str [params.newTpTriggerPxType]: 'last', 'index' or 'mark' used to specify the take profit trigger price type, default is 'last'
:param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
:param float [params.stopLoss.triggerPrice]: stop loss trigger price
:param float [params.stopLoss.price]: used for stop loss limit orders, not used for stop loss market price orders
:param str [params.stopLoss.type]: 'market' or 'limit' used to specify the stop loss price type
:param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
:param float [params.takeProfit.triggerPrice]: take profit trigger price
:param float [params.takeProfit.price]: used for take profit limit orders, not used for take profit market price orders
:param str [params.takeProfit.type]: 'market' or 'limit' used to specify the take profit price type
:param str [params.newTpOrdKind]: 'condition' or 'limit', the default is 'condition'
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr7  r6  r9  r8  r:  r;  Tr  r   r  r  )	rZ  r  r  privatePostTradeAmendAlgosr  privatePostTradeAmendOrderr  r  r  )r  rN   r  r  r  r  rO  r  r  r)  r  r  r  r  r  s                  r  
edit_orderokx.edit_order  s&    @ !!!V$))"d&QWXI4=#8dFW>W]aej]jpt  yB  qB  HL  PV  HVK!<<T[[=YZZH!<<T[[=YZZH  ~~h3tQ+  /ff? 	" [Zs5   D	DA=D	D(D	=D>AD	D	D	c                   #    Uc  [        U R                  S-   5      eU R                  USS5      nU R                  USS5      nU(       d  U(       a-  U R	                  U/X#5      I Sh  vN nU R                  US5      $ U R                  5       I Sh  vN   U R                  U5      nSUS	   0nU R                  US
S5      n	U	b  XS
'   OXS'   U R                  US
S/5      n
U R                  U R                  X5      5      I Sh  vN nU R                  US/ 5      nU R                  US5      nU R                  X5      $  N N N>7f)aE  
cancels an open order

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-order
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-order

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.trigger]: True if trigger orders
:param boolean [params.trailing]: set to True if you want to cancel a trailing order
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz) cancelOrder() requires a symbol argumentstopr7  r\  Fr   r  rN   r1  r2  r  r  )r3   rN   rO  r=  cancel_ordersr  rZ  r  r  r  privatePostTradeCancelOrderr  rP  r  )r  rN   r  r  r7  r\  
orderInnerr  r)  r2  r  r  r  r  s                 r  cancel_orderokx.cancel_orderC  sC     >#DGG.Y$YZZ##FFI>>>&*e<h#112$GGJ>>*a00!!!V$fTl

 **69oN$!.I!G		&9o">?99$++g:UVVx4tQ'..' H! Ws7   A&E(E ))EEA2EE;EEEc                 X    Ub&  [        U[        5      (       a  UR                  S5      $ U$ )zc
@ignore
       :param string[]|str ids: order ids
       :returns str[]: list of order ids
       ,)
isinstancestrr  )r  idss     r  	parse_idsokx.parse_idsk  s(     OC!5!599S>!Jr  r  c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      n/ nU R	                  U R
                  S0 5      nU R                  USS5      nU R                  USU5      nU R                  U R                  USS5      5      n	U R                  U R	                  US5      5      n
U R                  US	S
5      nU R                  USS5      nU(       d  U(       a  SnU	c  U R                  U5      nU
b5  [        S[        U
5      5       H  nUR                  X   US   S.5        M     [        S[        U5      5       HE  nU(       d  U(       a  UR                  X   US   S.5        M,  UR                  X   US   S.5        MG     O^[        S[        U	5      5       HE  nU(       d  U(       a  UR                  US   X   S.5        M,  UR                  US   X   S.5        MG     SnUS:X  a  U R                  U5      I Sh  vN nOU R                  U5      I Sh  vN nU R                  US/ 5      nU R!                  XSSU5      $  GN? NH N07f)aR  
cancel multiple orders

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-multiple-orders
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-order

:param str[] ids: order ids
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.trigger]: whether the order is a stop/trigger order
:param boolean [params.trailing]: set to True if you want to cancel trailing orders
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz* cancelOrders() requires a symbol argumentrd   r'  r3  r1  r2  r  r  r7  r\  FprivatePostTradeCancelAlgosr   rN   )r  r  )r  r  )r  r  )r  r1  r  )r3   rN   rZ  r  rP  rw  r  r  rO  r=  r  r  r  r  r3  r  r  )r  r  r  r  r  r)  rw  defaultMethodr'  clientOrderIdsalgoIdsr7  r\  r  r  
ordersDatas                   r  r  okx.cancel_ordersv  s[     >#DGG.Z$Z[[!!!V$//$,,C(((<_`!!&(MB(9(9&)_(]^..!BC##FFI>>>&*e<h2F!..%C"q#g,/ANN")*"(,$  0
 1c#h'wNN"%&"(,$ 
 NN!$"(,$  ( 1c.12wNN"(,'5'8$ 
 NN"(,#1#4$  3 22!==gFFH!CCGLLH< ^^Hfb9
  T4HH] 	"Z GLs4   /I7I0G8I7*I3+I7I5,I73I75I7c                 V  #    U R                  5       I Sh  vN   / nU R                  U R                  S0 5      nU R                  USS5      nU R                  USU5      nU R	                  USS5      nU R                  USS5      nU=(       d    Un	U	(       a  S	n[        S
[        U5      5       H  n
X   nU R                  US5      nU R                  USS5      nU R                  US5      nU R                  U5      nSnU	(       a  SnOUb  U	(       a  SnOSnSUS   0nUb  UOUUU'   UR                  U5        M     SnUS	:X  a  U R                  U5      I Sh  vN nOU R                  U5      I Sh  vN nU R                  US/ 5      nU R                  USSSU5      $  GN NI N17f)a  
cancel multiple orders for multiple symbols

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-multiple-orders
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-order

:param CancellationRequest[] orders: each order should contain the parameters required by cancelOrder namely id and symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.trigger]: whether the order is a stop/trigger order
:param boolean [params.trailing]: set to True if you want to cancel trailing orders
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nrd   r'  r3  r  r7  r\  Fr  r   rN   r1  r2  r  r  r  r  r  r  )rZ  r  rw  r  safe_bool_2r=  r  r  r  r  r  r  r3  r  r  )r  r  r  r)  rw  r  r'  r7  r\  isStopOrTrailingr  r  rN   r2  r  r  idKeyrequestItemr  r  s                       r  cancel_orders_for_symbolsokx.cancel_orders_for_symbols  s     !!!..~rB(((<_`!!&(MB""669=>>&*e<".h2Fq#f+&AIE!!%.B ..uiQM%%eX6F[[(FE *#)E%E&,!K 4A3LSUKNN;'% '& 22!==gFFH!CCGLLH< ^^Hfb9
  T4vFFA 	"> GLs4   F)F"EF)F%F)5F'6-F)%F)'F)timeoutc                    #    U R                  5       I Sh  vN   SUS:  a  U R                  US-  5      OS0nU R                  U R                  X25      5      I Sh  vN nU$  NL N7f)aE  
dead man's switch, cancel all orders after the given timeout

https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-all-after

:param number timeout: time in milliseconds, 0 represents cancel the timer
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: the api result
NtimeOutr   r  )rZ  parse_to_intprivatePostTradeCancelAllAfterr  )r  r  r  r)  r  s        r  cancel_all_orders_afterokx.cancel_all_orders_after&  sl      !!!Wq[t((48q
 <<T[[=YZZ # 	" [s"   A'A#AA'A%A'%A'r  c                 8    SSSSSSS.nU R                  X!U5      $ )Nr  rq  closed)r  order_failedr
  partially_filledfilled	effectiver  r  r  statusess      r  parse_order_statusokx.parse_order_statusC  s0    "& &!
 &99r  r  c                 `   U R                  US5      nUb<  US:w  a6  U R                  U R                  US5      U R                  US5      SUS.5      $ U R                  USS5      nU R                  US5      nU R                  US	5      nU R                  US
5      nU R                  US5      nU R                  US5      n	S n
S nU	S:X  a  Sn
Sn	OU	S:X  a  SnSn	O
U	S:X  a  SnSn	U R                  US5      nU R	                  X5      nU R                  XS5      nU R                  US5      nU R                  USS5      nU R                  US5      nU R                  U R                  US5      5      nU R                  US5      nS nS nU R                  U R                  SS5      nU R                  USU5      nU R                  US5      nUS:X  a%  U	S :X  a  US!:X  a  US":X  a  U R                  US#5      nOU R                  US#5      nS nUbM  [        R                  " U5      nU R                  US$5      nU R                  U5      nU R                  U5      US%.nU R                  US5      nUb  [        U5      S&:  a  S nU R                  US'S(5      nU R                  US)S*5      nU R                  US+5      nS,n U b  US-:H  n U R                  0 S.U_S/U_S0U_S1U_S2U R                  U5      _S3U_S4U_S5U_S6U	_S7U_S8U
_SU_S9U_S:U_S;U_S<U R                  US=S>/5      _S?U_UUUS UUS U S@.EU5      $ )ANsCode0r  r1  rejected)rN   r2  r  r  r  cTimer  fillTimer  r'  rB  Trd  rD  rQ  rC  rP  r  r  	accFillSzr  ordPxavgPxr  r7  r  rF  r  r  r  r@  r  rY  r  r  r  r.  r/  r+  r,  r9  Ftruer  rN   r2  r  r  lastTradeTimestamplastUpdateTimestampr  r  rZ  rc  rO  rW  rX  rU  r)  moveTriggerPxrv  )r  r  r  	remainingr  r7  tradesr9  )r  
safe_orderr  r  r  r  r  rw  rH   r  r  r~  r  rR  r  safe_number_n)!r  r  r  scoderN   r  r  r  r  r  rc  rZ  r  r  r  rO  rv  r  r  r  r  re  r  r  r7  r  r  r  r2  rW  rX  reduceOnlyRawr9  s!                                    r  r  okx.parse_orderN  s&   p   0ESL??&&ug6!%!1!1%!C$	$   x9%%eW5	"//w?!..ujAv.y1;HDU]KDU]KD##E84!!(3!!(C8!!%5""5$8""5'2(()9)9%)IJ((6 ((xL!!%=A##E:6EM 0x67IPVZePe##E40D %%eT2F$#..}=M ,,UH=M"55mDO))-8+C ((	:%C,>,B M**5-K,,UM9M((=
!'61J  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 "#6 
 f 
 D 
 ; 
  
 D 
 U 
 ] 
  
  D..u{O6TU! 
" w# 
$ $3 
4 5 	r  c                 
  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nU R	                  USS5      nU R                  U R                  S0 5      nU R                  USS	5      nU R                  USU5      n	U R                  US
S5      n
U
(       a  Sn	Ub  XeS'   OXS'   OUb  XeS'   OXS'   U R                  U/ SQ5      nSnU	S:X  a)  U R                  U R                  X[5      5      I Sh  vN nO(U R                  U R                  X[5      5      I Sh  vN nU R                  US/ 5      nU R                  US5      nU R                  X5      $  GNK Nf N?7f)a  
fetch an order by the id

https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-details
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-details

:param str id: the order id
:param str symbol: unified market symbol
:param dict [params]: extra and exchange specific parameters
:param boolean [params.trigger]: True if fetching trigger orders
:returns: `an order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz( fetchOrder() requires a symbol argumentr  rN   r1  r2  r   r'  r1  r  r7  privateGetTradeOrderAlgor  r  r  )r'  r1  r2  r  r7  r  r   )r3   rN   rZ  r  r  rP  rw  r  rO  r  r  r  r1  r  r  )r  rN   r  r  r  r)  r2  rw  r  r'  r7  r  r  r  r  s                  r  fetch_orderokx.fetch_orderb  s     >#DGG.X$XYY!!!V$fTl
 **69oN//$,,bA(((<RS!!&(MB##FFI>/F()6&$&!(%2	"#% 		&"[\//!::4;;w;VWWH!66t{{77RSSHB x4tQ'..A 	"6 XSs4   /FE<C&FE?(FF;F?FFc                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   U R	                  U R
                  S0 5      nU R	                  U R
                  S0 5      n	U R                  US	S
5      n
U R                  US	U
5      nU R                  US5      nU R                  USS5      nU R                  USS5      nU(       d  U(       d  X;   a  SnU(       a  SUS'   OU(       a  Uc  SUS'   U R                  U/ SQ5      nSnUS:X  a)  U R                  U R                  Xo5      5      I Sh  vN nO(U R                  U R                  Xo5      5      I Sh  vN nU R                  US/ 5      nU R                  UXrU5      $  GN GN NY N27f)aY  
fetch all unfilled currently open orders

https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-list
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-list

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of  open orders structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: True if fetching trigger or conditional orders
:param str [params.ordType]: "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"
:param str [params.algoId]: Algo ID "'433845797218942976'"
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:param boolean [params.trailing]: set to True if you want to fetch trailing orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NFr   r  rN   r  rd  rF  r'  r2  r'  r  r7  r\   privateGetTradeOrdersAlgoPendingr9  r'  r  r7  r\  r  )rZ  r[  fetch_paginated_call_dynamicr  rP  rw  r  rO  r=  r  r  r  r2  r  r  )r  r  r  rd  r  r  r)  r  rw  rF  r  r'  r'  r7  r\  r  r  r  s                     r  fetch_open_ordersokx.fetch_open_orders  s    $ !!!88ART^_::;Lf]bkkk	
 [[(F &tGH$G//$,,0A2F7GL(((<Z[!!&(MB""695##FFI>>>&*e<w7#<7F!2GI'/!*GI		&"KL77!BB4;;wC^__H!>>t{{7?Z[[H@ ~~h3  ve<<Q 	" lB `[sF   G!G8G!GD3G!G(G!,G-+G!G!G!G!c                   #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   SnSnU R                  SXd5      u  pxU R                  U5      US'   Ub  X5S'   SUS'   U R	                  U R
                  S0 5      n	U R	                  U R
                  S	0 5      n
U R                  U	S
S5      nU R                  US
U5      nU R                  US5      nU R                  USS5      nU R                  USS5      nU(       a  SnSUS'   OU(       d  X;   aQ  SnU R                  US5      nUb  UUS'   U R                  US5      nU(       a  Uc  [        U R                  S-   5      eO4Ub  X%S'   U R                  US5      nUb  UUS'   U R                  US/5      nU R                  U/ SQ5      nSnUS:X  a*  U R                  U R                  UU5      5      I Sh  vN nO)U R                  U R                  UU5      5      I Sh  vN nU R!                  US/ 5      nU R#                  UXbU5      $  GN* NW N/7f)a  
fetches information on multiple canceled orders made by the user

https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-7-days
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-history

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: timestamp in ms of the earliest order, default is None
:param int [limit]: max number of orders to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: True if fetching trigger or conditional orders
:param str [params.ordType]: "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"
:param str [params.algoId]: Algo ID "'433845797218942976'"
:param int [params.until]: timestamp in ms to fetch orders for
:param boolean [params.trailing]: set to True if you want to fetch trailing orders
:returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NrN   r  r   r  rd  r  r  rF  r'  r4  r'  r  r7  r\  F privateGetTradeOrdersAlgoHistoryr9  r  z fetchCanceledOrders() requires an "ordType" string parameter, "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"beginr  r  r  r  )rZ  r  r  r  rP  rw  r  rO  r=  r  r3   rN   r  r  r  r4  r  r  )r  r  r  rd  r  r)  r  r  r  rw  rF  r  r'  r'  r7  r\  r  r  sendr  r  s                        r  fetch_canceled_ordersokx.fetch_canceled_orders  sx    $ !!!

 [[(F &tGH889NPV_"==dC
$G%//$,,0ErJ7GL(((<Z[!!&(MB""695##FFI>>>&*e<7F!2GI27F%%fh7F!$*!684?+DGG  7@  -@  A  A #( %%eW5E !&		%'3yy IJ77!BB4;;wX\C]^^H!>>t{{7TX?YZZHH ~~h3  ve<<w 	"h _Zs4   II GI+I,)II+IIIc                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   SnSn	U R	                  SXt5      u  pU R                  U5      US'   Ub  X6S'   U R                  U R                  S0 5      n
U R                  U R                  S	0 5      nU R                  U
S
S5      nU R                  US
U5      nU R                  US5      nU R                  USS5      nU R                  USS5      nU(       d  U(       d  X;   a  SnSUS'   U(       a  SUS'   OIU(       a	  Uc  SUS'   O9Ub  X&S'   U R                  U	S5      nUb  UUS'   U R                  U	S/5      n	SUS'   U R                  U	/ SQ5      nSnUS:X  a*  U R                  U R                  UU5      5      I Sh  vN nOYUS:X  a*  U R                  U R                  UU5      5      I Sh  vN nO)U R!                  U R                  UU5      5      I Sh  vN nU R#                  US/ 5      nU R%                  UXrU5      $  GN^ GN( N N\ N47f)a  
fetches information on multiple closed orders made by the user

https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-7-days
https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-history
https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-3-months

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: True if fetching trigger or conditional orders
:param str [params.ordType]: "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"
:param str [params.algoId]: Algo ID "'433845797218942976'"
:param int [params.until]: timestamp in ms to fetch orders for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:param str [params.method]: method to be used, either 'privateGetTradeOrdersHistory', 'privateGetTradeOrdersHistoryArchive' or 'privateGetTradeOrdersAlgoHistory' default is 'privateGetTradeOrdersHistory'
:param boolean [params.trailing]: set to True if you want to fetch trailing orders
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NFr   r  rN   r  r  rd  rF  r'  r4  r'  r  r7  r\  r  r  r  r9  r  r  r  r  r  #privateGetTradeOrdersHistoryArchiver  )rZ  r[  r  r  r  r  r  rw  r  r  r=  r  r  r  r  r  r4  r  r  )r  r  r  rd  r  r  r)  r  r  r  rw  rF  r  r'  r'  r7  r\  r  r  r  r  s                        r  fetch_closed_ordersokx.fetch_closed_orders>  s    * !!!88ATV`a::;NPV_dmmm

 [[(F &tGH889Lf]"==dC
$G../BBG6FK(((<Z[!!&(MB""695""669=>>&*e<w7#<7F*GG!2GI%.	" #( %%eW5E !&		%'3'GGyy IJ77!BB4;;wX\C]^^H<<!EEdkkRY[_F`aaH!>>t{{7TX?YZZH@ ~~h3  ve<<s 	" n` _aZsX   J I48J I7FJ /I:0/J I< )J 	I>
+J 7J :J <J >J c                 .  #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X&S'   U R	                  SXd5      u  pdU R                  SXt5      u  pU R                  U5      US	'   Ub  Uc  X6S
'   U R                  U R                  Xi5      5      I Sh  vN n
U R                  U
S/ 5      nU R                  XX#U	5      $  N N N.7f)a  
fetch all trades made by the user

https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-months

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: Timestamp in ms of the latest time to retrieve trades for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
NFr   r  rN   r  r  r  r  rd  r  )rZ  r[  r  r  handle_until_optionr  r  privateGetTradeFillsHistoryr  r  r  )r  r  r  rd  r  r  r)  r  r  r  r  r  s               r  fetch_my_tradesokx.fetch_my_trades  s6     !!!88R\]::?F[`iii
 [[(F &tGH$G225'J88&Y"==dC
EM$G99$++g:UVV4 ~~h3  uUCCi 	" j* Ws4   DD8DDBD$D%+DDDc           	      h   #    SU0nU R                  X#X@R                  Xe5      5      I Sh  vN $  N7f)a  
fetch all the trades made from a single order

https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-months

:param str id: order id
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
r  N)r  r  )r  rN   r  r  rd  r  r)  s          r  fetch_order_tradesokx.fetch_order_trades2  s7      R
 ))&G@\]]]]s   )202rm  c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ U R                  U R                  S0 5      nU R                  US5      nU R                  USU5      nU R                  US5      n0 nSn	U R                  SU5      u  pU	c  U R                  US5      n	US:w  a  U	b  XS'   U R                  SSU5      u  pU
b  U R                  U
5      US'   Ub  X8S	'   SnUb  U R                  U5      nUS
   US'   U R                  SX5      u  pSnUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOWUS:X  a)  U R                  U R                  X5      5      I Sh  vN nO(U R                  U R                  X5      5      I Sh  vN nU R!                  US/ 5      nU R#                  XX#5      $  GN GN N NZ N37f)a#  
fetch the history of changes, actions done by the user or operations that altered balance of the user

https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-7-days
https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-3-months
https://www.okx.com/docs-v5/en/#rest-api-funding-asset-bills-details

:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated'
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
NFr   r  r'  mgnModeprivateGetAssetBillsr  rd  rN   r1  r  privateGetAccountBillsArchiver  )rZ  r[  r  r  rw  r  r  handle_margin_mode_and_paramsr  r  r  r  r	  r  r  r0  r  parse_ledger)r  rm  r  rd  r  r  rw  r'  r)  rT  r  r  r  r  r  s                  r  fetch_ledgerokx.fetch_ledgerH  s    " !!!88PZ[::=$W\eee..}bA!!'84!!&(F;68,
 
!??vV
))&)<J++%%/	"88fU"&"A"A$"GGJ$G}}T*H%d^GEN225'J44!??G@[\\H--!66t{{77RSSH!88W9TUUHb ~~h3  >> 	" fJ ]SUsX   H G48H G7D"H 2G:3.H !G<"(H 
G>*H 7H :H <H >H c                 B    SSSSSSSSSSSS.nU R                  X!U5      $ )Nr   r  rebater7  )r  r  345r<  7891011r  )r  r  r+  s      r  parse_ledger_entry_typeokx.parse_ledger_entry_type  s?    
 T22r  itemr  c                 v   U R                  US5      nU R                  X25      nU R                  X25      nU R                  US5      nU R                  US5      nS nUb(  U R	                  [
        R                  " U5      5      US.nU R                  US5      nU R                  US S5      n	U R                  UU R                  US5      UU R                  U5      S U R                  US5      S U R                  U R                  US	5      5      UU	U R                  US
5      S U R                  US5      SUS.U5      $ )Nr1  r  r7  r  r  r  billIdr  r  balChgr  r  )r  rN   r  r  r  referenceIdreferenceAccountr  r  r  r  r  r  r  r7  )r  r  rC  r  r~  rH   r  r  safe_ledger_entryr  r  r  )
r  r  r  rK  rm  r  r  r7  r  r  s
             r  parse_ledger_entryokx.parse_ledger_entry  sP   J %%dE2
&&z<%%j;%%dD1	((u5$))'*<*<]*KL C ##D(3!!(D#6%%""42"Y/++D': $001A1A$1OP&&tX6%%dE2'
  ! 	r  c                 (   U R                  US5      nU R                  U/ SQ5      nUc%  U R                  US0 5      nU R                  US5      nU R                  US5      nU R                  Xb5      nUS   nU R                  US5      nU R                  US0 5      n	U R	                  U	S	5      n
U R                  X5      nUS
:X  a  U R                  U
SS
5      nU R                  US5      nU R                  X5      nU R                  U5        UUUUUS.$ )Naddr)rL  pmtIdmemoaddrExcommentr1  rm  r3  r  rN   zUSDT-PolygonzUSDT-Polygon-Bridger;  )r  r  r;  addressrL  )r  safe_string_nrP  rC  index_byrO  rF  check_address)r  depositAddressr  r)  rL  r'  rK  rm  r3  r  networksByIdnetworkDatar;  rR  s                 r  parse_deposit_addressokx.parse_deposit_address  s*   : "">6:  1IJ;__^XrBF""695C%%ne<
%%j;  9??8Z<}}Xt4ool:T N"++L:OQ_`K"";	:--g<7#""
 	
r  c                 ^  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  USS5      nU R                  XsS   /S5      nU R                  US	5      $  N NT7f)
a  
fetch a dictionary of addresses for a currency, indexed by network

https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-deposit-address

:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
Nr1  rN   r  selectedTrm  Fr;  )rZ  r  privateGetAssetDepositAddressr  r  	filter_byparse_deposit_addressesr+  )	r  rm  r  r  r)  r  r  filteredparseds	            r  "fetch_deposit_addresses_by_network&okx.fetch_deposit_addresses_by_networkm  s      !!!==&8D>
 ;;DKK<XYY, ~~h3>>$
D9--h&9I8JER}}VY//= 	"
 Zs"   B-B)?B-B+AB-+B-c                    #    U R                  5       I Sh  vN   U R                  US5      nU R                  US5      nU R                  U5      nU R	                  X15      nU R                  X5      I Sh  vN nUb7  U R                  XT5      nUc!  [        U R                  S-   U-   S-   U-   5      eU$ U R	                  X5      nXu;   a  XW   $ [        UR                  5       5      nU R                  US5      n	U R                  XY5      $  N N7f)a  
fetch the deposit address for a currency associated with self account

https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-deposit-address

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the network name for the deposit address
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nr;  z# fetchDepositAddress() cannot find z deposit address for r   )rZ  r  r  r  rF  r9  r  r:   rN   rA  rB  )
r  rm  r  
rawNetworkr;  r  r  codeNetworkrB  r  s
             r  fetch_deposit_addressokx.fetch_deposit_address  s     !!!%%fi8
69-&&t,))*;@@NN^^H6F~$TWW/T%TW^%^ax%x{%  A  AM--d9"((HMMO$  q)~~h..# 	"
 Os#   DD
AD5D6BDDr)  rL  c                 h  #    U R                  XE5      u  pEU R                  U5        U R                  5       I Sh  vN   U R                  U5      nUb  [	        U5      S:  a  US-   U-   nUS   USU R                  U5      S.nU R                  US5      nUb]  U R                  U R                  S0 5      n	U R                  XR                  5       U5      nUS   S	-   U-   US
'   U R                  US5      nU R                  US5      n
U
c  U R                  5       I Sh  vN nU R                  U R                  U R                  U5      5      U l        U R                  US   U R                  U5      0 5      nU R                  US5      n
U
c  [!        U R"                  S-   5      eU R                  U
5      US'   U R                  US/5      nU R%                  U R'                  X}5      5      I Sh  vN nU R)                  US/ 5      nU R                  US5      nU R+                  UU5      $  GN GN NA7f)a  
make a withdrawal

https://www.okx.com/docs-v5/en/#funding-account-rest-api-withdrawal

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr   r  rN   r  )r1  toAddrdestamtr;  r  r  r3  r7  u    withdraw() requires a "fee" string parameter, network transaction fee must be ≥ 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.r  )handle_withdraw_tag_and_paramsr,  rZ  r  r  rS  r  r  rw  upperr  rT  map_to_safe_mapr{  ry  rF  r3   rN   privatePostAssetWithdrawalr  r  parse_transaction)r  rm  r  r)  rL  r  r  r)  r;  r  r7  ry  targetNetworkr  r  r  transactions                    r  r   okx.withdraw  s(     99#F7#!!!==&O#c(Q,mc)GD>((0	
 ""695~~dllJCH&&x'JG'~3g=GGYYvy1Fvu-;#4466J"2243C3CDOOU_3`aDO NN8J+?AXAXY`AacefM""=%8C{'  3U  )U  V  V..s3		&5'*88W9TUU ~~h3nnT1-%%k8<<U 	"$ 7 Vs5   8H2H*C"H2H-CH2.H0/<H2-H20H2c                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  [	        US-
  S5      US	'   Ub  X6S
'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      n	U R                  XX#U5      $  N N N.7f)a  
fetch all deposits made to an account

https://www.okx.com/docs-v5/en/#rest-api-funding-get-deposit-history

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NFr   r  rN   r1  r  r   r  rd  r  r  )
rZ  r[  r  r  ra  r  privateGetAssetDepositHistoryr  r  parse_transactions
r  rm  r  rd  r  r  r)  r  r  r  s
             r  fetch_depositsokx.fetch_deposits  s     !!!88R\]::?DY^ggg
 }}T*H%d^GEN #EAIq 1GH$G227GL;;DKK<XYYN ~~h3&&tuVLL{ 	" h" Z4   C8C28C8C4A7C8C6+C84C86C8c                 B  #    U R                  5       I Sh  vN   SU0nSnUb  U R                  U5      nUS   US'   U R                  U R                  XC5      5      I Sh  vN nU R	                  US5      nU R                  US0 5      nU R                  X5      $  N N<7f)ai  
fetch data on a currency deposit via the deposit id

https://www.okx.com/docs-v5/en/#rest-api-funding-get-deposit-history

:param str id: deposit id
:param str code: filter by currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
NdepIdrN   r1  r  r   )rZ  r  rM  r  rP  r  rH  )	r  rN   rm  r  r)  r  r  r  r<  s	            r  fetch_depositokx.fetch_deposit=  s      !!!R
 }}T*H%d^GEN;;DKK<XYYx0..q"-%%g88 	" Zs"   BBA	B B!;BBc                   #    U R                  5       I Sh  vN   SnU R                  USS5      u  pTU(       a  U R                  SXX45      I Sh  vN $ 0 nSnUb  U R                  U5      nUS   US'   Ub  [	        US-
  S5      US	'   Ub  X6S
'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      n	U R                  XX#U5      $  N N N.7f)a  
fetch all withdrawals made from an account

https://www.okx.com/docs-v5/en/#rest-api-funding-get-withdrawal-history

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
NFr   r  rN   r1  r  r   r  rd  r  r  )
rZ  r[  r  r  ra  r   privateGetAssetWithdrawalHistoryr  r  rN  rO  s
             r  fetch_withdrawalsokx.fetch_withdrawalsU  s     !!!88ASU_`::;Mt\ajjj
 }}T*H%d^GEN #EAIq 1GH$G227GL>>t{{7?[\\> ~~h3&&tuVLLk 	" k" ]rR  c                 D  #    U R                  5       I Sh  vN   SU0nSnUb  U R                  U5      nUS   US'   U R                  U R                  XC5      5      I Sh  vN nU R	                  US/ 5      nU R                  US0 5      nU R                  U5      $  N N=7f)a  
fetch data on a currency withdrawal via the withdrawal id

https://www.okx.com/docs-v5/en/#rest-api-funding-get-withdrawal-history

:param str id: withdrawal id
:param str code: unified currency code of the currency withdrawn, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
NwdIdrN   r1  r  r   )rZ  r  rX  r  r  r  rH  )	r  rN   rm  r  r)  r  r  r  
withdrawals	            r  fetch_withdrawalokx.fetch_withdrawal  s      !!!B
 }}T*H%d^GEN>>t{{7?[\\, ~~h3^^D!R0
%%j11A 	" ]s"   B BA	B  B!<B B c                     0 SS_SS_SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_nU R                  X!U5      $ )Nz-3pendingz-2r  rH  failedr  r  r  r  r  r  r  r<  r  r  r  r  121516r  r  s      r  parse_transaction_statusokx.parse_transaction_status  s    0
)
*
 (
 	

 
 
 
 
 
 
 
 
 
 )
 )
  )!
" )#
& &99r  rJ  c                    S nS nU R                  US5      nU R                  US5      nU R                  US5      nUnU R                  USS5      n	U R                  USU	5      n	Ub  SnUnOU R                  US5      nS	nU R                  US
5      n
U R                  U
5      nU R                  US5      nU R	                  U R                  US5      5      nU R                  US5      nU R                  US5      nS nUS	:X  a  SnOU R                  US5      n0 SU_SU_SU_SU_SS _SU_SU_SU_SS _SU	_SU	_SU_SU_SS _SU_SU_S U R                  U5      _S S UUS!.S".E$ )#Nr\  fromtorL  r&  r%  r]  rT  r<  r1  rC  r  txIdr  r   r7  r  rN   r  r  r;  addressFrom	addressTor)  tagFromtagTor  r  r  txidr  r  )r  r  )internalr(  r7  )r  r  r  r  rf  r  r  )r  rJ  r  r  rN   withdrawalIdrl  rm  r)  ro  rK  rm  r  r  rp  r  feeCosts                    r  rH  okx.parse_transaction  s'   P ''V<&&{F;$$[$7	"";v>"";?#DB !!+w7BD%%k59
&&z2!!+u5..t/?/?W/UVV4%%k48	9G&&{E:G
K
"
 
 f	

 t
 ;
 
 w
 t
 U
 5
 f
 D
 t
 D
  !
" Y/#
$  )
 	
r  c                   #    U R                  5       I Sh  vN   SnU R                  SU5      u  p2Uc  U R                  USS5      nUS:w  a  US:w  a  [        U R                  S-   5      eU R                  U5      nUS   US.nU R                  U R                  XR5      5      I Sh  vN nU R                  US	/ 5      nU R                  Xt5      $  N N*7f)
ah  
fetch the set leverage for a market

https://www.okx.com/docs-v5/en/#rest-api-account-get-leverage

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated'
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
Nr   r  r;  isolatedzV fetchLeverage() requires a marginMode parameter that must be either cross or isolatedrN   r  r  r  )
rZ  r
  r  r4   rN   r  privateGetAccountLeverageInfor  r  parse_leverage)r  r  r  rT  r  r)  r  r  s           r  fetch_leverageokx.fetch_leverageQ  s      !!!
!??QWX
))&)WEJ'!
j(@TWW'  A  AV$Tl!
 ;;DKK<XYY ~~h3""4009 	" Zs"   CCBC'C()CCr]  c                    S nS nS nS n[        S[        U5      5       H  nX   nU R                  US5      nU R                  US5      nU R                  US5      n	U	S:X  a  U R	                  US5      nMW  U	S:X  a  U R	                  US5      nMq  U R	                  US5      nU R	                  US5      nM     UU R                  X25      UUUS.$ )	Nr   r  r  r?  rA  r  r@  )r  r  rT  longLeverageshortLeverage)r  r  r  r  r  r  )
r  r]  r  r  rT  r}  r~  r  entryr>  s
             r  ry  okx.parse_leveragez  s    
q#h-(AKE//yAJ''x8H11%CLv%#00@( $ 1 1% A#00@ $ 1 1% A ) &&x8$(*
 	
r  c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  SX25      u  pESUS   0nUb  U R                  U5      US'   U R	                  U R                  Xe5      5      I Sh  vN nU R                  US/ 5      nU R                  US5      n	U	c  gU R                  X5      $  N N@7f)a  
fetch data on a single open contract trade position

https://www.okx.com/docs-v5/en/#rest-api-account-get-positions

:param str symbol: unified market symbol of the market the position is held in, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.instType]: MARGIN, SWAP, FUTURES, OPTION
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr   r  rN   r  r  r   )	rZ  r  r  r  r(  r  r  r  parse_position)
r  r  r  r  r  r  r)  r  r  positions
             r  fetch_positionokx.fetch_position  s      !!!V$88&Y fTl

 "&"A"A$"GGJ88W9TUU^ ~~h3>>$*""844{ 	" Vs"   CC A*CC?CCc                 (  #    U R                  5       I Sh  vN   0 nUbl  / n[        S[        U5      5       H,  nX   nU R                  U5      nUR	                  US   5        M.     [        U5      nUS:  a  SR                  U5      US'   U R                  U R                  S0 5      n	U R                  U	SS5      n
SnU
S	:X  a)  U R                  U R                  X25      5      I Sh  vN nO(U R                  U R                  X25      5      I Sh  vN nU R                  US
/ 5      n/ n[        S[        U5      5       H%  nUR	                  U R                  X   5      5        M'     U R                  USU R                  U5      S5      $  GNu N N7f)a  

https://www.okx.com/docs-v5/en/#rest-api-account-get-positions
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history history

fetch all open positions
:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.instType]: MARGIN, SWAP, FUTURES, OPTION
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr   rN   r  r  r   r'  r(  !privateGetAccountPositionsHistoryr  r  F)rZ  r  r  r  r  rE  r  rw  r  r  r  r(  r  r  filter_by_array_positionsr  )r  r  r  r)  	marketIdsr  r  r  marketIdsLengthfetchPositionsOptionsr'  r  	positionsr  s                 r  fetch_positionsokx.fetch_positions  s     !!!

 I1c'l+
U+  . , ")nO"$'HHY$7! $t||=Mr R!!"7C_`88!CCDKKPWD`aaH!<<T[[=YZZH^ NN8VR8	q#i.)AMM$--il;< *--fh@S@ST[@\^cddQ 	"& bZs5   FFCF'F((FFA;FFFc                 D   #    U R                  U/U5      I Sh  vN $  N7f)av  

https://www.okx.com/docs-v5/en/#rest-api-account-get-positions

fetch all open positions for specific symbol
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.instType]: MARGIN(if needed)
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
N)r  r  r  r  s      r  fetch_positions_for_symbolokx.fetch_positions_for_symbol3  s"      ))6(F;;;;     r  c                 F	   U R                  US5      nU R                  X2S S5      nUS   nU R                  US5      n[        R                  " U5      nU R	                  USS5      nUS:g  nU R                  U5      n	US   (       aO  US:X  a3  U R                  US	5      n
U R                  U
5      nUb  US
   U:X  a  SOSnUc  U R                  US5      nOIUbF  US:X  a@  [        R                  " US5      (       a  SnO![        R                  " US5      (       a  SnOS nU R                  US5      nU R                  U5      nU R                  US5      nU R                  US5      nUS   (       a+  [        R                  " [        R                  " Xm5      U5      nU R                  U5      nU R                  US5      nS nU R	                  USS5      nU R                  US5      nU R                  US5      nS nS nUS:X  a*  U R                  US5      n[        R                  " UU5      nO/US:X  a)  [        R                  " SU5      nU R                  US5      nU R                  US5      nU R                  U5      n[        R                  " UU5      nUc(  U R                  [        R                  " UUS5      5      nOUc  [        R                  " UU5      nSnU R                  [        R                  " [        R                  " UU5      SS5      5      nU R                  US5      nU R                  US5      nU R                  [        R                  " US 5      5      nU R                  US!5      n U R                  [        R                  " UUS5      5      n!U R                  0 S"U_S#U R                  US$5      _SU_S%U_S&U_S'U_S(U R                  U5      _S)U R                  U5      _S*U R                  US*5      _S+U_S,U	_SU_S-U R                  U5      _S.U R                  US/5      _S0U_S1U_S2U _U R!                  U 5      U R                  US35      UUU R                  U5      U R                  U5      U R                  U5      U R                  U5      U!S S S4.E5      $ )5Nr  r  r  posr?  	directionnetr\   posCcyr  rA  r@  r  r  rw  notionalUsdrk  r  r  	openAvgPxuplr  r;  imrrv  r  mmrr  z0.00005liqPxuplRatiorG  r  r  rN   posIdrf  rT  liquidationPrice
entryPriceunrealizedPnlrealizedPnlru  	contractsr{  	lastPrice
closeAvgPxr  r[  r  r  )r  r  maintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager]  marginRatiorW  rX  )r  r  rH   
string_absr  r~  r  r  	string_ltr  rS  rW  rT  
string_addr  safe_positionr  )"r  r  r  r  r  r  contractsAbsr  r[  r  r  parsedCurrencyr  contractSizeStringmarkPriceStringnotionalStringrf  rT  initialMarginStringentryPriceStringunrealizedPnlStringleverageStringr  collateralStringmaintenanceMarginStringr  !maintenanceMarginPercentageStringrounderr  r  percentageStringru  r  r  s"                                     r  r  okx.parse_position@  s8   F ##Hh7!!(D*E!x/))#.!!(I{C%%l3	(u}))(H=!%!8!8!@!-&,Vn&F6WD|''+>5=((c22% **344&#''?!22<@**8X>))(MB)$//0B0B<0dfuvN$$^4%%h	:
"--hM"..x?))(G<"& "&"2"28U"C&112EGZ[:%&-&8&8n&M##//(C"&"2"28U"C --.EF,3,>,>?VXf,g)"*&*&7&78J8JK^`npq8r&s# (")"4"45Ln"]&*&7&78J8J7K]K]^  BI  LJ  LO  QR  9S  'T#++Hg>++HjA&&w'9'9:JE'RS
%%h8	''(:(:;RTdfg(hi!! #
H#
$""8W5#
 f#
 	#

 *#
  0#
 $++,<=#
 T../BC#
 4++HmD#
 *#
 #
 L#
 **?;#
 ))(LA#
 D#
  f!#
" ##
$ Y/#'#4#4Xw#G!2+F++,<=!../BC'+'8'89P'Q)).9&!#9#
  	r  fromAccount	toAccountc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  S0 5      nU R	                  XsU5      nU R	                  XtU5      n	US   U R                  X5      SUU	S.n
US:X  a6  SU
S'   XS	'   U R	                  US
S5      U
S
'   U R	                  USS5      U
S'   O;U	S:X  a5  SU
S'   XS	'   U R	                  US
S5      U
S
'   U R	                  USS5      U
S'   U R                  U R                  X5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  X5      $  GNG N>7f)a  
transfer currency internally between wallets on the same account

https://www.okx.com/docs-v5/en/#rest-api-funding-funds-transfer

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from
:param str toAccount: account to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
NrG  rN   r  )r1  rC  r  ri  rj  masterr  r  subAcctri  r<  rj  r  r  r   )
rZ  r  r  rw  r  currency_to_precisionprivatePostAssetTransferr  r  parse_transfer)r  rm  r  r  r  r  r  rG  fromIdtoIdr)  r  r  rawTransfers                 r  r   okx.transfer  sz     !!!==&6FK!!.{K9ED>--d;

 X!GFO!%I"..vvsCGFO ,,VT3?GDMX!GFO!'I"..vvsCGFO ,,VT3?GDM66t{{77STT  ~~h3nnT1b1"";99Y 	"4 Us"   E"ED
E"!E "<E" E"r   c                 \   U R                  USS5      nU R                  US5      nU R                  XB5      nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  U R
                  S0 5      n	U R                  US5      n
U R                  US	5      nUb%  U R                  [        R                  " U5      5      nUUU
U R                  U
5      UUU R                  X5      U R                  X5      U R                  U R                  US
5      5      S.	$ )NtransIdr  r1  rC  ri  rj  rH  r  rY  r  )	r  rN   r  r  r  r  r  r  r  )r  r  r  r  r  rw  r  r~  rH   r  r  parse_transfer_status)r  r   r  rN   rK  rm  r  fromAccountIdtoAccountIdrH  r  balanceChanges               r  r  okx.parse_transfer  s(   j )X>%%h6
&&z<!!(E2((6:&&x6~~dllNBG%%h5	((48$&&w'9'9-'HIF"Y/++LH)),D001A1A(G1TU

 
	
r  c                 .    SS0nU R                  X!U5      $ )Nsuccessr  r  r  s      r  r  okx.parse_transfer_statuse  s#    t
 &99r  c                   #    U R                  5       I S h  vN   SU0nU R                  U R                  XC5      5      I S h  vN nU R                  US/ 5      nU R	                  US5      nU R                  U5      $  Nf N<7f)Nr  r  r   )rZ  privateGetAssetTransferStater  r  r  r  )r  rN   rm  r  r)  r  r  r   s           r  fetch_transferokx.fetch_transferk  s     !!!r
 ::4;;w;WXX* ~~h3>>$*""8,,9 	"
 Ys!   BA=+BA?;B?Bc                 >  #    U R                  5       I Sh  vN   SnSS0nUb  U R                  U5      nUS   US'   Ub  X&S'   Ub  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US/ 5      nU R                  XX#U5      $  N N,7f)	a  
fetch a history of internal transfers made on an account

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months

:param str code: unified currency code of the currency transferred
:param int [since]: the earliest time in ms to fetch transfers for
:param int [limit]: the maximum number of transfers structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr  r  rN   r1  r  rd  r  )rZ  r  r	  r  r  parse_transfers)	r  rm  r  rd  r  r  r)  r  	transferss	            r  fetch_transfersokx.fetch_transfers  s      !!!C
 }}T*H%d^GEN$G$G;;DKK<XYYB NN8VR8	##IvNN] 	" Zs"   BBAB.B/+BBr  GETc                    [        U[        5      nSU R                  -   S-   U R                  X5      -   nU R	                  X@R                  U5      5      n	U R                  U R                  S   S   5      U-   n
US:X  a   U	(       a  U
SU R                  U	5      -   -  n
GOUS:X  Ga  U R                  5         US:X  a  US	:X  d  US
:X  d  US:X  a  U R                  U R                  SS5      n[        U[        5      (       aU  [        S[        U5      5       H;  nXL   nU R                  US5      nUb  M  XR                  5       -   US'   XS'   XU'   M=     O.U R                  US5      nUc  XR                  5       -   US'   XS'   U R                  U R!                  5       5      nU R"                  U R$                  US.nX-   U-   nUS:X  a&  U	(       a  SU R                  U	5      -   nU
U-  n
UU-  nO)U(       d  U	(       a  U R'                  U	5      nUU-  nSUS'   U R)                  U R+                  U5      U R+                  U R,                  5      [.        R0                  S5      nUUS'   XXeS.$ )Nz/api/r  r   r   r  ?r  POSTr  r  r  rJ  rE  r   r1  rL  )zOK-ACCESS-KEYzOK-ACCESS-PASSPHRASEzOK-ACCESS-TIMESTAMPr  zapplication/jsonzContent-Typebase64zOK-ACCESS-SIGN)r   r'  bodyheaders)r  rA  rT   implode_paramsr  extract_paramsimplode_hostnamer   	urlencoder>  r  rw  r  r  rX  r  r  r  r  jsonhmacencoder  hashlibsha256)r  pathr   r'  r  r  r  isArrayr)  r  r   rJ  r  r  r2  r  authurlencodedQuery	signatures                      r  signokx.sign  sL   VT*DLL(3.1D1DT1RR		&"5"5d";<##DIIe$4V$<=G(?sT^^E222I++-T-A%ATM_E_cgkxcx++DLL*FXYfd++"1c&k2 &	(,(8(8	(J(0/7++-/GE),+3%L(-1I 3 %)$4$4VY$GM$,,4{{},Dy)(0uTZZ\2I!%(,'0G %/D&)DNN5,A&AO?*CO+De99U+DDLD*<'		$++d"3T[[5Mw~~_ghI(1G$%dOOr  c                 2   U R                  US5      nU R                  US5      nU R                  XB5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	[        R
                  " X5      n
0 SU_SU_SS _SS _S	U R                  S
5      _SS _SS _SS _SU R                  US5      _SU_SU R                  U5      _SU_SU_SU R                  U5      _SS _SS _SS _SU R                  U
5      0E$ )NnextFundingTimer  nextFundingRater  r  r  r{  r|  interestRater  estimatedSettlePricer  r  r  fundingTimestampfundingDatetimenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)	r  r  r  r  rH   
string_subr~  r  parse_funding_interval)r  r  r  nextFundingRateTimestampr  r  r  r  fundingTimeStringnextFundingTimeStringmillisecondsIntervals              r  parse_funding_rateokx.parse_funding_rate  s   : $(#4#4X?P#Q ##Hh7!!(3**85FG''-@ ,,X}E $ 0 0;L M&112G[
H
f
 
 $	

 D--c2
 #D
 
 
 4++HmD
 
 t||K8
 
 #$<
 "4<<0H#I
 "4
  '!
" &t#
$ 334HI%
 	
r  c                 6    SSSSSS.nU R                  X!U5      $ )Nr   r   r#  16h24h)360000014400000288000005760000086400000r  )r  r  	intervalss      r  r  okx.parse_funding_interval5  s-    
	 	X>>r  c                 @   #    U R                  X5      I Sh  vN $  N7f)aF  
fetch the current funding rate interval

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
N)fetch_funding_rater  s      r  fetch_funding_intervalokx.fetch_funding_interval?  s      ,,V<<<<s   c                 t  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  Xs5      $  N N=7f)a=  
fetch the current funding rate

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
Nr]   z2 fetchFundingRate() is only valid for swap marketsr  rN   r  r   )	rZ  r  r.   rN   publicGetPublicFundingRater  r  r  r
  )r  r  r  r  r)  r  r  r  s           r  r  okx.fetch_funding_rateK  s      !!!V$f~*^ ^__fTl
 88W9UVV" ~~h3tQ+&&u555 	" Ws"   B8B4A!B88B69<B86B8c                   #    U R                  5       I Sh  vN   U R                  USS5      nSS0nU R                  U R                  X25      5      I Sh  vN nU R	                  US/ 5      nU R                  XQ5      $  Ng N*7f)ai  
fetches the current funding rates for multiple symbols

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate

:param str[] symbols: unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `funding rates structure <https://docs.ccxt.com/#/?id=funding-rates-structure>`
Nr]   Tr  ANYr  )rZ  r  r  r  r  parse_funding_rates)r  r  r  r)  r  r  s         r  fetch_funding_ratesokx.fetch_funding_ratesq  s      !!!%%gvt<!5)88W9UVV" ~~h3''66+ 	" Ws!   BA>>BB )B Bc                   #    U R                  5       I Sh  vN   SS0nUb  [        U5      US'   SnUbE  U R                  U5      nUS   nUS   (       a%  US   (       a  SUS'   US	   US
'   OSUS'   US   US
'   U R                  SXd5      u  pxUS:X  a  U R	                  U5      US'   U R                  U R                  XX5      5      I Sh  vN n	U R                  U	S/ 5      n
/ n[        S[        U
5      5       H  nX   nU R                  US5      nU R                  US5      nU R                  U5      nU R                  US
5      nU R                  U5      nUR                  UUS   UUU R                  U5      U R                  US5      U R!                  US5      S.5        M     U R#                  US5      nU R%                  UXU5      $  GN GN7f)a  
fetch the history of funding payments paid and received on self account

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch funding history for
:param int [limit]: the maximum number of funding history structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
Nr  r  rd  r  r  rj  ctTyper  r1  rk  r  r   r]   r  r  r   r  r  r  r  )r  r  rm  r  r  rN   r  r  )rZ  r  r  r  r  r	  r  r  r  r  r  r  r  r  r  r  r  r  r  )r  r  r  rd  r  r)  r  r  r  r  r  r  r  r  r  r  marketInnerrK  rm  r  s                       r  fetch_funding_historyokx.fetch_funding_history  s     !!! CK
X "5zGG[[(FH%Fj!(#(0GH%%+I%6GEN(1GH%%+H%5GEN889NPV_6>"&"A"A$"GGJ;;DKK<WXX2 ~~h3q#d)$AGE))%6I%%eX6F**62K))%7J**:6DMM%h/& LL3&&uh7**5(;  %  fk200NNU 	"| Ys#   GGB4GGDGGc                 v  #    Uc  [        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eU R                  5       I Sh  vN   U R	                  U5      nSnU R                  SU5      u  pSUc  U R                  USS5      nUS:w  a  US	:w  a  [        U R                  S
-   5      eUUUS   S.nU R                  USS5      nUS	:X  a.  US:w  a$  US:w  a  US:w  a  [        U R                  S-   5      eXvS'   U R                  U R                  Xc5      5      I Sh  vN nU$  N N7f)a  
set the level of leverage for a market

https://www.okx.com/docs-v5/en/#rest-api-account-set-leverage

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated'
:param str [params.posSide]: 'long' or 'short' or 'net' for isolated margin long/short mode on futures and swap markets, default is 'net'
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentr  }   z3 setLeverage() leverage should be between 1 and 125r   r  r;  rv  zT setLeverage() requires a marginMode parameter that must be either cross or isolatedrN   r  r  r  r?  r  rA  r@  zR setLeverage() requires the posSide argument to be either "long", "short" or "net")	r3   rN   r4   rZ  r  r
  r  privatePostAccountSetLeverager  )	r  r]  r  r  r  rT  r)  r?  r  s	            r  set_leverageokx.set_leverage*  sW     >#DGG.Y$YZZ qLhnTWW'\\]]!!!V$
!??vV
))&)WEJ'!
j(@TWW'}}~~!Tl

 ""69e<#& W%7Gu<L +!  A  A!(I;;DKK<XYY C 	"$ Zs%   AD9D5CD9.D7/D97D9c                   #    U R                  5       I Sh  vN n[        U5      nSnUS:  au  U R                  US5      nUc<  U R                  US5      n[	        U R
                  S-   SR                  U5      -   5      eU R                  US5      nU R                  X5      nOUS   nUS   n	U R                  U	S	5      n
U
S
:H  nU	US.$  N7f)a<  

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration

fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
:param str symbol: unified symbol of the market to fetch the order book for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.accountId]: if you have multiple accounts, you must specify the account id to fetch the position mode
:returns dict: an object detailing whether the market is in hedged or one-way mode
Nr  r  rN   z fetchPositionMode() can not detect position mode, because you have multiple accounts. Set params["accountId"] to desired id from: z, r   r  posModelong_short_mode)r  r[  )	r  r  r  get_list_from_object_valuesr.   rN   rE  r+  r  )r  r  r  accountslengthselectedAccountr  
accountIdsrH  mainAccountr.  isHedgeds               r  fetch_position_modeokx.fetch_position_mode`  s     ,,..XA:((=I !==hM
#DGG  /t  %t  w{  w@  w@  AK  wL  %L  M  M#}}Xt<"&.."I&qkO%f-"";	://
 	
! /s   CC	B3Cr[  c                    #    SnU(       a  SnOSnSU0nU R                  U R                  XS5      5      I Sh  vN nU$  N7f)al  
set hedged to True or False for a market

https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-position-mode

:param bool hedged: set to True to use long_short_mode, False for net_mode
:param str symbol: not used by okx setPositionMode
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nr/  net_moder.  )!privatePostAccountSetPositionModer  )r  r[  r  r  	hedgeModer)  r  s          r  set_position_modeokx.set_position_mode  sP      	)I"Iy
 ??G@\]]  ^s   6A?ArT  c                   #    Uc  [        U R                  S-   5      eUR                  5       nUS:w  a  US:w  a  [        U R                  S-   5      eU R	                  5       I Sh  vN   U R                  U5      nU R                  USS5      nUb  US:  d  US	:  a  [        U R                  S
-   5      eU R                  US/5      nUUUS   S.nU R                  U R                  Xc5      5      I Sh  vN nU$  N N7f)af  
set margin mode to 'cross' or 'isolated'

https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-leverage

:param str marginMode: 'cross' or 'isolated'
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.leverage]: leverage
:returns dict: response from the exchange
Nz+ setMarginMode() requires a symbol argumentr;  rv  z< setMarginMode() marginMode must be either cross or isolatedr  r]  r  r(  z< setMarginMode() params["lever"] should be between 1 and 125rN   r)  )
r3   rN   r  r4   rZ  r  r  r  r*  r  )r  rT  r  r  r  r  r)  r  s           r  set_margin_modeokx.set_margin_mode  s     >#DGG.[$[\\  %%'
'!
j(@TWW'eeff!!!V$##FGZ@MuqyeckTWW'eeff6J<0!Tl

 ;;DKK<XYY 5 	" Zs%   A#C?%C;&BC?4C=5C?=C?c                   #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US/ 5      n/ n[        S[	        U5      5       H%  nUR                  U R                  X5   5      5        M'     U$  Nr N[7f)a3  
fetch the borrow interest rates of all currencies

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-interest-rate

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
Nr  r   )rZ  privateGetAccountInterestRater  r  r  r  parse_borrow_rate)r  r  r  r  r  r  s         r  fetch_cross_borrow_ratesokx.fetch_cross_borrow_rates  s      !!!;;FCC ~~h3q#d)$ALL//89 %% 	"Cs    BB	BBABBc                 0  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  US0 5      nU R                  U5      $  N{ N=7f)ab  
fetch the rate of interest to borrow a currency for margin trading

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-interest-rate

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `borrow rate structure <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
Nr1  rN   r  r   )rZ  r  rC  r  r  r  rD  )r  rm  r  r  r)  r  r  r  s           r  fetch_cross_borrow_rateokx.fetch_cross_borrow_rate  s      !!!==&8D>
 ;;DKK<XYY ~~h3~~dAr*%%d+++ 	"
 Zr  c                     U R                  US5      nU R                  US5      nU R                  U5      U R                  USS5      SUU R	                  U5      US.$ )Nr1  r  r  r  i \&)r  r  periodr  r  r  )r  r  r  rR  r  )r  r  r  r1  r  s        r  rD  okx.parse_borrow_rate  sg     tU+%%dD1	//4&&t^VD"Y/
 	
r  c                    0 n[        S[        U5      5       Hr  nX   nU R                  U R                  US5      5      nUb  U R	                  X5      (       d  MC  X;  a  / XX'   U R                  U5      n	XX   n
U
R                  U	5        Mt     [        UR                  5       5      n[        S[        U5      5       H  nX   nU R                  XX   XU5      XX'   M      U$ )Nr   r1  )
r  r  r  r  r  rD  r  rA  rB  filter_by_currency_since_limit)r  r  codesr  rd  borrowRateHistoriesr  r  rm  borrowRateStructureborrrowRateCoderB  s               r  parse_borrow_rate_historiesokx.parse_borrow_rate_histories"  s     %'q#h-(A;D**4+;+;D%+HID}d : :302'-&*&<&<T&B#"5";&&':; ) ',,./q#d)$A7D(,(K(KL_Legkty(z% % #"r  c                    #    U R                  5       I Sh  vN   0 nUb  X%S'   Ub  X5S'   U R                  U R                  XT5      5      I Sh  vN nU R                  US/ 5      nU R	                  XqX#5      $  Na N+7f)a  
retrieves a history of a multiple currencies borrow interest rate at specific time slots, returns all currencies if no symbols passed, default is None

https://www.okx.com/docs-v5/en/#financial-product-savings-get-public-borrow-history-public

:param str[]|None codes: list of unified currency codes, default is None
:param int [since]: timestamp in ms of the earliest borrowRate, default is None
:param int [limit]: max number of borrow rate prices to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` indexed by the market symbol
Nr  rd  r  )rZ  )publicGetFinanceSavingsLendingRateHistoryr  r  rS  )r  rO  r  rd  r  r)  r  r  s           r  fetch_borrow_rate_historiesokx.fetch_borrow_rate_histories>  s      !!!
  %H$GGGT[Hdee ~~h3//UJJ7 	" fs!   A<A87A<A:*A<:A<c                 (  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US/ 5      nU R                  XX#5      $  Nw N+7f)aJ  
retrieves a history of a currencies borrow interest rate at specific time slots

https://www.okx.com/docs-v5/en/#financial-product-savings-get-public-borrow-history-public

:param str code: unified currency code
:param int [since]: timestamp for the earliest borrow rate
:param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
Nr1  rN   r  rd  r  )rZ  r  rV  r  r  parse_borrow_rate_history)	r  rm  r  rd  r  r  r)  r  r  s	            r  fetch_borrow_rate_historyokx.fetch_borrow_rate_historyg  s      !!!==&8D>
  %H$GGGT[Hdee ~~h3--d%GG9 	" fs"   BBAB$B%*BBc                   #    U R                  5       I S h  vN   U R                  U5      nU R                  USS5      nU R                  US/5      nUS   UUUS.nU R	                  U R                  Xt5      5      I S h  vN nU R                  US/ 5      n	U R                  U	S0 5      n
U R                  US5      nU R                  U R                  X5      SUS	:X  a  S
05      $ S05      $  N Nn7f)Nr?  r  rN   )r  rC  r  r?  r  r   rm  r  r  r  rb  )	rZ  r  r  r  'privatePostAccountPositionMarginBalancer  r  r  parse_margin_modification)r  r  r  r  r  r  r?  r)  r  r  r  	errorCodes               r  modify_margin_helperokx.modify_margin_helper  s    !!!V$""69e<6I;/Tl	
 EEdkkRYFbcc ~~h3tQ+$$Xv6	{{499%HyC/dK
  	6>K
  	9 	" ds#   C0C,A(C0?C. A-C0.C0r  c                    U R                  USS5      nU R                  US5      nS nUS:X  a!  [        R                  " US5      (       a  SOSnOUn[        R                  " U5      nU R                  US5      nU R                  Xr5      nUS	   (       a  US
   OUS   n	U R                  US5      n
UUS   USU R                  U5      U	S S U
U R                  U
5      S.
$ )NrC  	posBalChgr  r<  r  addreducer  rk  r  r  r  r  rv  )
r  r  r  rT  r  rm  r  r  r  r  )	r  r  rH   r  r  r  r  r~  r  )r  r  r  	amountRawtypeRawr  r  r  responseMarketrm  r  s              r  r_  okx.parse_margin_modification  s    ` &&tUK@	""40c>#--i==58DD##I.##D(3))(;)7	)B~f%W^H_%%dD1	$X.$''/"Y/
 	
r  c                 D   #    U R                  XSU5      I Sh  vN $  N7f)aw  
remove margin from a position

https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin

:param str symbol: unified market symbol
:param float amount: the amount of margin to remove
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
rf  Nra  r  r  r  r  s       r  reduce_marginokx.reduce_margin  s"      ..vxPPPPr  c                 D   #    U R                  XSU5      I Sh  vN $  N7f)aZ  
add margin

https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin

:param str symbol: unified market symbol
:param float amount: amount of margin to add
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
re  Nrl  rm  s       r  
add_marginokx.add_margin  s"      ..vufMMMMr  c                 6  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       a  SOU R                  US   5      nU R                  US   S5      nU(       d!  US:w  a  [	        U R
                  S-   U-   5      eSnU R                  SU5      u  pbUc  U R                  US	S
5      nUUUS.nUS:X  a  US   US'   U R                  U R                  Xr5      5      I Sh  vN nU R                  US/ 5      n	U R                  X5      $  N N*7f)a  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market

https://www.okx.com/docs-v5/en/#rest-api-public-data-get-position-tiers

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated'
:returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
Nr[   rA  r  r  r  z< fetchMarketLeverageTiers() cannot fetch leverage tiers for r   r<  r;  )r  r<  r  rN   r  r  )rZ  r  r  r  r4   rN   r
  publicGetPublicPositionTiersr  r  parse_market_leverage_tiers)
r  r  r  r  r  r  rT  r)  r  r  s
             r  fetch_market_leverage_tiersokx.fetch_market_leverage_tiers  s+     !!!V$!&>xt/N/NvV\~/^vf~u5x +i!ilr!rss
!??@Z\bc
))&(GDJ 

 8 &tGH::4;;w;WXX, ~~h3//==S 	"$ Ys"   DDCD,D-)DDc                 f   / n[        S[        U5      5       H  nX   nU R                  US5      nUR                  U R	                  US5      U R                  Xb5      US   U R                  US5      U R                  US5      U R                  US5      U R                  US5      US	.5        M     U$ )
zo
@ignore
       :param dict info: Exchange response for 1 market
       :param dict market: CCXT market
       r   r  tierr  r  maxSzr  maxLever)ry  r  r  minNotionalmaxNotionalmaintenanceMarginRater   r  )r  r  r  r  r  r  r  )r  r  r  tiersr  ry  r  s          r  ru  okx.parse_market_leverage_tiersK  s    0 q#d)$A7D''h7HLL))$7**8<"7O#//g>#//g>)-)9)9$)F#//jA	 	 % r  c                   #    U R                  5       I Sh  vN   SnU R                  SU5      u  peUc  U R                  USS5      nSU0nSnUb  U R                  U5      n	U	S   US'   Ub  US-
  US'   Ub  XGS	'   Ub  U R	                  U5      nUS   US
'   U R                  U R                  Xu5      5      I Sh  vN n
U R                  U
S/ 5      nU R                  U5      nU R                  XX45      $  N N<7f)ax  
fetch the interest owed b the user for borrowing currency for margin trading

https://www.okx.com/docs-v5/en/#rest-api-account-get-interest-accrued-data

:param str code: the unified currency code for the currency of the interest
:param str symbol: the market symbol of an isolated margin market, if None, the interest for cross margin markets is returned
:param int [since]: timestamp in ms of the earliest time to receive interest records for
:param int [limit]: the number of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>` to retrieve
:param dict [params]: exchange specific parameters
:param int [params.type]: Loan type 1 - VIP loans 2 - Market loans *Default is Market loans*
:param str [params.marginMode]: 'cross' or 'isolated'
:returns dict[]: An list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
Nr}   r  r;  rN   r1  r  r  rd  r  r  )
rZ  r
  r  r  r   privateGetAccountInterestAccruedr  r  parse_borrow_interestsrN  )r  rm  r  r  rd  r  rT  r)  r  r  r  r  interests                r  fetch_borrow_interestokx.fetch_borrow_interests  s&     !!!
!??@UW]^
))&)WEJz
 }}T*H%d^GEN %	GH$G[[(F &tGH>>t{{7?[\\( ~~h3..t42285PPS 	"& ]s"   C9C5B#C9:C7;;C97C9r  c                    U R                  US5      nUb  U R                  X25      nU R                  US5      nUU R                  US5      U R                  U R                  US5      5      U R	                  US5      U R	                  US5      U R	                  US5      U R                  US5      UU R                  U5      S	.	$ )
Nr  r  r  r1  r  r  liabr  )	r  r  r  r  r  amountBorrowedrT  r  r  )r  r  r  r  r  r  )r  r  r  r  r  s        r  parse_borrow_interestokx.parse_borrow_interest  s    !!$1%%f5F%%dD1	&&vx8//0@0@u0MN((z: ,,T>B"..tV<**4;"Y/

 
	
r  c                 R  #    U R                  5       I Sh  vN   U R                  U5      nUS   U R                  X5      SS.nU R                  U R	                  XS5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  X5      $  N N=7f)a  
create a loan to borrow margin(need to be VIP 5 and above)

https://www.okx.com/docs-v5/en/#trading-account-rest-api-vip-loans-borrow-and-repay

:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
NrN   borrow)r1  rC  r  r  r   )rZ  r  r  privatePostAccountBorrowRepayr  r  r  parse_margin_loan)	r  rm  r  r  r  r)  r  r  loans	            r  borrow_cross_marginokx.borrow_cross_margin  s      !!!==&D>--d;

 ;;DKK<XYY  ~~h3~~dAr*%%d553 	" Zs"   B'B#AB''B%(<B'%B'c                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  US5      nUc  [        U R                  S-   5      eU R                  U5      nUS   U R                  X5      SUS.nU R                  U R                  Xc5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      n	U R                  X5      $  N N=7f)	a  
repay borrowed margin and interest

https://www.okx.com/docs-v5/en/#trading-account-rest-api-vip-loans-borrow-and-repay

:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.id]: the order ID of borrowing, it is necessary while repaying
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
NrN   r  z, repayCrossMargin() requires an id parameterrepay)r1  rC  r  r  r  r   )rZ  r  r  r3   rN   r  r  r  r  r  r  r  )
r  rm  r  r  rN   r  r)  r  r  r  s
             r  repay_cross_marginokx.repay_cross_margin  s      !!!g664(:#DGG.\$\]]==&D>--d;	
 ;;DKK<XYY  ~~h3~~dAr*%%d55= 	" Zs"   C(C$BC((C&)<C(&C(c                 x    U R                  US5      nS U R                  X25      U R                  US5      S S S US.$ )Nr1  rC  )rN   r  r  r  r  r  r  )r  r  r  )r  r  r  rK  s       r  r  okx.parse_margin_loan  sM     %%dE2
//
E&&tU3
 	
r  c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eU R	                  US   5      nU R                  US   S5      nUUUS   S.nU R                  U R                  Xb5      5      I Sh  vN nU R                  US	/ 5      nU R                  US
   U5      $  N N.7f)a:  
Retrieves the open interest of a currency

https://www.okx.com/docs-v5/en/#rest-api-public-data-get-open-interest

:param str symbol: Unified CCXT market symbol
:param dict [params]: exchange specific parameters
:returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
Nr  z3 fetchOpenInterest() supports contract markets onlyr  r  r  rN   )r  r  r  r  r   )
rZ  r  r4   rN   r  r  publicGetPublicOpenInterestr  r  parse_open_interest)	r  r  r  r  r  r  r)  r  r  s	            r  fetch_open_interestokx.fetch_open_interest'  s      !!!V$j!TWW'\\]]..vf~>vf~u5Tl

 99$++g:VWW  ~~h3''Q889 	" Xs"   CCBC#C$-CCc                 >  #    U R                  5       I Sh  vN   U R                  USSS5      nSnUb  U R                  US   5      nSnU R                  SX2S5      u  pBSnUS:X  a  SnOUS	:X  a  S
nSU0nU R	                  US5      nUb  XvS'   U R	                  US5      nUb  XS'   US
:X  a  Uc  Uc  [        U R                  S-   5      eU R                  U R                  Xb5      5      I Sh  vN n	U R                  U	S/ 5      n
U R                  X5      $  GN N+7f)a  
Retrieves the open interests of some currencies

https://www.okx.com/docs-v5/en/#rest-api-public-data-get-open-interest

:param str[] symbols: Unified CCXT market symbols
:param dict [params]: exchange specific parameters
:param str params['instType']: Instrument type, options: 'SWAP', 'FUTURES', 'OPTION', default to 'SWAP'
:param str params['uly']: Underlying, Applicable to FUTURES/SWAP/OPTION, if instType is 'OPTION', either uly or instFamily is required
:param str params['instFamily']: Instrument family, Applicable to FUTURES/SWAP/OPTION, if instType is 'OPTION', either uly or instFamily is required
:returns dict: an dictionary of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
NTr   r   r]   rB  r^   rC  r_   rD  r  r  r  zT fetchOpenInterests() requires either uly or instFamily parameter for OPTION marketsr  )rZ  r  r  handle_sub_type_and_paramsr  r4   rN   r  r  r  parse_open_interests)r  r  r  r  r  r  r)  r  r  r  r  s              r  fetch_open_interestsokx.fetch_open_interestsO  sE     !!!%%gtT4@[[,F
!<<=QSYcij
! H!H#X.vu-? EN%%fl;
!$.L!xCKJ4FTWW'}}~~99$++g:VWW  ~~h3((77M 	"* Xs"   DDCD/D0)DDr   c                 X  #    U R                  U R                  S0 5      nU R                  US0 5      nU R                  XrU5      nUS:w  a$  US:w  a  US:w  a  [        U R                  S-   5      eU R                  5       I Sh  vN   SnSn	XR                  ;   d  XR                  ;   a  U R                  U5      n	U	S   nOU R                  U5      n
U
S	   nUUS
.nSnSnU R                  SX5      u  pUS:X  a)  U R                  U R                  X5      5      I Sh  vN nO[Ub  X;S'   U R                  US5      nUb  XS'   U R                  US/5      nU R                  U R                  X5      5      I Sh  vN nU R!                  US/ 5      nU R#                  USX45      $  GN! N N/7f)a   
Retrieves the open interest history of a currency

https://www.okx.com/docs-v5/en/#rest-api-trading-data-get-contracts-open-interest-and-volume
https://www.okx.com/docs-v5/en/#rest-api-trading-data-get-options-open-interest-and-volume

:param str symbol: Unified CCXT currency code or unified symbol
:param str timeframe: "5m", "1h", or "1d" for option only "1d" or "8h"
:param int [since]: The time in ms of the earliest record to retrieve unix timestamp
:param int [limit]: Not used by okx, but parsed internally by CCXT
:param dict [params]: Exchange specific parameters
:param int [params.until]: The time in ms of the latest record to retrieve unix timestamp
:returns: An array of `open interest structures <https://docs.ccxt.com/#/?id=open-interest-structure>`
r   r   r   r   r   zF fetchOpenInterestHistory cannot only use the 5m, 1h, and 1d timeframeNr  rN   )r1  rK  r_   r  r  r  r  )r  rw  r  r4   rN   rZ  r,  r  r  r  r  *publicGetRubikStatOptionOpenInterestVolumer  r  r  -publicGetRubikStatContractsOpenInterestVolumer  parse_open_interests_history)r  r  r  r  rd  r  rw  r   rK  r  r  r)  r  r  r  r  s                   r  fetch_open_interest_historyokx.fetch_open_interest_history  s     ../I2N^^G\2>
$$ZIF	d!2yD7HTWW'oopp!!!
ll"2D2D(D[[(F)J}}V,H!$J
 99:TV\e8!LLT[[Y`MijjH #( %%fg6E !&6G95!OOPTP[P[\cPlmmH ~~h300tUJJU 	"$ k ns8   B F*F#BF*F&AF*8F(9+F*&F*(F*c                    U R                  US5      nU R                  X25      nU R                  US5      nU R                  USU5      nS nS nS nS n	U R                  U R                  S5      n
[	        U[
        5      (       aP  U
S:X  a%  U R                  US5      nU R                  US5      nO[U R                  US5      n	U R                  US5      nO6U R                  US5      nU R                  US	5      nU R                  US
5      n	U R                  U R                  U5      UUUU	UU R                  U5      US.U5      $ )Nr  r  r   r/  r_   r  r   oiCcyoioiUsd)r  ry  rz  openInterestAmountopenInterestValuer  r  r  )
r  r  r  rw  r  rA  r  safe_open_interestr  r  )r  r  r  rN   timer  ry  rz  r  r  r  s              r  r  okx.parse_open_interest  sX   * h1!!"-  40%%h48	
! m<h%%x%)%5%5h%B"!--h:
$($4$4Xq$A!"..x;))(G<J!%!1!1(D!A $ 0 07 C&&&&r*$&"4!2"Y/	(
 	 		r  enablec                    > [         [        U ]  U5        XR                  S'   U(       a  SU R                  S'   g SU R                  ;   a"  U R                  U R                  S5      U l        g g )Nr  r  zx-simulated-trading)r|  rJ   set_sandbox_moderw  r  r  )r  r  r  s     r  r  okx.set_sandbox_mode  sX    c4)&1&,]#25DLL./"dll299T\\3HIDL 3r  rO  c                 ,  #    U R                  5       I Sh  vN   0 nUb%  U R                  U5      nSR                  U5      US'   U R                  U R	                  X25      5      I Sh  vN nU R                  US5      nU R                  Xa5      $  Ny N)7f)aA  
fetch deposit and withdraw fees

https://www.okx.com/docs-v5/en/#rest-api-funding-get-currencies

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
Nr  r1  r  )rZ  currency_idsrE  r?  r  r  parse_deposit_withdraw_fees)r  rO  r  r)  r  r  r  s          r  fetch_deposit_withdraw_feesokx.fetch_deposit_withdraw_fees   s      !!!##E*C XXc]GEN77G8TUUX ~~h///<<e 	"
 Vs"   BBAB(B)(BBc                    0 nU R                  U5      n[        S[        U5      5       H  nX   nU R                  US5      nU R	                  U5      nUb  U R                  X5      (       d  ME  U R                  XH5      n	U	c  U R                  0 5      XH'   XdU   S   U'   U R                  US5      n
U
c  M  U
R                  S5      nU R                  US5      nU R                  US5      nUUb  SOS S	.nS S S	.nU R                  X5      nUUS
.XH   S   U'   M     [        UR                  5       5      n[        S[        U5      5       H/  nUU   nU R                  U5      nU R                  XH   U5      XH'   M1     U$ )Nr   r1  r  r3  r  r  r7  F)r7  ru  )r   r<  r  )market_codesr  r  r  r  r  rP  deposit_withdraw_feer  r  rF  rA  rB  r  $assign_default_deposit_withdraw_fees)r  r  rO  currencyIdKeydepositWithdrawFeesr  feeInforK  rm  depositWithdrawFeer3  
chainSplitrO  withdrawFeewithdrawResultdepositResultrR  depositWithdrawCodesr  s                      r  r  okx.parse_deposit_withdraw_fees>  s   , %'!!%(q#h-(AkG))'59J**:6D4==#=#=%)__5H%O"%-040I0I"0M'-@GD)&1*=((':="[[-
 OOJ:	"..w>&,7,C%$(
  "&' #55iF .,F#)*5kB1 )8  $$7$<$<$>?q#234A'*D}}T*H(,(Q(QReRkmu(v% 5 #"r  c                 X  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSnU R	                  SXT5      u  pdUS:w  a  US:w  a  [        U R                  S-   5      eU R                  U5      US   S-   US	   -   S
.nUb  US-
  US'   Ub  X7S'   U R                  U R                  Xt5      5      I Sh  vN nU R                  US/ 5      n	U R                  X5      n
U R                  U
S5      nU R                  XS   X#5      $  N NQ7f)a  
fetches historical settlement records

https://www.okx.com/docs-v5/en/#rest-api-public-data-get-delivery-exercise-history

:param str symbol: unified market symbol to fetch the settlement history for
:param int [since]: timestamp in ms
:param int [limit]: number of records
:param dict [params]: exchange specific params
:returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/#/?id=settlement-history-structure>`
Nz4 fetchSettlementHistory() requires a symbol argumentr   r^   r_   zC fetchSettlementHistory() supports futures and options markets onlyr  r  r  )r  r  r  r  rd  r  r  r  )r3   rN   rZ  r  r  r>   r  &publicGetPublicDeliveryExerciseHistoryr  r  parse_settlementsr  r  )r  r  r  rd  r  r  r  r)  r  r  settlementsr  s               r  fetch_settlement_historyokx.fetch_settlement_historyy  sE     >#DGG.d$dee!!!V$99:RTZc8 0tww)nnoo77=(#c)F9,==
  %	GH$GDDT[[QXEabb& ~~h3,,T:k;7009I5XXI 	" cs#   /D*D&B$D*D(AD*(D*c                 t    U R                  US5      nUU R                  X25      U R                  US5      S S S.$ )NinsIdr  )r  r  rO  r  r  )r  r  r  )r  
settlementr  r  s       r  parse_settlementokx.parse_settlement  sG     ##J8&&x8%%j$7
 	
r  c                 Z   / n[        S[        U5      5       H  nX   nU R                  US5      nU R                  US/ 5      n[        S[        U5      5       HJ  nU R	                  Xx   U5      n	UR                  U R                  U	UU R                  U5      S.5      5        ML     M     U$ )Nr   r  r  )r  r  )r  r  r  r  r  r  r  r  )
r  r  r  r  r  r  r  r  rN  r  s
             r  r  okx.parse_settlements  s     q#k*+ANE))%6InnUIr:G1c'l+!227:vF
dkk*!* $Y 77   ,	 , r  c                   #    U R                  5       I Sh  vN   SnU R                  SSU5      u  p!Ub  US:X  a  SnUS:w  a$  US:w  a  US:w  a  [        U R                  S-   5      eSU R	                  U5      0nU R                  U R                  X15      5      I Sh  vN nU R                  US	/ 5      nUS
   $  N N7f)a  
fetches the market ids of underlying assets for a specific contract market type

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-underlying

:param dict [params]: exchange specific params
:param str [params.type]: the contract market type, 'option', 'swap' or 'future', the default is 'option'
:returns dict[]: a list of `underlying assets <https://docs.ccxt.com/#/?id=underlying-assets-structure>`
Nr   r[   r_   r]   r^   z7 fetchUnderlyingAssets() supports contract markets onlyr  r  r   )rZ  r  r>   rN   r  publicGetPublicUnderlyingr  r  )r  r  r  r)  r  underlyingss         r  fetch_underlying_assetsokx.fetch_underlying_assets  s      !!!
!??@WY]_ef
J&$8!J("v)=JRZDZtww)bbcc77
C
 77G8TUU nnXvr:1~1 	" Vs"   B>B:BB>B<B><B>c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nUR                  S5      nUS   S   US   S   U R                  US5      S.nU R	                  U R                  Xb5      5      I Sh  vN nU R                  US	/ 5      n[        S
[        U5      5       H1  n	X   n
U R                  U
S5      nX:X  d  M   U R                  X5      s  $    g N Nd7f)a  
fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-option-market-data

:param str symbol: unified symbol of the market to fetch greeks for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
NrN   r  r  r  r  r   )r  r  r  r  r   r  )
rZ  r  r  r  publicGetPublicOptSummaryr  r  r  r  parse_greeks)r  r  r  r  r  r  r)  r  r  r  r  entryMarketIds               r  fetch_greeksokx.fetch_greeks  s      !!!V$$<nnS)&>%( .6''Q7

 77G8TUU< ~~h3q#d)$AGE ,,UH=M(((77	 %
 [ 	" Vs)   C.C*A0C.C,AC.C.,C.c                   #    U R                  5       I Sh  vN   0 nU R                  USSSS5      nSnUb  [        U5      nUb  US:w  aP  U R                  US5      nUb  XSS'   U R                  US5      nUb  XcS'   Uc  Uc  [	        U R
                  S-   5      eSnUb[  US:X  aU  U R                  US   5      nUS   nUR                  S	5      n	US
   S   US'   US
   S   US'   U R                  U	S5      US'   U R                  USS/5      nU R                  U R                  X25      5      I Sh  vN n
U R                  U
S/ 5      nU R                  X5      $  GNE N+7f)a  
fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract

https://www.okx.com/docs-v5/en/#public-data-rest-api-get-option-market-data

:param str[] [symbols]: unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str params['uly']: Underlying, either uly or instFamily is required
:param str params['instFamily']: Instrument family, either uly or instFamily is required
:returns dict: a `greeks structure <https://docs.ccxt.com/#/?id=greeks-structure>`
NTr  r  r  z? fetchAllGreeks() requires either a uly or instFamily parameterr   rN   r  r  r   r  r  )rZ  r  r  r  r4   rN   r  r  r  r  r  r  parse_all_greeks)r  r  r  r)  symbolsLengthr  r  r  r  r  r  r  s               r  fetch_all_greeksokx.fetch_all_greeks5  s     !!!%%gtT4FLMO!!3""651C!$))&,?J%(2%*"4 +l!lmm!WQZ0!$<&nnS1!'!6(.v|(D%%)%5%5k1%E	"6E<#8977G8TUU< ~~h3$$T33q 	"2 Vs"   E EDE 2E3)E E greeksc                    U R                  US5      nU R                  US5      nU R                  XB5      n0 SU_SU_SU R                  U5      _SU R	                  US5      _SU R	                  US5      _SU R	                  US5      _S	U R	                  US	5      _S
S _SS _SS _SU R	                  US5      _SU R	                  US5      _SU R	                  US5      _SS _SS _SS _SS _S US.E$ )Nr  r  r  r  r  deltagammathetavegarhobidSizeaskSizebidImpliedVolatilitybidVolaskImpliedVolatilityaskVolmarkImpliedVolatilitymarkVolbidPriceaskPricer{  r  )underlyingPricer  )r  r  r  r  r  )r  r  r  r  r  r  s         r  r  okx.parse_greeks{  s{   0 %%fd3	##FH5!!(3
f

 Y/
 T%%fg6	

 T%%fg6
 T%%fg6
 D$$VV4
 4
 t
 t
 #D$4$4VX$F
 #D$4$4VX$F
 $T%5%5fi%H
 
 
  !
" #
$  $'
 	
r  c                 *  #    U R                  5       I Sh  vN   U R                  U5      nU R                  US5      nU R                  US5      nSnU R                  SUS5      u  psUS   US.nUb  US:X  a  S	US
'   OUS:X  a  SUS
'   OX(S
'   Ub  XXS'   Ub  U R	                  U5      n	U	S   US'   U R                  U R                  X5      5      I Sh  vN n
U R                  U
S/ 5      nU R                  US5      nU R                  X5      $  N N<7f)a?  
       closes open positions for a market

       https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions

       :param str symbol: Unified CCXT market symbol
       :param str [side]: 'buy' or 'sell', leave in net mode
       :param dict [params]: extra parameters specific to the okx api endpoint
       :param str [params.clientOrderId]: a unique identifier for the order
       :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross
       :param str [params.code]: *required in the case of closing cross MARGIN position for Single-currency margin* margin currency

EXCHANGE SPECIFIC PARAMETERS
       :param boolean [params.autoCxl]: whether any pending orders for closing out needs to be automatically canceled when close position via a market order. False or True, the default is False
       :param str [params.tag]: order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
       :returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
       Nr2  rm  rg   r;  rN   rw  r  rA  r?  r#  r@  r1  r1  r  r   )
rZ  r  r  r
  r  privatePostTradeClosePositionr  r  r  r  )r  r  r  r  r  r2  rm  rT  r)  r  r  r  r  s                r  close_positionokx.close_position  s8    $ !!!V$((A/
!??QWY`a
Tl!
 %+	"%,	"%)	"$!.I}}T*H%d^GEN;;DKK<XYY$ ~~h3tQ'..U 	", Zs"   DDB=DD;DDc                 4  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  US0 5      nU R                  USU5      $  N} N?7f)aa  
fetches option data that is commonly found in an option chain

https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-ticker

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
Nr  rN   r  r   )rZ  r  r  r  r  r  parse_option)r  r  r  r  r)  r  r  r3  s           r  fetch_optionokx.fetch_option  s      !!!V$fTl
 33DKK4PQQ6 &"5vq"-  f55E 	"
 Rs!   BB?BB>BBc                   #    U R                  5       I Sh  vN   U R                  U5      nUS   S-   SS.nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  USS5      $  Nn N,7f)a  
fetches data for an underlying asset that is commonly found in an option chain

https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers

:param str code: base currency to fetch an option chain for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.uly]: the underlying asset, can be obtained from fetchUnderlyingAssets()
:returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
Nrm  z-USDrD  )r  r  r  r  )rZ  r  r  r  r  parse_option_chain)r  rm  r  r  r)  r  r  s          r  fetch_option_chainokx.fetch_option_chain  s      !!!==&F#f, 
 44T[[5QRR6 &"5&&vtX>>E 	" Ss"   B	BAB	B+B	B	r3  c                 z   U R                  US5      nU R                  XC5      nU R                  US5      n0 SU_SS _SUS   _SU_SU R                  U5      _SS _S	S _S
U R	                  US5      _SU R	                  US5      _SS _SS _SU R	                  US5      _SS _SS _SS _SU R	                  US5      _SS _$ )Nr  r  r  r  r  r  r  impliedVolatilityopenInterestr  ri  r  rm  midPricer{  r  rK  r  rt  ru  ry  rb  rz  )r  r  r  r  r  )r  r3  r  r  r  r  s         r  r  okx.parse_optionG  sL   * ##E84!!(3%%eT2	
E

 fX&
 	

 Y/
  
 D
 ((8
 ((8
 
 
 ))%8
 t
 d
 $
  $**5+>!
" 4#
 	
r  fromCodetoCodec                   #    U R                  5       I Sh  vN   UR                  5       UR                  5       UR                  5       U R                  U5      SS.nU R                  U R	                  XT5      5      I Sh  vN nU R                  US/ 5      nU R                  US0 5      nU R                  USU5      n	U R                  U	5      n
U R                  USU5      nU R                  U5      nU R                  XU5      $  N N7f)a  
fetch a quote for converting from one currency to another

https://www.okx.com/docs-v5/en/#funding-account-rest-api-estimate-quote

:param str fromCode: the currency that you want to sell and convert from
:param str toCode: the currency that you want to buy and convert into
:param float [amount]: how much you want to trade in units of the from currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
Nr#  )r  r  rfqSzCcyrfqSzr  r  r   r  r  )
rZ  rE  rS  $privatePostAssetConvertEstimateQuoter  r  r  r  r  parse_conversion)r  r
  r  r  r  r)  r  r  r  fromCurrencyIdfromCurrencytoCurrencyId
toCurrencys                r  fetch_convert_quoteokx.fetch_convert_quotes  s      !!!~~' (**62
 BB4;;wC_``0 ~~h3a,))&)XF}}^4''
FC]]<0
$$V:FFM 	" as#   DDA(D?D BDDc                   #    U R                  5       I Sh  vN   UUUUU R                  U5      SS.nU R                  U R                  Xe5      5      I Sh  vN nU R	                  US/ 5      nU R                  US0 5      n	U R                  U	SU5      n
U R                  U
5      nU R                  U	SU5      nU R                  U5      nU R                  XU5      $  N N7f)a/  
convert from one currency to another

https://www.okx.com/docs-v5/en/#funding-account-rest-api-convert-trade

:param str id: the id of the trade that you want to make
:param str fromCode: the currency that you want to sell and convert from
:param str toCode: the currency that you want to buy and convert into
:param float [amount]: how much you want to trade in units of the from currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
Nr#  )r  r  r  szCcyrY  r  r  r   r  r  )	rZ  rS  privatePostAssetConvertTrader  r  r  r  r  r  )r  rN   r
  r  r  r  r)  r  r  r  r  r  r  r  s                 r  create_convert_tradeokx.create_convert_trade  s      !!!''/
 ::4;;w;WXX. ~~h3a,))&)XF}}^4''
FC]]<0
$$V:FFM 	" Ys"   CC?CCBCCc                   #    U R                  5       I Sh  vN   SU0nU R                  U R                  XC5      5      I Sh  vN nU R                  US/ 5      nU R	                  US0 5      nU R                  US5      nU R                  US5      n	Sn
SnUb  U R                  U5      n
U	b  U R                  U	5      nU R                  XzU5      $  N N7f)a  
fetch the data for a conversion trade

https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-convert-history

:param str id: the id of the trade that you want to fetch
:param str [code]: the unified currency code of the conversion trade
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
NclTReqIdr  r   r  r  )rZ  privateGetAssetConvertHistoryr  r  r  r  r  r  )r  rN   rm  r  r)  r  r  r  r  r  r  r  s               r  fetch_convert_tradeokx.fetch_convert_trade  s      !!!
 ;;DKK<XYY, ~~h3a,))&)<''
;
%==8L#|4J$$V:FFI 	" Zs"   CC+CCBCCc                 (  #    U R                  5       I Sh  vN   0 nU R                  SXT5      u  pTUb  X%S'   Ub  X5S'   U R                  U R                  XT5      5      I Sh  vN nU R	                  US/ 5      nU R                  XqSSX#5      $  Nw N-7f)a;  
fetch the users history of conversion trades

https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-convert-history

:param str [code]: the unified currency code
:param int [since]: the earliest time in ms to fetch conversions for
:param int [limit]: the maximum number of conversion structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest conversion to fetch
:returns dict[]: a list of `conversion structures <https://docs.ccxt.com/#/?id=conversion-structure>`
Nr  r  rd  r  r  r  )rZ  r  r  r  r  parse_conversions)r  rm  r  rd  r  r)  r  rowss           r  fetch_convert_trade_historyokx.fetch_convert_trade_history   s      !!!227GL %H$G;;DKK<XYY, ~~h3%%d)ZVV= 	" Zs"   BBAB"B#,BB
conversionr  r  c                 v   U R                  USS5      nU R                  US5      nU R                  XR5      nU R                  US5      nU R                  Xs5      nUUU R                  U5      U R	                  U/ SQ5      UU R                  USS5      UU R                  USS	5      U R                  US
S5      S S.
$ )N	quoteTimer  r  r  )clQReqIdr  r  baseSz
fillBaseSzquoteSzfillQuoteSzcnvtPxr  )
r  r  r  rN   r  
fromAmountr  toAmountrO  r7  )r  r  r  r  r*  rR  )	r  r&  r  r  r  fromCoinr
  rj  r  s	            r  r  okx.parse_conversion:   s    j ''
KF	##J	:**8Bj*5((8"Y/$$Z1ST$,,Z<P **:y-P''
HhG
 	
r  c                   #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN n0 nU R                  US/ 5      n[        S[	        U5      5       Hi  nXE   nU R                  US5      nU R                  U5      nUUUSSSSSSSSU R                  US5      U R                  US5      S.SSS.SSS.S.SS	.X8'   Mk     U$  N N7f)
a  
fetches all available currencies that can be converted

https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-convert-currencies

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
Nr  r   r1  r  ra  r  )r  r   r<  )r  rN   rm  r  r  rO   r  r<  r   r7  rn  r  r  )rZ   privateGetAssetConvertCurrenciesr  r  r  r  r  r  )	r  r  r  r  r  r  r  rN   rm  s	            r  fetch_convert_currenciesokx.fetch_convert_currencies   s	     !!!>>vFF ~~h3q#d)$AGE!!%/B**2.D  !  $//u=#//u=
  $#!
  $#   5FL	 %@ c 	"Fs    CCCCBCChttpCodereasonr   r'  r  r  c
                    U(       d  g U R                  US5      n
U
S:w  a  U
S:w  a  U R                  S-   U-   nU R                  US/ 5      n[        S[	        U5      5       Hj  nX   nU R                  US5      nU R                  US5      nU R                  U R                  S	   X5        U R                  U R                  S
   UU5        Ml     U R                  U R                  S	   X5        [        U5      eg )Nrm  r  r   r  r   r  sMsgr  r  )	r  rN   r  r  r  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr.   )r  r7  r8  r   r'  r  r  r  requestHeadersrequestBodyrm  feedbackr  r  errorr`  messages                    r  handle_errorsokx.handle_errors   s    * &1CKdckww}t+H>>(FB7D1c$i( ,,UG<	**5&944T__W5Myc44T__W5MwX`a ) 001I4Z))r  c                 (  #    U R                  5       I Sh  vN   U R                  US5      nUc  [        U R                  S-   5      eUS:H  nU(       a  SOSnU(       a%  U(       a  SnO[	        U R                  S-   U-   5      eUS	S
.n	U R                  US5      n
U R                  US5      nUb  X9S'   Ub  XIS'   U
b  XS'   SnU R                  5       nUS-
  nUS-
  nUb  X=:  a)  U R                  U R                  X5      5      I Sh  vN nOFX>:  a)  U R                  U R                  X5      5      I Sh  vN nO[	        U R                  S-   5      eU R                  US5      nU R                  U5      nU R                  UXU5      $  GNu N NX7f)a  
fetches the history of margin added or reduced from contract isolated positions

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-7-days
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months

:param str [symbol]: not used by okx fetchMarginAdjustmentHistory
:param str [type]: "add" or "reduce"
:param int [since]: the earliest time in ms to fetch margin adjustment history for
:param int [limit]: the maximum number of entries to retrieve
:param dict params: extra parameters specific to the exchange api endpoint
:param boolean [params.auto]: True if fetching auto margin increases
:returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
Nautoz8 fetchMarginAdjustmentHistory() requires a type argumentre  160161162z* cannot fetch margin adjustments for type rv  )subTyper  r  r  rd  endTimei $l    X zS fetchMarginAdjustmentHistory() cannot fetch margin adjustments older than 3 monthsr  )rZ  r=  r3   rN   r4   r  r  r  r0  r  r	  r  parse_margin_modificationsr  )r  r  r  r  rd  r  rF  isAddrJ  r)  r  r  r  
oneWeekAgothreeMonthsAgor  modificationss                    r  fetch_margin_adjustment_history#okx.fetch_margin_adjustment_history   s     !!!~~ff-<#DGG.h$hii %e +W!WZ^!^__!
 !!&'267+#(K $G!&I!9_
z)Mu1!88W9UVVH#!??G@\]]HTWW'||}}V ~~h/77=00uUU[ 	"8 W]s5   FFC2F	F
-F7F8AFFFc                   #    U R                  5       I Sh  vN   U R                  US5      nU R                  US5      nU R                  U/ SQ5      nUc  SnSU0nUb-  [	        U5      nUS:X  a  U R                  US   5      n	U	S	   US
'   Ub  XWS'   Ub  XgS'   U R                  U R                  Xt5      5      I Sh  vN n
U R                  U
S5      nU R                  XU5      nU R                  XU5      $  N N<7f)uo  
       fetches historical positions

       https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history

       :param str [symbols]: unified market symbols
       :param int [since]: timestamp in ms of the earliest position to fetch
       :param int [limit]: the maximum amount of records to fetch, default=100, max=100
       :param dict params: extra parameters specific to the exchange api endpoint
       :param str [params.marginMode]: "cross" or "isolated"

EXCHANGE SPECIFIC PARAMETERS
       :param str [params.instType]: margin, swap, futures or option
       :param str [params.type]: the type of latest close position 1: close position partially, 2：close all, 3：liquidation, 4：partial liquidation; 5：adl, is it is the latest type if there are several types for the same position
       :param str [params.posId]: position id, there is attribute expiration, the posid will be expired if it is more than 30 days after the last full close position, then position will use new posid
       :param str [params.before]: timestamp in ms of the earliest position to fetch based on the last update time of the position
       :param str [params.after]: timestamp in ms of the latest position to fetch based on the last update time of the position
       :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
       NrT  r  )r  rT  r  r	  rd  r  r   rN   r  r  r  )rZ  r  safe_string_upperr  r  r  r  r  r  parse_positionsfilter_by_since_limit)r  r  r  rd  r  rT  r  r)  r  r  r  r  r  s                r  fetch_positions_historyokx.fetch_positions_history@!  s    ( !!!%%fl;
))&*=6#FG=EU
 LM!WQZ0$*4L!!!+I"*J??G@\]]D ~~h/((?	)))EBBm 	"$ ^s"   C<C8B&C<=C:>;C<:C<c                 8  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  USS5      nU R                  US5      nUb  XS'   Ub  X'S'   Ub  X7S'   Ub  XGS'   U R	                  U R                  Xu5      5      I Sh  vN n	U R                  U	S	/ 5      n
/ n[        S
[        U
5      5       H;  nX   nUR                  U R                  US
5      U R                  US5      S.5        M=     U R                  X5      $  N N7f)a  
fetches the long short ratio history for a unified market symbol

https://www.okx.com/docs-v5/en/#trading-statistics-rest-api-get-contract-long-short-ratio

:param str symbol: unified symbol of the market to fetch the long short ratio for
:param str [timeframe]: the period for the ratio
:param int [since]: the earliest time in ms to fetch ratios for
:param int [limit]: the maximum number of long short ratio structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest ratio to fetch
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
Nr  rN   r  r  rK  r  rd  r  r   r  )r  longShortRatio)rZ  r  r  r  8publicGetRubikStatContractsLongShortAccountRatioContractr  r  r  r  r  r  parse_long_short_ratio_history)r  r  r  r  rd  r  r  r)  r  r  r  r  r  r  s                 r  fetch_long_short_ratio_history"okx.fetch_long_short_ratio_history!  s9     !!!V$fTl
 ""67E:67+"EN  )H$G$GVVW[WbWbcjWstt ~~h3q#d)$AGEMM!--eQ7"&"2"25!"<  % 226BBG 	" us#   DDB DDA?DDc           	          U R                  US5      nS nUb  US   nUUUU R                  U5      S U R                  US5      S.$ )Nr  r  rZ  )r  r  r  r  r  rZ  )r  r  r  )r  r  r  r  r  s        r  parse_long_short_ratiookx.parse_long_short_ratio!  s\    %%dK8	H%F"Y/"..t5EF
 	
r  )ry  r  )NNNN)N)NN)__name__
__module____qualname____firstlineno__r   r}  r  r   r  r  r  r!   r+   r  r  r   r  r-   r   r  r  r  dictr"  r  r   rT  r   r]  r#   r~  r  r"   r$   r  r  r  r(   r  r  rA  r  r  r  r  r  r  r)   r	  r  r   r  floatr  r$  r   r   r   r  r  r   r  r  r  r  r  r  r   r  r  r  r   r  r  r  r  r  r  r  r   r  r  r   r!  r   r0  r9  r>  r*   r   rP  rU  rY  r^  rf  rH  r   rz  ry  r  r    r  r  r  r,   r   r  r  r  r  r  r%   r
  r  r  r  r&   r   r%  intr+  r7  boolr=  r@  r   rE  r
   rH  rD  rS  rW  r[  r   ra  r_  rn  rq  r   rv  ru  r   r  r  r  r  r  r  r'   r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r   r  r   r  r  r	   r  r  r  r$  r  r5  rC  rQ  rW  r   r]  r`  __static_attributes____classcell__)r  s   @r  rJ   rJ   )   sN   n# n`) OS[]lp h hV hux h h;;
3 ;
zUC U URU Ujm U  zI U U )+ 4l ') .S .. +- =g =~D *, V 4^4 ^F ^@ 8: 50n -/ |: || @DB 5?S 5? 5?S\ 5?nH4 H H6 HT 68 ,0 ,0F ,0\ 6:" 547 54 54n :< BS B BB :>b 4w 4W 4:X Xv X Xt <@d[] G= G=S G= G=bfglbm G=R
 
4 
4 ?CQUdhqs fH fH fH3 fH^a fHx|  ~B  yC fHP >BPTcgpr @Ys @Y# @Y]` @YD8)2)
T 
6 
EX 
0 ;= -5c -5AT -5^ *, {@ {@z XZ fc f f* Y[ gs g% g* os{} x,3 x,i x,y x,Z_ x,hk x,t mqy{ 9 9I 9Y 9X] 9fi 9v FH /'$|*< /'b FJQU^` J,S J,X fjx|  FH ?3 ? ?9 ?I ?_b ?ru ?B 9=R &/S &/# &/P	 AER _ItCy _I# _IB Y[ MGd;N6O MG^ BD S :	: 	:R Rv R Rh 8<B O/C O/ O/b 59tZ^gi Z=c Z= Z=TW Z=nrsxny Z=x 9=4^bkm m=# m=S m=X[ m=^ 7;\`ik n= n=3 n=VY n=ptuzp{ n=` 37TX\eg BDC BDs BDRU BDH ?CQUdhqs ^3 ^ ^3 ^^a ^, .2SW`b p?s p?# p?S p?gklwgx p?d3 Bt Bx B; BH]
h ]
R` ]
~ JL (0S (0PTUcPd (0T =? / /> /< QU]_ 9=3 9= 9= 9=# 9=do 9=v 04$UYbd KM KMC KMs KMimnyiz KMZ 8<B 9c 9 90 37TX\eg CMC CMs CMRU CMlpq|l} CMJ ;?r +2 +2C +2Z+:s +:Z[
T [
X [
Q\ [
z 8: '13 '1h '1R
t 
V 
x 
2 8: H53 H5T 8<B TeW Te4PX> Tel DF <s <\t \V \| ac 9:3 9: 9:C 9:TW 9:gt 9:vJ
t J
x J
= J
X:C :C : 9=R -s -# -M -> 154VZce :O# :OS :OPS :Ojno|j} :Ox &eBSW 1Pf:
6 :
[ :
x? @B 
=3 
=k 
= <> $6s $6+ $6L <@ 7 7| 7B 9=4^bkm VO# VOS VOX[ VOp ?C2 43 4 4l 7;2 
 
@ CGr d C B DHPR - -S -^ 57 ;K : ?A ,# ,_ ,B
 
(#8 7;\`ik 'K3 'KVY 'KR GKY]fh (HC (H (HSV (HT LN  Rd BG
d G
F G
N` G
R FH Q# Qu QL^ Q CE Ns NE NI[ N EG 4> 4>4P\K] 4>l& &$|J\ &P 7;$]apt} 8Q 8QC 8QWZ 8Qjm 8Q  EI  JX  EY 8Qt
$ 
 
. 
" JL $6c $65 $6L BD *6S *6X
 
. =? &9 &9P =A 38' 38P] 38j HLZ^mqz| >K >KTW >Kgj >K@2F 2hJt J BFb <=w <=|9#v <@daenp 2YS 2Y 2Y[^ 2Yh
"4 46 "H 68 7 7F 7r 9=R D4g D4DQWL D4L/
4 /
 /
6 /
b CGr </3 </i </V[ </| 68 ,6 ,6F ,6\ :< -?S -? -?^*
$ *
( *
6 *
]c *
X SW_a 2G# 2Gs 2GC 2Gfp 2Gh ]aik 3GS 3GC 3G 3GVY 3Gpz 3Gj >B" /GC /Gs /GQ[ /Gb =Atbfoq +Wc +W +W\_ +Wvz  |F  wG +WZE
4 E
x E
\d E
pz E
N 57 :: :x#c #3 #S ## #X\ #dg #J CGTXgkz~  HJ \VC \Vc \Vad \Vtw \V  OS  Tf  Og \V| @DRVeirt JCW JCC JC_b JCy}  G  zH JCX BFX\ko  C  LN 1C3 1CRU 1Ceh 1Cx{ 1C  SW  Xf  Sg 1Cf
4 
 
> 
 
r  rJ   )P ccxt.async_support.base.exchanger   ccxt.abstract.okxr   r  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   typingr-   ccxt.base.errorsr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   ccxt.base.decimal_to_precisionrG   ccxt.base.preciserH   rJ    r  r  <module>rt     s    6 )   w  w  w  w  w  w  w  w  w  w  w  * 0 - . - . ' & . 4 / . + ) * 0 ) ) + . 1 * ) + * 4 %bF
(K bF
r  