
    !:hUY                       d dl mZ d dlm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 d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z  d d
lm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dlm+Z+ d dlm,Z, d dlm-Z- d dlm.Z. d dlm/Z/ d dlm0Z0 d dl1m2Z2 d dl3m4Z4  G d dee      Z5y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)NetworkError)RateLimitExceeded)ExchangeNotAvailable)OnMaintenance)InvalidNonce)RequestTimeout)CancelPending)	TICK_SIZE)Precisec                   <    e Zd Zdef fdZi fdefdZi fdee   fdZ	de
defdZi fdefdZdi fd	ed
edefdZdRd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dRde
dedefdZddi fd	eded
edee   fdZdRdedefdZdddi fd	eded
edee   fdZd Zi fdefdZd Z d Z!i fd	ede"fdZ#di fd	ede$de%d e"d!e&f
d"Z'di fd	ede$de%d e"d!e&f
d#Z(di fd$ed	e)fd%Z*d& Z+di fd	e)fd'Z,d(e)fd)Z-dRd*e
dede.fd+Z/di fd$ed	e)fd,Z0dddi fd	e)ded
edee.   fd-Z1dddi fd	e)ded
edee.   fd.Z2dRd/e3de4fd0Z5i fd1ede4fd2Z6i fd1edee4   fd3Z7i fd1ed e"d4ed5ede8f
d6Z9dRd7e
d/e3de8fd8Z:d(e)de)fd9Z;di fd1ed e"d:ede<fd;Z=dddi fd1e)ded
edee<   fd<Z>dddi fd1e)ded
edee<   fd=Z?d(e)fd>Z@dRd?e
d/e3de<fd@ZAdddi fd	e)ded
efdAZBdddi fd$ed	e)ded
efdBZCdddi fd1e)ded
edeeD   fdCZEdD ZFdRdEe
d/e3deDfdFZGdGdHi ddfdIZHdJ ZIdKeJdLedMedNedOe
dPefdQZK xZLS )Sokcoinreturnc                    | j                  t        t        |          i dddddddg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d0dd1di d2dd3dd4dd5dd6dd7dd8dd9d d:dd;dd<dd=dd>dd?dd@ddAd dBddddddddCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYidZd[d\d]dXd^id_d`dadbdbdcdcdcdddedfdgddbdedhii didjdkdjdldcdmdcdndjdodpdqdedrdbdsdbdtdbdudvdwdvdxdedydzd{dzd|dvd}dvi d~dvddvddvddzddzddfddfddzddddzddzddzddddzddzddzddfdfdfdfdfdi didjddddjddddjdddrdbddbddbddvdudvddvddvddvddvddzddzdzdzdfddddd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ddddddddddddddddd dddddddddddid	d d dd d ddddddddddddddddi 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        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        d.t         d/t        d0t        d1t        d2t        d3t        i d4t        d5t         d6t        d7t        d8t        d9t         d:t        d;t        d<t        d=t        d>t        d?t        d@t        dAt        dBt
        dCt
        dDt        i dEt        dFt        dGt        dHt        dIt        dJt        dKt        dLt        dMt        dNt        dOt        dPt        dQt        dRt        dSt        dTt        dUt        i dVt        dWt        dXt        dYt        dZt        d[t        d\t        d]t        d^t        d_t        d`t        dat        dbt        dct        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        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        t
        t
        t        t*        t        t
        t
        t
        t        t
        t
        t
        dt        t        dddt,        dddiddgddd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      S (  Nidr1   nameOKCoin	countriesCNUSversionv5	rateLimit   proThasCORSspotmarginFswapfutureoptioncancelOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTriggerOrderfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchLedgerfetchMarketsfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionsfetchTickerfetchTickers	fetchTimefetchTradesfetchTransactionsfetchWithdrawals)reduceMarginrepayCrossMarginrepayIsolatedMargin	setMargintransferwithdraw
timeframes1m3m5m15m30m1H2H4H6H12H1D1W1M3M)rz   r{   r|   r}   r~   1h2h4h6h12h1d1wr   r   hostnamez
okcoin.comurlszdhttps://user-images.githubusercontent.com/51840849/87295551-102fbf00-c50e-11ea-90a9-462eebba5829.jpgrestzhttps://www.{hostname}zhttps://www.okcoin.comzhttps://www.okcoin.com/docs/en/z https://www.okcoin.com/coin-feeszIhttps://www.okcoin.com/account/register?flag=activity&channelId=600001513zhttps://testnet.okex.com)logoapiwwwdocfeesreferraltestr   get   g      ?g?   
   2   )zmarket/tickerszmarket/tickerzmarket/bookszmarket/candleszmarket/history-candleszmarket/tradeszmarket/history-tradeszmarket/platform-24-volumezmarket/open-oraclezmarket/exchange-ratezpublic/instrumentszpublic/timeztrade/ordergUUUUUU?ztrade/orders-pendingztrade/orders-historyztrade/orders-history-archiveztrade/fillsztrade/fills-historyg@ztrade/fills-archiveztrade/order-algoztrade/orders-algo-pendingztrade/orders-algo-historyzotc/rfq/trade   zotc/rfq/historyzaccount/balancezaccount/billsg?zaccount/bills-archivezaccount/configzaccount/max-sizezaccount/max-avail-sizezaccount/trade-feezaccount/max-withdrawalzasset/currencieszasset/balanceszasset/asset-valuationzasset/transfer-statezasset/billszasset/deposit-lightning   zasset/deposit-addresszasset/deposit-historyzasset/withdrawal-historyzasset/deposit-withdraw-statuszfiat/deposit-historyzfiat-withdraw-historyzfiat-channelzusers/subaccount/list)zusers/subaccount/apiKeyzaccount/subaccount/balanceszasset/subaccount/balanceszasset/subaccount/billsztrade/batch-ordersg?ztrade/cancel-orderztrade/cancel-batch-ordersztrade/amend-orderztrade/amend-batch-ordersgO贁N{?ztrade/cancel-algosztrade/cancel-advance-algoszotc/rfq/quotezasset/transferzasset/withdrawalzasset/withdrawal-lightningzasset/withdrawal-cancelzfiat/depositzfiat/cancel-deposit)zfiat/withdrawalzfiat/cancel-withdrawalzasset/subaccount/transfer)r   post)publicprivatefeatures)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectionr   stopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   Z   )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   gUUUUUU?)r   r   r   daysBackCanceledr   r   r   r   r   )	sandboxrJ   createOrdersrd   rg   rf   ri   rX   re   )linearinverse)rA   rC   rD   r   gMb`?gMbP?)takermakerg~jtX?)tradingrA   requiredCredentials)apiKeysecretpassword
exceptions12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5002950030500325003350035500365003750038500395004150044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5102351024510255102651030510315103251033510375103851044510465104751048510495105051051510525105351054510565105851059511005110251103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511565115951162511635116651174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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593005930159313594015950059501595025950359504595055950659507595086000160002600036000460005600066000760008600096001060011)600126001360014600156001660017600186001963999700107001370016)zInternal Server Errorzserver error)exactbroadprecisionModeoptionstypeCandles618)classicrA   fundingmainunifiedr  r  )r   r  r  r   r   )time
currenciesinstrumentsratez{instrument_id}/constituentsERC20EthereumBitcoinOmniTRON)r  BTCOMNITRC20)
re   !createMarketBuyOrderRequiresPricerc   defaultTypeaccountsByTypeaccountsByIdauth)warnOnFetchCurrenciesWithoutAuthorizationdefaultNetworknetworkscommonCurrenciesAETDefiBoxzHydro ProtocolHCMaggiezSuper BitcoinUnitradeYOYOWWinToken)	AEBOXHOTHSRMAGSBTCTRADEYOYOWIN)deep_extendsuperr1   describer   r    r*   r,   r)   r   r   r(   r   r+   r!   r$   r"   r   r%   r-   r#   r'   r.   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/okcoin.pyr@  zokcoin.describe%   s   fd < > ^
A
(^
A
H^
A
 $^
A
 t	^
A
 ^
A
 4^
A
  ::: %: 	:
 $: $: t: /: ,U: 0: t: &t: (: ': (:  "4!:" %d#:$ %:& &u':( "5):* +E+:, )%-:. #E/:0 ,U1:2 $T3:4 "45:6 &t7:8 (9:: 1%;:<  =:> &u?:@ #EA:B *5C:D $UE:F tG:H I:J  K:L dM:N "4O:P dQ:R !$S:T tU:V #DW:X  Y:Z !%[:\ t]:^ _:` Ta:b tc:d $Te:f #Dg:h !&$)',"  s:^
