
    ei7j                    D   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl1m3Z3 d dl1m4Z4 d d	l1m5Z5 d d
l1m6Z6 d dl1m7Z7 d dl1m8Z8 d dl1m9Z9 d dl1m:Z: d dl1m;Z; d dl1m<Z< d dl1m=Z= d dl1m>Z> d dl1m?Z? d dl1m@Z@ d dl1mAZA d dl1mBZB d dl1mCZC d dl1mDZD d dl1mEZE d dl1mFZF d dl1mGZG d dl1mHZH d dl1mIZI d dl1mJZJ d dlKmLZL d d lMmNZN  G d! d"ee          ZOdS )#    )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                   8    e Zd Zdef fdZdi dfdededef fdZd Zdefd	Z	dd
e
dede
de
def
 fdZi fdZi fdefdZi fdee         fdZd Zi fdee         fdZdedefdZi fdZi fdefdZdedefdZdi fdededefdZddededefdZi fdedefdZ di fde!de"fdZ#i fdedefdZ$di fde!de"fd Z%dd!edede&fd"Z'ddi fded#ededee&         fd$Z(ddede)fd%Z*d&ddi fded'ed#ededee)         f
d(Z+dddi fde
d#edefd)Z,d* Z-d+ Z.d, Z/dd-edede0fd.Z1i fdede0fd/Z2i fde3fd0Z4i fded1e5fd2Z6i fded1e5fd3Z7di fded4e8d5e9d6e5d7e:f
d8Z;di fded4e8d5e9d6e5d7e:f
d9Z<i fd:ee=         fd;Z>ddi fd<efd=Z?ddi fd<eded4e8d5e9d6e:d7e:fd>Z@di fd<ede
fd?ZAd@ ZBdi fdAee         de
fdBZCi fd:eeD         fdCZEi fdDefdEZFdFe
fdGZGddHededeHfdIZIdi fd<ede
fdJZJdddi fde
d#ededeeH         fdKZKdddi fde
d#edefdLZLdddi fde
d#ededeeH         fdMZMdddi fde
d#edefdNZNdddi fd<ede
d#edefdOZOdddi fdPe
d#ededeeP         fdQZQdR ZRddSededePfdTZSddedeTfdUZUi fdPedeeT         fdVZVi fdPedeTfdWZWdi fdPed6e5dXedYe
deXf
dZZYdddi fdPe
d#ededeeX         fd[ZZdi fd<edPe
fd\Z[dddi fdPe
d#ededeeX         fd]Z\di fd<edPe
fd^Z]dFe
fd_Z^dd`ededeXfdaZ_i fdede`fdbZaddcedede`fddZbi fdefdeZcdi fde!deed         fdfZei fdefdgZfddhedefdiZgi fdPed6e5djedkedehf
dlZiddmededehfdnZjdFe
de
fdoZkdi fd<edPe
dehfdpZldddi fdPe
d#ededeeh         fdqZmdrdsi ddfdtZnddedeofduZpdv Zqi fdedeofdwZri fdedeofdxZsdi fde!detfdyZudddi fde
d#edefdzZvdi fdcewde
fd{Zxdi fde
fd|Zydi fd}ezde
fd~Z{di fdede
fdZ|i fde}fdZ~i fdPedefdZddefdZd Zdddi fd#edefdZddi fdPed#edefdZi fdedefdZddededefdZi fded6e5defdZi fded6e5defdZi fdedee         fdZddedee         fdZddddi fdPe
de
d#ededee         f
dZddededefdZi fdPed6e5fdZi fdPefdZddefdZi fdefdZdi fde!defdZdddi fded#edefdZddefdZdezf fdZdi fde!fdZddZdddi fde
d#edefdZd Zd Zi fdZi fdedefdZdi fde!dee         fdZddededefdZdi fded5e9deHfdZi fdedefdZi fdPedefdZddedededefdZdi fdeded6e:defdZdi fd<ededed6e:def
dZdi fd<edPe
defdZdddi fdPe
d#ededee         fdZddedededefdZi fdefdZdewdededededefdZddddi fde
d4e
d#e:de:dee         f
dZdddi fde!d#ededeed         fdZddddi fde
d'e
d#ededee         f
dZddededefdZ xZS )okxreturnc                 4   |                      t          t          |                                           i dddddddgdd	d
ddddddi dd ddddddddddddddddddddddddddddd dd!di d"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2di d3d d4dd5dd6dd7dd8d d9dd:dd;dd<dd=dd>dd?dd@ddAddBddCdi dDddEddFddGdHdIddJddKddLddMddNddOddPddQddRddSddTddUdi dVd dWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfdi dgd dhddiddjddkddlddmddnddoddpddqdHdrddsddtdduddvddwdi dxddyddzdd{dd|dd}dd~dddddddddddddddddddddddddddddddddddddddddddddddddddddddiddddddddiddi ddddddddddddddddddddddddddddddddddi ddddddddddddÓddddƓddȓddddddddddddddddi ddddddddddddddddddddddddddޓddddƓddޓddi ddޓddddޓddޓddޓddޓddޓddޓddޓddޓddޓddޓddޓddޓddƓddddi ddddddddddddޓddȓddȓddȓddȓddȓdd dd dd ddddޓddޓdddddddddÐd	ddidi d	dޓd
dޓddޓddddddޓddޓddddddddddddddddddddi ddddddddddd dÓd!dÓd"dÓd#dÓd$dÓd%dÓd&dd'dȓd(dȓd)dȓd*dd+di d,dȓd-dd.d/d0dȓd1dȓd2dȓd3dÓd4dd5dȓd6dȓd7dȓd8dd9dd:dd;dd<dd=di d>dޓd?dd@dޓdAddBddCddDdޓdEddFdޓdGdޓdHdޓdIddJddKdޓdLdޓdMddNdi dOdޓdPdޓdQdޓdRddSdÓdTdޓdUdޓdVdޓdWdޓdXdޓdYdޓdZdޓd[d/d\d/d]d^d_dޓd`di dad dbd dcddddȓdedȓdfddgdޓdhddiddjddkddlddmddddnddoddpdi dqddrddsddtdduddvddwddxddyddzdȓd{dȓd|d d}d d~d dd ddȓddȓi dd ddȓddȓddޓddޓddޓddޓddޓddޓddddddޓddޓddޓddޓddޓddޓi ddޓddޓddޓddޓdddddddddddd/ddddddddȓddޓddޓddddddddސdi ddޓddޓddddddd
dޓddޓddddddddddddddddddddi ddddddddddddddddddddddÓddÓddÓddޓddddޓddi dddddʐd/ddȓd̐d/ddȓddd4dϓddƓddd?dғddޓddddddޓddޓddޓi d]d^d_dޓddޓddȓddddddƓddddޓddޓddޓddޓddޓddޓdQdƓdd/dd/i dd/dd/ddddddddÓddddޓdddhdddddddddddddddi ddddddddddddddddddddd dddddddddddddi ddddd	dd
dddȓddȓdd/dd/dd/dd/dd/dd/dd/dd/dd/ddޓddޓi ddddddޓddޓddޓddޓddޓddޓd d!d"ddd!d#dd$dd%dޓd&dޓd'd!dddȐd(ddd!d!d(d(d)dd*d+|                     d,          |                     d-          d.|                     d,          |                     d-          d.|                     d/          |                     d0          d.|                     d1          |                     d2          d.d3d4dddd5d6i d7t
          d8t
          d9t          d:t          d;t          d<t          d=t          d>t          d?t          d@t          dAt          dBt          dCt
          dDt          dEt
          dFt          dGt          i dHt
          dIt
          dJt
          dKt
          dLt
          dMt
          dNt
          dOt
          dPt
          dQt          dRt
          dSt          dTt          dUt
          dVt          dWt
          dXt
          i dYt
          dZt          d[t          d\t          d]t          d^t          d_t          d`t          dat
          dbt
          dct          ddt          det          dft          dgt          dht          dit          i djt           dkt           dlt          dmt"          dnt"          dot"          dpt"          dqt$          drt          dst&          dtt"          dut           dvt           dwt           dxt"          dyt
          dzt
          i d{t
          d|t"          d}t(          d~t(          dt
          dt          dt
          dt           dt(          dt(          dt(          dt(          dt"          dt"          dt"          dt"          dt"          i dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          i dt"          dt"          dt"          dt"          dt"          dt          dt"          dt          dt"          dt"          dt"          dt"          dt$          dt"          dt"          dt"          dt"          i dt"          dt"          dt$          dt"          dt"          dt           dt$          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt*          dt          i dt          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          i dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          i dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt          dt          dt"          dt"          dt"          dt"          dt"          dt,          i dt,          dt,          dt"          dt"          dt
          dt
          dt          dt
          dt
          dt.          dt
          dt
          dt$          dt
          d t
          dt
          dt
          i dt
          dt
          dt
          dt
          dt
          dt,          d	t          d
t          dt          dt
          dt$          dt
          dt
          dt
          dt"          dt"          dt"          i dt
          dt          dt
          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt"          dt
          d t          d!t          d"t
          d#t          d$t
          i d%t
          d&t
          d't
          d(t          d)t          d*t
          d+t
          d,t
          d-t
          d.t
          d/t
          d0t
          d1t
          d2t
          d3t
          d4t
          d5t
          i d6t
          d7t
          d8t          d9t          d:t          d;t          d<t
          d=t
          d>t
          d?t0          d@t          dAt
          dBt
          dCt0          dDt
          dEt
          dFt
          i dGt
          dHt
          dIt          dJt          dKt          dLt          dMt          dNt          dOt$          dPt
          dQt$          dRt
          dSt
          dTt
          dUt
          dVt
          dWt$          i dXt
          dYt
          dZt
          d[t
          d\t$          d]t
          d^t"          d_t$          d`t$          dat          dbt          dct          ddt
          det
          dft
          dgt
          dht2          i dit$          djt2          dkt2          dlt          dmt
          dnt
          dot
          dpt
          dqt
          drt
          dst
          dtt
          dut          dvt
          dwt
          dxt
          dyt
          i dzt
          d{t          d|t
          d}t
          d~t          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt4          dt          dt          dt          dt          dt
          dt&          dt          dt6          dt          dt
          dt          dt8          dt:          i dt&          dt&          dt          dt          dt
          dt          dt          dt          dt&          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          t          t4          t          t          t          t          dt          t          ddddt          idt<          i ddddddddddi dddddddddddddddddÐddddĐdœdƐdǓdȐdɓdʐd˓d̐d͓dΐdϓdАdѓi dҐdӓdԐdՓd֐d֓dאdؓdِdړdېdܓdݐdޓdߐdddddddddddddddddddi ddddddddddddddddd dddddddddd	d
