
    eiD[                       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  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l#m1Z1 d dl#m2Z2 d dl#m3Z3 d dl4m5Z5 d dl6m7Z7  G d dee          Z8dS )    )Exchange)ImplicitAPIN)AccountAnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBookOrderRequestCancellationRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)DDoSProtection)RateLimitExceeded)OnMaintenance)InvalidNonce)RequestTimeout)	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i fde
defdZi fdedefd	Zdddi fded
ededee         fdZddi fded
ededee         fdZdddi fdeded
ededee         f
dZdi fdededefdZdefdZi fdefdZd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#i fdee$         fdZ%di fdededede de!f
dZ&ddi fdedededede!de!fdZ'di fdedede de!fd Z(di fdefd!Z)di fdedefd"Z*di fd#ee         defd$Z+i fdee,         fd%Z-dddi f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( Z0di fd)ede d*ed+ede1f
d,Z2i fd)edee3         fd-Z4i fd)ede3fd.Z5dddi fd)ed
ededee1         fd/Z6dddi fd)ed
ededee1         fd0Z7dgd1e8d2edefd3Z9dgd4e8d2edefd5Z:dgd2edefd6Z;d7efd8Z<d9efd:Z=dgd;e8d2edefd<Z>d= Z?d> Z@dgd?e8d@eAde1fdAZBi fdBZCdgd@eAfdCZDdi fdDe
fdEZEdddi fd)ed
ededeeF         fdFZGdgdGe8d@eAdeFfdHZHdI ZIi fdeeJ         fdJZKdK ZLdddi fded
edefdLZMdM ZNdN ZOi fdefdOZPdgd2edeQfdPZRdddi fded
edefdQZSi fdefdRZTdi fde
deeU         fdSZVdgdTe8d2efdUZWdV ZXdW ZYdi fdededefdXZZi fdede[fdYZ\i fde]fdZZ^d[ Z_dgd\e8d2ede[fd]Z`d^d_i ddfd`Zad)ebdaedbedcedde8deefdfZc xZdS )h	cryptocomreturnc                    |                      t          t          |                                           i 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dGddHddIddJddKddLddMddNddOddPddQddRddSddTdi dUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddedddddddfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdxdydzd{d|d}d~ddddg ddddddddiiidddddddddddd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dddddddddddddddidddddddddddd	idi dddddddddddddddddddddddddddddddddddddddddddddddidddddddddddd	idi dddddddddddddddddddddddddddddddddddddddidd~dd|                     dĦ          |                     dŦ          |                     dƦ          |                     dĦ          g|                     dǦ          |                     dȦ          g|                     dɦ          |                     dʦ          g|                     d˦          |                     d̦          g|                     dͦ          |                     dΦ          g|                     dϦ          |                     dЦ          g|                     dѦ          |                     dƦ          g|                     dҦ          |                     dƦ          g|                     dӦ          |                     dƦ          g|                     dԦ          |                     dƦ          g|                     dզ          |                     dƦ          gg|                     dƦ          |                     dŦ          g|                     dǦ          |                     d֦          g|                     dɦ          |                     dĦ          g|                     d˦          |                     dȦ          g|                     dͦ          |                     dצ          g|                     dϦ          |                     d̦          g|                     dѦ          |                     dئ          g|                     dҦ          |                     d٦          g|                     dӦ          |                     dڦ          g|                     dԦ          |                     dۦ          g|                     dզ          |                     dܦ          ggdݜdޜiddddddddddddddddddddddddddd ddddddddddddddd
iddd ddddddddddddddddd dddddddd d dddddddid	dddidddiddidddiddidddddid t
          d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           d0t"          d1t$          d2t          d3t          d4t          t          t          t&          d5i d6          S (7  Nidr3   namez
Crypto.com	countriesMTversionv2	rateLimit
   	certifiedTprohasCORSFspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscancelOrdersForSymbolscloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersemulatedfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeesfetchTransactionsfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsandbox)setLeveragesetMarginModesetPositionModetransferwithdraw