A
H I^
A
h i^
A
j ~4 08:g6k^
A
D *+)*(-*/27).1257.002./'("-%u- /- /	-
 7- &u- .s- .q- +A- 4Q- 4Q- (- *1-  *1!-" (#-$ 0%-& )!'-( +A)-* 1!+-, ,Q--. 1!/-2 +E3-4 )%5-6 07-8 /9-: &u;-< 21=-> 0?-@ 0A-B 3EC-D 8E-H /I-J 0K-L 'M-P 0Q-R 46795724Y-\%u -f -e	
 4V ,U 3G +A -a 5a ( ( )!  +A!" 5a#$ 21%( ')* .u+, ,127573_J#\E^
A
~ $&*(,,0$($)%*-
 *.+/ )-(-).1
 &*7 $(#'"&#(	( #($($)+/26/4#'? $B %)&+!$$&%'*/& ',#'$(*.	# ',!$#'$(*/( $(&+!$$&,2%'#'$(*/	*  #GFP ##
 ##YP^
A
` ""
 $#	a^
A
t " $u^
A
~ H H 	H
 ZH ]H ZH ^H 1H ZH -H 0H -H ]H .H  ]!H" 1#H$ Z%H& ]'H( ])H* ]+H, ]-H. ]/H0 ]1H2 ]3H4 ]5H6 ]7H8 Z9H: ];H< 1=H> -?H@ ]AHB ]CHD -EHF -GHH -IHJ ZKHL ZMHN ZOHP ]QHR ]SHT ]UHV ZWHZ ][H\ 0]H^ \_H` 0aHb 0cHd 0eHf 0gHh 0iHj ]kHl ]mHn -oHp 0qHr 0sHt 0uHv 0wHx ZyH| Z}H~ YH@ YAHB ZCHD \EHF \GHH \IHJ \KHL .MHN -OHP .QHR \SHT YUHV YWHX YYHZ \[H\ ]]H^ ]_H` ]aHb \cHd ]eHf -gHh ]iHj YkHl \mHn \oHp \qHr \sHt \uHv \wHx \yHz \{H| \}H~ \H@ \AHB \CHD \EHF \GHH \IHJ ZKHL \MHN \OHP \QHR \SHT \UHV \WHX \YHZ \[H\ \]H^ Z_H` \aHb .cHd \eHf \gHh \iHj \kHl .mHn \oHp \qHr \sHt \uHv \wHx \yHz .{H| \}H~ \H@ YAHB .CHD \EHF \GHH \IHJ \KHL \MHN \OHP \QHR \SHT ZUHV ZWHX \YHZ \[H\ \]H^ \_H` \aHb \cHd \eHf \gHh \iHj \kHl \mHn \oHp \qHr \sHt \uHv \wHx \yHz \{H| \}H~ \H@ \AHB \CHD \EHF \GHH \IHJ \KHL \MHN \OHP \QHR \SHT \UHV \WHX \YHZ \[H\ \]H^ \_H` \aHb \cHd \eHf \gHh \iHj ZkHl ZmHn \oHp \qHr \sHt \uHv \wHx ]yHz ]{H| ]}H~ \H@ \AHB ]CHD ]EHF ZGHH ]IHJ ]KHL ]MHN ]OHP ]QHR .SHT ]UHV ]WHX ]YHZ ][H\ ]]H^ ]_H` ]aHb ]cHd ]eHf ]gHh 0iHj 0kHl 0mHn ]oHp .qHt ]uHx ]yHz ]{H~ ]H@ 0AHB -CHD ]EHF -GHH ]IHJ ]KHL ]MHN ]OHP -QHR .SHT ]UHV ]WHX ]YHZ ][H\ ]]H^ ]_H` ]aHb ]cHd ]eHf ]gHh ]iHj ]kHl ]mHn ]oHp ZqHr ZsHt ZuHv ZwHx ]yHz ]{H| ]}H~ ^H@ -AHB ]CHD ]EHF ^GHH ]IHJ ]KHL ]MHN ]OHP ]QHR 0SHT ZUHV ZWHX ZYHZ Z[H\ Z]H^ ._H` ]aHb .cHf ]gHh ]iHj ]kHl ]mHn ]oHp .qHr ]sHt ]uHv ]wHx ]yHz .{H| ]}H~ \H@	 .A	HB	 .C	HD	 ZE	HF	 ]G	HH	 ]I	HJ	 ]K	HL	 ]M	HN	 ]O	HP	 ]Q	HR	 ]S	HT	 ]U	HV	 ]W	HX	 ]Y	HZ	 ][	H\	 ]]	H^	 -_	Hb	 0c	Hd	 0e	Hf	 0g	Hh	 0i	Hj	 0k	Hl	 \m	Hn	 0o	Hp	 0q	Hr	 0s	Ht	 0u	Hv	 0w	Hx	 ('.)1'''*'''O
HT
 .B$8U
N^
A
\ Y]^
A
^ I 6:!'%""##  "#! %"+#+$4< >C")'$"#	9"_^
A
d  ''#!!e^
A
 ^
 ^
	    c                     | j                  |      }| j                  |d      }| j                  |d      }| j                  |d      S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        datar   ts)publicGetPublicTime	safe_list	safe_dictsafe_integer)rA  paramsresponserF  	timestamps        rC  
fetch_timezokcoin.fetch_time  sI     ++F3 ~~h/NN4+	  D11rD  c                     ddi}| j                  | j                  ||            }| j                  |dg       }| j                  |      S )a'  

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

        retrieves data on all markets for okcoin
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        instTypeSPOTrF  )publicGetPublicInstrumentsextend
safe_valueparse_markets)rA  rL  requestrM  marketss        rC  fetch_marketszokcoin.fetch_markets  sP     
 224;;w3OP//(FB7!!'**rD  marketc                    | j                  |d      }| j                  |d      }|dk(  rd}|dk(  }|dk(  }|dk(  }|dk(  }|xs |xs |}| j                  |d      }	| j                  |d	      }
| j                  |	      }| j                  |
      }|d
z   |z   }| j                  |d      }| j                  | j                  |di       }| j                  |dd      }t        j                  |d      }| j                  |d      }| j                  |i d|d|d|d|dd d|	d|
dd d|d|d|xr t        j                  |d      dddddddddddd d |r| j                  |d      nd d d d d | j                  |d       | j                  |d!      | j                  |      d"| j                  d      | j                  |      d#| j                  |d$      d d#d d d#d |rd n|d#d%|d&
      S )'NinstIdrQ  futuresrD   rA   rC   rE   baseCcyquoteCcy/tickSzr   leverr   maxMktSzr4   symbolbasequotesettlebaseIdquoteIdsettleIdr  rB   FactiveTcontractr   ctVallistTimelotSz)amountr   minmaxminSz)r   rp  r   cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTypecreated	precisionlimitsinfo)safe_stringsafe_string_lowersafe_currency_codesafe_value_2r   r/   
string_maxsafe_numberrT  	string_gtrK  parse_number)rA  rZ  r4   r  rA   rD   rC   rE   rl  rh  ri  re  rf  rd  tickSizer   maxLeveragemaxSpotCosts                     rC  parse_marketzokcoin.parse_market  s    fh/%%fj99D("("+6+V!!&)4""6:6&&v.''0e###FH5  D)R@&&vw<((c:&&vz:{{4 0"
"0"
f0"
 D0"
 U	0"

 d0"
 f0"
 w0"
 0"
 D0"
 D0"
 dD 1 1+s C0"
 E0"
 e0"
 e0"
 d0"
  !0"
" d#0"
$ AID,,VW=t"((<**67;**84  ,,S1,,[9
  ++FG<
  
  #+4$ _0"
 0 0	rD  c                 :   | j                  d      s(| j                  d   rt        | j                  dz         y| j	                  |      }| j                  |dg       }i }| j                  |d      }t        |j                               }t        dt        |            D ]w  }||   }| j                  |      }	||   }
i }t        dt        |
            D ]  }|
|   }| j                  |d      }||j                  d	      dk\  s2|j                  d	      }| j                  |d
|      }| j                  |      }||d| j!                  |d      | j!                  |d      | j#                  |d      | j%                  | j'                  | j                  |d                  d| j#                  |d      | j#                  |d      di|d	||<    | j)                  |
d      }| j+                  |
|	|| j                  |d      dddddddddi|d      ||	<   z |S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Fr*  z fetchCurrencies() is a private API endpoint that requires authentication with API keys. Set the API keys on the exchange instance or exchange.options["warnOnFetchCurrenciesWithoutAuthorization"] = False to suppress self warning message.NrF  ccyr   chain-r   canDepcanWdminFeewdTickSzrx   minWdmaxWdrq  )	r4   networkrk  depositrx   feer|  r}  r~  r5   rp  )r~  coder4   r5   rk  r  rx   r  r|  r}  r,  )check_required_credentialsr  r   r4   privateGetAssetCurrenciesrI  group_bylistkeysrangelenr  r  findsplitnetwork_id_to_code	safe_boolr  r  parse_precisionrU  safe_currency_structure)rA  rL  rM  rF  resultdataByCurrencyIdcurrencyIdsi
currencyIdr  chainsr,  jr  	networkIdparts	chainPartnetworkCode
firstChains                      rC  fetch_currencieszokcoin.fetch_currencies?  s^    ..u5||GH#DGG  /^  %^  _  _55f=H>>(FB7DF#}}T59/4467K1c+./ .(^
..z:)*5!#q#f+. A"1IE $ 0 0 @I!-INN34G14L ) 4$($4$4UAy$I	&*&=&=i&H"+'2&*'+~~eX'F(,ug(F#'#3#3E8#D)-):):4;O;OPTP`P`afhrPs;t)u *+/+;+;E7+K+/+;+;E7+K-"' %*1-. "__VQ7
#;;" $ ,,Z@"# $!% #'#'# !)!=  t;.^ MrD  Nrd  r   c                 D   | j                          | j                  |      }d|d   i}|dn|}|||d<   | j                  | j                  ||            }| j	                  |dg       }| j	                  |di       }| j                  |d      }	| j                  |||	      S )aD  

        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-order-book

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :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
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r\  r4   r=   szrF  r   rG  )load_marketsrZ  publicGetMarketBooksrT  rU  rK  parse_order_book)
rA  rd  r   rL  rZ  rW  rM  rF  firstrN  s
             rC  fetch_order_bookzokcoin.fetch_order_book  s     	V$fTl
 }5!GDM,,T[[&-IJ, x4a,%%eT2	$$UFI>>rD  tickerc                    | j                  |d      }| j                  |d      }| j                  ||d      }|d   }| j                  |d      }| j                  |d      }| j                  |dd      }|r| j                  |d	      nd }	| j                  |d
      }
| j                  |d      }| j                  |d      }| j	                  i d|d|d| j                  |      d|d|d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd d|d|d|dd dd dd dd |
|	|d |      S )!NrG  r\  r  rd  r   open24hrA   F	volCcy24hvol24hhigh24hlow24hrN  datetimehighlowbidbidPx	bidVolumebidSzaskaskPx	askVolumeaskSzvwapopenclosepreviousClosechange
percentageaverage)
baseVolumequoteVolumer~  )rK  r  safe_marketr  safe_tickeriso8601)rA  r  rZ  rN  marketIdrd  r   r  rA   r  r  r  r  s                rC  parse_tickerzokcoin.parse_ticker  s   * %%fd3	##FH5!!(FC8!/	2~~ffe4?Cd&&v{;%%fh7
	2vx0 !
f!
!
 Y/!
 D	!

 3!
 4##FG4!
 ))&':!
 4##FG4!
 ))&':!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	rD  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j	                  |di       }| j                  ||      S )a  

        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-ticker

        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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>`
        r\  r4   rF  r   )r  rZ  publicGetMarketTickerrT  rU  r  )rA  rd  rL  rZ  rW  rM  rF  r  s           rC  fetch_tickerzokcoin.fetch_ticker  s     	V$fTl
 --dkk'6.JKx4a,6   //rD  symbolsc                     | j                  |      }ddi}| j                  | j                  ||            }| j                  |dg       }| j	                  |||      S )a  

        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-tickers

        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :param str[]|None 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>`
        rQ  rR  rF  )market_symbolspublicGetMarketTickersrT  rI  parse_tickers)rA  r  rL  rW  rM  rF  s         rC  fetch_tickerszokcoin.fetch_tickers  sd     %%g.
 ..t{{7F/KL~~h3!!$88rD  tradec                 x   | j                  |d      }| j                  |d      }| j                  ||d      }|d   }| j                  |d      }| j                  |dd      }| j                  |dd	      }| j                  |d
      }	| j                  |d      }
| j                  |d      }d }|=t	        j
                  |      }| j                  |d      }| j                  |      }||d}| j                  |d      }|dk(  rd}n|dk(  rd}| j                  ||| j                  |      |||
d ||	||d |d|      S )NtradeIdr\  r  rd  rG  fillPxpxfillSzr  sideordIdr  feeCcyru  currencyexecTypeTr   Mr   )r~  rN  r  rd  r4   orderr  takerOrMakerr  r   rp  ru  r  )	r  r  rK  safe_string_2r/   
string_negr  
safe_trader  )rA  r  rZ  r4   r  rd  rN  r   rp  r  orderIdfeeCostStringr  feeCostSignedfeeCurrencyIdfeeCurrencyCoder  s                    rC  parse_tradezokcoin.parse_trade%  sz   B eY/##E84!!(FC8!%%eT2	""5(D9##E8T:v.""5'2((6$#..}=M ,,UH=M"55mDO%+C ''z:3"LS "L"Y/( 
  	rD  sincec                 x   | j                          | j                  |      }||dkD  rd}d|d   i}d}| j                  |ddd      \  }}d}|dk(  r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  |dg       }	| j                  |	|||      S )	a}  

        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-trades
        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-trades-history

        get the list of most recent trades for a particular symbol
        :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
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr   r\  r4   rp   methodpublicGetMarketTradesrF  )r  rZ  handle_option_and_paramsr  rT  publicGetMarketHistoryTradesrI  parse_trades)
rA  rd  r  r   rL  rZ  rW  r  rM  rF  s
             rC  fetch_tradeszokcoin.fetch_tradesn  s     	V$Mus{EfTl
 66v}hXop,,11$++gv2NOH88Wf9UVH~~h3  vue<<rD  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r   r      r   r   )rK  r  )rA  ohlcvrZ  s      rC  parse_ohlcvzokcoin.parse_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
rD  rz   c                 n   | j                          | j                  |      }| j                  |      }| j                  | j                  di       }| j                  | j                  ||      }	| j                  |dd      }
|
dk(  r|dk\  r|	|
j                         z  }	|d   |	d}|||d<   d}| j                  |dd	d
      \  }}d}|d
k(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }| j                  |||||      S )a  

        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-candlesticks
        https://www.okcoin.com/docs-v5/en/#rest-api-market-data-get-candlesticks-history

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        re   timezoneUTCi`T  r4   )r\  barNr   r  publicGetMarketCandlesrF  )r  rZ  parse_timeframerU  r  r  ry   lowerr   r  rT  publicGetMarketHistoryCandlesrI  parse_ohlcvs)rA  rd  	timeframer  r   rL  rZ  durationr  r  r	  rW  r  rM  rF  s                  rC  fetch_ohlcvzokcoin.fetch_ohlcv  sB    	V$''	2//$,,bAt	9E##GZ?H$58>>##CTl
 $GG66v|XWop--224;;w3OPH99$++gv:VWH~~h3  vy%GGrD  c                 \   |d d d}t        dt        |            D ]~  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d	<   |||<    | j                  |      S )