ddddddi ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7dddd8dedddd9dddd9dd:idcd;d<idrd=d>id#d?d@dd]dAg dBidCdDdEddFddUd=dGidkd=dHidhd=dIid=dJid=dKid=dKid d dLdddddddMdNdOdOdOdOdOdOdOdPdQdRdSdTdUdVdWdWdXdTdUdVdWdXdYdZd[	ddddddd\ddddddd\dd]ddddd^dddddddd_d`diddaddbddcdddddddddddded dddadfd ddddgddddhdi	djdkdidldmdjidmdjidndmdjidmdjidndo|                     dpdp|                     dq          dr          |                     dsds|                     dq          dr          |                     dtdt|                     dq          dr          |                     dudu|                     dq          dr          |                     dvdv|                     dq          dr          dwdxdyidzd{          S (|  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   zmarket/tickers   zmarket/tickerzmarket/booksg      ?zmarket/books-full   zmarket/candleszmarket/history-candleszmarket/tradeszmarket/history-tradesz&market/option/instrument-family-tradeszmarket/platform-24-volume
   zmarket/call-auction-detailzmarket/books-sbezmarket/block-tickerszmarket/block-tickerzmarket/sprd-tickerzmarket/sprd-candleszmarket/sprd-history-candleszmarket/index-tickerszmarket/index-candleszmarket/history-index-candleszmarket/mark-price-candlesz!market/history-mark-price-candleszmarket/exchange-rate   zmarket/index-componentszmarket/open-oracle2   zmarket/books-liteg?zpublic/option-tradeszpublic/block-tradeszpublic/instrumentszpublic/estimated-pricez public/delivery-exercise-historyz public/estimated-settlement-infozpublic/settlement-historyzpublic/funding-ratezpublic/funding-rate-historyzpublic/open-interestzpublic/price-limitzpublic/opt-summaryz(public/discount-rate-interest-free-quotazpublic/timezpublic/mark-pricezpublic/position-tierszpublic/interest-rate-loan-quotazpublic/underlyingzpublic/insurance-fundzpublic/convert-contract-coinzpublic/instrument-tick-bands   zpublic/premium-historyzpublic/economic-calendarzpublic/market-data-historyz#public/vip-interest-rate-loan-quotaz$rubik/stat/trading-data/support-coinz*rubik/stat/contracts/open-interest-historyzrubik/stat/taker-volumez rubik/stat/taker-volume-contractzrubik/stat/margin/loan-ratiozArubik/stat/contracts/long-short-account-ratio-contract-top-traderz6rubik/stat/contracts/long-short-account-ratio-contractz-rubik/stat/contracts/long-short-account-ratioz)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/public-tradeszsprd/tickerztradingBot/grid/ai-paramztradingBot/grid/min-investmentz"tradingBot/public/rsi-back-testingztradingBot/grid/grid-quantityzasset/exchange-listz$finance/staking-defi/eth/apy-historyz$finance/staking-defi/sol/apy-historyz$finance/savings/lending-rate-summaryz$finance/savings/lending-rate-historyz!finance/fixed-loan/lending-offersg
@z&finance/fixed-loan/lending-apy-historyz)finance/fixed-loan/pending-lending-volumezfinance/sfp/dcd/productsgUUUUUU?zcopytrading/public-configzcopytrading/public-lead-traders)	zcopytrading/public-weekly-pnlzcopytrading/public-pnlzcopytrading/public-statsz&copytrading/public-preference-currencyz'copytrading/public-current-subpositionsz'copytrading/public-subpositions-historyzcopytrading/public-copy-traderssupport/announcementszsupport/announcements-types)getpostzrfq/counterpartieszrfq/maker-instrument-settingszrfq/mmp-configzrfq/rfqsz
rfq/quotesz
rfq/tradeszrfq/public-tradesz
sprd/orderzsprd/orders-pendingzsprd/orders-historyzsprd/orders-history-archivezsprd/tradestrade/ordergUUUUUU?ztrade/orders-pendingztrade/orders-historyztrade/orders-history-archiveztrade/fillsztrade/fills-historyz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/bills-historyzasset/deposit-lightning   zasset/deposit-addresszasset/deposit-historyzasset/withdrawal-historyzasset/deposit-withdraw-statuszasset/monthly-statementzasset/convert/currencieszasset/convert/currency-pairzasset/convert/historyzaccount/instrumentszaccount/balancezaccount/positionszaccount/positions-historyz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/interest-limitsz!account/spot-borrow-repay-historyzaccount/greekszaccount/position-tiersz#account/set-account-switch-precheckzaccount/collateral-assetszaccount/mmp-configzaccount/move-positions-historyz"account/precheck-set-delta-neutralz)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/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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-pendingz%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/product-infoz finance/staking-defi/eth/balancez0finance/staking-defi/eth/purchase-redeem-historyz%finance/staking-defi/sol/product-infoz finance/staking-defi/sol/balancez0finance/staking-defi/sol/purchase-redeem-historyz'finance/flexible-loan/borrow-currenciesz'finance/flexible-loan/collateral-assetsz2finance/flexible-loan/max-collateral-redeem-amountzfinance/flexible-loan/loan-infoz"finance/flexible-loan/loan-historyz&finance/flexible-loan/interest-accruedz copytrading/current-subpositionsz copytrading/subpositions-historyzcopytrading/instrumentsz"copytrading/profit-sharing-detailsz copytrading/total-profit-sharingz-copytrading/unrealized-profit-sharing-detailsz+copytrading/total-unrealized-profit-sharingzcopytrading/configzcopytrading/copy-settingsz copytrading/current-lead-traderszcopytrading/batch-leverage-infoz copytrading/lead-traders-historyzbroker/dma/subaccount-infozbroker/dma/subaccount-trade-feebroker/dma/subaccount/apikeyzbroker/dma/rebate-per-orders,  broker/fd/rebate-per-orderszbroker/fd/if-rebatez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-dailyd   )broker/nd/rebate-per-ordersfinance/sfp/dcd/orderzfinance/sfp/dcd/orderszaffiliate/invitee/detailzusers/partner/if-rebater  z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rfq/cancel-all-afterz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-advance-algosztrade/easy-convertztrade/one-click-repayztrade/one-click-repay-v2ztrade/mass-cancelztrade/cancel-all-afterztrade/order-precheckztrade/cancel-algosztrade/amend-algoszasset/transferzasset/withdrawalzasset/withdrawal-lightningzasset/cancel-withdrawalzasset/convert-dust-assetsi zasset/convert/estimate-quotezasset/convert/tradei@ zaccount/set-position-modezaccount/set-leveragezaccount/position/margin-balancezaccount/set-fee-typezaccount/set-greekszaccount/set-isolated-modez!account/quick-margin-borrow-repayzaccount/borrow-repayzaccount/simulated_marginzaccount/position-builderzaccount/position-builder-graphzaccount/set-riskOffset-typezaccount/activate-optionzaccount/set-auto-loanz#account/account-level-switch-presetzaccount/set-account-levelzaccount/set-collateral-assetszaccount/mmp-resetz"account/fixed-loan/borrowing-orderz(account/fixed-loan/amend-borrowing-orderz"account/fixed-loan/manual-reborrowz(account/fixed-loan/repay-borrowing-orderzaccount/move-positionszaccount/set-auto-earnzaccount/set-settle-currencyzaccount/set-trading-configzasset/subaccount/transferz&account/subaccount/set-loan-allocationz"users/subaccount/create-subaccountzusers/subaccount/modify-apikeyz"users/subaccount/subaccount-apikeyzusers/subaccount/delete-apikeyz!users/subaccount/set-transfer-outztradingBot/grid/order-algoz&tradingBot/grid/amend-algo-basic-paramz 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/eth/cancel-redeemz!finance/staking-defi/sol/purchasezfinance/staking-defi/sol/redeemz&finance/staking-defi/sol/cancel-redeemzfinance/flexible-loan/max-loanz'finance/flexible-loan/adjust-collateralzcopytrading/algo-orderzcopytrading/close-subpositionzcopytrading/set-instrumentsz&copytrading/amend-profit-sharing-ratioz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  zbroker/dma/tradesr  )publicprivater   z0.0015z0.0010)takermakerz0.0005z0.0002z0.00050z0.00020)tradingrZ   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BSCBEP20BRC20r  TRX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-StackszStellar LumensTezosTONThetaWaxZilliqa)XLMXTZr  THETAWAXZILnetworksById)r  r  r  8H)r   r   8hr   5Mr   r$  r   timezoneUTCmethodprivateGetAccountPositionsprivatePostTradeBatchOrders!createMarketBuyOrderRequiresPricetypesrZ   r]   r\   r^   timeDifferencer   adjustForTimeDifferencedefaultTypeprivateGetAccountBillsprivateGetTradeOrderprivateGetTradeOrdersPending!privatePostTradeCancelBatchOrdersprivateGetTradeOrdersHistory)r  pwd)conditionaltriggerocomove_order_stopicebergtwap618)fundingr  rZ   r]   futuresr[   r\   r^   r@  r  )r>  r?  SPOTMARGINSWAPFUTURESOPTION)rZ   r[   r\   r]   rA  r^   rB  rC  rD  rE  rF  6b9ad766b55dBCDE)	rc   r   r   r   algoOrderTypesaccountsByTypeaccountsByIdexchangeTypebrokerId)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricerP  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingr<  leverageselfTradePreventionmarketBuyByCostmarketBuyRequiresPricemaxZ   i'  )rV  daysBacklimit	untilDayssymbolRequired)rV  r9  r^  rh  )rV  rf  r9  r^  rh  gUUUUUU?)rV  rf  re  daysBackCanceledrg  r9  r^  rh  )rf  rN  rO  )	r   rk   rl   r   r   r   r   r   r   defaultr  )extendsr   rk  )linearinverse)rj  rZ   r\   r]   USDz0.0001)rM   code	precisionEURAEDGBPAUD)rn  rq  rr  rs  rt  AEAETg        )optionsfeatures
currenciescommonCurrenciesrollingWindowSize) 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    T/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/okx.pyr~  zokx.describe+   s(A   c4 0 0 9 9 ; ; l>
%l>
El>
 $l>
 t	l>

 l>
 4l>
 l>
  CCC $C 	C
 $C $C TC "5C 'C tC C )$C $UC  C %dC  '!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 C 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 C 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 C 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 C 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 C 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 Cp -2 $$(#"!%#'  EC C Cl>
X  Yl>
x yl>
z ~0 -8F > #	  0 {l>
^ f(!f (f '	f
 ,Qf )%f 1!f (f 0f A!f 4Rf 5af +Bf /f .qf  -a!f" .u#f$ 6q%f f& /'f( /)f* 7+f, 4Q-f. <Q/f0 /1f2 213f4 -b5f6 ,U7f: /;f< .q=f> -a?f@ 1!AfB ;ECfD ;AEfF 4UGfH .qIf f fJ 6qKfL /MfN -aOfP -aQfR CBSfT &qUfV ,QWfX 0YfZ :2[f\ ,Q]f^ 0_f` 7afb 7cfd 1!eff 3Bgfh 5aifj >rkf f fn ?ofp Eaqfr 21sft ;Aufv 7wfx \]^yfz QRS{f| H}f~ DQf@ A!AfB GCfD HEfF HGfH ?IfL (MfP 'QfR %aSf f fT -aUfV &qWfX 3AYfZ 9![f\ =a]f^ 8_f` .uafb ?cfd ?eff ?gfh ?ifj <Vkfl A&mfn DVofr 3Esfv 4Qwfx :1yf fz :;2345BCCDCD;<1279Kf f fP 9!Qk kZl,al 8l )!	l
 #Bl %bl %al ,Ql %al .ql .ql 6ql &ql  &u!l" /#l$ /%l& 7'l( &u)l l* .q+l, .q-l. +A/l0 4Q1l2 4Q3l4 ;B5l6 5b7l8 >r9l: A";l< 8=l> ;B?l@ 3AAlD +EElF )%GlH 4UIlJ 0KlL /Ml l lN &uOlP .rQlR 21SlT 0UlV 0WlX 3EYlZ 8[l\ 21]l^ 3E_l` 6ualb 0clf .qglh *1ilj ,Qkll 4Qmln 8olp (ql l lr 0slt 8ulv )!wlx +Aylz 1!{l| 0}l~ 7l@ +AAlB ,QClD 3AElF 0GlH 1!IlJ -aKlL 21MlN <QOlP )!QlR 1!Sl l lT >qUlV 4QWlX -aYlZ 9"[l\ =b]l^ DQ_l` 7alb 7cld 8elf 6qglh 8ilj =akll =amln CAolp ;Bqlr 1!slv 0wl l lx 6vylz 4V{l| <Q}l~ 1%l@ DUAlB 8ClD =aElF 22GlJ >qKlL >qMlN >qOlP 5aQlR 4QSlT 3AUlV 4QWlX @YlZ @[l l l\ @]l^ 6q_l` >qalb 7cld :1elf CAglh CAilj CAkll :1mlp 25qlr :5slt 6vulv =fwlx >vyl| @}l~ ;El@ KEAl l lB @ClD ;EElF KEGlH B1IlJ B1KlL MaMlN :1OlP =aQlR A!SlV ;AWlX ;AYlZ 21[l\ =a]l^ ;A_l` Halb Fqcld -ael l lf 4Qglh ;Ailj :1kll ;Amlp 5aqlr :2slt 7ulv 7wlx 6sylz .q{l| )"}l~ 4Rl@ 6rAlB EeClD EaElF HGlH 1#Il lJ 8;1223453412Wl l lZ\(!\ )!\ 0	\
 .r\ ,R\ 8\ (\ )#\ +C\ +C\ 22\ 0\ /\  %a!\" ,Q#\$ +A%\& +A'\ \( 0)\, &u-\. -f/\0 -e1\2 4V3\4 ,U5\6 3G7\8 /9\: .v;\< 5a=\> -b?\@ 0A\B 3BC\D ,QE\F 1"G\H /I\J +AK\ \ \L -aM\N ,QO\R )!S\T +EU\V 5aW\X 25Y\Z 4R[\\ 27]\^ 7_\` .qa\d 8e\f 4Qg\h /i\j :1k\l /m\n -ao\p 4Qq\ \ \r ;Bs\t 1!u\v <Qw\x /y\z 3B{\| 3B}\~ 9"\@ 6qA\B 21C\D 0E\F >qG\H 4QI\J 8K\L ,QM\N -bO\P =aQ\R CAS\ \ \T =aU\V CAW\X 1"Y\Z 0[\\ 6q]\^ 5b_\b 4Rc\d A!e\f =bg\h 22i\j 9"k\l =bm\n 9"o\p <Rq\t 5au\v A!w\x ;Ay\ \ \z :1{\| 9!}\~ =a\@ @A\B :1C\D A!E\F 9!G\H 9!I\J <QK\L :1M\N 7O\P <QQ\R ;AS\T 6qU\V <QW\X ;AY\Z 6q[\ \ \\ =a]\^ :1_\` @a\b ?c\f ;Eg\h ;Ei\j 8k\l 6qm\n 6qo\r <Qs\t :1u\v A!w\x <Qy\z :1{\| A!}\~ 9!\@ B1A\ \ \D 1!E\F 8G\H 6qI\J A!K\L :1M\N :1O\P 8Q\R 9!S\V 6tW\X 6qY\Z 6t[\\ =a]\^ =a_\` 9!a\b <Qc\d :4e\f Eag\ \h NS7<1313:>8=-27<w\ \ \]K K[y y_l>
R !..x88!..x88 
 "..x88!..x88 
 "..x88!..x88 
 "..y99!..y99  Sl>
v " $ $wl>
@ 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. ]/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 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 L 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 L 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 L 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 L 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 L 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 L 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| \}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 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 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 L 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 L 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 L 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 L 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 L 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 L 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 L 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 L 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 L 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 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 LB ('&/&-(0&/-WL L L\ .B$8 ]R RAl>
f  +g l>
l  Ym l>
n eue 'e "" #$ $e  |9|[| #K| 5	|
 U| W| 7| W| 7| W| X| 7| J| 7| h|  n!|" 0#| |$ 0%|& F'|( 5)|*  +|, W-|. )/|0 G1|2 =3|4 <5|6 97|8 H9|: F;|< 6=|@ HA|B :C|D JE|F HG| | |H 9I|J 5K|L FM|N -O|P MQ|T :U|V 9W|X HY|Z 6[|\ 9]|^ F_|` Ga|b Hc|d 8e|f 6g|h :i|j Wk| | |l Fm|n Jo|p Kq|r Fs|t Fu|v Fw|x Wy|z :{|| 
}|@ 8A|B :C|D YE|F ;G|H 8I|J )K|L 8M|N :O| |P ," $ $[| | |eJ $$$! !KeT + """"""""	# 	#-Uel met !:#uez <{e| 4U}e~ AAA!eD !!EeF *5GeH vIeP 6 QeX 4Ye^ "<$_ef A! <( <& !%	  $(#'+# # #  ## "#" "	# 	# ##! !
 #&"'(&"&"(&! ! /Ie e eP  $&*(,$($(%)- -
 -2)-+/ )-(,)-1 1
 &*7 7 $(#'"&#(	( ( #'$(#'$)/3+/27? $  $D r% ',$&!$%**/& & ',#'$(*.	# # ',!$#'$(*/( ( $(&+!$$&,2%)#'$(*/	* 	* "% #!$# #KJ JX  )!4(  "9 "9 	  "9 "9 	 ub bH 335%^b^o^opx^y^y4z4z{{335%^b^o^opx^y^y4z4z{{335%^b^o^opx^y^y4z4z{{335%^b^o^opx^y^y4z4z{{335%^b^o^opx^y^y4z4z{{  e! "%W+l>
 l>
 l>
 l l l	    N
methodNamemarketc                     |                      |d          }|                     |d          }|                      |d          }||||d<   t          t          |                               ||||          S )NinstTypetype)safe_stringomitr}  rJ   handle_market_type_and_params)r  r  r  paramsdefaultValuer  r  r  s          r  r  z!okx.handle_market_type_and_params  sy    ##FJ776:..//Lx3%F6NS$==j&RXZfgggr  c                 h    |                      | j        di           }|                     |||          S )NrK  )	safe_dictrw  r  )r  r  exchangeTypess      r  convert_to_instrument_typezokx.convert_to_instrument_type  s1    t|^RHHtT:::r  symbolc                 0   d}|                     d          }|                     d          }d }|                    d          dk    r|                     |d          }n|                     |d          }|}|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |
          }i d	|dz   |z   dz   |z   dz   |z   dz   |	z   d
|dz   |z   dz   |z   dz   |z   dz   |z   dz   |	z   d|d|d|d|d|d|dddddd dd ddddddddddd|                     d          ||
|	dk    rdnd |                     |          d d d!d d d"d d d"d d d"d#d d$	S )%Nrn  -/r   r      r  rM   r  :basequotesettlebaseIdquoteIdsettleIdactiveFr  r^   rl  rm  rZ   r\   r]   Tr[   r  CcallputamountrQ  minrc  )r  rQ  cost)	contractcontractSizeexpiryexpiryDatetime
optionTypestrikerp  limitsinfo)splitfindr  convert_expire_date	parse8601r  )r  r  r  optionParts
symbolBaser  r  r  r  r  datetime	timestamps               r  create_expired_option_marketz okx.create_expired_option_market  s   ll3''\\#&&
;;sb  ##J22DD##K33D!!+q11!!+q11%%k155
++F3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2&%/3%6%6&&U''//    
   
     U+
 +
 +
 +	
r  marketId	delimiter
marketTypec                    |d uo1|                     d          dk    p|                     d          dk    }|r|| j        vr|                     |          S t          t          |                               ||||          S )Nz-Cr  z-P)r  markets_by_idr  r}  rJ   safe_market)r  r  r  r  r  isOptionr  s         r  r  zokx.safe_market  s    D(hd0C0Cb0H/ghmm\`NaNadfNf 	?X);;;44X>>>S$++HfiTTTr  c                   K   |                      |           d{V }|                     |dg           }t          |          }d|dk    rdnddd|d}t          dt          |                    D ]}||         }|                     |d          }|                     |d          |d	<   |                     |d
          |d<   |dk    rd|d<   ^|dk    rd|d<   j|dk    rd|d<   v|dk    rd|d<   |S )aI  
        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_statuszokx.fetch_status  sJ      33F;;;;;;;;* ~~h33YY
)Qdd]
 
 q#d))$$ 	( 	(AGE$$UG44E --eU;;F5M ,,UF;;F5M	!!#0x  +%%#'x  +%%#'x  *$$#'x r  c                    K   |                      |           d{V }|                     |dg           }|                     |di           }|                     |d          S )aa  
        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_timezokx.fetch_time   so       11&99999999 ~~h33tQ++  ---r  c           	      P  K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]Q}||         }|                     |d          }|                     |d          }|                    ||d|dd           R|S )az  
        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)rM   r  currencyr  ro  )privateGetAccountConfigr  r  r  r  append)	r  r  r  r  resultr  account	accountIdr  s	            r  fetch_accountszokx.fetch_accounts7  s       55f========N ~~h33q#d))$$ 
	 
	A1gG((%88I##GX66DMM       r  c                 F    |                                  | j        d         z
  S )Nr/  )millisecondsrw  )r  s    r  noncez	okx.noncev  s!      ""T\2B%CCCr  c                 H  K   | j         d         r|                                  d{V  g d}|                     | j         d          }||                     |d|          }n|                     | j         d|          }g }g }t	          dt          |                    D ]1}|                    |                     ||         |                     2t          j	        |  d{V }t	          dt          |                    D ]}| 
                    |||                   }|S )a!  
        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
        r0  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_marketszokx.fetch_marketsy  sC      <12 	.++---------444!^^DL.II)NN#5wFFEENN4<GGEq#e**%% 	J 	JAOOD66uQxHHIIII 2222222q#h--(( 	< 	<A&&vx{;;FFr  c                    |                      |d          }|                     |d          }|dk    rd}|dk    }|dk    }|dk    }|dk    }|p|p|}|                      |dd	          }	|                      |d
d	          }
|                      |d          }|                     |          }|                      |d          }|C|sA|                    d          }|                      |d          }	|                      |d          }
|	d	k    s|
d	k    rZ|rX|                      |dd	          }|                    d          }|                      |d          }	|                      |d          }
|                     |	          }|                     |
          }|dz   |z   }|d	k    s|d	k    r|}d }d }d }|r||dz   |z   }|r6|                     |d          }||                     |          }|dz   |z   }ny|rw|                     |d          }|                      |d          }|                      |d          }|3|                     |          }|dz   |z   dz   |z   dz   |z   }|dk    rdnd}|                     | j        |di           }|                      |dd          }t          j	        |d          }| 
                    |d          }|                      |d          }|                     |d          }|                     |i d|d|d|d |d!|d"|d#|	d$|
d%|d&|d|d'|ot          j        |d          d|d|d|d(|d)k    d*||r|
|k    nd |r|	|k    nd |r| 
                    |d+          nd ||                     |          |                     |          ||                     |d,d-          | 
                    |d.          | 
                    |d/          d0|                     d          |                     |          d1| 
                    |d2          d d1d d d1d |rd n|d1d3|d4          S )5NinstIdr  rA  r]   rZ   r\   r^   baseCcy quoteCcy	settleCcyulyr  r   r   r  r  expTimestkoptTypePr  r  r  leverr  maxMktSzr  
instIdCoderM   r  r  r  r  r  r  r  r  r[   r  liver  ctValcontTdSwTimelistTimelotSztickSzr  r  minSz)r_  r  rQ  r  )rl  rm  r  r  r  r  r  createdrp  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  rM   r  rZ   r]   r\   r^   r  r  r  r  r  
underlyingpartsr  r  r  r  r  strikePricer  ymdr   maxLeveragemaxSpotCostr  r  s                               r  parse_marketzokx.parse_market  s   r fh//%%fj999D("("+6+V!!&)R88""6:r::##FK88((22%%fe44
"D"$$S))E%%eQ//F&&ua00Gr\\w"}}4}%%fh;;FLL%%E%%eQ//F&&ua00G&&v..''00e#2::"F
 	J!#. J**69==%++f--C#c\C/F J**69=="..vu==!--fi@@
%++f--C#c\C/#5CcIJVF+5+<+<6J	4B??&&vw<<(c::&&vz::!!&'22&&v|<<
{{4 1"
"1"
*1"
 f1"
 D	1"

 U1"
 f1"
 f1"
 w1"
 1"
 D1"
 D1"
 dD 1+s C C1"
 D1"
 f1"
 f1"
  f&!1"
" #1"
$ 08Aw(**T/7A(**TAISD,,VW===t"ll622''44$**6>:NN**67;;))&(;;   ,,S11,,[99 
  ++FG<< 
   
  #+<44  $ a1"
 1"
 1"
 1 1 1	r  c           	        K   d|                      |          i}|dk    r|                     | j        dddg          }g }t          dt	          |                    D ]K}||         }||d<   |                    |                     |                     ||                               Lt          j	        |  d {V }g }	t          dt	          |                    D ]F}| 
                    ||i           }
|                     |
dg           }|                     |	|          }	G|                     |	          S |                     |                     ||                     d {V }|                     |dg           }g }t          dt	          |                    D ]S}||         }| j        r-|                     |d	d
          }|                    d          r>|                    |           T|                     |          S )Nr  r^   defaultUnderlyingBTC-USDzETH-USDr   r  r  
instFamilyr  TEST)r  r  rw  r  r  r  publicGetPublicInstrumentsr  r  r  r  r  parse_marketsisSandboxModeEnabledr  
startswith)r  r  r  requestoptionsUnderlyingr  r  r  promisesResultmarketsresrw  r  dataResponsemarketsWithoutTestr  r  s                    r  r  zokx.fetch_markets_by_type5  s6     77==
 8 $t|=PS\^gRh i iH1c"34455 _ _.q1
!+ ? ?GU[@\@\ ] ]^^^^#*>8#<<<<<<<NG1c.1122 > >nn^Q;;..fb99++GW==%%g...88Wf9U9UVVVVVVVVD ~~h;;q#l++,, 	, 	,A?D( !--dL"EE
((00 %%d++++!!"4555r  c                 l  K   |                      | j        dd          }|                     d          r|ri S |                     |           d{V }|                     |dg           }|                     |d          }t          |                                          }|                     |          S )a  
        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  ccy)		safe_boolrw  check_required_credentialsprivateGetAssetCurrenciesr  group_bylistvaluesparse_currencies)r  r  isSandboxModer  r  dataByCurrencyIdry  s          r  fetch_currencieszokx.fetch_currenciest  s       t|]EJJ..u55 	 	I 77????????X ~~h33==u55*113344
$$Z000r  r  c                    |}|                      |di           }|                     |d          }|                     |          }i }d}t          |          }t	          d|          D ]2}	||	         }
|                     |
dd          }|dk    rd}|                    d          }|                     |d          }d                    |          }|                     ||          }||d | 	                    |
d	          | 	                    |
d
          | 
                    |
d          |                     |                     |                     |
d                              d| 
                    |
d          | 
                    |
d          di|
d	||<   4|                     ||||                     |d          d d d d d dd d di||d          S )Nr   r-  cryptochainr  fiatr  r   canDepcanWdfeewdTickSzr   minWdmaxWdr  )	rM   networkr  depositr   r>  rp  r  r  rN   r  )r  ro  rM   rN   r  rC  r   r>  rp  r  r  r  )r  r  r  r  r  r  array_slicejoinnetwork_id_to_coder.  r  r  parse_precisionr  )r  r  chains
firstChain
currencyIdro  r  r  chainsLengthjr:  	networkIdidPartsr  	chainPartnetworkCodes                   r  parse_currencyzokx.parse_currency  s   ^^FAr22
%%j%88
&&z226{{q,'' 	 	A1IE((<<IBooc**G$$Wa00EI11)TBBK&>>%:: NN5'::''u55!..t/C/CDDTDTUZ\fDgDg/h/hii#//w??#//w??! ! % %H[!!  ++$$Z88   #-
 -
   	r  rf  c                 p  K   |                                   d{V  |                     |          }d|d         i}d}|                     |ddd          \  }}|dk    r|d}|d	n|}|||d
<   d}|dk    s|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     |di           }	|                     |	d          }
| 	                    |	||
          S )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  rM   r   r)  publicGetMarketBookspublicGetMarketBooksFulli  r  szi  r  r   r  )
load_marketsr  handle_option_and_paramsrT  r  rS  r  r  r  parse_order_book)r  r  rf  r  r  r%  r)  r  r  r  r  s              r  fetch_order_bookzokx.fetch_order_book  s      !!!!!!!!!V$$fTl
 66v?OQY[qrr///EMEE!GDM000eckk!::4;;wPV;W;WXXXXXXXXHH!66t{{7F7S7STTTTTTTTH, ~~h33tQ++%%eT22	$$UFI>>>r  tickerc           
         |                      |d          }|                     |d          }|                     ||d          }|d         }|                     |d          }|                     |d          }|                     |dd          }|r|                     |d	          nd }	|                     |d
          }
|                     |d          }|                     |d          }|                     i d|d|d|                     |          d|d|d|                     |d          d|                     |d          d|                     |d          d|                     |d          dd d|d|d|dd dd dd dd |
|	|                     |d           |                     |d!          |d"|          S )#Nr  r  r  r  rM  open24hrZ   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  rZ  r  r  r  r  rM  rl  rZ   ru  rt  ra  rb  s                r  parse_tickerzokx.parse_ticker)  sc   L %%fd33	##FH55!!(FC88!//	22~~ffe44?CMd&&v{;;;%%fh77
	22vx00 !
f!
!
 Y//!
 D	!

 3!
 4##FG44!
 ))&'::!
 4##FG44!
 ))&'::!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&))&(;;**67;;-!
 !
 !
. /  	r  c                 ^  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )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  rM   r  r   )rV  r  publicGetMarketTickerr  r  r  ry  r  r  r  r  r%  r  r  r  s           r  fetch_tickerzokx.fetch_tickers  s       !!!!!!!!!V$$fTl
 33DKK4P4PQQQQQQQQ6 ~~h33tQ++  ///r  symbolsc                 \  K   |                                   d{V  |                     |          }|                     |          }d}|                     d||          \  }}d|                     |          i}|dk    rR|                     | j        dd          }|                     |dd|          }|t          | j	        d	z             ||d<   | 
                    |                     ||                     d{V }|                     |d
g           }	|                     |	|          S )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  )rV  market_symbolsget_market_from_symbolsr  r  r  rw  safe_string_2r3   rM   publicGetMarketTickersr  r  parse_tickers
r  r~  r  r  r  r%  r  rJ  r  tickerss
             r  fetch_tickerszokx.fetch_tickers  sf      !!!!!!!!!%%g..--g66
!??PVX^__
F77
CC
 !! $ 0 0?RT] ^ ^++FE:GXYYJ!'  3I  )I  J  J  J!+44T[[&5Q5QRRRRRRRR6 ..6266!!'7333r  c                 V  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     |                     |d          |          S )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  rM   r  r   )rV  r  publicGetPublicMarkPricer  r  ry  r  )r  r  r  r  r%  r  r  s          r  fetch_mark_pricezokx.fetch_mark_price  s       !!!!!!!!!V$$fTl
 66t{{7F7S7STTTTTTTT ~~h//  a!8!8&AAAr  c                 ^  K   |                                   d{V  |                     |          }|                     |          }d}|                     d||d          \  }}d|                     |          i}|dk    rR|                     | j        dd          }|                     |dd	|          }|t          | j	        d
z             ||d<   | 
                    |                     ||                     d{V }|                     |dg           }	|                     |	|          S )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  )rV  r  r  r  r  r  rw  r  r3   rM   r  r  r  r  r  s
             r  fetch_mark_priceszokx.fetch_mark_prices  sg      !!!!!!!!!%%g..--g66
!??PVX^`fgg
F77
CC
 !! $ 0 0?RT] ^ ^++FE:GXYYJ!'  3L  )L  M  M  M!+66t{{7F7S7STTTTTTTT..6266!!'7333r  tradec                    |                      |d          }|                      |d          }|                     ||d          }|d         }|                     |d          }|                     |dd          }|                     |dd	          }|                      |d
          }	|                      |d          }