timeframes1m5m15m30m1h4h6h12h1D7D14D1M)r   r   r   r   r   r   r   r   1d1w2wr   urlszehttps://user-images.githubusercontent.com/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpegz#https://uat-api.3ona.co/exchange/v1zhttps://uat-api.3ona.co/v2)v1r;   derivativeszhttps://api.crypto.comz"https://api.crypto.com/exchange/v1zhttps://api.crypto.com/v2zhttps://deriv-api.crypto.com/v1)baser   r;   r   zhttps://crypto.com/z"https://crypto.com/exch/kdacthrnxtg      ?)urldiscount)z?https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.htmlz0https://exchange-docs.crypto.com/spot/index.htmlz7https://exchange-docs.crypto.com/derivatives/index.htmlz0https://crypto.com/exchange/document/fees-limits)logotestapiwwwreferraldocfeesr   publicgetzv1/public/get-announcements   g
@)public/authpublic/get-instrumentspublic/get-bookpublic/get-candlestickpublic/get-tradespublic/get-tickerspublic/get-valuations#public/get-expired-settlement-pricepublic/get-insurancezpublic/get-announcementszpublic/get-risk-parametersz"public/staking/get-conversion-rate   )r   postr   z private/set-cancel-on-disconnectz private/get-cancel-on-disconnectzprivate/user-balancezprivate/user-balance-historyzprivate/get-positionszprivate/create-ordergUUUUUU?zprivate/amend-ordergUUUUUU?zprivate/create-order-listzprivate/cancel-orderzprivate/cancel-order-listzprivate/cancel-all-orderszprivate/close-positionzprivate/get-order-historyd   zprivate/get-open-ordersprivate/get-order-detailgUUUUUU?private/get-tradeszprivate/change-account-leverageprivate/get-transactions"private/create-subaccount-transferprivate/get-subaccount-balancesprivate/get-order-listzprivate/create-withdrawalzprivate/get-currency-networkszprivate/get-deposit-addressprivate/get-accountszprivate/get-withdrawal-historyzprivate/get-deposit-historyzprivate/get-fee-ratezprivate/get-instrument-fee-ratezprivate/fiat/fiat-deposit-infoz!private/fiat/fiat-deposit-historyz"private/fiat/fiat-withdraw-historyz!private/fiat/fiat-create-withdrawz#private/fiat/fiat-transaction-quota)z#private/fiat/fiat-transaction-limitz#private/fiat/fiat-get-bank-accountszprivate/staking/stakezprivate/staking/unstakez$private/staking/get-staking-positionz'private/staking/get-staking-instrumentszprivate/staking/get-open-stakez!private/staking/get-stake-historyz"private/staking/get-reward-historyzprivate/staking/convertz private/staking/get-open-convertz#private/staking/get-convert-historyz'private/create-isolated-margin-transferz'private/change-isolated-margin-leverage)r   private)	r   r   r   r   zpublic/get-tickerr   z%public/margin/get-transfer-currenciesz!public/margin/get-load-curreniceszpublic/respond-heartbeatz$private/export/create-export-requestz"private/export/get-export-requestsz%private/export/download-export-outputzprivate/get-account-summary)r   r   r   r   r   zprivate/otc/get-otc-userzprivate/otc/get-instrumentszprivate/otc/request-quotezprivate/otc/accept-quotezprivate/otc/get-quote-historyzprivate/otc/get-trade-historyzprivate/otc/create-order)	r   r   r   r   r   r   r   r   r   zprivate/convert-collateral)r   r   r   r   r   tradingz0.0025z0.005010000z0.00250000z0.0015250000z0.001500000z0.00082500000z0.000651000000025000000	100000000	250000000	500000000z0.004z0.0018z0.0005z0.0004z0.00035z0.00031z0.00025)makertaker)r   r   tiersoptionsSPOTMARGINDERIVATIVES)fundingrB   rC   r   rD   rE   BSCETHTRON)BEP20ERC20TRC20CCXT)defaultTypeaccountsByIdnetworksbrokerfeatures)lastmarkindex)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingicebergleveragemarketBuyByCostmarketBuyRequiresPricemax)r   limitdaysBack	untilDayssymbolRequired)r   triggerr  r
  )r   r  r  r  r
  )r   r  r  r	  r  r  r
  )r   r  r  daysBackCanceledr	  r  r  r
  r  ,  )	r   rQ   rR   ry   r|   r{   r~   r\   rz   defaultr   )extendsr`   r  )linearinverse)r  rB   rD   rE   commonCurrenciesUSD_STABLE_COINUSDCprecisionMode
exceptions219306314315325415100011000210003100041000510006100071000810009200012000220005300033000430005300063000730008300093001030013300143001630017300233002430025400014000240003400044000540006400074010140102401034010440107404014080142901430054300343004)43012500019010001)exactbroad)deep_extendsuperr3   describeparse_numberr0   r(   r'   r    r"   r%   r+   r.   r#   r&   r!   r)   r/   r,   r-   )self	__class__s    Z/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/cryptocom.pyrQ  zcryptocom.describe"   s   i 6 6 ? ? A A JD
+JD
LJD
 $JD
 t	JD

 JD
 JD
 4JD
  [[[ $[ 	[
 $[ $[ U[ "4[ t[ [ )$[ $U[  [ /[ ,U[  0![" t#[ [$ %[& "4'[( %d)[* T+[,  -[. /[0  1[2 &u3[4 +E5[6 )%7[8 $Z9[: ';[< (=[> "4?[@ &tA[B (C[D 1$E[ [ [F  G[H +EI[J *:K[L +DM[N &uO[P #DQ[R *4S[T $UU[V uW[X "5Y[Z *5[[\ +E][^ t_[`  a[b %ec[d /e[f "5g[ [ [h +Ei[j k[l !%m[n +Eo[p  q[r ds[t "4u[v dw[x !$y[z t{[|  }[~ '[@ $UA[B !$C[D (E[F )%G[H )$I[ [ [J uK[L tM[N O[P UQ[R tS[T "4U[V #DW[X 'Y[Z $U[[\ !%][^ (_[` )%a[b #Dc[d e[f #Eg[h &ui[j 4k[ [l  %!&#(! u[ [ [JD
H  IJD
d ?6#?  5>5#D	  -? $   
 K/ eJD
V 91  ,26</067122356CI4589:;    A!! &  1!>1!>1! 3F1! ;F	1!
 4V1! 3E1! 251! 81! 3E1! 81! 81! 5f1! 81! 6v1! 71!  1#!1!" >v#1! 1!$ 7%1!& A&'1!( >v)1!* 5f+1!, 8-1!. <V/1!0 :611!2 3F31!4 =f51!6 :671!8 3A91!: >q;1!< =f=1!> @?1!@ A&A1!B @C1!D B6E1! 1!F DJCI5678DEGH>?ABBC78@ACDGMGMa1! 1! 1!3 'G GT +,67/0671212EFAB89
  
   !>!>! 8! =f	!
 <V! :6! :6! CF! A&! DV! :6! 3E! 3E! 8! 8!  8!!" 6v#!$ 9>254:?EBH8>;A9<8;=C=C8>;! ! !  / /d +16</067122356CI45
  
   !>!>! 3F! ;F	!
 4V! 3E! 8! 3E! 8! 8! 5f! 9&! 8! 6v! 7!  1#!!" >v#!$ 9?BH?E6<+! ! ! '  ' Ah hWJD
h	 !..x88!..w77 "..s33T5F5Fx5P5PQ!..w779J9J79S9ST!..w779J9J89T9TU!..x88$:K:KG:T:TU!..x88$:K:KH:U:UV!..y994;L;LY;W;WX!..z::D<M<Mc<R<RS!..z::D<M<Mc<R<RS!..{;;T=N=Ns=S=ST!..{;;T=N=Ns=S=ST!..{;;T=N=Ns=S=ST" "..s33T5F5Fw5O5OP!..w779J9J79S9ST!..w779J9J89T9TU!..x88$:K:KG:T:TU!..x88$:K:KH:U:UV!..y994;L;LW;U;UV!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX!..{;;T=N=Ny=Y=YZ!..{;;T=N=Ny=Y=YZ!..{;;T=N=Ny=Y=YZ"  !i	JD
l
 %%"&#0)+! ! #"# 
 ! m
JD
N #&*(, %)$(%)- -
 -2)-+/6:#'#'"&#(	( ( #(/3$)#($)+/263$ $8 r% ',!$$(%&*/& & ',#($)*/	# # '+!$#($)*/( ( ',!$$(%&#($)*/$ $ ',!$$(,0%&#($)*/	* 	*  #OJ JX  )!4(  "9 "9 	  "9 "9 	 ub bOJD
V !6!WJD
\ Y]JD
^ 7<7,7 <7 <	7
 <7 <7 ]7 -7 -7 Z7 -7 ^7 \7 Z7 Z7  Z!7" .#7 7$ .%7& Y'7( Z)7* Z+7, \-7. \/70 \172 \374 Z576 \778 \97: \;7< \=7> \?7@ \A7B \C7D ZE7 7 7F ZG7H ZI7J ZK7L ZM7N ZO7P ZQ7R 0S7T \U7V 0W7X 0Y7Z Z[7\ ]]7^ ^_7` .a7b \c7d \e7f \g7 7h (*,m7 7 7p s: :_JD
 J J J	    c                 l  K   |                      d          si S d}|                     |ddd          \  }}|ri S i }	 |                     |           d{V }n0# t          $ r#}t	          |t
                    ri cY d}~S |d}~ww xY w|                     |di           }|                     |di           }t          |                                          }i }t          dt          |                    D ]:}	||	         }
||
         }|
}|                     |          }i }|                     |dg           }t          dt          |                    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id|d          ||<   <|S )a=  
        fetches all available currencies on an exchange

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-currency-networks

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Fr`   skipFetchCurrenciesNresultcurrency_mapr   network_list
network_iddeposit_enabledwithdraw_enabledwithdrawal_feer   min_withdrawal_amountminr  )	infor6   networkactivedepositr   fee	precisionlimits	full_nameamountcrypto)rc  r6   coder7   re  rf  r   rg  rh  ri  typer   )check_required_credentialshandle_option_and_params'v1PrivatePostPrivateGetCurrencyNetworks	Exception
isinstancer    	safe_dictlistkeysrangelensafe_currency_code	safe_listsafe_stringnetwork_id_to_code	safe_boolsafe_numbersafe_currency_structure)rS  paramsrX  responsee
resultDatacurrencyMaprv  rY  ikeycurrencyr6   rm  r   chainsjchain	networkIdrd  s                       rU  fetch_currencieszcryptocom.fetch_currencies/  s      ..u55 	I#&*&C&CFL]_tv{&|&|#V 	I	!II&QQQQQQQQHH 	 	 	!]++  						G	d ^^Hh;;
nnZDDK$$&&''q#d))$$ -	 -	Aq'C"3'HB**2..DH^^HnbAAF1c&kk**  q	 ,,ULAA	11)<<!#&"#~~e5FNN $u6H% P P++E3CDD!%"#'#3#3E;R#S#S#'% %% %!!   77 ((;?? !##  !$#9 9  F4LL& s#   A 
B$B:B BBc                 $  K   |                      |           d{V }|                     |di           }|                     |dg           }g }t          dt	          |                    D ]#}||         }|                     |d          }|dk    }	|dk    }
|dk    }|d	k    }|                     |d
          }|                     |d          }|	rdn|}|                     |          }|                     |          }|	rdn|                     |          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }| 	                    |                     |d                    }|t          |          nd}|dz   |z   }d}d}|dk    rd}d}n|dk    rd}|dz   |z   }d}nm|dk    r&d}|dz   |z   dz   |                     |          z   }d}nA|d	k    r;d}|dk    rdnd}|dz   |z   dz   |                     |          z   dz   |z   dz   |z   }d}|                    i d|                     |d          d|d|d |d!|d"|d#|d$|d%|d|	d&|p|d|
d|d|d'|                     |d(          d)|d*|rdnd|rdnd|                     |d+          ||                     |          |                     |          ||                     |                     |d,                    |                     |                     |d-                    d.|                     d/          |                     |d0          d1ddd1ddd1ddd1d2d|d3
           %|S )4a9  

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-instruments

        retrieves data on all markets for cryptocom
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        NrY  datar   	inst_typeCCY_PAIRPERPETUAL_SWAPFUTUREWARRANTbase_ccy	quote_ccyput_callstrikemargin_buy_enabledmargin_sell_enabledexpiry_timestamp_ms/rB   FrD   :TrE   -rF   callCPr6   symbolr   quotesettlebaseIdquoteIdsettleIdrn  rC   re  tradablecontractr  contract_sizeprice_tick_sizeqty_tick_size)pricerk  1max_leveragera  )r  rk  r  cost)
r  contractSizeexpiryexpiryDatetimer  
optionTyperh  ri  createdrc  )v1PublicGetPublicGetInstrumentsrt  rz  rw  rx  r{  ry  safe_string_lowerr}  	omit_zerointyymmddappendr~  iso8601rR  )rS  r  r  resultResponser  rY  r  marketr  rB   rD   rE   rF   r  r  r  r   r  r  r  r  marginBuyEnabledmarginSellEnabledexpiryStringr  r  rn  r  symbolOptionTypes                                rU  fetch_marketszcryptocom.fetch_markets  s      ==fEEEEEEEEp (B??~~nfb99q#d))$$ V	 V	A!WF((==I
*D 00D(*F)+F%%fj99F&&v{;;G#0ttH**622D++G44E!HTTt'>'>x'H'HF//
CCJ%%fh77F#~~f6JKK $v7L M M>>$*:*:6CX*Y*YZZL+7+CS&&&$FCZ%'FDHJ&& ...#-h&&#-3dkk&6I6IIi''+5+?+?33c #-3dkk&6I6IICORXX[^^aqqMM 0d&&vx880&0 0 	0
 &0 &0 70 H0 0 0 ,D2C0 0 &0 &0 $..<<0  H!0" 86$$$#0$ &.855D $ 0 0 I I "&,,v"6"6++F33(!..t/?/?HY/Z/Z[["//0@0@0Y0YZZ   $0055#//GG! !
  $# 
  $# 
  $#  $  _0 0 0 0 0 0 0b rV  Nsymbolsc                   K   |                                   d{V  d}i }|nd}t          |t                    r5t          |          }|dk    rt	          | j        dz             |d         }n|}|                     |          }|d         |d<   |                     |                     ||                     d{V }| 	                    |di           }| 
                    |dg           }	|                     |	|          S )	a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
        https://exchange-docs.crypto.com/derivatives/index.html#public-get-tickers

        :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>`
        Nr   zB fetchTickers() symbols argument cannot contain more than 1 symbolr   r6   instrument_namerY  r  )load_marketsrs  ru  rx  r%   r6   r  v1PublicGetPublicGetTickersextendrt  rz  parse_tickers)