N)r~  rN  r  r   r  balancetotalholdused	availablefree)r  r  r  r  accountsafe_balance)rA  rM  r  r  r  r  r  r  s           rC  parse_account_balancezokcoin.parse_account_balance  s    V 

 q#h-( 	#AqkG))':>J**:6DllnG#//CGG"..w?GFO"..wDGFO"F4L	#   ((rD  c                 4   | j                          | j                  dd|      \  }}i }d}|dk(  r"| j                  | j                  ||            }n!| j	                  | j                  ||            }|dk(  r| j                  |      S | j                  |      S )a!  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        rQ   Nr  )r  handle_market_type_and_paramsprivateGetAssetBalancesrT  privateGetAccountBalanceparse_funding_balanceparse_trading_balance)rA  rL  
marketTypequeryrW  rM  s         rC  fetch_balancezokcoin.fetch_balance  s     	 >>~tU[\
E
 "33DKK4OPH44T[[%5PQH& "--h77--h77rD  c                 \   d|i}| j                  |dg       }| j                  |di       }| j                  |d      }| j                  |dg       }t        dt        |            D ]  }||   }| j	                  |d      }	| j                  |	      }
| j                         }| j	                  |d      }| j	                  |d      }||+| j	                  |d	      |d
<   | j	                  |d      |d<   n
||d<   ||d
<   |||
<    ||d<   | j                  |      |d<   | j                  |      S )Nr~  rF  r   uTimedetailsr  eqavailEqavailBalr  	frozenBalr  r  rN  r  )	rU  rK  r  r  r  r  r  r  r  )rA  rM  r  rF  r  rN  r)  r  r  r  r  r  r*  r+  s                 rC  r#  zokcoin.parse_trading_balance*  sI   )x4a,%%eW5	//%B7q#g,' 	#AajG))'59J**:6DllnG!!'40B&&w	:G
"&"2"27J"G"&"2"27K"H#% ")"F4L	# ({!\\)4z  ((rD  c                 ~   d|i}| j                  |dg       }t        dt        |            D ]~  }||   }| j                  |d      }| j	                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d	      |d
<   |||<    | j                  |      S )Nr~  rF  r   r  balr  r,  r  r-  r  )rU  r  r  r  r  r  r  )	rA  rM  r  rF  r  r  r  r  r  s	            rC  r"  zokcoin.parse_funding_balanceC  s    )x4q#d)$ 		#A1gG))'59J**:6DllnG#//?GG"..w
CGFO"..wDGFO"F4L		#   ((rD  ru  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d<   d|d<   | j	                  |dd|d	|      S )
a  
        create a market buy order by providing the symbol and cost

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-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>`
        rA   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr%  	quote_ccytgtCcyrZ  buyN)r  rZ  r&   r4   create_order)rA  rd  ru  rL  rZ  s        rC  !create_market_buy_order_with_costz(okcoin.create_market_buy_order_with_costR  sj     	V$f~tww)ddee6;23&x  5$fMMrD  r  r  rp  r   c                 b   | j                          | j                  |      }| j                  ||||||      }| j                  | j                  dd      }	| j                  |d      }
|
dk(  s|
dk(  s|dk(  s|dk(  s
|dk(  s|d	k(  rd
}	|	dk(  r|g}d}|	dk(  r| j                  |      }nF|	d
k(  r| j                  |      }n/|	dk(  r| j                  |      }nt        | j                  dz         | j                  |dg       }| j                  |d      }| j                  ||      }||d<   ||d<   |S )a	  

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-place-order
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-place-algo-order
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-place-multiple-orders
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-advance-algo-order

        create a trade 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]: MARGIN orders only, or swap/future orders in net mode
        :param bool [params.postOnly]: True to place a post only order
        :param float [params.triggerPrice]: conditional orders only, the price at which the order is to be triggered
        :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 float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rJ   privatePostTradeBatchOrdersordTyper   conditionalocomove_order_stopr   twapprivatePostTradeOrderAlgoNprivatePostTradeOrderz createOrder() self.options["createOrder"] must be either privatePostTradeBatchOrders or privatePostTradeOrder or privatePostTradeOrderAlgorF  r   r  r  )r  rZ  create_order_requestr  r  r>  r=  r7  r   r4   rU  parse_order)rA  rd  r  r  rp  r   rL  rZ  rW  r  requestOrdTyperM  rF  r  r  s                  rC  r4  zokcoin.create_ordere  s   : 	V$++FD$vV!!$,,?\]))'9=i'^}-LRVZ_R_eim~e~  EI  MV  EV  \`  dj  \j0F22 iG,,11':H2255g>H4477@H  +x  !x  y  yx4a(  /ffrD  c                 4   | j                  |      }|d   ||d}| j                  |g d      }	| j                  |dd      }
| j                  |dd      }| j	                  |d|      }| j                  |d	d
      }| j                  |dd      }| j	                  |d|      }| j                  |dd
      }| j                  |dd      }| j	                  |d      }|d u}| j	                  |d      }|d u}| j                  | j                  ddd      }| j                  |dd      }d}||dk7  rd}n|}| j                  |dd      }|r6|dk(  r|d   n|d   }| j                  |d|      }| j                  |      |d<   |r|nd}||d<   |dk(  }d}| j                  ||d k(  |      \  }}| j                  |g d!      }|
d"k(  xs |d#k(  }|
d$k(  xs |d%k(  }|	d uxs |d&k(  } |d uxs |d uxs |d'k(  }!|xr |xs |d(k(  }"| j                  | j                  d)d*      }#| j                  |d)|#      }$|s|$|d)<   |s|"rd|d+<   |dk(  r|$d,k(  rd }%d}&| j                  |d-d.d      \  }&}| j                  |d/d0      }'| j                  |d/d0g      }|'| j                  ||'      }%ny|&re|t        | j                  d1z         | j!                  |      }(| j!                  |      })t#        j$                  |(|)      }*| j                  ||*      }%n| j                  ||      }%|%|d0<   nZ| j'                  ||      |d0<   nD| j'                  ||      |d0<   n.| j'                  ||      |d0<   | s|!s| j)                  ||      |d2<   |rd |d+<   n2|r	|"sd#|d+<   n'|rd%|d+<   n|s|ra|r-| j                  |g d3      }+|+t        | j                  d4z         | j)                  ||+      |d<   | j                  |g d5      },| j                  |d6      }-|-c|-d7k(  }.|-dk(  }/|.s|/st        | j                  d8z         |.r0|,t        | j                  d9z         | j)                  ||,      |d<   n(|-dk(  r#d:|d<   n|,| j)                  ||,      |d<   nd:|d<   | j                  |d;dd
      }0|0,|0d
k7  r"|0d<k7  r|0d=k7  rt        | j                  d>z         |0|d<   |r| j                  |g d?      }1|1t        | j                  d@z         | j)                  ||1      |d<   | j                  |g dA      }2| j                  |d6      }3|3c|3d7k(  }4|3dk(  }5|4s|5st        | j                  dBz         |4r0|2t        | j                  dCz         | j)                  ||2      |d<   n(|3dk(  r#d:|d<   n|2| j)                  ||2      |d<   nd:|d<   | j                  |d;d	d
      }6|6|6d
k7  r"|6d<k7  r|6d=k7  rt        | j                  dDz         |6|d	<   n| r4d&|d+<   | j)                  ||	      |dE<   |rd:n| j)                  ||      |dF<   n|!rd'|d+<   |d uxr |d u}7|7rdG|d+<   |3| j)                  ||      |d<   |d:n| j)                  ||      |d<   ||d	<   |3| j)                  ||      |d<   |d:n| j)                  ||      |d<   ||d<   |:| j                  | j                  dH      }8|85|8| j+                         z   |d<   |8|dI<   n||d<   | j                  |ddg      }| j-                  ||      S )JNr4   )r\  r  r8  )r   	stopPrice	triggerPxr   GTCr   tpTriggerPxtpOrdPxtpTriggerPxTyper   r   slTriggerPxslOrdPxslTriggerPxTypeclOrdIdclientOrderIdstopLoss
takeProfitdefaultMarginModer   crosstdModeFcashTrB   r3  rf  re  r  rZ  	post_only)r  r  r   r   rC  r   rM  r   r   rJ  rG  rB   rN  rO  r   iocr   fokr   r9  optimal_limit_iocr2  base_ccyr8  r1  rJ   r%  ru  r  a	   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentr  )r   rC  rI  zc createOrder() requires a trigger price in params["stopLoss"]["triggerPrice"] for a stop loss order)r   r   rJ  r  r   zL createOrder() params["stopLoss"]["type"] must be either "limit" or "market"z` createOrder() requires a limit price in params["stopLoss"]["price"] for a stop loss limit order-1r   r   r   zT createOrder() stop loss trigger price type must be one of "last", "index" or "mark")r   rC  rF  z createOrder() requires a trigger price in params["takeProfit"]["triggerPrice"], or params["takeProfit"]["stopPrice"], or params["takeProfit"]["tpTriggerPx"] for a take profit order)r   r   rG  zN 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"rD  orderPxr:  brokerIdtag)rZ  safe_value_nr  r  rU  r  r  r  r  handle_post_onlyomitr   safe_number_2cost_to_precisionr$   r4   number_to_stringr/   
string_mulamount_to_precisionprice_to_precisionuuid16rT  )9rA  rd  r  r  rp  r   rL  rZ  rW  r   r   r   rG  rH  r   rJ  rK  rM  rN  stopLossDefinedrO  takeProfitDefinedrP  r   rB   defaultCurrencyr  	tradeModeisMarketOrderpostOnlyrU  rV  r   r9  	marketIOCdefaultTgtCcyr2  quoteAmountr%  ru  amountStringpriceStringcostRequeststopLossTriggerPricestopLossLimitPricestopLossOrderTypestopLossLimitOrderTypestopLossMarketOrderTypestopLossTriggerPriceTypetakeProfitTriggerPricetakeProfitLimitPricetakeProfitOrderTypetakeProfitLimitOrderTypetakeProfitMarketOrderTypetakeProfitTriggerPriceTypetwoWayConditionr[  s9                                                            rC  r?  zokcoin.create_order_request  s&	   V$Tl 
4 ((1[\&&v}eD++F4E}U//&)U;**63DfM))&/=Q//&)U;**63DfM**69oN??6:6#4/__V\:
't3 ..t||=PR^`gh''hG
"v)=F*J^^FHe<F26%-fWofVnO''GH!44X>GEN"(Jf	%(00@SU[\&6  $`  ae#7e#7t+C1B$D0moT6QmW[_lWl"*sL8K0K	((xL!!&(MB &GHI!)GIu} [("&K8<5@D@]@]^dfs  vY  [_  A`=5v--ffdCD!YYv~>F'&*&<&<VT&J: =".tww  :E  0E  #F  F+/+@+@+HL*.*?*?*FK*1*<*<\;*WK*.*@*@*UK&*&<&<VV&L$/GDM$($<$<VV$LGDM $ 8 8 H 44VVDGDMk $ 7 7 F!,GI!&GI!&GI 1'+'8'8Co'p$'/&tww  2W  (W  X  X)-)@)@I])^&%)%6%6xAf%g"$($4$4Xv$F!$0.?7.J*/@H/L+2=T*477  6D  ,D  E  E/-5".tww  :\  0\  #]  ]151H1HQc1dGI.*h6-1	*'3)-)@)@I[)\GI&)-GI&+/+=+=hHZ\mou+v(+70F:AY]dAd  lD  HN  lN*477  6L  ,L  M  M1IG-. )-):)::Gs)t&)1&tww  2i  (i  j  j)-)@)@I_)`&'+'8'8El'm$&*&6&6z6&J#&20Cw0N,1D1P-4?X*477  6F  ,F  G  G1/7".tww  :C  0C  #D  D151H1HQe1fGI.,8-1	*)5)-)@)@I])^GI&)-GI&-1-?-?
L^`qsy-z*-92f<C]ahCh  pJ  NT  pT*477  6N  ,N  O  O1KG-.!*GI#'#:#:6<#PGK )6D<S<STZ\a<bGI!.GI /t ;\-W[B[O %*	"*)-)@)@)Y&.5oTDD[D[\bdkDl	"-<)*()-)@)@)W&.5oTDD[D[\bdkDl	"-<)* ''jAH#%-%=	"!)!.GIYYv	?'CDF{{7F++rD  r4   c                 N   |t        | j                  dz         | j                          | j                  |dd      }| j	                  |d      }|s|r&| j                  |g||      }| j	                  |d      S | j                  |      }d|d   i}| j                  |dd	      }	|	|	|d<   nt        |      |d
<   | j                  |dd	g      }
| j                  | j                  ||
            }| j	                  |dg       }| j                  |d      }| j                  ||      S )a  

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-order
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-algo-order
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-advance-algo-order

        cancels an open 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 bool [params.trigger]: True if cancel trigger or conditional orders
        :param bool [params.advanced]: True if canceling advanced orders only
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        z) cancelOrder() requires a symbol argumentstopr   advancedr   r\  r4   rL  rM  r  rF  )r   r4   r  r  rU  cancel_ordersrZ  r  strr_  privatePostTradeCancelOrderrT  rJ  r@  )rA  r4   rd  rL  r   r  
orderInnerrZ  rW  rM  r%  rM  rF  r  s                 rC  cancel_orderzokcoin.cancel_order_  s1    >#DGG.Y$YZZ##FFI>??6:6h++RD&&AJ??:q11V$fTl

 **69oN$!.GI"2wGG		&9o">?33DKK4OPx4tQ'v..rD  c                 H    t        |t              r|j                  d      S |S )zg
 @ignore
        :param string[]|str ids: order ids
        :returns str[]: list of order ids
        ,)
isinstancer  r  )rA  idss     rC  	parse_idszokcoin.parse_ids  s!     c399S>!JrD  c                    |t        | j                  dz         | j                          | j                  |dd      }| j	                  |d      }| j                  |g d      }| j                  |      }g }| j                  | j                  |dd            }| j                  | j	                  |d	            }	|| j                  |      }|	4t        d
t        |	            D ]  }
|j                  |	|
   |d   d        t        d
t        |            D ];  }
|s|r|j                  ||
   |d   d       "|j                  ||
   |d   d       = n4t        d
t        |            D ]  }
|j                  |d   ||
   d        d}|r| j                  |      }n%|r| j                  |      }n| j                  |      }| j                  |dg       }| j                  ||dd|      S )a(  
        cancel multiple orders

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-multiple-orders
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-algo-order
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-cancel-advance-algo-order

        :param str[] ids: order ids
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr  r   r  )r  r   r  rL  rM  algoIdr   r4   )r  r\  )r  r\  )r\  rL  rF  )r   r4   r  r  rU  r_  rZ  r  r  r  appendprivatePostTradeCancelAlgos"privatePostTradeCancelAdvanceAlgos!privatePostTradeCancelBatchOrdersrI  parse_orders)rA  r  rd  rL  r   r  rZ  rW  clientOrderIdsalgoIdsr  rM  
ordersDatas                rC  r  zokcoin.cancel_orders  s    >#DGG.Z$Z[[##FFI>??6:66#BCV$(9(9&)_(]^..!BC!..%C"q#g,/ ANN")!*"(,$ 
 1c#h' 
hNN"%a&"(,$ 
 NN!$Q"(,$ 
 1c.12 $Tl-a0  
 77@H>>wGH==gFH" ^^Hfb9
  VT4HHrD  statusc                 8    dddddd}| j                  |||      S )Ncanceledr  closed)r  livepartially_filledfilled	effectiver  rA  r  statusess      rC  parse_order_statuszokcoin.parse_order_status  s/    " &!
 &&99rD  r  c                 |   | j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }d }	d }
|dk(  rd	}	d
}n|dk(  rd}
d
}n	|dk(  rd}
d
}| j                  |d      }| j                  ||      }| j	                  ||d      }| j                  |d      }| j                  |dd      }| j                  |d      }| j                  | j                  |d            }| j                  |d      }d }d }| j                  | j                  dd      }| j                  |d|      }|dk(  r|dk(  r|dk(  r| j                  |d      }n| j                  |d      }d }|Lt        j                  |      }| j                  |d      }| j                  |      }| j                  |      |d}| j                  |d      }|t        |      d k  rd }| j                  |d!d"      }| j                  |d#d$      }| j                  |d%      }d&}||d'k(  }| j                  i d(|d)|d*|d+|d,| j                  |      d-|d.|d/|d0|d1|
d2|	d|d3|d4|d5|d6| j                  |d7d8g      d9||||d ||d |d:|      S );Nr  r  cTimer(  fillTimer  r8  rT  Tr   rV  r   rU  r   r\  r  	accFillSzr  ordPxavgPxstater  r2  rX  r3  rZ  r1  r  r  r  rL  r   rI  rJ  rF  rG  
reduceOnlyFtruer~  r4   rM  rN  r  lastTradeTimestamplastUpdateTimestamprd  r  r   rl  r   r   r   r   rD  moveTriggerPxr  )ru  rp  r  	remainingr  r  tradesr  )r  rK  r  r  safe_symbolr  r  r/   r  r  r  r  r`  
safe_orderr  safe_number_n)rA  r  rZ  r4   rN  r  r  r  r  rl  r   r  rd  r  r   r  r  r  rp  ru  rn  r2  r  r  r  r  rM  r   r   reduceOnlyRawr  s                                  rC  r@  zokcoin.parse_order  s   T x9%%eW5	"//w?!..ujAv.y1;HDU]KDU]KD##E84!!(F3!!(FC8!!%5""5$8""5'2(()9)9%)IJ((6 ((xL!!%=AEM 0v7L##E40D %%eT2F$#..}=M ,,UH=M"55mDO))-8+C ((	:%C,>,B M**5-K,,UM9M((=
!'61J  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 "#6 
 f 
 D 
 ; 
  
 D 
 U 
 ] 
  
  D..u{O6TU! 
" w# 
$ $3 
4 5 	rD  c                 .   |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  |dd      }| j                  |dd      }|r|||d	<   n||d
<   n|||d<   n||d<   | j                  |g d      }d}	|r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
d      }| j                  |      S )a  

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-order-details
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-algo-order-list

        fetches information on an order made by the user
        :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
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr\  r4   rL  rM  r  r   algoClOrdIdr  r  )rM  r  r   rF  r   )r   r4   r  rZ  r  r  r_  privateGetTradeOrderAlgorT  privateGetTradeOrderrU  rJ  r@  )rA  r4   rd  rL  rZ  rW  rM  r   r%  rM  rF  r  s               rC  fetch_orderzokcoin.fetch_order  s+    >#DGG.X$XYYV$fTl

 **69oN##FFI>()6&$&!(%2	"#% 		&"FG44T[[%5PQH00We1LMHx4tQ'&&rD  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  |d      }| j                  |d      xs | j                  |d      du}|r|d|d<   | j	                  |dg      }d}	|r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