|                      |d          }d }|Dt	          j        |          }|                      |d          }|                     |          }||d}|                      |d          }|dk    rd}n|dk    rd}|                     |||                     |          |||
d ||	||d |d|          S )NtradeIdr  r  r  r  fillPxpxfillSzrU  sideordIdr>  feeCcyr  r  execTypeTr  Mr  )r  r  r  r  rM   orderr  takerOrMakerr  rQ  r  r  r>  )	r  r  r  r  rH   
string_negr  
safe_trader  )r  r  r  rM   r  r  r  rQ  r  r  orderIdfeeCostStringr>  feeCostSignedfeeCurrencyIdfeeCurrencyCoder  s                    r  parse_tradezokx.parse_trade	  s   d eY//##E844!!(FC88!%%eT22	""5(D99##E8T::v..""5'22((66$#.}==M ,,UH==M"55mDDO%+ C ''z::3"LLS  "L"Y//( 
  
   	r  sincec                   K   |                                   d{V  d}|                     |dd          \  }}|r#|                     d||||dddd	  	         d{V S |                     |          }d|d	         i}d}|d
         r0|                     |                     ||                     d{V }n|||d<   d}	|                     |ddd          \  }	}|	dk    r0|                     |                     ||                     d{V }n5|	dk    r/|                     |                     ||                     d{V }|                     |dg           }
| 	                    |
|||          S )a  
        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  rM   r^   rf  r)  publicGetMarketTradespublicGetMarketHistoryTradesr  )
rV  rW  fetch_paginated_call_cursorr  publicGetPublicOptionTradesr  r  r  r  parse_trades)r  r  r  rf  r  r  r  r%  r  r)  r  s              r  fetch_tradeszokx.fetch_tradesp	  s      !!!!!!!!!88PZ[[& 	F99-QVX]_egpry{  BE  F  F  F  F  F  F  F  F  FV$$fTl
 ( 
	a!==dkk'SY>Z>Z[[[[[[[[HH #( F!::6=RZ\sttNFF000!%!;!;DKKQW<X<X!Y!YYYYYYY999!%!B!B4;;wX^C_C_!`!```````F ~~h33  vue<<<r  c           	      T   |                      d|d           }|d         }|dk    rdnd}|                     |d          |                     |d          |                     |d          |                     |d          |                     |d	          |                     ||          gS )
Nr   r   rZ   r	     r   r   r  r  )r  r  r  )r  ohlcvr  r)  r  volumeIndexs         r  parse_ohlcvzokx.parse_ohlcv	  s     00vtLL1v FNNaaeQ''UA&&UA&&UA&&UA&&UK00
 	
r  r   	timeframec           	        K   |                                   d{V  |                     |          }d}|                     |dd          \  }}|r!|                     d|||||d           d{V S |                     |d          }|                     |ddg          }	|                     |d          }|                     | j        di           }
|                     |
d	d
          }|du }|d}n|	rdnd}t          ||          }| 
                    |          }|                     | j        ||          }|d
k    r|dk    r||                                z  }|d         ||d}d}|s|                                 }|dz  }|d|z  z
  }||k     rd}|	rdnd}t          ||          }t          |dz
  d          }||d<   |                     |||z            |d<   |                     |d          }|||d<   |                     |d          }|                     |
d|          }|                     |d|          }|                     |d          }|dk    }d}|dk    rc|r1|                     |                     ||                     d{V }n|                     |                     ||                     d{V }n|dk    rs|d         d         |d<   |r0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }np|r?|r|dk    rd}d|d<   |                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     |||||          S )a  
        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     rQ  rN  rO  r'  r(  r  r  i`T  rM   )r  barrf  Candles  i  HistoryCandlesr   r   beforer  untilr  r  r  r  rf  r  )rV  r  rW  "fetch_paginated_call_deterministicr  in_arrayr  r  rw  r  parse_timeframer   lowerr  rc  sumr  &publicGetMarketHistoryMarkPriceCandlesr  publicGetMarketMarkPriceCandles"publicGetMarketHistoryIndexCandlespublicGetMarketIndexCandlespublicGetMarketHistoryCandlespublicGetMarketCandlesr  parse_ohlcvs)r  r  r  r  rf  r  r  r  	priceTypeisMarkOrIndexrw  r'  limitIsUndefinedmaxLimitdurationr  r%  r1  nowdurationInMillisecondshistoryBorder	startTimer  r  isHistoryCandlesr  r  s                              r  fetch_ohlcvzokx.fetch_ohlcv	  s     . !!!!!!!!!V$$88zZZ& 	}@@vW\^cenpvx{|||||||||$$VW55	i&'1BCC67++..|R@@##GZ??!TM=EE+4ssHx((E''	22t	9EEH$5$58>>###CTl
 

  ##%%C%-_"H0F#FGM}$$."/833SE8,,EAIq))I )GH#xx/E/MNNGG!!&'22$GGYYvw//F&&wDD<<66** $44 d!%!L!LT[[Y`bhMiMi!j!jjjjjjj!%!E!EdkkRY[aFbFb!c!ccccccc'!! &v| <GH `!%!H!HU\^dIeIe!f!fffffff!%!A!A$++gW]B^B^!_!_______ [# +#E'*GG$!%!C!CDKKPWY_D`D`!a!aaaaaaa!%!<!<T[[RX=Y=Y!Z!ZZZZZZZ ~~h33  vy%GGGr  c           
        K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r!|                     d|||d|d           d{V S |                     |          }d|d	         i}|t          |d
z
  d          |d<   |||d<   |                     |                     ||                     d{V }g }	| 	                    |dg           }
t          dt          |
                    D ]}|
|         }|                     |d          }|	                    ||                     |                     |d                    |                     |d          ||                     |          d           |                     |	d          }|                     ||d         ||          S )a  
        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  rM   r   r   r  rf  r  fundingTimerealizedRate)r  r  fundingRater  r  r  r  )r3   rM   rV  rW  r  r  rc  !publicGetPublicFundingRateHistoryr  r  r  r  r  r  safe_symbolr  r  r  sort_byfilter_by_symbol_since_limit)r  r  r  rf  r  r  r  r%  r  ratesr  r  rater  sorteds                  r  fetch_funding_rate_historyzokx.fetch_funding_rate_history;
  sL      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	E@@AZ\bdikprvx~  AD  E  E  E  E  E  E  E  E  EV$$fTl
  #EAIq 1 1GH$GG??GU[@\@\]]]]]]]]. ~~h33q#d))$$ 		 		A7D))$>>ILL**4+;+;D(+K+KLL#//nEE& LL33      e[11009I5RWXXXr  c                 b    |dk    r|                      |          S |                     |          S )Nr@  )parse_funding_balanceparse_trading_balance)r  r  r  s      r  parse_balance_by_typezokx.parse_balance_by_type}
  s5    9--h777--h777r  c                    d|i}|                      |dg           }|                     |di           }|                     |d          }|                      |dg           }t          dt	          |                    D ]}||         }|                     |d          }	|                     |	          }
|                                 }|                     |d          }|                     |d          }||d	<   |3|                     |d
          |d<   |                     |d          |d<   n||d<   |||
<   ||d<   |                     |          |d<   | 	                    |          S )Nr  r  r   uTimedetailsr-  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  balancerJ  ro  r  r  r  s                 r  r  zokx.parse_trading_balance
  sr   )~~h33tQ++%%eW55	..	266q#g,,'' 	# 	#AajG))'599J**:66DllnnG!!'400B&&w	::G!GG"&"2"27J"G"G"&"2"27K"H"H")"F4LL'{!\\)44z  (((r  c                    d|i}|                      |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d	          |d
<   |||<   |                     |          S )Nr  r  r   r-  balr  r  r  r  r  )r  r  r  r  r  r  r  )	r  r  r  r  r  r  rJ  ro  r  s	            r  r  zokx.parse_funding_balance
  s    )~~h33q#d))$$ 		# 		#A1gG))'599J**:66DllnnG#//??GG"..w
CCGFO"..wDDGFO"F4LL  (((r  r>  c                 $   ||                      d |          |                     t          j        |                     |dd                              |                     t          j        |                     |dd                              d d dS )Nr  makerUr  takerU)r  r  r  r  rp  	tierBased)r  r  rH   r  r  )r  r>  r  s      r  parse_trading_feezokx.parse_trading_fee
  s     &&tV44&&w'9$:L:LSRY[c:d:d'e'eff&&w'9$:L:LSRY[c:d:d'e'eff
 
 	
r  c                 :  K   |                                   d{V  |                     |          }d|                     |d                   i}|d         r|d         |d<   nG|d         s|d         s|d	         r|d
         dz   |d         z   |d<   nt          | j        dz             |                     |                     ||                     d{V }|                     |dg           }|                     |di           }| 	                    ||          S )a_  
        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  rZ   rM   r  r\   r]   r^   r  r  r  r  zE fetchTradingFee() supports spot, swap, future or option markets onlyr  r   )
rV  r  r  r>   rM   privateGetAccountTradeFeer  r  r  r  r|  s           r  fetch_trading_feezokx.fetch_trading_fee
  sL      !!!!!!!!!V$$77vGG
 &> 	r &tGHF^ 	rvh/ 	r6(3C 	r#H-3fY6GGGENNtw)ppqqq77GV8T8TUUUUUUUU& ~~h33tQ++%%eV444r  c                 l  K   |                                   d{V  |                     dd|          \  }}i }d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||          S )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>`
        Nrz   r@  )rV  r  privateGetAssetBalancesr  privateGetAccountBalancer  )r  r  r  queryr%  r  s         r  fetch_balancezokx.fetch_balance
  s       !!!!!!!!! >>~tU[\\
E
 ""!99$++gu:U:UVVVVVVVVHH!::4;;wPU;V;VWWWWWWWWHN ))*h???r  r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             ddd}|                     |dd|d|                     ||                     d{V S )	  
        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>`
        NrZ   z: createMarketBuyOrderWithCost() supports spot markets onlyF	quote_ccyr,  tgtCcyr  buyrV  r  r>   rM   create_orderr  r  r  r  r  r  reqs         r  !create_market_buy_order_with_costz%okx.create_market_buy_order_with_costo  s       !!!!!!!!!V$$f~ 	gtw)eefff16!
 
 &&vxdDKKX[]cLdLdeeeeeeeeer  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             ddd}|                     |dd|d|                     ||                     d{V S )	r  NrZ   z; createMarketSellOrderWithCost() supports spot markets onlyFr   r  r  sellr  r  s         r  "create_market_sell_order_with_costz&okx.create_market_sell_order_with_cost  s       !!!!!!!!!V$$f~ 	htw)ffggg16!
 
 &&vxtT[[Y\^dMeMefffffffffr  r  r  r  rQ  c                    |                      |          }|                     |dd          }|                     |dd          }	|	d up	|d up|dk    }
|d         ||d}|
p|dk    }|                     |d	          }|o|d u}|s|                     ||          |d
<   |d         }|d         }|                     |g d          }|                     |dd          }|                     |d|          }|                     |dd          }|                     |d|          }|                     |dd          }|                     |dd          }|                     |d          }|                     |d          }|d u}|d u}|                     |dd          }|d u}|                     |dd          }|d u}|d up|dk    } |                     |dd          p|d u}!|                     | j        d d!d"          }"|                     |d!d#          }#d}$|#	|#d$k    rd%}$n|"}#|                     |d&d          }$|rS|$rE|d'k    r|d(         n|d)         }%|                     |d*|%          }&| 	                    |&          |d*<   |$r|#nd$}'|'|d#<   n|r|d+         s|d,         rd }(| 
                    |d-d.          \  }(}|(|(|d/<   n[d })| 
                    |d-d0          \  })}|)r=|d'k    }*|d up|	d up|!}+|+r"|*rd1nd2|d/<   |!r|                     |d          }n	|*rd2nd1|d/<   |#|d#<   |d3k    },d}-|                     |,|d4k    |          \  }-}|                     |g d5          }|d6k    p|d7k    }.|d8k    p|d9k    }/|,r|.p|d:k    }0|                     | j        d;d<          }1|                     |d;|1          }2|s|$s|2|d;<   |,s|0rd3|d=<   |r|d'k    r|2d>k    rd%}3| 
                    |d-d?d%          \  }3}|                     |d@d
          }4|                     |d@d
g          }|3rs|W|4T|                     |          }5|                     |          }6t          j        |5|6          }7|                     |7          }4n |4t%          | j        dAz             n|4|n|4}4|                     ||4          |d
<   |0r|rd:|d=<   n| s|
s|                     ||          |dB<   |-rd4|d=<   n|.r|0sd7|d=<   n|/rd9|d=<   |r!t          j        |dC          }8|8|d<   dD|d=<   n*|r||d<   dD|d=<   n|s|ri }9|re|                     |g dE          }:|:t%          | j        dFz             |                     ||:          };i }<|;|<d<   |                     |g dG          }=|                     |dH          }>|>h|>dIk    }?|>d3k    }@|?s|@st%          | j        dJz             |?r3|=t%          | j        dKz             |                     ||=          |<d<   n-|>d3k    rdL|<d<   n!|=|                     ||=          |<d<   ndL|<d<   |                     |dMdd          }A|A.|Adk    r#|AdNk    r|AdOk    rt%          | j        dPz             |A|<d<   |                     |9|<          }9|rn|                     |g dQ          }B|Bt%          | j        dRz             i }C|                     ||B          |Cd<   |                     |g dS          }D|                     |dHdT          }E|Em|EdIk    }F|Ed3k    }G|Fs|Gst%          | j        dUz             |Fr8|Dt%          | j        dVz             |E|CdT<   |                     ||D          |Cd<   n2|Ed3k    rdL|Cd<   n&|DdI|CdT<   |                     ||D          |Cd<   ndL|Cd<   |                     |dMdd          }H|H.|Hdk    r#|HdNk    r|HdOk    rt%          | j        dWz             |H|Cd<   |                     |9|C          }9t1          |9                                          }It5          |I          }J|JdXk    r|9g|dY<   | r<d|d=<   |                     ||          |dZ<   |,rdLn|                     ||          |d[<   n|
rd|d=<   |d uo|	d u}K|Krd|d=<   |d\k    r|                     |d;          }|                     |d#          d$k    r|#|d#<   |=|                     ||          |d<   dL}L||                     ||          }L|L|d<   ||d<   |	=|                     ||	          |d<   dL}M||                     ||          }M|M|d<   ||d<   |=|                     | j        d]          }N|N|N|                                 z   |d<   |N|d^<   n||d<   |                     |ddg          }|                     ||          S )_NrZ  tpTriggerPxrY  slTriggerPxr8  rM   )r  r  ordTyper:  closeFractionrU  rZ   r  )rW  	stopPrice	triggerPxr\  GTCtpOrdPxtpTriggerPxTyperM  slOrdPxslTriggerPxTypeclOrdIdclientOrderIdstopLoss
takeProfittrailingPercentcallbackRatiotrailingPricecallbackSpreadr9  
reduceOnlyFdefaultMarginModerV  crosstdModecashTr[   r  r  r  r-  r\   r]   rk   positionSideposSider]  shortlongr  	post_only)r  r-  rV  r\  r  rW  r  rY  rZ  r  r  r[   r  r  r  rR  iocrS  fokoptimal_limit_iocr  base_ccyr  r   r,  r  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  100r;  )rW  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)rQ  rY  r  r  rf  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-1rP  rO  rN  zT createOrder() stop loss trigger price type must be one of "last", "index" or "mark")rW  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)rQ  rZ  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  orderPxr
  rL  tag)r  safe_value_2r  amount_to_precisionsafe_value_n
safe_valuer  rw  r.  r  rW  r  handle_post_onlysafe_number_2number_to_stringrH   
string_mulr  r;   rM   cost_to_precisionprice_to_precision
string_divr  r2  keysr  uuid16)Or  r  r  r  r  rQ  r  r  rZ  rY  r8  r%  isConditionalOrOCOr  shouldOmitSizerZ   r  rW  r\  r  r  r  r  r  r  r  hasStopLosshasTakeProfitr  isTrailingPercentOrderr  isTrailingPriceOrderr9  isReduceOnlyr!  rV  r[   defaultCurrencyr  	tradeModer%  r]  isBuyisProtectiveisMarketOrderpostOnlyr*  r+  	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
slOrdPxReqrL  sO                                                                                  r  create_order_requestzokx.create_order_request  s   V$$++F4E}UU))&/=QQ$D0moT6QmW[_lWlTl 
 
4 );TU]((AA+IT0I 	E 44VVDDGDMf~*%((1[1[1[\\&&v}eDD//&)U;;**63DfMM//&)U;;**63DfMM**69oNN??6:66__V\::
t+#4/,,V5FXX!0!<**6?DTUU,D8t+C1Bv|UCCb]aHa ..t|=PR^`ghh''hGG
"v)=)=FF*J^^FHe<<F 	+ C6:emm&//&QW.++FE?KK!%!8!8!B!B&,8