rS  r  r  r  requestr  symbolsLengthr  rY  r  s
             rU  fetch_tickerszcryptocom.fetch_tickersf  s$      !!!!!!!!!F'4(( ! #G 1$$$TW/s%sttt  [[((F)/G%&99$++gv:V:VWWWWWWWW2 (B77~~ffb11!!$000rV  r  c                    K   |                                   d{V  |                     |          }|                     |g|           d{V }|                     ||          S )a  

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers

        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>`
        N)r  r  r  
safe_value)rS  r  r  tickerss       rU  fetch_tickerzcryptocom.fetch_ticker  sz       !!!!!!!!!V$$**F8V<<<<<<<<w///rV  sincer  c                 n  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S d}i }| |                     |          }|d         |d<   |||d<   |||d<   |                     |d	          }|                     |d	g          }|||d
<   |                     |                     ||                     d{V }	|                     |	di           }
| 	                    |
dg           }| 
                    ||||          S )a  
        fetches information on multiple orders made by the user

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-history

        :param str symbol: unified market symbol of the market the orders were made in
        :param int [since]: the earliest time in ms to fetch orders for, max date range is one day
        :param int [limit]: the maximum number of order structures to retrieve, default 100 max 100
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :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 Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NFr~   paginater6   r  
start_timer  untilend_timerY  r  )r  rp  fetch_paginated_call_dynamicr  safe_integeromit#v1PrivatePostPrivateGetOrderHistoryr  rt  rz  parse_orders)rS  r  r  r  r  r  r  r  r  r  r  orderss               rU  fetch_orderszcryptocom.fetch_orders  s      !!!!!!!!!88PZ[[& 	h::=&RWY^`fggggggggg[[((F)/G%&$)GL!$GG!!&'226G9--"'GJAA$++gW]B^B^________P ~~h"55fb11  >>>rV  c                 `  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S |                     |          }d|d         i}|||d<   |||d<   |                     |d	          }|                     |d	g          }|||d
<   |                     |                     ||                     d{V }	|                     |	di           }
| 	                    |
dg           }| 
                    ||||          S )a  
        get a list of the most recent trades for a particular symbol

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-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, maximum date range is one day
        :param int [limit]: the maximum number of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :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=public-trades>`
        NFr   r  r  r6   start_tscountr  end_tsrY  r  )r  rp  r  r  r  r  v1PublicGetPublicGetTradesr  rt  rz  parse_trades)rS  r  r  r  r  r  r  r  r  r  rY  tradess               rU  fetch_tradeszcryptocom.fetch_trades  s~      !!!!!!!!!88PZ[[& 	h::=&RWY^`fgggggggggV$$vd|
 "'GJ$GG!!&'226G9-- %GH88Wf9U9UVVVVVVVV* (B7733  >>>rV  r   	timeframec           	      Z  K   |                                   d{V  d}|                     |ddd          \  }}|r!|                     d|||||d           d{V S |                     |          }|d         |                     | j        ||          d}||dk    rd}||d<   |                                 }	|                     |          }
|                     |d	|	          }| 	                    |d	g          }|3||
d
z  z
  |d<   | | 
                    ||
|z  d
z            |d<   n||d<   n||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-candlestick

        :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 int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :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
        NFrz   r  r  r6   )r  r  r  r  i  r  r  rY  r  )r  rp  "fetch_paginated_call_deterministicr  r{  r   microsecondsparse_timeframer  r  sumv1PublicGetPublicGetCandlestickr  rt  rz  parse_ohlcvs)rS  r  r  r  r  r  r  r  r  nowdurationr  r  rY  r  s                  rU  fetch_ohlcvzcryptocom.fetch_ohlcv/  s      !!!!!!!!!88z[`aa& 	}@@vW\^cenpvx{|||||||||V$$%d|))$/9iPP
 
 s{{$GG!!''	22!!&'3776G9--"'(T/"9GJ $(HHUHu4Dt4K$L$L!!$)!! %GH==dkk'SY>Z>Z[[[[[[[[, (B77~~ffb11  vy%GGGrV  c                   K   |                                   d{V  |                     |          }d|d         i}|rt          |d          |d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |d          }	|                     |	d	          }
| 	                    |	||
          S )
aK  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-book

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the number of order book entries to return, max 50
        :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
        Nr  r6   2   depthrY  r  r   t)
r  r  rb  v1PublicGetPublicGetBookr  rt  rz  r  r  parse_order_book)rS  r  r  r  r  r  r  rY  r  	orderBook	timestamps              rU  fetch_order_bookzcryptocom.fetch_order_bookr  s      !!!!!!!!!V$$vd|
  	."5"~~GG66t{{7F7S7STTTTTTTT& (B77~~ffb11OOD!,,	%%i55	$$Y	BBBrV  c                    |                      |di           }|                     |dg           }|                     |d         dg           }d|i}t          dt	          |                    D ]}||         }|                     |d          }|                     |          }	|                                 }