|||      S )	a$  

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-order-list
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-algo-order-list

        fetch all unfilled currently open orders
        :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"
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr4   r\  r   r8  r  r   rF  )
r  rZ  r  rU  r_   privateGetTradeOrdersAlgoPendingrT  privateGetTradeOrdersPendingrI  r  )rA  rd  r  r   rL  rW  rZ  r8  r   rM  rF  s              rC  fetch_open_orderszokcoin.fetch_open_orders  s    	
 [[(F &tGH$GG""695//&&1fd6F6Fvy6Yae6e!*GI6F8,<<T[[RX=YZH88Wf9UVH~~h3  vue<<rD  c                 l   | j                          ddi}d}|| j                  |      }|d   |d<   | j                  |d      }| j                  |d      xs | j                  |d      du}|r|d|d<   | j	                  |dg      }d}	|r"| j                  | j                  ||            }	nad}
| j                  |d	d
d      \  }
}|
dk(  r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	dg       }| j                  ||||      S )a  

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-algo-order-history
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-order-history-last-3-months
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-order-history-last-7-days

        fetches information on multiple closed orders made by the user
        :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"
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rQ  rR  Nr4   r\  r8  r  r   rX   r  privateGetTradeOrdersHistoryrF  )r  rZ  r  rU  r_   privateGetTradeOrdersAlgoHistoryrT  r   r  #privateGetTradeOrdersHistoryArchiverI  r  )rA  rd  r  r   rL  rW  rZ  r8  r   rM  r  rF  s               rC  fetch_closed_orderszokcoin.fetch_closed_orders  s]     	
 [[(F &tGH""695//&&1fd6F6Fvy6Yae6e!*GI6F8,<<T[[RX=YZHF!::6CVX`  cA  BNFF77<<T[[RX=YZCCDKKPWY_D`aT ~~h3  vue<<rD  r  c                    | j                  |d      }| j                  |g d      }|%| j                  |di       }| j                  |d      }| j                  |d      }| j                  ||      }|d   }| j                  |d      }|j	                  |dz   d	      }	| j                  |	      }
| j                  |       |||
||d
S )Naddr)r\  pmtIdmemoaddrExcommentr  r  r  r   )r~  r  r  addressr\  )r  safe_string_nrU  safe_currencyreplacer  check_address)rA  depositAddressr  r  r\  r  r  r  r  r  r  s              rC  parse_deposit_addresszokcoin.parse_deposit_addressM  s    : "">6:  1IJ;__^XrBF""695C%%ne<
%%j(;  9MM*s"2B7	)))4T 	7#"
 	
rD  r  c                 Z   | j                          | j                  | j                  dd      }| j                  |d|      }| j                  |      }| j	                  |d      }| j                  ||      }| j                  ||      }|!t        | j                  dz   |z   dz   |z         |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
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r+  r  r  z# fetchDepositAddress() cannot find z deposit address for )	r  r  r  r  r_  "fetch_deposit_addresses_by_networkrU  r#   r4   )rA  r  rL  r+  r  r  rM  r  s           rC  fetch_deposit_addresszokcoin.fetch_deposit_address  s     	))$,,8H'R$$VYG	--i869-::4H;7> +P!PS^!^ax!x{!  A  ArD  c                 2   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |dd      }| j                  ||d   gd      }| j                  |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
        r  r4   rF  selectedTr  Fr  )r  r  privateGetAssetDepositAddressrT  rU  	filter_byparse_deposit_addressesindex_by)	rA  r  rL  r  rW  rM  rF  filteredparseds	            rC  r  z)okcoin.fetch_deposit_addresses_by_network  s     	==&8D>
 55dkk'66RS, x4>>$