&I )GH 	+f~ N!1 N#'+'D'DV]\j'k'k$f+)5GI&&!F%)%B%B6=Zb%c%cNFF 
N!%(7t(C's^bIb'sgs' N =B1MvGI.+ I)-6<)H)H;@1MgGI. *GH(00@SU[\\&6  $s  $s  $s  t  te#7e#7"*sL8K0K	((xLL!!&(MBB 	'6 	' &GH 	GI 	G!)GI M [((8<5@D@]@]^dfs  vY  [_  A`  A`=5v#11&&$GGH!YYv~>>F8 
N ,'//3/D/DV/L/L.2.C.CE.J.J.5.@{.[.[+/+<+<[+I+I%-".tw  :z  0z  #{  #{  { . /7.>66X$($:$:68$L$LGDM 9X 9%8	" Gk G $ 7 7 F F 	'!,GI 	' 	'!&GI 	'!&GI! K	<'.'9/5'Q'Q$'?GO$!2GI! G	<(5G$%!2GI D	<M D	<M D'+'8'8CoCoCo'p'p$'/&tw  2a  (a  b  b  b"55f>RSS)4&%)%6%6xAfAfAf%g%g"$($4$4Xv$F$F!$0.?7.J*/@H/L+2 2=T 2*47  6D  ,D  E  E  E/ 2-5".tw  :}  0}  #~  #~  ~151H1HQc1d1dGI..*h66-1	*'3)-)@)@I[)\)\GI&&)-GI&+/+=+=hHZ\mou+v+v(+70F::AY]dAdAd  lD  HN  lN  lN*47  6L  ,L  M  M  M1IG-. $M7 C C D)-):)::GsGsGs)t)t&)1&tw  2i  (i  j  j  j)-)@)@I_)`)`&'+'8'8ElElEl'm'm$&*&8&8V[&Y&Y#&20Cw0N,1D1P-4 	2?X 	2*47  6F  ,F  G  G  G1 2/7".tw  :C  0C  #D  #D  D3FGK0151H1HQe1f1fGI..,88-1	*)5+2GK()-)@)@I])^)^GI&&)-GI&-1-?-?
L^`qsy-z-z*-92f<<C]ahChCh  pJ  NT  pT  pT*47  6N  ,N  O  O  O1KG-. $M7 C C !3!3!5!566M}--La-:O() 	=!*GI#'#:#:6<#P#PGK )6!bD<S<STZ\a<b<bGI 	=!.GI /t ;\-W[B[O  +%*	"v~~))GX6622f<< %/!*)-)@)@)Y)Y&!
&!%!8!8!I!IJ%/	"-<)*()-)@)@)W)W&!
&!%!8!8!I!IJ%/	"-<)* ''jAAH#%-%=	"!)!.GIYYv	?'CDDF{{7F+++r  c                   K   |                                   d{V  |                     |          }|                     ||||||          }|                     | j        dd          }	|                     |d          }
|
dk    s$|
dk    s|
dk    s|dk    s|dk    s|d	k    s|d
k    rd}	|	dk    r#|	dk    r|	dk    rt          | j        dz             |	dk    r|g}d}|	dk    r|                     |           d{V }n=|	dk    r|                     |           d{V }n| 	                    |           d{V }| 
                    |dg           }|                     |di           }|                     ||          }||d<   ||d<   |S )a
  
        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>`
        Nrk   r+  r  r9  r8  r;  r:  r<  r=  privatePostTradeOrderAlgoprivatePostTradeOrderz createOrder() self.options["createOrder"] must be either privatePostTradeBatchOrders or privatePostTradeOrder or privatePostTradeOrderAlgor  r   r  r  )rV  r  ri  r  rw  r.   rM   rl  rk  r+  r  r  parse_order)r  r  r  r  r  rQ  r  r  r%  r)  requestOrdTyper  r  r  r  s                  r  r  zokx.create_order  sj     > !!!!!!!!!V$$++FD$vVV!!$,?\]]))'9==i''^}-L-LR`duRuRu{  DU  |U  |U  [_  ch  [h  [h  nr  v  n  n  EI  MS  ES  ES0F---F>Y4Y4Y`f  kH  aH  aH  +x  !x  y  y  y222 iG,,,!77@@@@@@@@HH222!;;GDDDDDDDDHH!==gFFFFFFFFH~~h33tQ++  //ffr  ordersc           	        K   |                                   d{V  g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |di           }|                     ||          }|                     ||||	|
|          }|                    |           | 	                    |           d{V }| 
                    |d	g           }|                     |          S )
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  rQ  r  r  )rV  r  r  r  r7  r  r  ri  r  r+  r  parse_orders)r  ro  r  ordersRequestsr  rawOrderr  r  r  r  rQ  orderParamsextendedParamsorderRequestr  r  s                   r  create_orderszokx.create_orders  sl      !!!!!!!!!q#f++&& 
	0 
	0AayH''(;;H##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K![[f==N44XtT6SXZhiiL!!,////99.IIIIIIII. ~~h33  &&&r  rM   c                    |                      |          }d|d         i}	d }
|dk    s|dk    s|dk    s|dk    s|dk    s|dk    rd	}
|                     |d
d          }||
r||	d<   n||	d
<   n|
r||	d<   n||	d<   |                     |dd          }|                     |d          }|                     |dd          }|                     |dd          }|                     |d          }|                     |dd          }|                     |d          }|                     |d          }|d u}|d u}|
r||t          | j        dz             |X|t          | j        dz             |                     ||          |	d<   |dk    rdn|                     ||          |	d<   ||	d<   |X|t          | j        dz             |                     ||          |	d<   |dk    rdn|                     ||          |	d<   ||	d<   n|?|                     ||          |	d<   |dk    rdn|                     ||          |	d<   ||	d<   |?|                     ||          |	d<   |dk    rdn|                     ||          |	d<   ||	d<   |r|                     |d          }|                     |d           }|                     |d!          }|                     ||          |	d<   |dk    rdn|                     ||          |	d<   ||	d<   |r|                     |d          }|                     |d           }|                     |d!          }|d"k    r|nd#|	d$<   |                     ||          |	d<   |dk    rdn|                     ||          |	d<   ||	d<   ||                     ||          |	d%<   |
s||                     ||          |	d&<   | 	                    |g d'          }| 
                    |	|          S )(Nr  rM   r9  r8  r;  r:  r<  r=  Tr  r  algoClOrdIdalgoIdr  rY  newSlTriggerPx
newSlOrdPxnewSlTriggerPxTyperM  rZ  newTpTriggerPx
newTpOrdPxnewTpTriggerPxTyper  r  z\ editOrder() requires a stopLossPrice or takeProfitPrice parameter for editing an algo orderzF editOrder() requires a newSlOrdPx parameter for editing an algo orderr  r/  zF editOrder() requires a newTpOrdPx parameter for editing an algo orderrW  rQ  r  rf  	conditionnewTpOrdKindnewSznewPx)r  r  rZ  rY  r  r  rM  )r  r  r4  r7  r  r4   rM   r=  r5  r  r  )r  rM   r  r  r  r  rQ  r  r  r%  isAlgoOrderr  rV  rY  r\  r]  rZ  rc  r  r  rC  rD  stopLossTypetakeProfitTypes                           r  edit_order_requestzokx.edit_order_request  s\   V$$fTl
 I4=#8#8dFW>W>W]aej]j]jpt  yB  qB  qB  HL  PV  HV  HVK**69oNN$ 3)6&&%2	"" &$&!!#% #00JZ[[==#'#3#3F<PRX#Y#Y !%!2!26;LN^!_!_//&,??%)%5%5f>RTZ%[%["??6:66__V\::
t+#4/ &	K$,3I3Q   ,J  "J  K  K  K#/ ($TW/w%wxxx,0,C,CFL`,a,a()151A1AH_H_`fhuHvHv%0H,-%1"*$TW/w%wxxx,0,C,CFLb,c,c()151A1AH_H_`fhwHxHx%0J,-#/,0,C,CFL`,a,a()151A1AH_H_`fhuHvHv%0H,-%1,0,C,CFLb,c,c()151A1AH_H_`fhwHxHx%0J,- I'+x'P'P$ $' B B#//&AA,0,C,CFL`,a,a()1=1I1IPTPgPghnp}P~P~%0H,- K)-^)T)T&"&//*g"F"F!%!1!1*f!E!E=Kw=V=V..]h',0,C,CFLb,c,c()1?81K1KRVRiRijp  sB  SC  SC%0J,-#77GGGG 	J #'#:#:65#I#I 6  $J  $J  $J  K  K{{7F+++r  c           	      P  K   |                                   d{V  |                     |          }|                     |||||||          }	d}
|dk    s|dk    s|dk    s|dk    s|dk    s|dk    rd}
d}|
r0|                     |                     |	|                     d{V }n/|                     |                     |	|                     d{V }|                     |d	g           }|                     |d
i           }|                     ||          }||d<   ||d<   |S )a
  
        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>`
        Nr9  r8  r;  r:  r<  r=  Tr  r   r  r  )	rV  r  r  privatePostTradeAmendAlgosr  privatePostTradeAmendOrderr  r  rm  )r  rM   r  r  r  r  rQ  r  r  r%  r  r  r  r  r  s                  r  
edit_orderzokx.edit_orderS  s     @ !!!!!!!!!V$$))"fdD&%QWXXI4=#8#8dFW>W>W]aej]j]jpt  yB  qB  qB  HL  PV  HV  HVK 	[!<<T[[RX=Y=YZZZZZZZZHH!<<T[[RX=Y=YZZZZZZZZH  ~~h33tQ++  //ffr  c                   K   |t          | j        dz             |                     |dd          }|                     |dd          }|s|r4|                     |g||           d{V }|                     |d          S |                                  d{V  |                     |          }d|d	         i}|                     |d
d          }	|	|	|d
<   n||d<   | 	                    |d
dg          }
| 
                    |                     ||
                     d{V }|                     |dg           }|                     |d          }|                     ||          S )a  
        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stopr9  r^  Fr   r  rM   r  r  r  r  )r3   rM   r4  r.  cancel_ordersr  rV  r  r  r  privatePostTradeCancelOrderr  r7  rm  )r  rM   r  r  r9  r^  
orderInnerr  r%  r  r  r  r  r  s                 r  cancel_orderzokx.cancel_order  s      >#DG.Y$YZZZ##FFI>>>>&*e<< 	1h 	1#112$GGGGGGGGJ>>*a000!!!!!!!!!V$$fTl

 **69oNN$!.GI!GG		&9o">??99$++gu:U:UVVVVVVVVx44tQ''v...r  c                 ^    |*t          |t                    r|                    d          S |S )zg
 @ignore
        :param string[]|str ids: order ids
        :returns str[]: list of order ids
        N,)
isinstancestrr  )r  idss     r  	parse_idszokx.parse_ids  s,     OC!5!5O99S>>!Jr  r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }g }|                     | j        di           }|                     |dd          }|                     |d|          }|                     |                     |dd                    }	|                     |                     |d                    }
|                     |d	d
          }| 	                    |dd          }|s|rd}|	|                     |          }|
Dt          dt          |
                    D ]&}|                    |
|         |d         d           't          dt          |                    D ]O}|s|r%|                    ||         |d         d           +|                    ||         |d         d           Pnmt          dt          |	                    D ]O}|s|r%|                    |d         |	|         d           +|                    |d         |	|         d           Pd}|dk    r|                     |           d{V }n|                     |           d{V }|                     |dg           }|                     ||dd|          S )a  
        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 argumentrc   r)  r5  r  r  rz  r  r9  r^  FprivatePostTradeCancelAlgosr   rM   )rz  r  )r  r  )r  ry  )r  r  r  )r3   rM   rV  r  r7  rw  r  r  r4  r.  r  r  r  r  r5  r  rq  )r  r  r  r  r  r%  rw  defaultMethodr)  clientOrderIdsalgoIdsr9  r^  r  r  
ordersDatas                   r  r  zokx.cancel_orders  s_      >#DG.Z$Z[[[!!!!!!!!!V$$//$,CC(((<_``!!&(MBB(9(9&)_(](]^^..!B!BCC##FFI>>>>&*e<< 	3h 	32F!..%%C"q#g,,//  ANN")!*"(,$ $     1c#hh'' 
 
 	w 	NN"%a&"(,$ $    
 NN!$Q"(,$ $    
 1c.1122 
 
 	w 	NN"(,'5a'8$ $    
 NN"(,#1!#4$ $     222!==gFFFFFFFFHH!CCGLLLLLLLLH< ^^Hfb99
  VT4HHHr  c                   K   |                                   d{V  g }|                     | j        di           }|                     |dd          }|                     |d|          }|                     |dd          }|                     |dd          }|p|}	|	rd	}t          d
t          |                    D ]}
||
         }|                     |d          }|                     |dd          }|                     |d          }| 	                    |          }d}|	rd}n	||	rd}nd}d|d         i}||n|||<   |
                    |           d}|d	k    r|                     |           d{V }n|                     |           d{V }|                     |dg           }|                     |ddd|          S )a3  
        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>`
        Nrc   r)  r5  r  r9  r^  Fr  r   rM   r  r  r  r  rz  ry  r  r  )rV  r  rw  r  safe_bool_2r.  r  r  r  r  r  r  r5  r  rq  )r  ro  r  r%  rw  r  r)  r9  r^  isStopOrTrailingr  r  rM   r  r  r  idKeyrequestItemr  r  s                       r  cancel_orders_for_symbolszokx.cancel_orders_for_symbols(  s/      !!!!!!!!!..~rBB(((<_``!!&(MBB""669==>>&*e<<".h 	32Fq#f++&& 	( 	(A1IE!!%..B ..uiQQM%%eX66F[[((FE & *# &)EE%E&,!K 4A3LSUKNN;''''222!==gFFFFFFFFHH!CCGLLLLLLLLH< ^^Hfb99
  T4vFFFr  timeoutc                    K   |                                   d{V  d|dk    r|                     |dz            ndi}|                     |                     ||                     d{V }|S )au  
        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  )rV  parse_to_intprivatePostTradeCancelAllAfterr  )r  r  r  r%  r  s        r  cancel_all_orders_afterzokx.cancel_all_orders_afterw  s       !!!!!!!!!Wq[[t((4888q
 <<T[[RX=Y=YZZZZZZZZ r  r  c                 B    ddddddd}|                      |||          S )Nr  rl  closed)r  order_failedr  partially_filledfilled	effectiver  r  r  statusess      r  parse_order_statuszokx.parse_order_status  s:    "& &!
 
 &&999r  r  c                 h   |                      |d          }|H|dk    rB|                     |                      |d          |                      |d          d|d          S |                     |dd          }|                     |d          }|                     |d	          }|                     |d
          }|                      |d          }|                      |d          }	d }
d }|	dk    rd}
d}	n|	dk    rd}d}	n
|	dk    rd}d}	|                      |d          }|                     ||          }|                     ||d          }|                      |d          }|                     |dd          }|                      |d          }|                     |                      |d                    }|                      |d          }d }d }|                      | j        dd          }|                      |d|          }|                      |d          }|dk    r)|	d k    r#|d!k    r|d"k    r|                      |d#          }n|                      |d#          }d }|Wt          j	        |          }|                      |d$          }| 
                    |          }|                     |          |d%}|                      |d          }|t          |          d&k     rd }|                     |d'd(          }|                     |d)d*          }|                      |d+          }d,} | |d-k    } |                     i d.|d/|d0|d1|d2|                     |          d3|d4|d5|d6|	d7|d8|