|                     |d          |
d<   |                     |d	          |
d
<   |
||	<   |                     |          S )NrY  r  r   position_balancesrc  r  quantitytotalreserved_qtyused)	rt  rz  r  rw  rx  r{  ry  accountsafe_balance)rS  r  responseResultr  positionBalancesrY  r  balance
currencyIdrm  r   s              rU  parse_balancezcryptocom.parse_balance  s   (B??~~nfb99??474GLL)q#.//00 	# 	#A&q)G))'3DEEJ**:66DllnnG#//DDGG"..wGGGFO"F4LL  (((rV  c                    K   |                                   d{V  |                     |           d{V }|                     |          S )a~  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-user-balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        N)r  v1PrivatePostPrivateUserBalancer  )rS  r  r  s      rU  fetch_balancezcryptocom.fetch_balance  sh       !!!!!!!!!==fEEEEEEEEX !!(+++rV  r6   c                 ,  K   |                                   d{V  d}||                     |          }d|i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetches information on an order made by the user

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-detail

        :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>`
        Norder_idrY  )r  r  "v1PrivatePostPrivateGetOrderDetailr  rt  parse_order)rS  r6   r  r  r  r  r  orders           rU  fetch_orderzcryptocom.fetch_order  s       !!!!!!!!![[((F
 @@WV\A]A]^^^^^^^^D x266v...rV  rn  siderk  r  c                 >   |                      |          }|                                }|d         |                                |                     ||          d}	|dk    s|dk    s|dk    r|                     ||          |	d<   |                     | j        dd          }
|
|	d	<   d }d }|                     d
||          \  }}|                     d
|          \  }}|dk    s|d|	d<   n|dk    rd|	d<   |                     |dd          }|)|dk    rd|	d<   n|dk    rd|	d<   n|dk    rd|	d<   n||	d<   | 	                    |dd          }|s|dk    rdg|	d<   d|	d<   | 
                    |g d          }|                     |d          }|                     |d          }|d u}|d u}|d u}|r|                     ||          |	d <   |                     |          }|dk    s|dk    s|dk    rH|d!k    r!t          j        ||          rd|	d"<   nd|	d"<   nt          j        ||          rd|	d"<   nd|	d"<   n|d!k    r!t          j        ||          rd#|	d"<   nd$|	d"<   nt          j        ||          rd$|	d"<   nqd#|	d"<   nk|r1|dk    s|dk    rd|	d"<   nd$|	d"<   |                     ||          |	d <   n8|r1|dk    s|dk    rd|	d"<   nd#|	d"<   |                     ||          |	d <   n||	d"<   |                     |g d%          }|                     |	|          S )&Nr6   )r  r  r  LIMIT
STOP_LIMITTAKE_PROFIT_LIMITr  r   r   	broker_idrQ   rC   r   spot_marginrB   r   r   time_in_forceGTCGOOD_TILL_CANCELr   IMMEDIATE_OR_CANCELr   FILL_OR_KILLpostOnlyFr   	POST_ONLY	exec_inst	stopPricer   	ref_pricer   r   r!  buyrn  TAKE_PROFIT	STOP_LOSSr  clientOrderIdr   r   r   r   r   )r  upperamount_to_precisionprice_to_precisionr{  r   handle_market_type_and_params$custom_handle_margin_mode_and_paramssafe_string_upper_2r}  safe_string_nr~  number_to_stringr1   	string_ltr  r  )rS  r  rn  r  rk  r  r  r  uppercaseTyper  r   
marketTyper   r   r  r   r   r   	isTriggerisStopLossTriggerisTakeProfitTriggerpriceStrings                         rU  create_order_requestzcryptocom.create_order_request  s.   V$$

%d|JJLL00@@
 

 W$$-<*G*G]^qMqMq#66vuEEGG!!$,&AA%

!??vW]^^
F!FF}V\]]
F(""
(>%-GM""6!!%+GM"..v}oVV"e##+=((%%+@((%%+9((+6(>>&*e<< 	:+--$/=GK '9GO$))&2\2\2\]]((AA**63DEE!-	*$6.d: &	,#'#:#:6<#P#PGK //66K((m|.K.KQ^buQuQu5==(lCC 7*=*6(lCC >*6*=5==(lCC 6*7*5(lCC 8*5*7 	,((m|.K.K"."-#'#:#:6=#Q#QGK    	,((m?R.R.R"5"/#'#:#:6?#S#SGK  +GFO6  $Q  $Q  $Q  R  R{{7F+++rV  c                 (  K   |                                   d{V  |                     |          }|                     ||||||          }|                     |           d{V }	|                     |	di           }
|                     |
|          S )a  
        create a trade order

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market', 'limit', 'stop_loss', 'stop_limit', 'take_profit', 'take_profit_limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much 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 str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'PO'
        :param str [params.ref_price_type]: 'MARK_PRICE', 'INDEX_PRICE', 'LAST_PRICE' which trigger price type to use, default is MARK_PRICE
        :param float [params.triggerPrice]: price to trigger a trigger order
        :param float [params.stopLossPrice]: price to trigger a stop-loss trigger order
        :param float [params.takeProfitPrice]: price to trigger a take-profit trigger order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NrY  )r  r  r6  v1PrivatePostPrivateCreateOrderrt  r  )rS  r  rn  r  rk  r  r  r  r  r  rY  s              rU  create_orderzcryptocom.create_orderm  s      & !!!!!!!!!V$$++FD$vVV==gFFFFFFFF (B77///rV  r  c           	      H  K   |                                   d{V  g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |di           }|                     ||||	|
|          }|                    |           |                     |d	d
          }||d}|                     | 	                    ||                     d{V }|                     |dg           }|                     |d          }|d|ig}| 
                    |          S | 
                    |          S )aY  
        create a list of trade orders

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-list
        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-oco

        :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  rn  r  rk  r  r  contingency_typeLISTr;  
order_listrY  list_idr  )r  rw  rx  r{  r  rt  create_advanced_order_requestr  #v1PrivatePostPrivateCreateOrderListr  r  )rS  r  r  ordersRequestsr  rawOrdermarketIdrn  r  rk  r  orderParamsorderRequest
contigencyr  r  rY  listId	ocoOrderss                      rU  create_orderszcryptocom.create_orders  s      !!!!!!!!!q#f++&& 		0 		0AayH''(;;H##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K==hdTZ\acnooL!!,////%%f.@&II
 *(
 
 AA$++gW]B^B^________T 8R88!!&)44$f-.I$$Y///  (((rV  c                 &   |                      |          }|                                }|d         |                                d}	|dk    s|dk    s|dk    r|                     ||          |	d<   |                     | j        dd          }
|
|	d	<   |                     |d
d          }|)|dk    rd|	d<   n|dk    rd|	d<   n|dk    rd|	d<   n||	d<   |                     |dd          }|s|dk    rdg|	d<   d|	d<   |                     |g d          }|                     |d          }|                     |d          }|d u}|d u}|d u}|r| 	                    |          }|dk    s|dk    s|dk    rH|dk    r!t          j        ||          rd|	d<   nd|	d<   nt          j        ||          rd|	d<   nd|	d<   n|dk    r!t          j        ||          rd|	d<   n`d|	d<   nZt          j        ||          rd|	d<   n?d|	d<   n9|r|dk    s|dk    rd|	d<   n%d|	d<   n|r|dk    s|dk    rd|	d<   nd|	d<   n||	d<   |dk    r|dk    s|dk    s|dk    rd }d}|                     |d d!d          \  }}|                     |d"d#          }|                     |d"          }||                     ||          }n|ro|t!          | j        d$z             | 	                    |          }| 	                    |          }t          j        ||          }|                     ||          }n|                     ||          }||	d#<   n|                     ||          |	d%<   |                     |g d&          }|                     |	|          S )'Nr6   )r  r  r  r  r  r  r   r   r  r   r  r  r  r   r  r   r  r  Fr   r  r  r  r   r   r"  rn  r#  r$  MARKETTrQ   !createMarketBuyOrderRequiresPricer  notionala	   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%  )r  r'  r)  r{  r   r,  r}  r-  r~  r.  r1   r/  rp  safe_number_2r  cost_to_precisionr(   r6   
string_mulr(  r  )rS  r  rn  r  rk  r  r  r  r0  r  r   r   r  r   r   r   r2  r3  r4  r5  quoteAmountrM  r  amountStringcostRequests                            rU  r@  z'cryptocom.create_advanced_order_request  s   
 V$$

%d|JJLL
 
 W$$-<*G*G]^qMqMq#66vuEEGG!!$,&AA%..v}oVV"e##+=((%%+@((%%+9((+6(>>&*e<< 	:+--$/=GK '9GO$))&2\2\2\]]((AA**63DEE!-	*$6.d: #	,//66K((m|.K.KQ^buQuQu5==(lCC 7*=*6(lCC >*6*=5==(lCC 6*7*5(lCC 8*5*7 	,((m|.K.K"."-  	,((m?R.R.R"5"/+GFOEMM(!:!:Q\@\@\bo  tA  cA  cAK04-8<8U8UV\^k  nQ  SW  9X  9X5-v%%ffjAADYYvv..F"44VTBB2 	E=&tw  2}  (}  ~  ~  ~#'#8#8#@#@L"&"7"7">">K")"4\;"O"OK"&"8"8"M"MKK"44VVDD"-GJ"&":":66"J"JGJ6  $Q  $Q  $Q  R  R{{7F+++rV  c                    K   |                                   d{V  |                     |||||          }|                     |           d{V }	|                     |	di           }
|                     |
          S )ar  
        edit a trade order

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-amend-order

        :param str id: order id
        :param str symbol: unified market symbol of the order to edit
        :param str [type]: not used by cryptocom editOrder
        :param str [side]: not used by cryptocom editOrder
        :param float amount:(mandatory) how much of the currency you want to trade in units of the base currency
        :param float price:(mandatory) the price for the order, 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]: the original client order id of the order to edit, required if id is not provided
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NrY  )r  edit_order_requestv1PrivatePostPrivateAmendOrderrt  r  )rS  r6   r  rn  r  rk  r  r  r  r  rY  s              rU  
edit_orderzcryptocom.edit_order?  s        !!!!!!!!!))"ffeVLL<<WEEEEEEEE(B77'''rV  c                 v   i }|||d<   nM|                      |dd          }|t          | j        dz             ||d<   |                     |ddg          }||t          | j        dz             |                     ||          |d<   |                     ||          |d<   |                     ||          S )Nr  orig_client_oidr&  zA editOrder() requires an id argument or orig_client_oid parameterz editOrder() requires both amount and price arguments. If you do not want to change the amount or price, you should pass the original valuesnew_quantity	new_price)safe_string_2r$   r6   r  r(  r)  r  )rS  r6   r  rk  r  r  r  originalClientOrderIds           rU  rV  zcryptocom.edit_order_requestU  s    >"$GJ$($6$6v?PRa$b$b!$,'2u(uvvv-B)*6,=+OPPN#DG  /}  %}  ~  ~  ~"&":":66"J"J#66vuEE{{7F+++rV  c                   K   |                                   d{V  d}i }| |                     |          }|d         |d<   |                     |                     ||                     d{V }|                     d|i          gS )a  
        cancel all open orders

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-all-orders

        :param str symbol: unified market symbol of the orders to cancel
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict} Returns exchange raw message{@link https://docs.ccxt.com/?id=order-structure:
        Nr6   r  rc  )r  r  #v1PrivatePostPrivateCancelAllOrdersr  