D9--h&9I8JER}}VY//rD  fromAccount	toAccountc                    | j                          | j                  |      }| j                  | j                  di       }| j	                  |||      }| j	                  |||      }	|d   | j                  ||      d||	d}
|dk(  r7d|
d<   |	|
d<   | j	                  |d	d
      |
d	<   | j	                  |dd
      |
d<   n;|	dk(  r6d|
d<   ||
d<   | j	                  |d	d
      |
d	<   | j	                  |dd
      |
d<   | j                  | j                  |
|            }| j                  |dg       }| j                  |di       }| j                  ||      S )a   

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

        transfer currency internally between wallets on the same account
        :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>`
        r'  r4   0)r  amtr  fromtomasterr   r  subAcctr  r  r  r   rF  r   )
r  r  rU  r  r  currency_to_precisionprivatePostAssetTransferrT  rJ  parse_transfer)rA  r  rp  r  r  rL  r  r'  fromIdtoIdrW  rM  rF  rawTransfers                 rC  rw   zokcoin.transfer  sp    	==&7GL!!.+{K	9ED>--dF;

 X!GFO!%GI"..vvsCGFO ,,VT3?GDMX!GFO!'GI"..vvsCGFO ,,VT3?GDM00Wf1MN  x4nnT1b1"";99rD  rw   c                 |   | j                  |dd      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  | j
                  di       }	| j                  |d| j                               }
| j                  |d	      }|$| j                  t        j                  |            }|||
| j                  |
      ||| j                  |	|      | j                  |	|      | j                  | j                  |d
            d	S )NtransIdbillIdr  r  r  r  r(  rG  r  r  )	r~  r4   rN  r  r  rp  r  r  r  )r  r  r  r  rU  r  rK  millisecondsr  r/   
string_absr  parse_transfer_status)rA  rw   r  r4   r  r  rp  fromAccountIdtoAccountIdr(  rN  balanceChanges               rC  r  zokcoin.parse_transfer!	  s9   j )X>%%h6
&&z8<!!(E2((6:&&x6t||^RH%%hd6G6G6IJ	((48$&&w'9'9-'HIF"Y/++L-H)),D001A1A(G1TU

 
	
rD  c                 0    ddi}| j                  |||      S )Nsuccessokr  r  s      rC  r  zokcoin.parse_transfer_statusm	  s%    t
 &&99rD  r  c                 x   | j                  ||      \  }}| j                  |       | j                          | j                  |      }|t	        |      dkD  r|dz   |z   }|d   |d| j                  |      d}| j                  |d      }|^| j                  | j                  di       }	| j                  |	|j                         |      }|d   dz   |z   |d	<   | j                  |d      }| j                  |d
      }
|
Q| j                  |d   | j                  |      i       }| j                  |d
      }
|
t        | j                  dz         | j                  |
      |d
<   | j                  | j                  ||            }| j                  |dg       }| j!                  |d      }| j#                  ||      S )a  

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

        make a 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>`
        r   :r4   4)r  toAddrdestr  r  r,  r  r  r  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.rF  )handle_withdraw_tag_and_paramsr  r  r  r  rb  r  rU  r  upperr_  r  r   r4   privatePostAssetWithdrawalrT  rJ  parse_transaction)rA  r  rp  r  r\  rL  r  rW  r  r,  r  targetNetworkrM  rF  transactions                  rC  rx   zokcoin.withdraws	  s    99#vFV7#==&O#c(Q,mc)GD>((0	
 ""695t||ZDH&&x'JG'~3g=GGYYvy1Fvu-; OOHZ,@$BYBYZaBbdfgM""=%8C{'  3U  )U  V  V..s3224;;w3OP x4nnT1-%%k8<<rD  c                 T   | j                          i }d}|| j                  |      }|d   |d<   |t        |dz
  d      |d<   |||d<   | j                  d||      \  }}| j	                  | j                  ||            }| j                  |d	g       }| j                  |||||      S )