d|d9|d:|d;|d<|                     |d=d>g          d?||||d ||d | d@|          S )ANsCode0r  r  rejected)rM   r  r  r  rz  cTimer  fillTimer  r  r)  Trf  r+  rS  r*  rR  r  r  	accFillSzr  ordPxavgPxr  r>  r  r-  r  r  r  rB  r   rU  r  r  r   r  r  r  r  r   Ftruer  rM   r  r  r  lastTradeTimestamplastUpdateTimestampr  r  r\  rM  rQ  rY  rZ  rW  r  moveTriggerPxrq  )r  r  r  	remainingr  r>  tradesr   )r  
safe_orderr  r  r  r  r  rw  rH   r  r  r  r  r9  r  safe_number_n)!r  r  r  scoderM   r  r  r  r  r  rM  r\  r  r  r  rQ  rq  r  r  r  r  rO  r  r  r>  r  r  r  r  rY  rZ  reduceOnlyRawr   s!                                    r  rm  zokx.parse_order  s   p   00ESLL??&&ug66!%!1!1%!C!C$	$ $    x99%%eW55	"//w??!..ujAAv..y11;HDDU]]KDDU]]KD##E844!!(F33!!(FC88!!%55""5$88""5'22(()9)9%)I)IJJ((66 ((xLL!!%=AA##E:66EMM 0 0x67I7IPVZePePe##E400DD %%eT22F$#.}==M ,,UH==M"55mDDO))-88+ C ((	::%C,>,>,B,B M**5-KK,,UM9MM((==
!'61J  
E 
" 
 ] 
 	 

 Y// 
 !"4 
 "#6 
 f 
 D 
 ; 
  
 D 
 U 
 ] 
  
  D..u{O6TUU! 
" w# 
$ $3 
  
  
4 5  	r  c                 \  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |dd          }|                     | j        di           }|                     |dd	          }|                     |d|          }	|                     |d
d          }
|
rd}	|||d<   n||d<   n|||d<   n||d<   | 	                    |g d          }d}|	dk    r0| 
                    |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     |d          }|                     ||          S )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  rM   r  r  r   r)  r3  r  r9  privateGetTradeOrderAlgory  rz  r  )r)  r  r  r  r9  r  r   )r3   rM   rV  r  r  r7  rw  r  r4  r  r  r  r3  r  rm  )r  rM   r  r  r  r%  r  rw  r  r)  r9  r  r  r  r  s                  r  fetch_orderzokx.fetch_order  s      >#DG.X$XYYY!!!!!!!!!V$$fTl
 **69oNN//$,bAA(((<RSS!!&(MBB##FFI>> 
	&/F()6&&$&!!(%2	""#% 		&"["["[\\///!::4;;wPU;V;VWWWWWWWWHH!66t{{7E7R7RSSSSSSSSHB x44tQ''v...r  c                   K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}| |                     |          }|d         |d<   |||d<   |                     | j        di           }|                     | j        di           }	|                     |d	d
          }
|                     |d	|
          }|                     |d          }|                     |dd          }|                     |dd          }|s|s||	v rd}|rd|d<   n	|r|d|d<   | 	                    |g d          }d}|dk    r0| 
                    |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        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  rM   r  rf  rH  r)  r4  r  r  r9  r^   privateGetTradeOrdersAlgoPendingr;  r)  r  r9  r^  r  )rV  rW  fetch_paginated_call_dynamicr  r7  rw  r  r4  r.  r  r  r  r4  r  rq  )r  r  r  rf  r  r  r%  r  rw  rH  r  r)  r  r9  r^  r  r  r  s                     r  fetch_open_orderszokx.fetch_open_ordersD  s}     $ !!!!!!!!!88ART^__& 	l::;LfV[]bdjkkkkkkkkk	
 [[((F &tGH$GG//$,0A2FF7GLL(((<Z[[!!&(MBB""6955##FFI>>>>&*e<< 	8w 	87n#<#<7F 	+!2GI 	+'/!*GI		&"K"K"KLL777!BB4;;wX]C^C^________HH!>>t{{7TY?Z?Z[[[[[[[[H@ ~~h33  vue<<<r  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   d}d}|                     d||          \  }}|                     |          |d<   |||d<   d|d<   |                     | j        di           }	|                     | j        d	i           }
|                     |	d
d          }|                     |d
|          }|                     |d          }|                     |dd          }|                     |dd          }|rd}d|d<   n|s||
v rQd}|                     |d          }|||d<   | 	                    |d          }|r|t          | j        dz             n;|||d<   |                     |d          }|||d<   | 	                    |dg          }| 	                    |g d          }d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )aa  
        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>`
        NrM   r  r   r  rf  r  r  rH  r)  r6  r  r  r9  r^  F privateGetTradeOrdersAlgoHistoryr;  rz  z fetchCanceledOrders() requires an "ordType" string parameter, "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"beginr  r  r  r  )rV  r  r  r  r7  rw  r  r4  r.  r  r3   rM   r  r  r  r6  r  rq  )r  r  r  rf  r  r%  r  r  r  rw  rH  r  r)  r  r9  r^  rz  r  sendr  r  s                        r  fetch_canceled_orderszokx.fetch_canceled_orders  s     $ !!!!!!!!!

 [[((F &tGH889NPVX^__e"==dCC
$GG%//$,0ErJJ7GLL(((<Z[[!!&(MBB""6955##FFI>>>>&*e<< 	47F!2GI 	4N227F%%fh77F!$*!6844 A?+DG  7@  -@  A  A  A #( %%eW55E !&		%'33yy I I IJJ777!BB4;;wX\C]C]^^^^^^^^HH!>>t{{7TX?Y?YZZZZZZZZHH ~~h33  vue<<<r  c                 X  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}| |                     |          }|d         |d<   d}d}	|                     d||          \  }}	|                     |          |d<   |||d<   |                     | j        di           }
|                     | j        d	i           }|                     |
d
d          }|                     |d
|          }|                     |d          }| 	                    |dd          }| 
                    |dd          }|s|s||v rd}d|d<   |rd|d<   nJ|r|d|d<   n@|||d<   |                     |	d          }|||d<   |                     |	dg          }	d|d<   |                     |	g d          }d}|dk    r0|                     |                     ||                     d{V }ne|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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  rM   r  r  rf  rH  r)  r6  r  r  r9  r^  r  r  r  r;  r  r  r  r  r  #privateGetTradeOrdersHistoryArchiver  )rV  rW  r  r  r  r  r  rw  r  r  r.  r  r  r  r  r  r6  r  rq  )r  r  r  rf  r  r  r%  r  r  r  rw  rH  r  r)  r  r9  r^  r  r  r  r  s                        r  fetch_closed_orderszokx.fetch_closed_orders  s_     * !!!!!!!!!88ATV`aa& 	n::;NPVX]_dflmmmmmmmmm

 [[((F &tGH889LfV\]]e"==dCC
$GG../BBGG6FKK(((<Z[[!!&(MBB""6955""669==>>&*e<< 	+w 	+7n#<#<7F*GG 	(!2GI 
	(%.	" #( %%eW55E !&		%'33'GGyy I I IJJ777!BB4;;wX\C]C]^^^^^^^^HH<<<!EEdkkRY[_F`F`aaaaaaaaHH!>>t{{7TX?Y?YZZZZZZZZH@ ~~h33  vue<<<r  c                 v  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}| |                     |          }|d         |d<   |||d<   |                     d||          \  }}|                     d||          \  }}	|                     |          |d	<   ||||d
<   |                     |                     ||	                     d{V }
| 	                    |
dg           }| 
                    |||||	          S )al  
        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  rM   r  r  r  r  rf  r  )rV  rW  r  r  handle_until_optionr  r  privateGetTradeFillsHistoryr  r  r  )r  r  r  rf  r  r  r%  r  r  r  r  r  s               r  fetch_my_tradeszokx.fetch_my_trades?  s      !!!!!!!!!88R\]]& 	j::?FTY[`bhiiiiiiiii
 [[((F &tGH$GG225'6JJ88&RXYYe"==dCC
EM$GG99$++gu:U:UVVVVVVVV4 ~~h33  vueUCCCr  c           	      r   K   d|i}|                      ||||                     ||                     d{V S )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  rM   r  r  rf  r  r%  s          r  fetch_order_tradeszokx.fetch_order_trades  sQ       R
 ))&%GU[@\@\]]]]]]]]]r  ro  c                   K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S |                     | j        di           }|                     |d          }|                     |d|          }|                     |d          }i }d}	|                     d|          \  }	}|	|                     |d          }	|dk    r|	|	|d<   |                     dd|          \  }
}|
| 	                    |
          |d<   |||d	<   d}| | 
                    |          }|d
         |d<   |                     d||          \  }}d}|dk    r0|                     |                     ||                     d{V }ne|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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-entry-structure>`
        NFr   r  r)  mgnModeprivateGetAssetBillsr  rf  rM   r-  r  privateGetAccountBillsArchiver  )rV  rW  r  r  rw  r  r  handle_margin_mode_and_paramsr  r  r  r  r  r  r  r2  r  parse_ledger)r  ro  r  rf  r  r  rw  r)  r%  rV  r  r  r  r  r  s                  r  fetch_ledgerzokx.fetch_ledger  s     " !!!!!!!!!88PZ[[& 	f::=$PUW\^deeeeeeeee..}bAA!!'844!!&(F;;68,,
 
!??vVV
F))&)<<J+++%%/	"88fUUe"&"A"A$"G"GGJ$GG}}T**H%d^GEN225'6JJ444!??GUZ@[@[\\\\\\\\HH---!66t{{7E7R7RSSSSSSSSHH!88We9T9TUUUUUUUUHb ~~h33  x>>>r  c                 L    dddddddddddd}|                      |||          S )Nr   r  rebater>  )r  r  345r>  7891011r  )r  r  r-  s      r  parse_ledger_entry_typezokx.parse_ledger_entry_type  sI    
 
 tT222r  itemc                    |                      |d          }|                     ||          }|                     ||          }|                     |d          }|                      |d          }d }|*|                     t          j        |                    |d}|                      |d          }|                     |d d          }	|                     ||                      |d          || 	                    |          d |                      |d          d | 
                    |                      |d	                    ||	|                     |d
          d |                     |d          d|d|          S )Nr-  r  r>  r  r  r  billIdr  r  balChgr  r  )r  rM   r  r  r  referenceIdreferenceAccountr  r  r  r  r  r  r  r>  )r  r  safe_currencyr  r  rH   r  r  safe_ledger_entryr  r  r  )
r  r  r  rJ  ro  r  r  r>  r  r  s
             r  parse_ledger_entryzokx.parse_ledger_entry  s   J %%dE22
&&z8<<%%j(;;%%dD11	((u55$))'*<]*K*KLL  C ##D(33!!(D#66%%""422"Y//++D':: $001A1A$1O1OPP&&tX66%%dE22'
 '
  !  	r  c                    |                      |d          }|                     |g d          }|-|                     |di           }|                      |d          }|                      |d          }|                     ||          }|d         }|                      |d          }|                     |di           }	|                     |	d	          }
|                     |
|          }|d
k    r|                     |
dd
          }|                      |d          }|                     ||          }|                     |           |||||dS )Naddr)r3  pmtIdmemoaddrExcommentr-  ro  r:  r  rM   zUSDT-PolygonzUSDT-Polygon-BridgerB  )r  r  rB  addressr3  )r  safe_string_nr7  r  index_byr4  rF  check_address)r  depositAddressr  r  r3  r  rJ  ro  r:  r  r#  networkDatarB  rP  s                 r  parse_deposit_addresszokx.parse_deposit_address_  sk   : "">6::  1I1I1IJJ;__^XrBBF""6955C%%ne<<
%%j(;;  99??8Z<<}}Xt44oolE::T N""++L:OQ_``K"";	::--gt<<7###""
 
 	
r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |dd          }|                     ||d         gd          }|                     |d	          S )
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
        Nr-  rM   r  selectedTro  FrB  )rV  r  privateGetAssetDepositAddressr  r  	filter_byparse_deposit_addressesr  )	r  ro  r  r  r%  r  r  filteredparseds	            r  "fetch_deposit_addresses_by_networkz&okx.fetch_deposit_addresses_by_network  s       !!!!!!!!!==&&8D>
 ;;DKKQW<X<XYYYYYYYY, ~~h33>>$
D99--h&9I8JERR}}VY///r  c                 v  K   |                                   d{V  |                     |d          }|                     |d          }|                     |          }|                     ||          }|                     ||           d{V }|:|                     ||          }| t          | j        dz   |z   dz   |z             |S |                     ||          }||v r||         S t          |
                                          }|                     |d          }	|                     ||	          S )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>`
        NrB  z# fetchDepositAddress() cannot find z deposit address for r   )rV  r  r  r  rF  r  r  r:   rM   r2  r?  )
r  ro  r  
rawNetworkrB  r  r  codeNetworkr?  r  s
             r  fetch_deposit_addresszokx.fetch_deposit_address  s`      !!!!!!!!!%%fi88
69--&&t,,))*d;;@@vNNNNNNNN^^Hg66F~$TW/T%TW^%^ax%x{%  A  A  AM--dD99(""K((HMMOO$$  q))~~h...r  r  r3  c                   K   |                      ||          \  }}|                     |           |                                  d{V  |                     |          }|t	          |          dk    r|dz   |z   }|d         |d|                     |          d}|                     |d          }|l|                     | j        di           }	|                     |	|	                                |          }|d         d	z   |z   |d
<   | 
                    |d          }|                     |d          }
|
|                                  d{V }|                     |                     | j        |                    | _        |                     |d         |                     ||d                   i           }|                     |d          }
|
t!          | j        dz             |                     |
          |d<   | 
                    |dg          }|                     |                     ||                     d{V }|                     |dg           }|                     |d          }|                     ||          S )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  rM   r  )r-  toAddrdestamtrB  r  r  r:  r>  ro  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  rV  r  r  r:  r  r  rw  upperr  r7  map_to_safe_mapr|  ry  rF  r3   rM   privatePostAssetWithdrawalr  r  parse_transaction)r  ro  r  r  r3  r  r  r%  rB  r  r>  ry  targetNetworkr  r  r  transactions                    r  r   zokx.withdraw  s      99#vFFV7###!!!!!!!!!==&&O#c((Q,,mc)GD>((00	
 
 ""6955~~dlJCCH&&x'JJG'~3g=GGYYvy11Fvu--;#4466666666J"2243C3CDOU_3`3`aaDO NN8J+?AXAXY`bjkqbrAsAsuwxxM""=%88C{'  3U  )U  V  V  V..s33		&5'**88We9T9TUUUUUUUU ~~h33nnT1--%%k8<<<r  c                 0  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}| |                     |          }|d         |d<   |t	          |dz
  d          |d	<   |||d
<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |dg           }	| 	                    |	||||          S )aT  
        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  rM   r-  r   r   r  rf  r  r  )
rV  rW  r  r  rc  r  privateGetAssetDepositHistoryr  r  parse_transactions
r  ro  r  rf  r  r  r%  r  r  r  s
             r  fetch_depositszokx.fetch_depositsA  sk      !!!!!!!!!88R\]]& 	h::?DRWY^`fggggggggg
 }}T**H%d^GEN #EAIq 1 1GH$GG227GVLL;;DKKQW<X<XYYYYYYYYN ~~h33&&tXueVLLLr  c                 n  K   |                                   d{V  d|i}d}| |                     |          }|d         |d<   |                     |                     ||                     d{V }|                     |d          }|                     |di           }|                     ||          S )a  
        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depIdrM   r-  r  r   )rV  r  r  r  r7  r  r  )	r  rM   ro  r  r%  r  r  r  rC  s	            r  fetch_depositzokx.fetch_deposit  s       !!!!!!!!!R
 }}T**H%d^GEN;;DKKQW<X<XYYYYYYYYx00..q"--%%gx888r  c                 0  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}| |                     |          }|d         |d<   |t	          |dz
  d          |d	<   |||d
<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |dg           }	| 	                    |	||||          S )ab  
        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  rM   r-  r   r   r  rf  r  r  )
rV  rW  r  r  rc  r   privateGetAssetWithdrawalHistoryr  r  r  r   s
             r  fetch_withdrawalszokx.fetch_withdrawals  sl      !!!!!!!!!88ASU_``& 	k::;MtUZ\acijjjjjjjjj
 }}T**H%d^GEN #EAIq 1 1GH$GG227GVLL>>t{{7TZ?[?[\\\\\\\\> ~~h33&&tXueVLLLr  c                 n  K   |                                   d{V  d|i}d}| |                     |          }|d         |d<   |                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |          S )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wdIdrM   r-  r  r   )rV  r  r&  r  r  r  r  )	r  rM   ro  r  r%  r  r  r  
withdrawals	            r  fetch_withdrawalzokx.fetch_withdrawal  s       !!!!!!!!!B
 }}T**H%d^GEN>>t{{7TZ?[?[\\\\\\\\, ~~h33^^D!R00
%%j111r  c                     i ddddddddddd	d
dddddddddddddddddddddd}|                      |||          S )Nz-3pendingz-2r  r/  failedr  r  r  r  r  r  r  r>  r  r  r  r  121516r  r  s      r  parse_transaction_statuszokx.parse_transaction_status  s    0
)
*
 (
 	

 
 
 
 
 
 
 
 
 
 )
 )
  )!
" )#
& &&999r  r  c                 <   d }d }|                      |d          }|                      |d          }|                      |d          }|}|                     |dd          }	|                     |d|	          }	|d}|}n|                      |d          }d	}|                      |d
          }
|                     |
          }|                     |d          }|                     |                      |d                    }|                      |d          }|                     |d          }d }|d	k    rd}n|                     |d          }i d|d|d|d|dd d|d|d|dd d|	d|	d|d|dd d|d|d |                     |          d d ||d!d"S )#Nr)  fromtor3  r  r  r*  r#  rC  r-  r  r  txIdr  r   r>  r  rM   r  r  rB  addressFrom	addressTor  tagFromtagTor  r  r  txidr  r  )r  r  )internalr  r>  )r  r  r  r  r2  r  r  )r  r  r  r  rM   withdrawalIdr7  r8  r  r:  rJ  ro  r  r  r;  r  feeCosts                    r  r  zokx.parse_transactionE  sj   P ''V<<&&{F;;$$[$77	"";v>>"";??#DBB !!+w77BD%%k599
&&z22!!+u55..t/?/?W/U/UVVV44%%k488	9GG&&{E::G
K
"
 
 f	

 t
 ;
 
 w
 t
 U
 5
 f
 D
 t
 D
  !
" Y//#
$   )
 
 
 	
r  c                   K   |                                   d{V  d}|                     d|          \  }}||                     |dd          }|dk    r|dk    rt          | j        dz             |                     |          }|d         |d}|                     |                     ||                     d{V }|                     |d	g           }| 	                    ||          S )
a  
        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 isolatedrM   r  r  r  )
rV  r  r  r4   rM   r  privateGetAccountLeverageInfor  r  parse_leverage)r  r  r  rV  r  r%  r  r  s           r  fetch_leveragezokx.fetch_leverage  s'      !!!!!!!!!
!??QWXX
F))&)WEEJ'!!
j(@(@TW'  A  A  AV$$Tl!
 
 ;;DKKQW<X<XYYYYYYYY ~~h33""4000r  r_  c                    d }d }d }d }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|	dk    r|                     |d          }i|	dk    r|                     |d          }|                     |d          }|                     |d          }||                     ||          |||dS )	Nr   r  r  r&  r(  r   r'  )r  r  rV  longLeverageshortLeverage)r  r  r  r  r  r  )
r  r_  r  r  rV  rF  rG  r  entryr%  s
             r  rC  zokx.parse_leverage  s   
q#h--(( 	B 	BAQKE//yAAJ''x88H11%CCLv%%#00@@(( $ 1 1% A A#00@@ $ 1 1% A A&&x88$(*
 
 	
r  c                   K   |                                   d{V  |                     |          }|                     d||          \  }}d|d         i}||                     |          |d<   |                     |                     ||                     d{V }|                     |dg           }|                     |d          }	|	dS |                     |	|          S )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  rM   r  r  r   )	rV  r  r  r  r*  r  r  r  parse_position)
r  r  r  r  r  r  r%  r  r  positions
             r  fetch_positionzokx.fetch_position  s
      !!!!!!!!!V$$88&RXYYe fTl

 "&"A"A$"G"GGJ88We9T9TUUUUUUUU^ ~~h33>>$**4""8V444r  c                   K   |                                   d{V  i }|g }t          dt          |                    D ]:}||         }|                     |          }|                    |d                    ;t          |          }|dk    rd                    |          |d<   |                     | j        di           }	|                     |	dd          }
d}|
d	k    r0| 	                    | 
                    ||                     d{V }n/|                     | 
                    ||                     d{V }|                     |d
g           }g }t          dt          |                    D ]0}|                    |                     ||                              1|                     |d|                     |          d          S )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   rM   r  r  r   r)  r*  !privateGetAccountPositionsHistoryr  r  F)rV  r  r  r  r  rE  r  rw  r  rN  r  r*  r  rJ  filter_by_array_positionsr  )r  r~  r  r%  	marketIdsr  rH  r  marketIdsLengthfetchPositionsOptionsr)  r  	positionsr  s                 r  fetch_positionszokx.fetch_positions.  s      !!!!!!!!!

 I1c'll++ / /
U++  ....!)nnO""$'HHY$7$7! $t|=Mr R R!!"7C_``888!CCDKKPWY_D`D`aaaaaaaaHH!<<T[[RX=Y=YZZZZZZZZH^ NN8VR88	q#i..)) 	= 	=AMM$--il;;<<<<--fh@S@ST[@\@\^cdddr  c                 @   K   |                      |g|           d{V S )a  

        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)rT  r  r  r  s      r  fetch_positions_for_symbolzokx.fetch_positions_for_symbol  s2       ))6(F;;;;;;;;;r  rK  c                 
   |                      |d          }|                     ||d d          }|d         }|                      |d          }t          j        |          }|                     |dd          }|dk    }|                     |          }	|d         r\|dk    r=|                      |d	          }
|                     |
          }||d
         |k    rdnd}||                      |d          }n:|8|dk    r2t          j        |d          rd}nt          j        |d          rd}nd }| 	                    |d          }| 
                    |          }|                      |d          }|                      |d          }|d         r(t          j        t          j        ||          |          }|                     |          }|                      |d          }d }|                     |dd          }|                      |d          }|                      |d          }d }d }|dk    r,|                      |d          }t          j        ||          }n1|dk    r+t          j        d|          }|                      |d          }|                      |d          }|                     |          }t          j        ||          }|*|                     t          j        ||d                    }n[|Y|d         rt          j        ||          }n;t          j        t          j        t          j        ||          |          |          }d}|                     t          j        t          j        ||          dd                    }| 	                    |d          }|                      |d           }|                     t          j        |d!                    }|                     |d"          } |                     t          j        ||d                    }!|                     i d#|d$|                      |d%          d|d&|d'|d(|d)|                     |          d*|                     |          d+| 	                    |d+          d,|d-|	d|d.|                     |          d/| 	                    |d0          d1|d2|d3| |                     |           |                     |d4          |||                     |          |                     |          |                     |          |                     |          |!d d d5          S )6Nr  r  r  posr&  	directionnetr[   posCcyr  r(  r'  r  r  rr  notionalUsdrm  r  r  	openAvgPxuplr   r"  imrr@  r  mmrr  rl  z0.00005liqPxuplRatior.  r  r  rM   posIdrP  rV  liquidationPrice
entryPriceunrealizedPnlrealizedPnlrp  	contractsrv  	lastPrice
closeAvgPxr  r]  r  r  )r  r  maintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager_  marginRatiorY  rZ  )r  r  rH   
string_absr  r  r  r  	string_ltr  r:  r>  r;  
string_addr  safe_positionr  )"r  rK  r  r  r  rY  contractsAbsr  r]  ri  r\  parsedCurrencyr  contractSizeStringmarkPriceStringnotionalStringrP  rV  initialMarginStringentryPriceStringunrealizedPnlStringleverageStringrp  collateralStringmaintenanceMarginStringrl  !maintenanceMarginPercentageStringrounderrm  re  percentageStringrp  r  rq  s"                                     r  rJ  zokx.parse_position  sU   F ##Hh77!!(FD*EE!x//)#..!!(I{CC%%l33	( 	$u}}))(H==!%!8!8!@!@!-&,Vn&F&F66WD|''+>>5==(c22 $% *344 $&#''??!22<@@**8X>>))(MBB) 	w$/0B<Qc0d0dfuvvN$$^44%%h	::
"--hMM"..x??))(G<<"&  "&"2"28U"C"C&12EGZ[[:%%&-&8n&M&M##//(CC"&"2"28U"C"C --.EFF,3,>?VXf,g,g)"*&*&7&78JK^`npq8r8r&s&s## (h e&-&89PR`&a&a##&-&89KGL^_km  MA  MA  CS  :T  :T  Vd  'e  'e#&*&7&78J7K]^  BI  LJ  LJ  LO  QR  9S  9S  'T  'T#++Hg>>++HjAA&&w'9:JE'R'RSS
%%h88	''(:;RTdfg(h(hii!! #
H#
$""8W55#
 f#
 	#

 *#
  0#
 $++,<==#
 T../BCC#
 4++HmDD#
 *#
 #
 L#
 **?;;#
 ))(LAA#
 D#
  f!#
" ##
$ Y//#'#4#4Xw#G#G!2+F++,<==!../BCC'+'8'89P'Q'Q)).99&!#9#
 #
 #
   	r  fromAccount	toAccountc                 4  K   |                                   d{V  |                     |          }|                     | j        di           }|                     |||          }|                     |||          }	|d         |                     ||          d||	d}