safe_order)rS  r  r  r  r  r  s         rU  cancel_all_orderszcryptocom.cancel_all_ordersf  s       !!!!!!!!![[((F)/G%&AA$++gW]B^B^________ 23344rV  c                 ,  K   |                                   d{V  d}||                     |          }d|i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        cancels an open order

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order

        :param str id: the order id of the order to cancel
        :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>`
        Nr  rY  )r  r  v1PrivatePostPrivateCancelOrderr  rt  r  )rS  r6   r  r  r  r  r  rY  s           rU  cancel_orderzcryptocom.cancel_ordery  s       !!!!!!!!![[((F
 ==dkk'SY>Z>Z[[[[[[[[ (B77///rV  idsc                   K   |t          | j        dz             |                                  d{V  |                     |          }g }t	          dt          |                    D ]7}||         }|d         t          |          d}|                    |           8d|d}	|                     | 	                    |	|                     d{V }
| 
                    |
dg           }|                     ||dd|          S )	a  
        cancel multiple orders

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list

        :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   r6   r  r  r<  r=  rY  )r$   r6   r  r  rw  rx  strr  #v1PrivatePostPrivateCancelOrderListr  rz  r  )rS  rf  r  r  r  orderRequestsr  r6   r  r  r  rY  s               rU  cancel_orderszcryptocom.cancel_orders  s3      >#DG.Z$Z[[[!!!!!!!!!V$$q#c((## 	( 	(AQB#)$<GG E   '''' &'
 
 AA$++gW]B^B^________(B77  tVDDDrV  c                 2  K   |                                   d{V  g }t          dt          |                    D ]x}||         }|                     |d          }|                     |d          }|                     |          }|d         t          |          d}	|                    |	           yd|d}
|                     |                     |
|                     d{V }| 	                    |dg           }| 
                    |ddd|          S )	a/  
        cancel multiple orders for multiple symbols

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list

        :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
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr   r6   r  rh  r<  r=  rY  )r  rw  rx  r{  r  ri  r  rj  r  rz  r  )rS  r  r  rk  r  r  r6   r  r  	orderItemr  r  rY  s                rU  cancel_orders_for_symbolsz#cryptocom.cancel_orders_for_symbols  sB      !!!!!!!!!q#f++&& 		, 		,A1IE!!%..B%%eX66F[[((F#)$<GG I   ++++ &'
 
 AA$++gW]B^B^________(B77  tT6BBBrV  c                 p  K   |                                   d{V  d}i }| |                     |          }|d         |d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )a&  
        fetch all unfilled currently open orders

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-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 order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr6   r  rY  r  )r  r  !v1PrivatePostPrivateGetOpenOrdersr  rt  rz  r  )
rS  r  r  r  r  r  r  r  r  r  s
             rU  fetch_open_orderszcryptocom.fetch_open_orders  s       !!!!!!!!![[((F)/G%&??GU[@\@\]]]]]]]]L ~~h"55fb11  >>>rV  c                 p  K   |                                   d{V  d}|                     |dd          \  }}|r |                     d||||d           d{V S i }d}| |                     |          }|d         |d<   |||d<   |||d	<   |                     |d
          }|                     |d
g          }|||d<   |                     |                     ||                     d{V }	|                     |	di           }
| 	                    |
dg           }| 
                    ||||          S )a  
        fetch all trades made by the user

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-trades

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for, maximum date range is one day
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :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>`
        NFry   r  r   r6   r  r  r  r  r  rY  r  )r  rp  r  r  r  r  v1PrivatePostPrivateGetTradesr  rt  rz  r  )rS  r  r  r  r  r  r  r  r  r  rY  r  s               rU  fetch_my_tradeszcryptocom.fetch_my_trades  s      !!!!!!!!!88R\]]& 	o::?FTY[`bhjmnnnnnnnnn[[((F)/G%&$)GL!$GG!!&'226G9--"'GJ;;DKKQW<X<XYYYYYYYY< (B7733  >>>rV  c                     d }d }d }|                     d          dk    r6|                    d          \  }}|                    d          }|d         }n|}||gS )N?r   =r   )findsplit)rS  addressStringaddresstagrawTagsplitteds         rU  parse_addresszcryptocom.parse_addressV  sl    c""Q&&+11#66OGV||C((H1+CC#G~rV  rm  r|  r}  c                   K   |                      ||          \  }}|                                  d{V  |                     |          }|d         ||d}|||d<   d}|                     |          \  }}|                     |          }	|	|	|d<   |                     |                     ||                     d{V }
|                     |
d          }|                     ||          S )a  
        make a withdrawal

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-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>`
        Nr6   )r  rk  r|  address_tagr\  rY  )	handle_withdraw_tag_and_paramsr  safe_currencyhandle_network_code_and_paramsnetwork_code_to_id$v1PrivatePostPrivateCreateWithdrawalr  rt  parse_transaction)rS  rm  rk  r|  r}  r  r  r  networkCoder  r  rY  s               rU  r   zcryptocom.withdrawb  s!      99#vFFV!!!!!!!!!%%d++ 
 

 ?%(GM""AA&IIV++K88	 $-GL!BB4;;wX^C_C_````````" (33%%fh777rV  c                 .  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }t          |          }|dk    rt          | j        dz             i }	t          d|          D ]}
|                     ||
          }| 
                    |d          }| 
                    |d          }|                     |          }|                     |          \  }}|                     |           | 
                    |d	          }|                     ||          }|||||d