a  

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

        fetch all deposits made to an account
        :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
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr4   r  r   r   beforer   afterrF  )r  r  rs  handle_until_optionprivateGetAssetDepositHistoryrT  rI  parse_transactions	rA  r  r  r   rL  rW  r  rM  rF  s	            rC  fetch_depositszokcoin.fetch_deposits	  s     	
 }}T*H%d^GEN #EAIq 1GH$GG227GVL55dkk'66RSN ~~h3&&tXueVLLrD  c                 T   | j                          i }d}|| j                  |      }|d   |d<   |t        |dz
  d      |d<   |||d<   | j                  d||      \  }}| j	                  | j                  ||            }| j                  |d	g       }| j                  |||||      S )
a'  

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

        fetch all withdrawals made from an account
        :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
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr4   r  r   r   r  r   r  rF  )r  r  rs  r   privateGetAssetWithdrawalHistoryrT  rI  r  r  s	            rC  fetch_withdrawalszokcoin.fetch_withdrawals	  s     	
 }}T*H%d^GEN #EAIq 1GH$GG227GVL88Wf9UV> ~~h3&&tXueVLLrD  c           
      @    dddddddddd	}| j                  |||      S )Npendingr  failedr  )	z-3z-2rY  r  r   r   3r  5r  r  s      rC  parse_transaction_statuszokcoin.parse_transaction_status1
  s=    2 

 &&99rD  r  c                    d }d }| j                  |d      }| j                  |d      }| j                  |d      }|}| j                  |dd      }	| j                  |d|	      }	|d}|}n| j                  |d      }d	}| j                  |d
      }