|dk    r?d|
d<   |	|
d	<   |                     |d
d          |
d
<   |                     |dd          |
d<   nD|	dk    r>d|
d<   ||
d	<   |                     |d
d          |
d
<   |                     |dd          |
d<   |                     |                     |
|                     d{V }|                     |dg           }|                     |di           }| 	                    ||          S )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>`
        NrI  rM   r  )r-  r  r  r4  r5  masterr  r  subAcctr4  r>  r5  r  r  r   )
rV  r  r  rw  r  currency_to_precisionprivatePostAssetTransferr  r  parse_transfer)r  ro  r  r  r  r  r  rI  fromIdtoIdr%  r  r  rawTransfers                 r  r   zokx.transfer2  s      !!!!!!!!!==&&6FKK!!.+{KK	9EED>--dF;;

 

 X!GFO!%GI"..vvsCCGFO ,,VT3??GDMMX!GFO!'GI"..vvsCCGFO ,,VT3??GDM66t{{7F7S7STTTTTTTT  ~~h33nnT1b11"";999r  r   c                    |                      |dd          }|                     |d          }|                     ||          }|                     |d          }|                     |d          }|                     |d          }|                     | j        di           }	|                     |d          }
|                     |d	          }|'|                     t          j	        |                    }|||
| 
                    |
          |||                     |	|          |                     |	|          |                     |                     |d
                    d	S )NtransIdr  r-  r  r4  r5  rJ  r  rU  r  )	r  rM   r  r  r  r  r  r  r  )r  r  r  r  r  rw  r  r  rH   rr  r  parse_transfer_status)r  r   r  rM   rJ  ro  r  fromAccountIdtoAccountIdrJ  r  balanceChanges               r  r  zokx.parse_transferm  s^   j )X>>%%h66
&&z8<<!!(E22((6::&&x66~~dlNBGG%%h55	((488$&&w'9-'H'HIIF"Y//++L-HH)),DD001A1A(G1T1TUU

 

 
	
r  c                 8    ddi}|                      |||          S )Nsuccessr  r  r  s      r  r  zokx.parse_transfer_status  s(    t
 &&999r  c                 $  K   |                                   d {V  d|i}|                     |                     ||                     d {V }|                     |dg           }|                     |d          }|                     |          S )Nr  r  r   )rV  privateGetAssetTransferStater  r  r  r  )r  rM   ro  r  r%  r  r  r   s           r  fetch_transferzokx.fetch_transfer  s      !!!!!!!!!r
 ::4;;wPV;W;WXXXXXXXX* ~~h33>>$**""8,,,r  c                 d  K   |                                   d{V  d}ddi}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     |||||          S )	aS  
        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  rM   r-  r  rf  r  )rV  r  r  r  r  parse_transfers)	r  ro  r  rf  r  r  r%  r  	transferss	            r  fetch_transferszokx.fetch_transfers  s       !!!!!!!!!C
 }}T**H%d^GEN$GG$GG;;DKKQW<X<XYYYYYYYYB NN8VR88	##IxvNNNr  r  GETc                 .   t          |t                    }d| j        z   dz   |                     ||          z   }|                     ||                     |                    }	|                     | j        d         d                   |z   }
|dk    r|	r|
d|                     |	          z   z  }
n|dk    r| 	                                 |dk    r|d	k    s|d
k    s|dk    r| 
                    | j        dd          }t          |t                    ret          dt          |                    D ]F}||         }| 
                    |d          }|$||                                 z   |d<   ||d<   |||<   Gn7| 
                    |d          }|||                                 z   |d<   ||d<   |                     |                                           }| j        | j        |d}||z   |z   }|dk    r%|	r"d|                     |	          z   }|
|z  }
||z  }n#|s|	r|                     |	          }||z  }d|d<   |                     |                     |          |                     | j                  t.          j        d          }||d<   |
|||dS )Nz/api/r  r   r   r  ?r  POSTr  r  r  rL  rG  r   r  r3  )zOK-ACCESS-KEYzOK-ACCESS-PASSPHRASEzOK-ACCESS-TIMESTAMPr  zapplication/jsonzContent-Typebase64zOK-ACCESS-SIGN)r   r)  bodyheaders)r  r2  rS   implode_paramsr  extract_paramsimplode_hostnamer   	urlencoder/  r  rw  r  r  r@  r  r  r  r  jsonhmacencoder  hashlibsha256)r  pathr   r)  r  r  r  isArrayr%  r  r   rL  r  rH  r  r  authurlencodedQuery	signatures                      r  signzokx.sign  s   VT**DL(3.1D1DT61R1RR		&$"5"5d";";<<##DIe$4V$<==G(?? 3sT^^E2222I++---T-A%A%ATM_E_E_cgkxcxcx++DL*FXYYfd++ 1"1c&kk22 . . &q	(,(8(8	(J(J(0/7$++--/GE),+3E%L(-F1I. %)$4$4VY$G$GM$,,4t{{}},Dy)(0uTZZ\\22I!%(,'0 G v%/D ,&)DNN5,A,A&AO?*CO+D !e !99U++DDLD*<'		$++d"3"3T[[5M5Mw~_ghhI(1G$%fdwOOOr  c                    |                      |d          }|                     |d          }|                     ||          }|                     |d          }|                      |d          }|                     |d          }|                     |d          }	t	          j        |	|          }
i d|d|dd dd d	|                     d
          dd dd dd d|                     |d          d|d|                     |          d|d|d|                     |          dd dd dd d|                     |
          iS )NnextFundingTimer  nextFundingRater  r  r  rv  rw  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_ratezokx.parse_funding_rateM  s   : $(#4#4X?P#Q#Q ##Hh77!!(F33**85FGG''-@@ ,,X}EE $ 0 0;L M M&12GIZ[[
H
f
 
 $	

 D--c22
 #D
 
 
 4++HmDD
 
 t||K88
 
 #$<
 "4<<0H#I#I
 "4
  '!
" &t#
$ 334HII%
 
 	
r  c                 @    dddddd}|                      |||          S )Nr   r   r%  16h24h)360000014400000288000005760000086400000r  )r  r  	intervalss      r  r  zokx.parse_funding_interval  s7    
 
	 	8X>>>r  c                 >   K   |                      ||           d{V S )at  
        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_raterV  s      r  fetch_funding_intervalzokx.fetch_funding_interval  s0       ,,VV<<<<<<<<<r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )ak  
        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  rM   r  r   )	rV  r  r.   rM   publicGetPublicFundingRater  r  r  r  )r  r  r  r  r%  r  r  rH  s           r  r  zokx.fetch_funding_rate  s       !!!!!!!!!V$$f~ 	`*^ ^___fTl
 88Wf9U9UVVVVVVVV" ~~h33tQ++&&uf555r  c                 (  K   |                                   d{V  |                     |dd          }ddi}|                     |                     ||                     d{V }|                     |dg           }|                     ||          S )a  
        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  )rV  r  r  r  r  parse_funding_rates)r  r~  r  r%  r  r  s         r  fetch_funding_rateszokx.fetch_funding_rates  s       !!!!!!!!!%%gvt<<!5)88Wf9U9UVVVVVVVV" ~~h33''g666r  c                   K   |                                   d{V  ddi}|t          |          |d<   d}|N|                     |          }|d         }|d         r)|d         rd|d<   |d	         |d
<   nd|d<   |d         |d
<   |                     d||          \  }}|dk    r|                     |          |d<   |                     |                     ||                     d{V }	|                     |	dg           }
g }t          dt          |
                    D ]}|
|         }| 
                    |d          }|                     |d          }|                     |          }|                     |d
          }|                     |          }|                     |d          }|                     |d          }d}|t          j        |d          s|}n|}|                    ||d         |||                     |          |                     |d          |                     |          d            |                     |d          }|                     ||||          S )aW  
        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  rf  r  r  rl  ctTyper  r-  rm  r  r   r\   r  r  r   r  r  r  	posBalChgr  r  )r  r  ro  r  r  rM   r  r  )rV  r  r  r  r  r  r  r  r  r  r  r  r  r  rH   	string_eqr  r  r  r  r  )r  r  r  rf  r  r%  r  r  r  r  r  r  r  rH  r  r  marketInnerrJ  ro  r  positionBalanceChanger  r  s                          r  fetch_funding_historyzokx.fetch_funding_history  s      !!!!!!!!! CK
X "5zzGG[[((FH%Fj! 6(# 6(0GH%%+I%6GENN(1GH%%+H%5GEN889NPVX^__e6>>"&"A"A$"G"GGJ;;DKKQV<W<WXXXXXXXX2 ~~h33q#d))$$ 	 	AGE))%66I%%eX66F**622K))%77J**:66D ,,UH==M$($4$4UK$H$H!F)G4EmUX4Y4Y)&.MM%h/& LL33&&uh77++F33      fk2200NNNr  c                   K   |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  d{V  |                     |          }d}|                     d|          \  }}||                     |dd          }|dk    r|d	k    rt          | j        d
z             |||d         d}|                     |dd          }|d	k    r.|dk    r#|dk    r|dk    rt          | j        dz             ||d<   |                     |                     ||                     d{V }|S )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"  r@  zT setLeverage() requires a marginMode parameter that must be either cross or isolatedrM   r   r  r  r&  r[  r(  r'  zR setLeverage() requires the posSide argument to be either "long", "short" or "net")	r3   rM   r4   rV  r  r  r  privatePostAccountSetLeverager  )	r  r_  r  r  r  rV  r%  r&  r  s	            r  set_leveragezokx.set_leverage  s      >#DG.Y$YZZZ qLLhnnTW'\\]]]!!!!!!!!!V$$
!??vVV
F))&)WEEJ'!!
j(@(@TW'}}~~~!Tl
 

 ""69e<<##&  W%7%7Gu<L<L +!  A  A  A!(GI;;DKKQW<X<XYYYYYYYY r  c                   K   |                                   d{V }t          |          }d}|dk    r|                     |d          }|C|                     |d          }t	          | j        dz   d                    |          z             |                     |d          }|                     ||          }n|d         }|d         }	|                     |	d	          }
|
d
k    }|	|dS )at  

        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  rM   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.   rM   rE  r  r  )r  r  r  accountslengthselectedAccountr  
accountIdsrJ  mainAccountr  isHedgeds               r  fetch_position_modezokx.fetch_position_mode  s9      ,,........XA::((==I !==hMM
#DG  /t  %t  w{  w@  w@  AK  wL  wL  %L  M  M  M#}}Xt<<"&..y"I"I&qkO%f-"";	:://
 
 	
r  r]  c                    K   d}|rd}nd}d|i}|                      |                     ||                     d{V }|S )a  
        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_modezokx.set_position_mode  sj       	 	#)II"Iy
 ??GU[@\@\]]]]]]]] r  rV  c                 $  K   |t          | j        dz             |                                }|dk    r|dk    rt          | j        dz             |                                  d{V  |                     |          }|                     |dd          }||dk     s|d	k    rt          | j        d
z             |                     |dg          }|||d         d}|                     | 	                    ||                     d{V }|S )a  
        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"  r@  z< setMarginMode() marginMode must be either cross or isolatedr   r_  r   r  z< setMarginMode() params["lever"] should be between 1 and 125rM   r  )
r3   rM   r  r4   rV  r  r  r  r  r  )r  rV  r  r  r  r   r%  r  s           r  set_margin_modezokx.set_margin_mode  sC      >#DG.[$[\\\  %%''
'!!
j(@(@TW'eefff!!!!!!!!!V$$##FGZ@@MuqyyeckkTW'eefff6J<00!Tl
 

 ;;DKKQW<X<XYYYYYYYY r  c                 B  K   |                                   d{V  |                     |           d{V }|                     |dg           }g }t          dt	          |                    D ]0}|                    |                     ||                              1|S )aY  
        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   )rV  privateGetAccountInterestRater  r  r  r  parse_borrow_rate)r  r  r  r  r  r  s         r  fetch_cross_borrow_rateszokx.fetch_cross_borrow_rates+  s       !!!!!!!!!;;FCCCCCCCC ~~h33q#d))$$ 	: 	:ALL//Q889999r  c                 \  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |          S )a  
        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>`
        Nr-  rM   r  r   )rV  r  r  r  r  r  r  )r  ro  r  r  r%  r  r  r  s           r  fetch_cross_borrow_ratezokx.fetch_cross_borrow_rateH  s       !!!!!!!!!==&&8D>
 ;;DKKQW<X<XYYYYYYYY ~~h33~~dAr**%%d+++r  c                     |                      |d          }|                     |d          }|                     |          |                     |dd          d||                     |          |dS )Nr-  r  r  r  i \&)r  r  periodr  r  r  )r  r  r  r9  r  )r  r  r  r-  r  s        r  r  zokx.parse_borrow_ratei  s{     tU++%%dD11	//44&&t^VDD"Y//
 
 	
r  c                 &   i }t          dt          |                    D ]}||         }|                     |                     |d                    }||                     ||          r;||vrg ||<   |                     |          }	||         }
|
                    |	           t          |                                          }t          dt          |                    D ]+}||         }| 	                    ||         |||          ||<   ,|S )Nr   r-  )
r  r  r  r  r  r  r  r2  r?  filter_by_currency_since_limit)r  r  codesr  rf  borrowRateHistoriesr  r  ro  borrowRateStructureborrrowRateCoder?  s               r  parse_borrow_rate_historieszokx.parse_borrow_rate_histories}  s-    %'q#h--(( 	< 	<AA;D**4+;+;D%+H+HIID}dE : :} 33302'-&*&<&<T&B&B#"5d";&&':;;;',,..//q#d))$$ 	{ 	{A7D(,(K(KL_`dLegkmrty(z(z%%""r  c                   K   |                                   d{V  i }|||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )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  rf  r  )rV  )publicGetFinanceSavingsLendingRateHistoryr  r  r  )r  r  r  rf  r  r%  r  r  s           r  fetch_borrow_rate_historieszokx.fetch_borrow_rate_histories  s       !!!!!!!!!
  %GH$GGGGT[]cHdHdeeeeeeee ~~h33//eUEJJJr  c                 P  K   |                                   d{V  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        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>`
        Nr-  rM   r  rf  r  )rV  r  r  r  r  parse_borrow_rate_history)	r  ro  r  rf  r  r  r%  r  r  s	            r  fetch_borrow_rate_historyzokx.fetch_borrow_rate_history  s       !!!!!!!!!==&&8D>
  %GH$GGGGT[]cHdHdeeeeeeee ~~h33--dD%GGGr  c                 (  K   |                                   d {V  |                     |          }|                     |dd          }|                     |dg          }|d         |||d}|                     |                     ||                     d {V }|                     |dg           }	|                     |	di           }