|	|<   |	S )a  
        fetch a dictionary of addresses for a currency, indexed by network

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-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  r6   rY  deposit_address_listr   z7 fetchDepositAddressesByNetwork() generating address...r|  rd  )rc  r  rd  r|  r}  )r  r  %v1PrivatePostPrivateGetDepositAddressr  rt  rz  rx  r    r6   rw  r{  ry  r  check_addressr|  )rS  rm  r  r  r  r  r  	addressesaddressesLengthrY  r  valuer{  r  responseCoder|  r}  r  rd  s                      rU  "fetch_deposit_addresses_by_networkz,cryptocom.fetch_deposit_addresses_by_network  s      !!!!!!!!!%%d++
 CCDKKPWY_D`D`aaaaaaaa( ~~h"55NN4)?DD	i..a*c cdddq/** 	 	ANN9a00E ,,UI>>M))%<<J22:>>L--m<<LGSw'''((	::I--iFFG("" F7OO rV  c                   K   |                      |d          }|                     |dg          }|                     ||           d{V }||v r||         S t          |                                          }||d                  S )a  
        fetch the deposit address for a currency associated with self account

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-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>`
        rd  Nr   )safe_string_upperr  r  ru  rv  )rS  rm  r  rd  depositAddressesrv  s         rU  fetch_deposit_addresszcryptocom.fetch_deposit_address  s       ((;;6I;//!%!H!Hv!V!VVVVVVV&&&#G,,(--//00D#DG,,rV  c                   K   |                                   d{V  d}i }| |                     |          }|d         |d<   |||d<   |||d<   |                     |d          }|                     |dg          }|||d<   |                     |                     ||                     d{V }|                     |di           }	|                     |	d	g           }
|                     |
|||          S )
a  
        fetch all deposits made to an account

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-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]: timestamp in ms for the ending date filter, default is the current time
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr6   r  r  	page_sizer  r  rY  deposit_list)	r  r  r  r  %v1PrivatePostPrivateGetDepositHistoryr  rt  rz  parse_transactions)rS  rm  r  r  r  r  r  r  r  r  depositLists              rU  fetch_depositszcryptocom.fetch_deposits  s2      !!!!!!!!!))$//H"*4.GJ"'GJ#(GK !!&'226G9-- %GHCCDKKPWY_D`D`aaaaaaaa. ~~h"55nnT>2>>&&{HeUKKKrV  c                   K   |                                   d{V  d}i }| |                     |          }|d         |d<   |||d<   |||d<   |                     |d          }|                     |dg          }|||d<   |                     |                     ||                     d{V }|                     |di           }	|                     |	d	g           }
|                     |
|||          S )
a  
        fetch all withdrawals made from an account

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-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]: timestamp in ms for the ending date filter, default is the current time
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr6   r  r  r  r  r  rY  withdrawal_list)	r  r  r  r  (v1PrivatePostPrivateGetWithdrawalHistoryr  rt  rz  r  )rS  rm  r  r  r  r  r  r  r  r  withdrawalLists              rU  fetch_withdrawalszcryptocom.fetch_withdrawals  s3      !!!!!!!!!))$//H"*4.GJ"'GJ#(GK !!&'226G9-- %GHFFt{{SZ\bGcGcdddddddd2 ~~h"55.?DD&&~xNNNrV  tickerr  c                    |                      |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k    r|                     |d          nd |d|          S ) Nr  r  _r  ar  r  datetimehighhlowlbidb	bidVolumeaskk	askVolumevwapopencloser   previousClosechange
percentagecaveragevUSDvv)
baseVolumequoteVolumerc  )r  r{  safe_marketsafe_tickerr  r~  )rS  r  r  r  rD  r  r   s          rU  parse_tickerzcryptocom.parse_tickerP  s   B %%fc22	##FC00!!(FC88  11,, !
fX&!
!
 Y//!
 D$$VS11	!

 4##FC00!
 4##FC00!
 !
 4##FC00!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $**6377!!
" t#!
$ **6377>Cunn4++FD999SW)!
 !
 !
* +  	rV  tradec                    |                      |dd          }|                     |dd          }|                     ||d          }|                     |d          }|                     |d          }|                     ||                     |dd	          ||                     |          |d
         |                     |d          |                     |dd          |                     |d          |                     |dd          |                     |dd          d d | 	                    |          | 
                    t          j        |                    dd|          S )Nr  create_timer  r  r  fee_instrument_namer   dtrade_idr  r  sr  
taker_sideptraded_priceqtraded_quantityr  r  )rc  r6   r  r  r  r  r  takerOrMakerr  rk  r  rn  rg  )safe_integer_2r]  r  r{  
safe_trader  safe_string_lower_2r  rO  ry  rR  r1   
string_neg)rS  r  r  r  rD  feeCurrencyfeeCostStrings          rU  parse_tradezcryptocom.parse_trade  sp   F ''sMBB	%%eS2CDD!!(FC88&&u.CDD((77$$UC<<"Y//X&%%eZ88,,UC@@ 225,GG''sNCC((5FGG 33K@@))'*<]*K*KLL  
  
" #  	rV  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr  or  r  r  r  )r  r~  )rS  ohlcvr  s      rU  parse_ohlcvzcryptocom.parse_ohlcv  s     eS))UC((UC((UC((UC((UC((
 	
rV  statusc                 @    dddddd}|                      |||          S )Nr  canceledclosedrejectedexpired)ACTIVECANCELEDFILLEDREJECTEDEXPIREDr{  rS  r  statusess      rU  parse_order_statuszcryptocom.parse_order_status  s7    "" 
 
 &&999rV  r   c                 <    dddd}|                      |||          S )Nr  r   r   )r  r  r  r  )rS  r   timeInForcess      rU  parse_time_in_forcezcryptocom.parse_time_in_force  s1     %#(!
 

 k;GGGrV  r  c           
      R   |                      |d          }|H|dk    rB|                     |                     |d          |                     |d          |dd          S |                      |d          }|                     |d          }|                     ||          }|                     |d	          }d }|4d
}t          dt          |                    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!|                     |d"          d#d d$|                     |d%          |                     |d&          |                     |          |                     |d'          d(g d)|          S )*Nrm  r   r  
client_oidr  )r6   r&  rc  r  r  r  r  Fr  Tr  rc  r6   r&  r  r  lastTradeTimestampupdate_timer  r  rn  
order_typer   r  r  r  r  limit_pricerk  r  filledcumulative_quantity	remainingr  	avg_pricecumulative_valuecumulative_feer  )r  rg  r  )r  ra  r{  safe_symbolr  rw  rx  r  r  r  r  r~  ry  )rS  r  r  rm  r  rD  r  execInstr  r  instr  s               rU  r  zcryptocom.parse_order  sM   ^   //4199??&&uj99!%!1!1%!F!F$	$ $    ##E=99##E+<==!!(F33??5+66H1c(mm,,  {;&&#HE ' &&u.CDD  
E 
$""5*55 
 T--e\BB 
 	 

 W-- 
 !$"3"3E="I"I 
 d--d.>.>uh.O.OPP 
 f 
 D**5,?? 
 433D4D4DUO4\4\]] 
  
 D**5&99 
 T%%e];; 
 d&&uj99 
 d&&u.CDD 
  ! 
" t''{;;# 
$ $$U,>?? 33K@@((0@AA  / 
  
  
0 1  	rV  c                 >    ddddd}|                      |||          S )Npendingokfailed)r   r  23r  r  s      rU  parse_deposit_statuszcryptocom.parse_deposit_statusL	  s4    	
 
 &&999rV  c                 D    dddddddd}|                      |||          S )Nr  r  r  r  )r   r  r   r  456r  r  s      rU  parse_withdrawal_statusz!cryptocom.parse_withdrawal_statusU	  s=    
 
 &&999rV  transactionr  c                    d }|                      |d          }d }d|v rd}|                     |          }n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S )Nr  
client_wid
withdrawalrf  r|  r  r  rg  r  rc  r6   txidr  r  rd  	addressToaddressFromr}  tagTotagFromrn  rk  updatedr  )internalcommentrg  )r{  r  r  r  ry  r  r~  r  )rS  r  r  rn  	rawStatusr  r{  r|  r}  r  rm  r  feeCostrg  s                 rU  r  zcryptocom.parse_transactiona	  sA   X $$[(;;	;&&D11)<<FFD..y99F((i@@))-88%%k:>>
&&z8<<%%k=AA	"";66#W55C
K
$"";55
 D$$[&99
 	

 Y//
 t
 w
 
 4
 3
 S
 t
 D
 d&&{H==
 
  f!
" t((mDD#
$ ''\BB)
 
 
 	
rV  c                 (   |                      | j        d          }|                     |dd          }|                     |d          }d}|                     ||          \  }}||dk    rt          | j        dz             n|dk    s|du rd}||gS )aR  
 @ignore
        marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Array: the marginMode in lowercase
        r   rC   FNcrossz only cross margin is supportedT)r{  r   r}  r  handle_margin_mode_and_paramsr*   r6   )rS  
methodNamer  r   isMarginr   s         rU  r+  z.cryptocom.custom_handle_margin_mode_and_params	  s     &&t|]CC>>&(E::68,,
!??
FSS
F!W$$"47-N#NOOO % x''X-=-=$
F##rV  c                    |                      |dg           }t          |          }|d d dd d di d}|t          d|          D ]}||         }|                     |d          }|                     |d          }	|                     ||	          }
d d d|                     |d          ddd	|d
         |
<   |dk    r*|                     |d          |d         d<   d|d         d<   |S )Nr[  )rg  r  )rc  r   rf  r   r   r\  rm  r_  F)rf  r   r   r   r   rg  r  )rz  rx  rw  r{  r|  r~  )rS  rg  r  networkListnetworkListLengthrY  r  networkInfor  currencyCoder  s              rU  parse_deposit_withdraw_feez$cryptocom.parse_deposit_withdraw_fee	  sG   " nnS."==,," 
 "  
 
 "1/00 = =)!n ,,[,GG	#//&AA"55iNN'+4@@(,(8(8FV(W(Wgl m m3 3z";/ %))040@0@N^0_0_F:&u-7<F:&|4rV  codesc                    K   |                                   d{V  |                     |           d{V }|                     |d          }|                     |d          }|                     ||d          S )a  
        fetch deposit and withdraw fees

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-currency-networks

        :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 `fee structures <https://docs.ccxt.com/?id=fee-structure>`
        NrY  rZ  rj  )r  rq  r  rz  parse_deposit_withdraw_fees)rS  r!  r  r  r  r  s         rU  fetch_deposit_withdraw_feesz%cryptocom.fetch_deposit_withdraw_fees	  s       !!!!!!!!!EEfMMMMMMMMx22nnT>:://UKPPPrV  c                   K   |                                   d{V  i }d}||                     |          }|||d<   |||d<   |                     |d          }|                     |dg          }|||d<   |                     |                     ||                     d{V }|                     |di           }	|                     |	dg           }
|                     |
|||          S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-transactions

        :param str [code]: unified currency code
        :param int [since]: timestamp in ms of the earliest ledger entry
        :param int [limit]: max number of ledger entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        Nr  r  r  r  rY  r  )	r  r  r  r  #v1PrivatePostPrivateGetTransactionsr  rt  rz  parse_ledger)rS  rm  r  r  r  r  r  r  r  rY  ledgers              rU  fetch_ledgerzcryptocom.fetch_ledger
  s#      !!!!!!!!!))$//H$)GL!$GG!!&'226G9--"'GJAA$++gW]B^B^________< (B7733  5%@@@rV  itemc                    |                      |d          }|                     |d          }|                     ||          }|                     ||          }|                     |d          }d }t	          j        |d          rd}t	          j        |          }nd}|                     ||                     |d          ||                     |d          |                     |d	          |                     |d
          |                     |                     |d                    || 	                    |          || 
                    |          d d d d d dd|          S )Nevent_timestamp_msr  transaction_qtyr   outinr  
account_idr  trade_match_idjournal_typer  )rc  r6   	directionr   referenceIdreferenceAccountrn  r  rk  r  r  beforeafterr  rg  )r  r{  ry  r  r1   r/  
string_abssafe_ledger_entryparse_ledger_entry_typerR  r  )rS  r*  r  r  r  rm  rk  r3  s           rU  parse_ledger_entryzcryptocom.parse_ledger_entryD
  s   * %%d,@AA	%%d,=>>
&&z8<<%%j(;;!!$(9::	VS)) 	I'//FFI%%""444"''l;;++D*== $ 0 07G H H001A1A$1W1WXX''//"Y//  '
 '
& '  	rV  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ddddd}|                      |||          S )NTRADINGr  	TRADE_FEErg  WITHDRAW_FEEWITHDRAWr  DEPOSITrf  ROLLBACK_WITHDRAWrollbackROLLBACK_DEPOSITFUNDINGREALIZED_PNLINSURANCE_FUND	insuranceSOCIALIZED_LOSSLIQUIDATION_FEESESSION_RESETreset
ADJUSTMENT
adjustmentSESSION_SETTLE
settlementUNCOVERED_LOSSADMIN_ADJUSTMENTdelist
conversion)DELISTSETTLEMENT_FEEAUTO_CONVERSIONMANUAL_CONVERSIONr  )rS  rn  
ledgerTypes      rU  r:  z!cryptocom.parse_ledger_entry_typey
  s   
w

 E
 	

 y
  
 

 u
 G
 k
 w
 u
 W
 ,
 l
  g!
" #
$ #+!-+
 
 