| j                  |
      }| j                  |d      }| j	                  | j                  |d            }| j                  |d      }| j                  |d      }d }|d	k(  rd}n| j                  |d      }i d|d|d|d|dd d|d|d|dd d|	d|	d|d|dd d|d|d | j                  |      d d ||d!d"S )#NwdIdr  r  r\  r  r  
withdrawaldepIdr  r  r  r  txIdrG  r   r  r~  r4   r  rp  r  addressFrom	addressTor  tagFromtagTor  r  updatedtxidrN  r  )r  ru  )r  internalr  )r  r  r  r  r  rK  r  )rA  r  r  r  r4   withdrawalIdr  r  r  r  r  r  rp  r  r  rN  feeCosts                    rC  r  zokcoin.parse_transactionV
  s'   P ''V<&&{F;$$[$7	"";v>"";?#DB !!+w7BD%%k59
&&z2!!+u5..t/?/?W/UVV4%%k48	9G&&{E:G
K
"
 
 f	

 t
 ;
 
 w
 t
 U
 5
 f
 D
 t
 D
  !
" Y/#
$  )
 	
rD  c                    | j                          ddi}||dkD  rd}d}|| j                  |      }|d   |d<   d}| j                  |ddd	      \  }}d}|d	k(  r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  |d
g       }	| j                  |	|||      S )av  

        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-transaction-details-last-3-days
        https://www.okcoin.com/docs-v5/en/#rest-api-trade-get-transaction-details-last-3-months

        fetch all trades made by the user
        :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
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        rQ  rR  Nr   r4   r\  rd   r  privateGetTradeFillsHistoryrF  )r  rZ  r   r"  rT  privateGetTradeFillsrI  r  )
rA  rd  r  r   rL  rW  rZ  r  rM  rF  s
             rC  fetch_my_tradeszokcoin.fetch_my_trades
  s     	
 ECKE[[(F &tGH66vPXZwx2277GV8TUH00Wf1MNH~~h3  vue<<rD  c           	      R    d|i}| j                  |||| j                  ||            S )a  
        fetch all the trades made from a single order
        :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>`
        order_id)r$  rT  )rA  r4   rd  r  r   rL  rW  s          rC  fetch_order_tradeszokcoin.fetch_order_trades
  s4     
 ##FE5$++gv:VWWrD  c                    | j                          d}| j                  |ddd      \  }}i }|||d<   d}|| j                  |      }|d   |d<   | j                  d||      \  }}d}|d	k(  r"| j	                  | j                  ||            }nH|d
k(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

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

        :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
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Nrb   r  privateGetAccountBillsr   r4   r  endprivateGetAccountBillsArchiveprivateGetAssetBillsrF  )
r  r   r  r  r+  rT  r,  r)  rU  parse_ledger)
rA  r  r  r   rL  r  rW  r  rM  rF  s
             rC  fetch_ledgerzokcoin.fetch_ledger
  s    	66v}hXpq
 $GG}}T*H%d^GEN225'6J4499$++gv:VWH--00Wf1MNH224;;w3OPHb x4  x>>rD  c                 D    dddddddddddd}| j                  |||      S )Nrw   r  rebater  )r   r   r  r  r  r  7891011r  )rA  r  typess      rC  parse_ledger_entry_typezokcoin.parse_ledger_entry_typeE  sA    
 tT22rD  itemc                 v   | j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j                  |d      }d }|'| j	                  t        j                  |            |d}| j                  |d      }| j                  |d d      }	| j                  || j                  |d      || j                  |      d | j                  |d      d | j                  | j                  |d	            ||	| j                  |d
      d | j                  |d      d|d|      S )Nr  rG  r  r  r\  r  r  r  r  balChgr/  r  )r~  r4   rN  r  r  referenceIdreferenceAccountr  r  rd  rp  r  r  r  r  )r  r  r  rK  parse_to_numericr/   r  r  safe_ledger_entryr  r7  r  )
rA  r8  r  r  r  rN  r  r  r  rd  s
             rC  parse_ledger_entryzokcoin.parse_ledger_entryU  sT   J %%dE2
&&z8<%%j(;%%dD1	((u5$--g.@.@.OP C ##D(3!!(D#6%%""42"Y/++D': $001A1A$1OP&&tX6%%dE2'
  ! 	rD  r   GETc                    t        |t              }d| j                  z   dz   | j                  ||      z   }| j	                  || j                  |            }	| j                  | j                  d   d         |z   }
|dk(  r|	r|
d| j                  |	      z   z  }
n|dk(  r| j                          | j                  | j                               }| j                  | j                  |d}||z   |z   }|d	k(  r!|	r>d| j                  |	      z   }|
|z  }
||z  }n|s|	r| j                  |	      }||z  }d
|d<   | j                  | j!                  |      | j!                  | j"                        t$        j&                  d      }||d<   |
|||dS )Nz/api/r`  r   r   r   ?r   )zOK-ACCESS-KEYzOK-ACCESS-PASSPHRASEzOK-ACCESS-TIMESTAMPr@  zapplication/jsonzContent-Typebase64zOK-ACCESS-SIGN)urlr  bodyheaders)r  r  r:   implode_paramsr_  extract_paramsimplode_hostnamer   	urlencoder  r  r  r   r   jsonhmacencoder   hashlibsha256)rA  pathr   r  rL  rF  rE  isArrayrW  r%  rD  rN  r)  urlencodedQuery	signatures                  rC  signzokcoin.sign  s   VT*DLL(3.1D1DT61RR		&$"5"5d";<##DIIe$4V$<=G(?sT^^E222I++-T%6%6%89I!%(,'0G v%/D&)DNN5,A&AO?*CO+De99U+DDLD*<'		$++d"3T[[5Mw~~_ghI(1G$%fdwOOrD  c                 P    |dk(  r| j                  |      S | j                  |      S )Nr  )r"  r#  )rA  r  rM  s      rC  parse_balance_by_typezokcoin.parse_balance_by_type  s,    9--h77--h77rD  httpCodereasonrD  r  rF  rE  c
                    |sy | j                  |d      }
|
dk7  r| j                  dz   |z   }| j                  |dg       }t        dt	        |            D ]k  }||   }| j                  |d      }| j                  |d      }| j                  | j                  d   ||       | j                  | j                  d	   ||       m | j                  | j                  d   |
|       t        |      y )
Nr  r   rF  r   sCodesMsgr  r  )	r  r4   rU  r  r  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )rA  rW  rX  rD  r  rF  rE  rM  requestHeadersrequestBodyr  feedbackrF  r  error	errorCodemessages                    rC  handle_errorszokcoin.handle_errors  s    * &13;ww}t+H??8VR8D1c$i( bQ ,,UG<	**5&944T__W5MyZbc44T__W5MwX`ab 001I4QYZ))rD  )N)M__name__
__module____qualname__r   r@  r
   rO  r   r   rY  dictr  r   r  r  r   r  r   r  r  r   r   r  r   r  r  r  r  r  r  r   r&  r#  r"  floatr5  r   r   r   r4  r?  r   r  r  r  r  r   r@  r  r  r  r   r	   r  r  r  r   rw   r  r  r   rx   r	  r  r  r  r$  r'  r   r.  r7  r?  rT  rV  intre  __classcell__)rB  s   @rC  r1   r1   #   s   _
# _
B !# 2s 2. $& +$v, + P4 PF Pd ') ?Z ?B :>b ,?s ,?3 ,?Y ,?\54 5 56 5n 02 ,03 ,0f ,0\ 04B 9W 97 9$G Gv G GR 6:UW =3 =s =# =\`af\g =<
 
4 
. 26DW[df $H# $Hc $HQT $Hkoptku $HL8)t $& %8( %8N)2) RT N N5 N& gksu 73 7i 7y 7RW 7`c 7r os{} ,3 ,i ,y ,Z_ ,hk ,B 37r '/s '/C '/R	 04B HI HIT: :{ {v { {z 26b )'c )'3 )'V /3TXac )= )=3 )=c )=hlmrhs )=V 154VZce Q=# Q=S Q=PS Q=jnotju Q=fX
h X
R` X
t 79 # ^ * DF (0s (0$~J^ (0T [] 9:S 9:% 9:c 9:c 9:an 9:vJ
t J
x J
= J
X:C :C : DHPR 6=S 6=% 6=# 6=Wb 6=p *.Dt\^ EM3 EMc EM EMcghsct EMN -1tRV_a =Mc =M =MC =Mfjkvfw =M~#:s #:J[
T [
X [
Q\ [
z -1tRV_a =c = =C =B 9=4^bkm XS X# XS XX[ X& (,$TZ\ \? \?C \?s \?aefqar \?|3 Bt Bx B; BH &eBSW  PD8#c #3 #S ## #X\ #dg #rD  r1   )6ccxt.base.exchanger   ccxt.abstract.okcoinr   rN  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   ccxt.base.decimal_to_precisionr.   ccxt.base.preciser/   r1    rD  rC  <module>ru     s    ( ,  Y  Y  Y  Y  Y  Y  * 0 - . - . ' & . + ) * ) ) . 1 * ) + * 4 %A/X{ A/rD  