|                     |d          }|                     |                     |
|          d|d	k    rd
ndi          S )Nr&  r[  rM   )r  r  r  r&  r  r   ro  r  r  r  r.  )	rV  r  r  r  'privatePostAccountPositionMarginBalancer  r  r  parse_margin_modification)r  r  r  r  r  r  r&  r%  r  r  rH  	errorCodes               r  modify_margin_helperzokx.modify_margin_helper  s<     !!!!!!!!!V$$""69e<<6I;//Tl	
 
 EEdkkRY[aFbFbcccccccc ~~h33tQ++$$Xv66	{{499%HHyC//ddhK
   	r  r  c                    |                      |dd          }|                     |d          }d }|dk    rt          j        |d          rdnd}n|}t          j        |          }|                     |d          }|                     ||          }|d	         r|d
         n|d         }	|                     |d          }
||d         |d|                     |          |	d d |
|                     |
          d
S )Nr  r  r  r>  r  addreducer  rm  r  r  r  r  r@  )
r  r  r  rV  r  ro  r  r  r  r  )	r  r  rH   r  rr  r  r  r  r  )r  r  r  	amountRawtypeRawr  r  r  responseMarketro  r  s              r  r  zokx.parse_margin_modification  s   ` &&tUK@@	""400c>>#-i==K558DDD#I..##D(33))(F;;)7	)B_~f%%W^H_%%dD11	$X.$''//"Y//
 
 	
r  c                 B   K   |                      ||d|           d{V S )a  
        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=margin-structure>`
        r  Nr  r  r  r  r  s       r  reduce_marginzokx.reduce_marginV  s4       ..vvxPPPPPPPPPr  c                 B   K   |                      ||d|           d{V S )a  
        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=margin-structure>`
        r  Nr  r  s       r  
add_marginzokx.add_marginc  s4       ..vvufMMMMMMMMMr  c                 x  K   |                                   d{V  |                     |          }|d         rdn|                     |d                   }|                     |d         d          }|s |dk    rt	          | j        dz   |z             d}|                     d|          \  }}||                     |d	d
          }|||d}|dk    r|d         |d<   |                     |                     ||                     d{V }| 	                    |dg           }	| 
                    |	|          S )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>`
        NrZ   rC  r  r  r  z< fetchMarketLeverageTiers() cannot fetch leverage tiers for r   r#  r"  )r  r#  r  rM   r  r  )rV  r  r  r  r4   rM   r  publicGetPublicPositionTiersr  r  parse_market_leverage_tiers)
r  r  r  r  r  r  rV  r%  r  r  s
             r  fetch_market_leverage_tierszokx.fetch_market_leverage_tiersp  sz      !!!!!!!!!V$$!&>^xxt/N/NvV\~/^/^vf~u55 	tx +i!ilr!rsss
!??@Z\bcc
F))&(GDDJ 
 

 8 &tGH::4;;wPV;W;WXXXXXXXX, ~~h33//f===r  c                    g }t          dt          |                    D ]}||         }|                     |d          }|                    |                     |d          |                     ||          |d         |                     |d          |                     |d          |                     |d          |                     |d          |d	           |S )
zs
 @ignore
        :param dict info: Exchange response for 1 market
        :param dict market: CCXT market
        r   r  tierr  r	  maxSzra  maxLever)r#  r  r  minNotionalmaxNotionalmaintenanceMarginRater  r  )r  r  r  r  r  r  r  )r  r  r  tiersr  r#  r  s          r  r   zokx.parse_market_leverage_tiers  s    0 q#d))$$ 	 	A7D''h77HLL))$77**8V<<"7O#//g>>#//g>>)-)9)9$)F)F#//jAA	 	 	 	 	 	 r  c                 >  K   |                                   d{V  d}|                     d|          \  }}||                     |dd          }d|i}d}| |                     |          }	|	d         |d<   ||dz
  |d<   |||d	<   | |                     |          }|d         |d
<   |                     |                     ||                     d{V }
|                     |
dg           }|                     |          }| 	                    ||||          S )a  
        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"  rM   r-  r   r  rf  r  r  )
rV  r  r  r  r   privateGetAccountInterestAccruedr  r  parse_borrow_interestsr  )r  ro  r  r  rf  r  rV  r%  r  r  r  r  interests                r  fetch_borrow_interestzokx.fetch_borrow_interest  sb      !!!!!!!!!
!??@UW]^^
F))&)WEEJz
 }}T**H%d^GEN %	GH$GG[[((F &tGH>>t{{7TZ?[?[\\\\\\\\( ~~h33..t44228T5%PPPr  r  c                    |                      |d          }||                     ||          }|                     |d          }||                      |d          |                     |                      |d                    |                     |d          |                     |d          |                     |d          |                      |d          ||                     |          d		S )
Nr  r  r  r-  r-  r  liabr  )	r  r  r  r-  r  amountBorrowedrV  r  r  )r  r  r  r  r  r  )r  r  r  r  r  s        r  parse_borrow_interestzokx.parse_borrow_interest  s    !!$11%%ff55F%%dD11	&&vx88//0@0@u0M0MNN((z:: ,,T>BB"..tV<<**4;;"Y//

 

 
	
r  c                   K   |                                   d{V  |                     |          }|d         |                     ||          dd}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )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>`
        NrM   borrow)r-  r  r  r  r   )rV  r  r  privatePostAccountBorrowRepayr  r  r  parse_margin_loan)	r  ro  r  r  r  r%  r  r  loans	            r  borrow_cross_marginzokx.borrow_cross_margin  s       !!!!!!!!!==&&D>--dF;;
 

 ;;DKKQW<X<XYYYYYYYY  ~~h33~~dAr**%%dH555r  c                   K   |                                   d{V  |                     |dd          }|                     |d          }|t          | j        dz             |                     |          }|d         |                     ||          d|d}|                     |                     ||                     d{V }| 	                    |dg           }| 
                    |di           }	|                     |	|          S )	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>`
        NrM   r  z, repayCrossMargin() requires an id parameterrepay)r-  r  r  r  r  r   )rV  r  r  r3   rM   r  r  r5  r  r  r  r6  )
r  ro  r  r  rM   r  r%  r  r  r7  s
             r  repay_cross_marginzokx.repay_cross_margin?  s&      !!!!!!!!!g6664((:#DG.\$\]]]==&&D>--dF;;	
 
 ;;DKKQW<X<XYYYYYYYY  ~~h33~~dAr**%%dH555r  c                     |                      |d          }d |                     ||          |                     |d          d d d |dS )Nr-  r  )rM   r  r  r  r  r  r  )r  r  r  )r  r  r  rJ  s       r  r6  zokx.parse_margin_loank  s]     %%dE22
//
HEE&&tU33
 
 	
r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             |                     |d                   }|                     |d         d          }|||d         d}|                     |                     ||                     d{V }|                     |d	g           }| 	                    |d
         |          S )ah  
        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  rM   )r  r  r  r  r   )
rV  r  r4   rM   r  r  publicGetPublicOpenInterestr  r  parse_open_interest)	r  r  r  r  r  r  r%  r  r  s	            r  fetch_open_interestzokx.fetch_open_interest  s      !!!!!!!!!V$$j! 	^TW'\\]]]..vf~>>vf~u55Tl
 

 99$++gv:V:VWWWWWWWW  ~~h33''Q888r  c                 ~  K   |                                   d{V  |                     |ddd          }d}||                     |d                   }d}|                     d||d          \  }}d}|dk    rd}n|d	k    rd
}d|i}|                     |d          }|||d<   |                     |d          }|||d<   |d
k    r||t          | j        dz             |                     |                     ||                     d{V }	| 	                    |	dg           }
| 
                    |
|          S )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\   rD  r]   rE  r^   rF  r  r  r  zT fetchOpenInterests() requires either uly or instFamily parameter for OPTION marketsr  )rV  r  r  handle_sub_type_and_paramsr  r4   rM   r>  r  r  parse_open_interests)r  r~  r  r  r  r  r%  r  r  r  r  s              r  fetch_open_interestszokx.fetch_open_interests  s      !!!!!!!!!%%gtT4@@[[,,F
!<<=QSY[acijj
F!! HH!!H#X.vu--? GEN%%fl;;
!$.GL!xCKJ4FTW'}}~~~99$++gv:V:VWWWWWWWW  ~~h33((w777r  r   c                   K   |                      | j        di           }|                      |di           }|                     |||          }|dk    r#|dk    r|dk    rt          | j        dz             |                                  d{V  d}d}	|| j        v s	|| j        v r|                     |          }	|	d         }n| 	                    |          }
|
d	         }||d
}d}d}| 
                    d|	|          \  }}|dk    r0|                     |                     ||                     d{V }nj|||d<   |                     |d          }|||d<   |                     |dg          }|                     |                     ||                     d{V }|                     |dg           }|                     |d||          S )aV  
        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  rM   )r-  r  r^   r  r  r  r  )r  rw  r  r4   rM   rV  r(  r  r  r  r  *publicGetRubikStatOptionOpenInterestVolumer  r  r  -publicGetRubikStatContractsOpenInterestVolumer  parse_open_interests_history)r  r  r  r  rf  r  rw  r   rJ  r  r  r%  r  r  r  r  s                   r  fetch_open_interest_historyzokx.fetch_open_interest_history  s0      ../I2NN^^G\2>>
$$ZIFF	d!2!2yD7H7HTW'ooppp!!!!!!!!!
dl""$2D(D(D[[((F)JJ}}V,,H!$J
 
 99:TV\^deef8!LLT[[Y`bhMiMijjjjjjjjHH #( %%fg66E !&6G955!OOPTP[P[\cekPlPlmmmmmmmmH ~~h3300tUEJJJr  c                    |                      |d          }|                     ||          }|                     |d          }|                     |d|          }d }d }d }d }	|                      | j        d          }
t	          |t
                    r`|
dk    r-|                     |d          }|                     |d          }no|                     |d          }	|                     |d          }nB|                     |d          }|                     |d	          }|                     |d
          }	|                     |                     |          ||||	|| 	                    |          |d|          S )Nr  r  r   r1  r^   r   r   oiCcyoioiUsd)r  rt  ru  openInterestAmountopenInterestValuer  r  r  )
r  r  r  rw  r  r2  r  safe_open_interestr  r  )r  r-  r  rM   timer  rt  ru  rN  rO  r  s              r  r?  zokx.parse_open_interest  s   * h11!!"f--  400%%h488	
! m<<h%% 
	Dx%)%5%5h%B%B"!--h::

$($4$4Xq$A$A!"..x;;))(G<<J!%!1!1(D!A!A $ 0 07 C C&&&&r**$&"4!2"Y//	(
 	(
 	 	 		r  enablec                     t          t          |                               |           || j        d<   |rd| j        d<   d S d| j        v r"|                     | j        d          | _        d S d S )Nr  r  zx-simulated-trading)r}  rJ   set_sandbox_moderw  r  r  )r  rR  r  s     r  rT  zokx.set_sandbox_modeS  sz    c4))&111&,]# 	J25DL.///"dl2299T\3HIIDLLL 32r  r  c                 R  K   |                                   d{V  i }|-|                     |          }d                    |          |d<   |                     |                     ||                     d{V }|                     |d          }|                     ||          S )ao  
        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  r-  r  )rV  currency_idsrE  r0  r  r  parse_deposit_withdraw_fees)r  r  r  r%  r  r  r  s          r  fetch_deposit_withdraw_feeszokx.fetch_deposit_withdraw_fees[  s       !!!!!!!!!##E**C XXc]]GEN77GV8T8TUUUUUUUUX ~~h////e<<<r  c                    i }|                      |          }t          dt          |                    D ]!}||         }|                     |d          }|                     |          }||                     ||          r|                     ||          }	|	|                     i           ||<   |||         d         |<   |                     |d          }
|
|
                    d          }|                     |d          }| 	                    |d          }||dnd d	}d d d	}| 
                    ||          }||d
||         d         |<   #t          |                                          }t          dt          |                    D ]>}||         }|                     |          }|                     ||         |          ||<   ?|S )Nr   r-  r  r:  r  r   r>  F)r>  rp  )r   rC  r  )market_codesr  r  r  r  r  r7  deposit_withdraw_feer  r  rF  r2  r?  r  $assign_default_deposit_withdraw_fees)r  r  r  currencyIdKeydepositWithdrawFeesr  feeInforJ  ro  depositWithdrawFeer:  
chainSplitrM  withdrawFeewithdrawResultdepositResultrP  depositWithdrawCodesr  s                      r  rW  zokx.parse_deposit_withdraw_fees  s   , %'!!%((q#h--(( 	 	AqkG))'599J**:66D4==u#=#=%)__5H$%O%O"%-040I0I"0M0M'-@G#D)&1*=(('::="[[--
 OOJ::	"..w>>&,7,C%%$( (
  "&' ' #55iFF .,F F#D)*5kB  $$7$<$<$>$>??q#23344 	w 	wA'*D}}T**H(,(Q(QRefjRkmu(v(v%%""r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d}|                     d||          \  }}|dk    r|dk    rt          | j        dz             |                     |          |d         dz   |d	         z   d
}||dz
  |d<   |||d<   |                     |                     ||                     d{V }| 	                    |dg           }	| 
                    |	|          }
|                     |
d          }|                     ||d         ||          S )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  rf  r  r  r  )r3   rM   rV  r  r  r>   r  &publicGetPublicDeliveryExerciseHistoryr  r  parse_settlementsr  r  )r  r  r  rf  r  r  r  r%  r  r  settlementsr  s               r  fetch_settlement_historyzokx.fetch_settlement_history  s      >#DG.d$deee!!!!!!!!!V$$99:RTZ\bccf8 0 0tw)nnooo77==(#c)F9,==
 
  %	GH$GGDDT[[QXZ`EaEabbbbbbbb& ~~h33,,T6::k;77009I5RWXXXr  c                     |                      |d          }||                     ||          |                     |d          d d dS )NinsIdr  )r  r  rQ  r  r  )r  r  r  )r  
settlementr  r  s       r  parse_settlementzokx.parse_settlement  sW     ##J88&&x88%%j$77
 
 	
r  c                    g }t          dt          |                    D ]}||         }|                     |d          }|                     |dg           }t          dt          |                    D ]]}|                     ||         |          }	|                    |                     |	||                     |          d                     ^|S )Nr   r  r  )r  r  )r  r  r  r  rn  r  r  r  )
r  ri  r  r  r  rH  r  r  rL  rm  s
             r  rh  zokx.parse_settlements  s     q#k**++ 		 		ANE))%66InnUIr::G1c'll++  !2271:vFF
dkk*!* $Y 7 77 7       r  c                   K   |                                   d{V  d}|                     dd|          \  }}||dk    rd}|dk    r#|dk    r|dk    rt          | j        dz             d|                     |          i}|                     |                     ||                     d{V }|                     |d	g           }|d
         S )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   rZ   r^   r\   r]   z7 fetchUnderlyingAssets() supports contract markets onlyr  r  r   )rV  r  r>   rM   r  publicGetPublicUnderlyingr  r  )r  r  r  r%  r  underlyingss         r  fetch_underlying_assetszokx.fetch_underlying_assets3  s      !!!!!!!!!
!??@WY]_eff
FJ&$8$8!J(""v)=)=JRZDZDZtw)bbccc77
CC
 77GV8T8TUUUUUUUU nnXvr::1~r  c                 J  K   |                                   d{V  |                     |          }|d         }|                    d          }|d         d         |d         d         |                     |d          d}|                     |                     ||                     d{V }|                     |d	g           }t          d
t          |                    D ]>}	||	         }
|                     |
d          }||k    r| 	                    |
|          c S ?dS )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>`
        NrM   r  r  r  r  r   )r  r  r  r  r   r  )
rV  r  r  r  publicGetPublicOptSummaryr  r  r  r  parse_greeks)r  r  r  r  r  r  r%  r  r  r  rH  entryMarketIds               r  fetch_greekszokx.fetch_greeksW  sH      !!!!!!!!!V$$$<nnS))&>%( .6''Q77
 

 77GV8T8TUUUUUUUU< ~~h33q#d))$$ 	8 	8AGE ,,UH==M((((77777 )tr  c                 2  K   |                                   d{V  i }|                     |dddd          }d}|t          |          }||dk    rU|                     |d          }|||d<   |                     |d          }|||d<   ||t	          | j        dz             d}|y|dk    rs|                     |d                   }|d         }|                    d	          }	|d
         d         |d<   |d
         d         |d<   |                     |	d          |d<   |                     |ddg          }| 	                    | 
                    ||                     d{V }
|                     |
dg           }|                     ||          S )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   rM   r  r  r   r  r  )rV  r  r  r  r4   rM   r  r  r  ru  r  r  parse_all_greeks)r  r~  r  r%  symbolsLengthr  r  r  r  r  r  r  s               r  fetch_all_greekszokx.fetch_all_greeks  s      !!!!!!!!!%%gtT4FFLLMO!!3!3""6511C!$))&,??J%(2%*"4 +l!lmmm!!WQZ00!$<&nnS11!'!6(.v|(D%%)%5%5k1%E%E	"6E<#89977GV8T8TUUUUUUUU< ~~h33$$T7333r  greeksc                 8   |                      |d          }|                     |d          }|                     ||          }i d|d|d|                     |          d|                     |d          d|                     |d          d|                     |d          d	|                     |d	          d
d dd dd d|                     |d          d|                     |d          d|                     |d          dd dd dd dd d |dS )Nr  r  r  r  r  deltagammathetavegarhobidSizeaskSizebidImpliedVolatilitybidVolaskImpliedVolatilityaskVolmarkImpliedVolatilitymarkVolbidPriceaskPricerv  rj  )underlyingPricer  )r  r  r  r  r  )r  r}  r  r  r  r  s         r  rv  zokx.parse_greeks  s   0 %%fd33	##FH55!!(F33
f

 Y//
 T%%fg66	

 T%%fg66
 T%%fg66
 D$$VV44
 4
 t
 t
 #D$4$4VX$F$F
 #D$4$4VX$F$F
 $T%5%5fi%H%H
 
 
  !
" #
$  $'
 
 
 	