. 
D$777rV  c                 P  K   |                                   d{V  |                     |           d{V }|                     |di           }|                     |di           }|                     |dg           }|                    |           |                     ||          S )a|  
        fetch all the accounts associated with a profile

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-accounts

        :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
        NrY  master_accountsub_account_list)r  v1PrivatePostPrivateGetAccountsrt  rz  r  parse_accounts)rS  r  r  rY  masterAccountaccountss         rU  fetch_accountszcryptocom.fetch_accounts
  s       !!!!!!!!!==fEEEEEEEE@ (B77v/?DD>>&*<bAA&&&""8V444rV  c                 `    |                      |d          |                      |d          d |dS )Nuuidlabel)r6   rn  rm  rc  r  )rS  r   s     rU  parse_accountzcryptocom.parse_account
  s?    6 ""7F33$$Wg66	
 
 	
rV  c                 V  K   |                                   d{V  d}||                     |          }d}|                     d||          \  }}|                     d|dg d           |dk    rd}d|                                i}|                     |                     ||                     d{V }|                     |di           }	|                     |	d	g           }
| 	                    |
|          }| 
                    |d
          }|                     ||||          S )a/  
        fetches historical settlement records

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-expired-settlement-price

        :param str symbol: unified market symbol of the settlement history
        :param int [since]: timestamp in ms
        :param int [limit]: number of records
        :param dict [params]: exchange specific params
        :param int [params.type]: 'future', 'option'
        :returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/?id=settlement-history-structure>`
        Nr   rn  )rE   rF   r  r  rF   r  instrument_typerY  r  r  )r  r  r*  check_required_argumentr'  *v1PublicGetPublicGetExpiredSettlementPricer  rt  rz  parse_settlementssort_byfilter_by_symbol_since_limit)rS  r  r  r  r  r  rn  r  r  rY  r  settlementssorteds                rU  fetch_settlement_historyz"cryptocom.fetch_settlement_history
  sV      !!!!!!!!![[((F99:RTZ\bccf$$%=tVMvMvMvwww8Dtzz||
 HHU\^dIeIeffffffff$ (B77~~ffb11,,T6::k;7700NNNrV  c                     |                      |d          }|                     |d          }||                     ||          |                     |d          ||                     |          dS )Nxr  r  )rc  r  r  r  r  )r  r{  r  r~  r  )rS  rP  r  r  rD  s        rU  parse_settlementzcryptocom.parse_settlement  sx     %%j#66	##J44&&x88%%j#66"Y//
 
 	
rV  c                     g }t          dt          |                    D ]1}|                    |                     ||         |                     2|S )Nr   )rw  rx  r  rr  )rS  rm  r  rY  r  s        rU  rj  zcryptocom.parse_settlements(  sZ     q#k**++ 	I 	IAMM$//AGGHHHHrV  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             |d         ddd}|                     |                     ||                     d{V }|                     |di           }|                     |d	g           }|                     |d
i           }|                     ||          S )a  
        fetches historical funding rates

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-valuations

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        NrD   z0 fetchFundingRate() supports swap contracts onlyr6   estimated_funding_rater   )r  valuation_typer  rY  r  r   )	r  r  r&   r6   v1PublicGetPublicGetValuationsr  rt  rz  parse_funding_rate)	rS  r  r  r  r  r  rY  r  entrys	            rU  fetch_funding_ratezcryptocom.fetch_funding_rate8  s      !!!!!!!!!V$$f~ 	ZDG&XXYYY%d|6
 

 <<T[[RX=Y=YZZZZZZZZ" (B77~~ffb11tQ++&&uf555rV  c                    |                      |d          }d }|'t          t          j        |dz                      dz  }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iS )Nr  i6 rc  r  	markPrice
indexPriceinterestRateestimatedSettlePricer  r  fundingRater  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeintervalr   )r  r  mathceilr  r  r~  )rS  r  r  r  r  s        rU  rx  zcryptocom.parse_funding_ratea  sd    %%h44	 "49Y-@#A#ABBWL
H
d&&tV44
 
 $	

 D
 #D
 
 Y//
 4++Hc::
  0
 t||,<==
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
rV  c           
      d  K   |t          | j        dz             |                                  d{V  d}|                     |dd          \  }}|r |                     d|||d|           d{V S |                     |          }|d         st          | j        dz             |d	         d
d}|||d<   |||d<   |                     |d          }|                     |dg          }|||d<   | 	                    | 
                    ||                     d{V }	|                     |	di           }
|                     |
dg           }|                     |
d          }g }t          dt          |                    D ]v}||         }|                     |d          }|                    ||                     ||          |                     |d          ||                     |          d           w|                     |d          }|                     ||d         ||          S )a  
        fetches historical funding rates

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-valuations

        :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] to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is the current time
        :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 argumentFrj   r  8hrD   z7 fetchFundingRateHistory() supports swap contracts onlyr6   funding_hist)r  rv  r  r  r  r  rY  r  r  r   r  r  )rc  r  r  r  r  r  r  )r$   r6   r  rp  r  r  r&   r  r  rw  r  rt  rz  r{  rw  rx  r  r  r~  r  rk  rl  )rS  r  r  r  r  r  r  r  r  r  rY  r  rD  ratesr  ry  r  rn  s                     rU  fetch_funding_rate_historyz$cryptocom.fetch_funding_rate_history  s      >#DG.e$efff!!!!!!!!!88AZ\fgg& 	@@@AZ\bdikprvx~V$$f~ 	aDG&__```%d|,
 
 "'GJ$GG!!&'226G9-- %GH<<T[[RX=Y=YZZZZZZZZ" (B77~~ffb11##F,=>>q#d))$$ 		 		AGE))%55ILL**8V<<#//s;;& LL33      e[11009I5RWXXXrV  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |                     |d          |          S )a  
        fetch data on a single open contract trade position

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions

        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr  r6   rY  r  r   )r  r   v1PrivatePostPrivateGetPositionsr  rt  rz  parse_position)rS  r  r  r  r  r  rY  r  s           rU  fetch_positionzcryptocom.fetch_position  s       !!!!!!!!!V$$vd|
 >>t{{7TZ?[?[\\\\\\\\. (B77~~ffb11""4>>$#:#:FCCCrV  c                 8  K   |                                   d{V  |                     |          }i }d}|nd}t          |t                    r5t	          |          }|dk    rt          | j        dz             |d         }n|}|                     |          }|d         |d<   |                     | 	                    ||                     d{V }| 
                    |di           }|                     |dg           }	g }
t          dt	          |	                    D ]a}|	|         }|                     |d          }|                     |ddd	          }|
                    |                     ||                     b|                     |
d
dd          S )a  
        fetch all open positions

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr   zD fetchPositions() symbols argument cannot contain more than 1 symbolr   r6   r  rY  r  r  r  F)r  market_symbolsrs  ru  rx  r%   r6   r  r  r  rt  rz  rw  r{  r  r  r  filter_by_array_positions)rS  r  r  r  r  r  r  r  r  	positionsrY  r  ry  rD  marketInners                  rU  fetch_positionszcryptocom.fetch_positions  s      !!!!!!!!!%%g..F'4(( ! #G 1$$$TW/u%uvvv  [[((F)/G%&>>t{{7TZ?[?[\\\\\\\\. (B??NN>62>>	q#i..)) 	C 	CAaLE''/@AAH**8T4LLKMM$--e[AABBBB--fheLLLrV  positionc                    |                      |d          }|                     ||d d          }|                     ||d d          }|                     |d          }|                      |d          }|                     i d|dd d|d|d	|                     |          d
d dt          j        |d          rdnddt          j        |          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  update_timestamp_msr  rc  r6   r  r  r  r   r  r   r"  sell	contractsr  
entryPricer|  rN  r  
collateralopen_pos_costinitialMarginr  maintenanceMargininitialMarginPercentageopen_position_pnl)maintenanceMarginPercentageunrealizedPnlliquidationPricer   r  marginRatior   r   )
r{  r  r  r  safe_positionr  r1   	string_gtr8  r~  )rS  r  r  rD  r  r  rk  s          rU  r  zcryptocom.parse_position+  s    ##H.?@@!!(FD*EE!!(FD*EE%%h0EFF	!!(J77!! #
H#
$#
 f#
 	#

 Y//#
 d#
 W.vs;;GEE#
 +F33#
 F>2#
 $#
 #
 #
 #
 $**8_EE#
 T--h??#
   !#