r  c                 ~  K   |                                   d{V  |                     |          }|                     |d          }|                     |d          }d}|                     d|d          \  }}|d         |d}||dk    rd	|d
<   n|dk    rd|d
<   n||d
<   |||d<   | |                     |          }	|	d         |d<   |                     |                     ||                     d{V }
|                     |
dg           }|                     |d          }| 	                    ||          S )aJ  
        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>`
        Nr  ro  rf   r"  rM   rA  r  r(  r&  r
  r'  r  r-  r  r   )
rV  r  r  r  r  privatePostTradeClosePositionr  r  r  rm  )r  r  r  r  r  r  ro  rV  r%  r  r  r  r  s                r  close_positionzokx.close_position  s     $ !!!!!!!!!V$$((AA//
!??QWY`aa
FTl!
 
 %+	""%,	""%)	"$!.GI}}T**H%d^GEN;;DKKQW<X<XYYYYYYYY$ ~~h33tQ''v...r  c                 `  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |d|          S )a  
        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  rM   r  r   )rV  r  r{  r  r  r  parse_option)r  r  r  r  r%  r  r  r:  s           r  fetch_optionzokx.fetch_optionE  s       !!!!!!!!!V$$fTl
 33DKK4P4PQQQQQQQQ6 &"55vq"--  f555r  c                 :  K   |                                   d{V  |                     |          }|d         dz   dd}|                     |                     ||                     d{V }|                     |dg           }|                     |dd          S )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>`
        Nro  z-USDrF  )r  r  r  r  )rV  r  r  r  r  parse_option_chain)r  ro  r  r  r%  r  r  s          r  fetch_option_chainzokx.fetch_option_chains  s       !!!!!!!!!==&&F#f, 
 
 44T[[&5Q5QRRRRRRRR6 &"55&&vtX>>>r  r:  c                    |                      |d          }|                     ||          }|                     |d          }i d|dd d|d         d|d|                     |          dd d	d d
|                     |d          d|                     |d          dd dd d|                     |d          dd dd dd d|                     |d          dd S )Nr  r  r  r  r  r  r  impliedVolatilityopenInterestr  rd  r  rh  midPricerv  rj  rM  r  ro  rp  rt  r]  ru  )r  r  r  r  r  )r  r:  r  r  r  r  s         r  r  zokx.parse_option  sf   * ##E844!!(F33%%eT22	
E

 fX&
 	

 Y//
  
 D
 ((88
 ((88
 
 
 ))%88
 t
 d
 $
  $**5+>>!
" 4#
 	
r  fromCodetoCodec                 t  K   |                                   d{V  |                                |                                |                                |                     |          dd}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |d|          }	|                     |	          }
|                     |d|          }|                     |          }| 	                    ||
|          S )aJ  
        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  )
rV  r  r:  $privatePostAssetConvertEstimateQuoter  r  r  r  r  parse_conversion)r  r  r  r  r  r%  r  r  r  fromCurrencyIdfromCurrencytoCurrencyId
toCurrencys                r  fetch_convert_quotezokx.fetch_convert_quote  s;      !!!!!!!!!~~'' ((**622
 
 BB4;;wX^C_C_````````0 ~~h33a,,))&)XFF}}^44''
FCC]]<00
$$V\:FFFr  c                 
  K   |                                   d{V  |||||                     |          dd}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }	|                     |	d|          }
|                     |
          }|                     |	d|          }|                     |          }|                     |	||          S )au  
        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  szCcyrU  r  r  r   r  r  )	rV  r:  privatePostAssetConvertTrader  r  r  r  r  r  )r  rM   r  r  r  r  r%  r  r  r  r  r  r  r  s                 r  create_convert_tradezokx.create_convert_trade   s"      !!!!!!!!!''//
 
 ::4;;wPV;W;WXXXXXXXX. ~~h33a,,))&)XFF}}^44''
FCC]]<00
$$V\:FFFr  c                   K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |d          }|                     |d          }	d}
d}||                     |          }
|	|                     |	          }|                     ||
|          S )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  )rV  privateGetAssetConvertHistoryr  r  r  r  r  r  )r  rM   ro  r  r%  r  r  r  r  r  r  r  s               r  fetch_convert_tradezokx.fetch_convert_trade7   s      !!!!!!!!!
 ;;DKKQW<X<XYYYYYYYY, ~~h33a,,))&)<<''
;;
%==88L#|44J$$V\:FFFr  c                 N  K   |                                   d{V  i }|                     d||          \  }}|||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||dd||          S )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  rf  r  r  r  )rV  r  r  r  r  parse_conversions)r  ro  r  rf  r  r%  r  rowss           r  fetch_convert_trade_historyzokx.fetch_convert_trade_historyh   s       !!!!!!!!!227GVLL %GH$GG;;DKKQW<X<XYYYYYYYY, ~~h33%%dD)ZPUVVVr  
conversionr  r  c                    |                      |dd          }|                     |d          }|                     ||          }|                     |d          }|                     ||          }|||                     |          |                     |g d          ||                     |dd          ||                     |dd	          |                     |d
d          d d
S )N	quoteTimer  r  r  )clQReqIdr  r  baseSz
fillBaseSzquoteSzfillQuoteSzcnvtPxr  )
r  r  r  rM   r  
fromAmountr  toAmountrQ  r>  )r  r  r  r  r   r9  )	r  r  r  r  r  fromCoinr  r5  r  s	            r  r  zokx.parse_conversion   s    j ''
KFF	##J	::**8\BBj*55((Z88"Y//$$Z1S1S1STT$,,Z<PP **:y-PP''
HhGG
 
 	
r  c                   K   |                                   d{V  |                     |           d{V }i }|                     |dg           }t          dt	          |                    D ]}}||         }|                     |d          }|                     |          }|||dddddddd|                     |d          |                     |d          dddddddddd	||<   ~|S )
a6  
        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   r-  r  rc  r  )r  r   rC  )r  rM   ro  r  r  rN   r  rC  r   r>  rp  r  r
  )rV   privateGetAssetConvertCurrenciesr  r  r  r  r  r  )	r  r  r  r  r  r  rH  rM   ro  s	            r  fetch_convert_currencieszokx.fetch_convert_currencies   s\      !!!!!!!!!>>vFFFFFFFF ~~h33q#d))$$ 	 	AGE!!%//B**2..D  !  $//u==#//u== 
  $#! !
  $#      5 F4LL8 r  httpCodereasonr   r)  r  r  c
                 ,   |sd S |                      |d          }
|
dk    r|
dk    r| j        dz   |z   }|                     |dg           }t          dt	          |                    D ]z}||         }|                      |d          }|                      |d          }|                     | j        d	         ||           |                     | j        d
         ||           {|                     | j        d	         |
|           t          |          d S )Nro  r  r   r  r   r  sMsgr  r  )	r  rM   r  r  r  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr.   )r  r  r  r   r)  r  r  r  requestHeadersrequestBodyro  feedbackr  r  errorr  messages                    r  handle_errorszokx.handle_errors!  s&    	4* &11CKKdckkw}t+H>>(FB77D1c$ii(( b bQ ,,UG<<	**5&9944T_W5MyZbccc44T_W5MwX`aaaa001I4QYZZZ)))tr  c                 N  K   |                                   d{V  |                     |d          }|t          | j        dz             |dk    }|rdnd}|r|rd}nt	          | j        dz   |z             |d	d
}	|                     |d          }
|                     |d          }|||	d<   |||	d<   |
|
|	d<   d}|                                 }|dz
  }|dz
  }|||k    r0|                     | 	                    |	|                     d{V }nM||k    r0| 
                    | 	                    |	|                     d{V }nt	          | j        dz             |                     |d          }|                     |          }|                     ||||          S )aD  
        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 argumentr  160161162z* cannot fetch margin adjustments for type r@  )subTyper  r  r  rf  endTimei $l    X zS fetchMarginAdjustmentHistory() cannot fetch margin adjustments older than 3 monthsr  )rV  r.  r3   rM   r4   r  r  r  r2  r  r  r  parse_margin_modificationsr  )r  r  r  r  rf  r  r  isAddr  r%  r  r  r  
oneWeekAgothreeMonthsAgor  modificationss                    r  fetch_margin_adjustment_historyz#okx.fetch_margin_adjustment_history=!  s      !!!!!!!!!~~ff--<#DG.h$hiii +%%e 	` ` +W!WZ^!^___!
 
 !!&'2267++#(GK $GG!&GI!!9_
z)Muz11!88Wf9U9UVVVVVVVVHH^##!??GU[@\@\]]]]]]]]HHTW'||}}}V ~~h//77==00uUUUr  c                 N  K   |                                   d{V  |                     |d          }|                     |d          }|                     |g d          }|d}d|i}|;t	          |          }|dk    r&|                     |d                   }	|	d	         |d
<   |||d<   |||d<   |                     |                     ||                     d{V }
|                     |
d          }| 	                    |||          }| 
                    |||          S )u|  
        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>`
        NrV  r  )r  rV  r  r  rf  r   r   rM   r  r  r  )rV  r  safe_string_upperr  r  r  rN  r  r  parse_positionsfilter_by_since_limit)r  r~  r  rf  r  rV  r  r%  r{  r  r  r  rS  s                r  fetch_positions_historyzokx.fetch_positions_history!  s`     ( !!!!!!!!!%%fl;;
))&*==6#F#F#FGG=EU
 LLM!!WQZ00$*4L!!!+GI"*GJ??GU[@\@\]]]]]]]]D ~~h//((w??	)))UEBBBr  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |dd          }|                     |d          }|||d<   |||d<   |||d<   |||d<   |                     |                     ||                     d{V }	|                     |	d	g           }
g }t          d
t          |
                    D ]J}|
|         }|	                    | 
                    |d
          | 
                    |d          d           K|                     ||          S )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  rM   r  r  r  r  rf  r  r   r   )r  longShortRatio)rV  r  r  r  8publicGetRubikStatContractsLongShortAccountRatioContractr  r  r  r  r  r  parse_long_short_ratio_history)r  r  r  r  rf  r  r  r%  r  r  r  r  r  rH  s                 r  fetch_long_short_ratio_historyz"okx.fetch_long_short_ratio_history!  s      !!!!!!!!!V$$fTl
 ""67E::67++"GEN  )GH$GG$GGVVW[WbWbcjlrWsWstttttttt ~~h33q#d))$$ 	 	AGEMM!--eQ77"&"2"25!"<"<      2266BBBr  c           	          |                      |d          }d }||d         }||||                     |          d |                     |d          dS )Nr  r  r  )r  r  r  r  r  r  )r  r  r  )r  r  r  r  r  s        r  parse_long_short_ratiozokx.parse_long_short_ratio"  sj    %%dK88	H%F"Y//"..t5EFF
 
 	
r  )NNNN)N)NN)__name__
__module____qualname__r   r~  r  r   r  r  r  r!   r+   r  r  r   r  r-   r   r  r  r  dictr  r  r   r7  r   rQ  r   rY  r#   ry  r}  r"   r$   r  r  r  r(   r  r  r2  r  r  r  r  r  r  r)   r  r  r   r  floatr  r  r   r   r   ri  r  r   rw  r  r  r  r  r  r   r  r  r  r   rm  r  r  r  r  r  r  r   r  r  r  r   r  r  r  r*   r   r!  r$  r'  r+  r2  r  r   rD  rC  rL  r    rT  rW  rJ  r,   r   r  r  r  r  r  r%   r  r  r  r  r&   r  r  intr  r  boolr  r  r   r  r
   r  r  r  r	  r  r   r  r  r  r  r   r!  r   r   r.  r2  r8  r;  r6  r@  r'   rD  rI  r?  rT  rX  rW  rj  rn  rh  rs  r   rx  r|  rv  r  r   r  r   r  r  r	   r  r  r  r  r  r  r  r  r  r   r  r  __classcell__)r  s   @r  rJ   rJ   )   sG       m# m m m m m m^+ OS[]lp h h hV hux h h h h h h; ; ;;
3 ;
 ;
 ;
 ;
zU UC U URU Ujm U  zI U U U U U U )+ 4 4 4 4l ') . .S . . . .. +- = =g = = = =~D D D *,  V    4`4 `F ` ` ` `D 8: =6 =6 =6 =6~ -/ D1 D1: D1 D1 D1 D1L6t 6 6 6 6 6p @DB 5? 5?S 5? 5?S\ 5? 5? 5? 5?nH H4 H H6 H H H HT 68 ,0 ,0 ,0F ,0 ,0 ,0 ,0\ 6:" 54 547 54 54 54 54 54n :< B BS B B B B BB :>b 4 4w 4W 4 4 4 4:X X Xv X X X X Xt <@d[] G= G= G=S G= G=bfglbm G= G= G= G=R
 
 
4 
 
 
 
4 ?CQUdhqs fH fH fH fH3 fH^a fHx|  ~B  yC fH fH fH fHP >BPTcgpr @Y @Ys @Y# @Y]` @Y @Y @Y @YD8 8 8) ) )2) ) )
 
T 
6 
EX 
 
 
 
0 ;= -5 -5c -5AT -5 -5 -5 -5^ *, {@ {@ {@ {@ {@ {@z XZ f fc f f f f f* Y[ g gs g% g g g g* os{} @, @,3 @,i @,y @,Z_ @,hk @, @, @, @,D mqy{ 9 9 9I 9Y 9X] 9fi 9 9 9 9v FH /' /'$|*< /' /' /' /'b FJQU^` J, J,S J, J, J, J,X fjx|  FH ? ?3 ? ?9 ?I ?_b ?ru ? ? ? ?B 9=R &/ &/S &/# &/ &/ &/ &/P	 	 	 AER _I _ItCy _I# _I _I _I _IB Y[ MG MGd;N6O MG MG MG MG^ BD  S    :	: 	: 	: 	: 	:R R Rv R R R R Rh 8<B O/ O/C O/ O/ O/ O/ O/b 59tZ^gi Z= Z=c Z= Z=TW Z=nrsxny Z= Z= Z= Z=x 9=4^bkm m= m=# m=S m=X[ m= m= m= m=^ 7;\`ik n= n= n=3 n=VY n=ptuzp{ n= n= n= n=` 37TX\eg BD BDC BDs BDRU BD BD BD BDH ?CQUdhqs ^ ^3 ^ ^3 ^^a ^ ^ ^ ^, .2SW`b p? p?s p?# p?S p?gklwgx p? p? p? p?d3 3 3 B Bt Bx B; B B B BH]
 ]
h ]
R` ]
 ]
 ]
 ]
~ JL (0 (0S (0PTUcPd (0 (0 (0 (0T =? / / /> / / / /< QU]_ 9= 9=3 9= 9= 9=# 9=do 9= 9= 9= 9=v 04$UYbd KM KM KMC KMs KMimnyiz KM KM KM KMZ 8<B 9 9c 9 9 9 9 90 37TX\eg CM CMC CMs CMRU CMlpq|l} CM CM CM CMJ ;?r +2 +2 +2C +2 +2 +2 +2Z+:s +: +: +: +:Z[
 [
T [
X [
Q\ [
 [
 [
 [
z 8: '1 '13 '1h '1 '1 '1 '1R
 
t 
V 
x 
 
 
 
2 8: H5 H53 H5 H5 H5 H5T 8<B Te TeW Te4PX> Te Te Te Tel DF < <s < < < <_ _t _V _ _ _ _B ac 9: 9:3 9: 9:C 9:TW 9:gt 9: 9: 9: 9:vJ
 J
t J
x J
= J
 J
 J
 J
X:C :C : : : : 9=R - -s -# -M - - - -> 154VZce :O :O# :OS :OPS :Ojno|j} :O :O :O :Ox &eBSW 1P 1P 1P 1Pf:
 :
6 :
[ :
 :
 :
 :
x? ? ? @B 
= 
=3 
=k 
= 
= 
= 
= <> $6 $6s $6+ $6 $6 $6 $6L <@ 7 7 7| 7 7 7 7B 9=4^bkm ]O ]O# ]OS ]OX[ ]O ]O ]O ]O~ ?C2 4 43 4 4 4 4 4l 7;2 
 
 
 
 
 
@ CGr  d C    B DHPR - - -S - - - -^ 57  ;K    : ?A , ,# ,_ , , , ,B
 
 
 
 
 
(# # #8 7;\`ik 'K 'K3 'KVY 'K 'K 'K 'KR GKY]fh (H (HC (H (HSV (H (H (H (HT LN   Rd    BG
 G
d G
F G
N` G
 G
 G
 G
R FH Q Q# Qu QL^ Q Q Q Q CE N Ns NE NI[ N N N N EG 4> 4> 4>4P\K] 4> 4> 4> 4>l& & &$|J\ & & & &P 7;$]apt} 8Q 8Q 8QC 8QWZ 8Qjm 8Q  EI  JX  EY 8Q 8Q 8Q 8Qt
 
$ 
 
. 
 
 
 
" JL $6 $6c $65 $6 $6 $6 $6L BD *6 *6S *6 *6 *6 *6X
 
 
 
 
 
. =? &9 &9 &9 &9 &9 &9P =A 38 38' 38P] 38 38 38 38j HLZ^mqz| >K >K >KTW >Kgj >K >K >K >K@2 2F 2 2 2 2hJt J J J J J J BFb <= <=w <= <= <= <=|9# 9# 9# 9#v <@daenp 2Y 2YS 2Y 2Y[^ 2Y 2Y 2Y 2Yh
 
 
"  4 46 " " " "H 68 7 7 7F 7 7 7 7r 9=R D4 D4g D4DQWL D4 D4 D4 D4L/
 /
4 /
 /
6 /
 /
 /
 /
b CGr </ </3 </i </V[ </ </ </ </| 68 ,6 ,6 ,6F ,6 ,6 ,6 ,6\ :< -? -?S -? -? -? -? -?^*
 *
$ *
( *
6 *
]c *
 *
 *
 *
X SW_a 2G 2G# 2Gs 2GC 2Gfp 2G 2G 2G 2Gh ]aik 3G 3GS 3GC 3G 3GVY 3Gpz 3G 3G 3G 3Gj >B" /G /GC /Gs /GQ[ /G /G /G /Gb =Atbfoq +W +Wc +W +W\_ +Wvz  |F  wG +W +W +W +WZE
 E
4 E
x E
\d E
pz E
 E
 E
 E
N 57 : :: : : : :x#c #3 #S ## #X\ #dg # # # #J CGTXgkz~  HJ \V \VC \Vc \Vad \Vtw \V  OS  Tf  Og \V \V \V \V| @DRVeirt JC JCW JCC JC_b JCy}  G  zH JC JC JC JCX BFX\ko  C  LN 1C 1C3 1CRU 1Ceh 1Cx{ 1C  SW  Xf  Sg 1C 1C 1C 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>r     sw   6 5 5 5 5 5 ) ) ) ) ) )   w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w  w       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . 4 4 4 4 4 4 / / / / / / . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * 0 0 0 0 0 0 ) ) ) ) ) ) ) ) ) ) ) ) + + + + + + . . . . . . 1 1 1 1 1 1 * * * * * * ) ) ) ) ) ) + + + + + + * * * * * * 4 4 4 4 4 4 % % % % % %}G
 }G
 }G
 }G
 }G
(K }G
 }G
 }G
 }G
 }G
r  