" &t##
$ ,0!--h8KLL $!#3#
 #
 #
   	rV  c                 *    |                                  S N)milliseconds)rS  s    rU  noncezcryptocom.nonceZ  s      """rV  c                 \   d}||k    rt          |          S t          |t                     r|S d}d }t          |t                    r|}n6|                     |          }t          |                                          }t          dt          |                    D ]}||         }||z  }||         }	|	dk    r|dz  }#t          |	t                    rCt          dt          |	                    D ]$}
||                     |	|
         |dz             z  }%{|t          |	          z  }|S )N    r   Noner   )ri  rs  ru  keysortrv  rw  rx  params_to_string)rS  objectlevelmaxLevelreturnString
paramsKeysrn  r  r  r  r  s              rU  r  zcryptocom.params_to_string]  sE   Hv;;fc"" 	M
fd## 	-JJ\\&))Ffkkmm,,Jq#j//** 
	+ 
	+AQ-CCL3KE&E4(( +q#e**-- O OA D$9$9%(EAI$N$NNLLO E

*rV  c                   K   |                                   d{V  |                     |          }|d         dd}|                     |d          }|                     |d          }|||d<   ||                     |d         |          |d<   |                     |                     ||                     d{V }|                     |d          }	|                     |	|          S )	aP  
        closes open positions for a market

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position

        :param str symbol: Unified CCXT market symbol
        :param str [side]: not used by cryptocom.closePositions
        :param dict [params]: extra parameters specific to the okx api endpoint

 EXCHANGE SPECIFIC PARAMETERS
        :param str [params.type]: LIMIT or MARKET
        :param number [params.price]: for limit orders only
        :returns dict[]: `A list of position structures <https://docs.ccxt.com/?id=position-structure>`
        Nr6   rL  )r  rn  rn  r  r  rY  )	r  r  r  r{  r)  !v1PrivatePostPrivateClosePositionr  rt  r  )
rS  r  r  r  r  r  rn  r  r  rY  s
             rU  close_positionzcryptocom.close_positionw  s      !!!!!!!!!V$$%d|
 
 %%ff55  11"GFO#66vh7GOOGG??GU[@\@\]]]]]]]] (33///rV  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )ax  
        fetch the trading fees for a market

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-instrument-fee-rate

        :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  r6   rY  )r  r  (v1PrivatePostPrivateGetInstrumentFeeRater  rt  parse_trading_fee)rS  r  r  r  r  r  r  s          rU  fetch_trading_feezcryptocom.fetch_trading_fee  s       !!!!!!!!!V$$vd|
 FFt{{SZ\bGcGcdddddddd  ~~h"55%%dF333rV  c                    K   |                                   d{V  |                     |           d{V }|                     |di           }|                     |          S )am  

        https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-fee-rate

        fetch the trading fees for multiple markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/?id=fee-structure>` indexed by market symbols
        NrY  )r  v1PrivatePostPrivateGetFeeRatert  parse_trading_fees)rS  r  r  rY  s       rU  fetch_trading_feeszcryptocom.fetch_trading_fees  s|       !!!!!!!!!<<VDDDDDDDD  (B77&&v...rV  c                    i }||d<   t          dt          | j                            D ]}| j        |         }|                     |          }|d         }|rdnd}|rdnd}|||                     t          j        |                     ||          d                    |                     t          j        |                     ||          d                    d d d	}	|	||<   |S )
Nrc  r   rD   effective_deriv_taker_rate_bpseffective_spot_taker_rate_bpseffective_deriv_maker_rate_bpseffective_spot_maker_rate_bpsr   rc  r  r   r   r  	tierBased)rw  rx  r  r  rR  r1   
string_divr{  )
rS  r  rY  r  r  r  isSwaptakerFeeKeymakerFeeKey
tradingFees
             rU  r  zcryptocom.parse_trading_fees  s    !vq#dl++,, 	( 	(A\!_F[[((FF^F>Di::JiK>Di::JiK  **7+=d>N>NxYd>e>egn+o+opp**7+=d>N>NxYd>e>egn+o+opp"! J (F6NNrV  rg  c                 T   |                      |d          }|                     ||          }|||                     t          j        |                      |d          d                    |                     t          j        |                      |d          d                    d d dS )Nr  effective_maker_rate_bpsr   effective_taker_rate_bpsr  )r{  r  rR  r1   r  )rS  rg  r  rD  r  s        rU  r  zcryptocom.parse_trading_fee  s     ##C):;;!!(F33&&w'9$:J:J3Pj:k:kmt'u'uvv&&w'9$:J:J3Pj:k:kmt'u'uvv
 
 	
rV  r   GETc           	         |                      |d          }|                      |d          }| j        d         |         dz   |z   }	|                     ||                     |                    }
|dk    r|
r|	d|                     |
          z   z  }	n5|                                  t          |                                           }|                     i |          }t          |
                                          }|                     |d          }||z   | j        z   |z   |z   }|                     |                     |          |                     | j                  t           j                  }t%          |          }|                     |||| j        ||d          }|dk    rd}d	}|                    ||          }d
di}|	|||dS )Nr   r   r   r  r   rw  )r6   methodr  api_keysigr  z{}z[]zContent-Typezapplication/json)r   r  bodyheaders)r{  r   r  extract_params	urlencodero  ri  r  r  ru  rv  r  apiKeyhmacencodesecrethashlibsha256rx  jsonreplace)rS  pathr   r  r  r  r  rn  accessr   queryr  requestParamsr  
strSortKeypayload	signatureparamsKeysLengthparamsStringarrayStrings                       rU  signzcryptocom.sign  s   Q''!!#q))it$s*T1		&$"5"5d";";<<X 3sT^^E2222++---

%%E KKF33Mm002233J..}a@@JUlT[0:=EG		$++g"6"6DK8P8PRYR`aaI":99 ;    D  1$$#"||K>> 2G fdwOOOrV  reasonr   r  r  r  c
                     |                      |d          }
|
dk    rI| j        dz   |z   }|                     | j        d         |
|           t	          | j        dz   |z             d S )Nrm  r    rM  )r{  r6   throw_exactly_matched_exceptionr  r    )rS  rm  r  r   r  r  r  r  requestHeadersrequestBody	errorCodefeedbacks               rU  handle_errorszcryptocom.handle_errors8  sp    $$Xv66	w}t+H001I9V^___# 4555trV  r  )e__name__
__module____qualname__r   rQ  r   r  r   r   r  r   r   r  ri  r   r  r   r   r   r  r   r  ru  r  r   r  r   r  r	  r  r   r   floatr   r6  r9  r   rJ  r@  rX  rV  rb  re  rl  r   ro  rr  ru  r  r   r   r
   r  r  r  r  dictr  r  r  r  r  r  r  r  r	   r  r+  r   r$  r   r)  r;  r:  r   ra  re  ro  rr  rj  rz  r   rx  r  r  r   r  r  r  r  r  r   r  r   r  r  r  r  r  r  __classcell__)rT  s   @rU  r3   r3       s       K# K K K K K KZ -/ x x: x x x xt *, { {V { { { {z 6:" 41 417 41 41 41 41 41l 68 0 0 0F 0 0 0 0 04$UYbd J? J? J?C J?s J?imnsit J? J? J? J?X <@d[] 6? 6? 6?S 6? 6?bfglbm 6? 6? 6? 6?p ?CQUdhqs AH AH AH AH3 AH^a AHx|  ~B  yC AH AH AH AHF @DB )C )CS )C )CS\ )C )C )C )CV) ) ) ) ) *, 6, 6, 6, 6, 6, 6,p 8<B 5/ 5/C 5/ 5/ 5/ 5/ 5/n os{} P, P,3 P,i P,y P,Z_ P,hk P, P, P, P,d mqy{ #0 #0 #0I #0Y #0X] #0fi #0 #0 #0 #0J FH K) K)$|*< K) K) K) K)Z x|  EG ^, ^,C ^,y ^,PY ^,ch ^,qt ^, ^, ^, ^,@ fjx|  FH ( (3 ( (9 (I (_b (ru ( ( ( (, TX`b , ,S ,# ,u ,S , , , ," 59 5 5c 5 5 5 5& 9=R  0  0S  0#  0  0  0  0D AER E EtCy E# E E E E> Y[ C Cd;N6O C C C C< 59tZ^gi :? :?c :? :?TW :?nrsxny :? :? :? :?x 37TX\eg @? @?C @?s @?RU @? @? @? @?D
 
 
 QU]_ .8 .83 .8 .8 .8# .8do .8 .8 .8 .8` JL 9 9S 9PTUcPd 9 9 9 9v =? - - -> - - - -& 04$UYbd 5L 5L 5LC 5Ls 5Limnyiz 5L 5L 5L 5Ln 37TX\eg 7O 7OC 7Os 7ORU 7Olpq|l} 7O 7O 7O 7Or; ;4 ; ;6 ; ; ; ;z9 9 9v 9 9 9 9 9v
 
 
4 
 
 
 
(: : : : :Hs H H H H\ \ \v \ \ \ \ \|: : :
: 
: 
:S
 S
T S
X S
Q\ S
 S
 S
 S
j GI $ $ $ $(, , , , , ,\ BFb Q Qw Q Q Q Q  .2SW`b :A :As :A# :AS :Agklwgx :A :A :A :Ax3 3t 3x 3; 3 3 3 3j8 8 84 +- .5 .5g .5 .5 .5 .5`
 
 
B <@daenp /O /OS /O /O[^ /O /O /O /Ob
 
 
&    <> '6 '6s '6 '6 '6 '6R
 
6 
[ 
 
 
 
@ >BPTcgpr DY DYs DY# DY]` DY DY DY DYL 8: (D (D3 (D (D (D (DT 8<B 8M 8MW 8M4PX> 8M 8M 8M 8Mt- -t -V - - - -^# # #  4 CGr (0 (03 (0i (0V[ (0 (0 (0 (0T ;=  4  4c  4AT  4  4  4  4D /1 / /[ / / / /:  <
 
T 
6 
EX 
 
 
 
& &eBSW %P %P %P %PN# s  c TX `c        rV  r3   )9 ccxt.async_support.base.exchanger   ccxt.abstract.cryptocomr   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   typingr   ccxt.base.errorsr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   ccxt.base.preciser1   r3    rV  rU  <module>r	     s#   6 5 5 5 5 5 / / / / / /   o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o  o       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) + + + + + + . . . . . . * * * * * * ) ) ) ) ) ) + + + + + + 4 4 4 4 4 4 % % % % % %^4 ^4 ^4 ^4 ^4+ ^4 ^4 ^4 ^4 ^4rV  