
    !:hs9                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlm Z  d dl!m"Z" d dl!m#Z# d dl!m$Z$ d d	l!m%Z% d d
l!m&Z& d dl!m'Z' d dl!m(Z( d dl!m)Z) d dl!m*Z* d dl!m+Z+ d dl!m,Z, d dl!m-Z- d dl!m.Z. d dl!m/Z/ d dl!m0Z0 d dl!m1Z1 d dl2m3Z3 d dl4m5Z5  G d dee      Z6y)    )Exchange)ImplicitAPIN)AccountAnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBookOrderRequestCancellationRequest	OrderSide	OrderTypePositionStrStringsTickerTickers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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i fdefdZ'di fdedefdZ(di f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$ Z.di fd%ede d&ede/fd'Z0i fd%edee1   fd(Z2i fd%ede1fd)Z3dddi fd%ed
ededee/   fd*Z4dddi fd%ed
ededee/   fd+Z5d`d,e6d-edefd.Z7d`d/e6d-edefd0Z8d`d-edefd1Z9d2efd3Z:d4efd5Z;d`d6e6d-edefd7Z<d8 Z=d9 Z>d`d:e6d;e?de/fd<Z@i fd=ZAd`d;e?fd>ZBdi fd?e
fd@ZCdddi fd%ed
ededeeD   fdAZEd`dBe6d;e?deDfdCZFdD ZGi fdeeH   fdEZIdF ZJdddi fded
edefdGZKdH ZLdI ZMdddi fded
edefdJZNi fdefdKZOdi fde
deeP   fdLZQd`dMe6d-efdNZRdO ZSdP ZTdi fdededefdQZUi fdedeVfdRZWi fdeXfdSZYdT ZZd`dUe6d-edeVfdVZ[dWdXi ddfdYZ\d%e]dZed[ed\ed]e6d^efd_Z^ xZ_S )a	cryptocomreturnc                 ~   | j                  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dfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdxdydzd{d|dyd}d~ddg ddd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ddddd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dydd| j	                  d      | j	                  d      | j	                  d      | j	                  d      g| j	                  d      | j	                  d«      g| j	                  dë      | j	                  dī      g| j	                  dū      | j	                  dƫ      g| j	                  dǫ      | j	                  dȫ      g| j	                  dɫ      | j	                  dʫ      g| j	                  d˫      | j	                  d̫      g| j	                  dͫ      | j	                  dΫ      g| j	                  dϫ      | j	                  dЫ      gg	| j	                  d      | j	                  d      g| j	                  d      | j	                  d«      g| j	                  dë      | j	                  dѫ      g| j	                  dū      | j	                  dҫ      g| j	                  dǫ      | j	                  dӫ      g| j	                  dɫ      | j	                  dԫ      g| j	                  d˫      | j	                  dի      g| j	                  dͫ      | j	                  d֫      g| j	                  dϫ      | j	                  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	ddiddiddidddiddidddddidt
        di dt        dt        dt        dt        dt        d t        dt        dt        dt        dt        dt        dt        dt        dt        d	t        d
t        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        d t        d!t        d"t        d#t        d$t        d%t        d&t         d't"        d(t$        d)t        d*t        d+t        d,t        d-t        d.t&        ii d/      S (0  Nidr2   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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.com/exchange/v1zhttps://api.crypto.com/v2zhttps://deriv-api.crypto.com/v1z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   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-risk-parametersz"public/staking/get-conversion-rate   )get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/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/staking/stakezprivate/staking/unstakez$private/staking/get-staking-positionz'private/staking/get-staking-instrumentszprivate/staking/get-open-stakez!private/staking/get-stake-history)z"private/staking/get-reward-historyzprivate/staking/convertz private/staking/get-open-convertz#private/staking/get-convert-history)publicprivater   )	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.004025000z0.003550000z0.0015100000z0.001250000z0.00091000000z0.000820000000z0.0007	100000000z0.0006	200000000z0.0004z0.0025z0.0016z0.00015z0.00014z0.00013z0.00012z0.0001)makertaker)r   r   tiersoptionsSPOTMARGINDERIVATIVES)fundingrA   rB   r   rC   rD   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   rP   rQ   rw   rz   ry   r|   rZ   rx   extendsdefault)linearinverse)r
  rA   rC   rD   commonCurrenciesUSD_STABLE_COINUSDCprecisionMode
exceptions219314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superr2   describeparse_numberr/   r'   r   r!   r$   r*   r-   r&   r"   r%   r    r(   r.   r+   r,   )self	__class__s    H/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/cryptocom.pyrJ  zcryptocom.describe!   s-   i ? A mD
+mD
LmD
 $mD
 t	mD

 mD
 mD
 4mD
  ZZZ $Z 	Z
 $Z $Z UZ "4Z tZ Z )$Z $UZ  Z /Z ,UZ  0!Z" t#Z$ %Z& "4'Z( %d)Z*  +Z, -Z.  /Z0 &u1Z2 +E3Z4 )%5Z6 $Z7Z8 '9Z: (;Z< "4=Z> &t?Z@ (AZB 1$CZD  EZF +EGZH *:IZJ +DKZL &uMZN #EOZP *4QZR $USZT uUZV "5WZX *5YZZ +E[Z\ t]Z^  _Z` %eaZb /cZd "5eZf +EgZh iZj !%kZl +EmZn  oZp dqZr "4sZt duZv !$wZx tyZz  {Z| '}Z~ $UZ@ !$AZB (CZD )%EZF )$GZH uIZJ tKZL MZN UOZP tQZR "4SZT #DUZV 'WZX $UYZZ !%[Z\ (]Z^ )%_Z` #DaZb cZd #EeZf &ugZh 4iZj ukZl "'#(! sZmD
F GmD
b ?6#? ?5#D
 -? $
 K-cmD
R  ,26</067122356CI45:;  A!!$  '!>'!>'! 3F'! ;F	'!
 4V'! 3E'! 8'! 3E'! 8'! 8'! 5f'! 8'! 6v'! 7'! 1#'!  >v!'!" 7#'!$ A&%'!& >v''!( 5f)'!* 8+'!, <V-'!. :6/'!0 3F1'!2 =f3'!4 :65'!6 3A7'!8 >q9'!: 4Q;'!< 6q='!> CA?'!@ FqA'!B =aC'!D @E'!F CD78@ACDM'!) %<~ +,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<+! ' ]VSmD
@	 !..w7!..w7 "..s3T5F5Fw5OP!..w79J9J89TU!..w79J9J89TU!..x8$:K:KG:TU!..x8$:K:KH:UV!..y94;L;LX;VW!..z:D<M<Mh<WX!..{;T=N=Nx=XY!..{;T=N=Nx=XY
" "..s3T5F5Fw5OP!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..x8$:K:KI:VW!..y94;L;LY;WX!..z:D<M<Mi<XY!..{;T=N=Ny=YZ!..{;T=N=Nx=XY
"A	mD
|	 %%"&#0)+! #"#
 !}	mD
^
 #&*(, %)$(%)-
 -2)-+/6:#'#'"&#(	( #(/3$)#($)+/263$8 r% ',!$$(%&*/& ',#($)*/	# '+!$#($)*/( ',!$$(%&#($)*/$ ',!$$(,0%&#($)*/	*  #OJX y
 "9 "9 	 "9 "9 	o__
mD
` !6!amD
f YgmD
h 5<5<5 <5 <	5
 ]5 -5 -5 Z5 -5 ^5 \5 Z5 Z5 Z5 .5  .!5" Y#5$ Z%5& Z'5( \)5* \+5, \-5. \/50 Z152 \354 \556 \758 \95: \;5< \=5> \?5@ ZA5B ZC5D ZE5F ZG5H ZI5J ZK5L ZM5N 0O5P \Q5R 0S5T 0U5V ZW5X ]Y5Z ^[5\ .]5^ \_5` \a5b \c5d Ze5f ]g5h }i5l o8imD
 m m	    c                    | j                  d      sy| j                  |      }| j                  |di       }| j                  |di       }t        |j	                               }i }t        dt        |            D ]  }||   }||   }	|}
| j                  |
      }i }| j                  |	dg       }t        dt        |            D ]  }||   }| j                  |d      }| j                  |      }|||d| j                  |dd      | j                  |d	d      | j                  |d
      dd| j                  |d      ddid	||<    | j                  |	|
|| j                  |	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
        FNresultcurrency_mapr   network_list
network_iddeposit_enabledwithdraw_enabledwithdrawal_feer   min_withdrawal_amountminr  )	infor5   networkactivedepositr   fee	precisionlimits	full_nameamountcrypto)r[  r5   coder6   r]  r^  r   r_  r`  ra  typer   )check_required_credentials'v1PrivatePostPrivateGetCurrencyNetworks	safe_dictlistkeysrangelensafe_currency_code	safe_listsafe_stringnetwork_id_to_code	safe_boolsafe_numbersafe_currency_structure)rL  paramsresponse
resultDatacurrencyMaprk  rQ  ikeycurrencyr5   re  r   chainsjchain	networkIdr\  s                     rN  fetch_currencieszcryptocom.fetch_currencies  s    ..u5??GV ^^Hh;
nnZDK$$&'q#d)$ -	Aq'C"3'HB**2.DH^^HnbAF1c&k* q	 ,,ULA	11)<!#&"#~~e5FN $u6H% P++E3CD!%"#'#3#3E;R#S#'%%!	(  77 ((;? !## !$#9 F4L7-	\ rO  c                    | j                  |      }| j                  |di       }| j                  |dg       }g }t        dt	        |            D ]  }||   }| j                  |d      }|dk(  }	|dk(  }
|dk(  }|dk(  }| j                  |d	      }| j                  |d
      }|	rdn|}| j                  |      }| j                  |      }|	rdn| j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  |d            }|t        |      nd}|dz   |z   }d}d}|dk(  rd}d}nt|dk(  rd}|dz   |z   }d}nb|dk(  r"d}|dz   |z   dz   | j                  |      z   }d}n;|dk(  r6d}|dk(  rdnd}|dz   |z   dz   | j                  |      z   dz   |z   dz   |z   }d}|j                  i d| j                  |d      d|d|d |d!|d"|d#|d$|d%|d|	d&|xs |d|
d|d|d'| j                  |d(      d)|d*|rdnd|rdnd| j                  |d+      || j                  |      | j                  |      || j                  | j                  |d,            | j                  | j                  |d-            d.| j                  d/      | j                  |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
        rQ  datar   	inst_typeCCY_PAIRPERPETUAL_SWAPFUTUREWARRANTbase_ccy	quote_ccyNput_callstrikemargin_buy_enabledmargin_sell_enabledexpiry_timestamp_ms/rA   FrC   :TrD   -rE   callCPr5   symbolbasequotesettlebaseIdquoteIdsettleIdrf  rB   r]  tradablecontractr  contract_sizeprice_tick_sizeqty_tick_size)pricerc  1max_leveragerY  )r   rc  r  cost)
r  contractSizeexpiryexpiryDatetimer  
optionTyper`  ra  createdr[  )v1PublicGetPublicGetInstrumentsri  ro  rl  rm  rp  rn  safe_string_lowerrr  	omit_zerointyymmddappendrs  iso8601rK  )rL  ru  rv  resultResponser  rQ  ry  marketr  rA   rC   rD   rE   r  r  r  r  r  r  r  r  marginBuyEnabledmarginSellEnabledexpiryStringr  r  rf  r  symbolOptionTypes                                rN  fetch_marketszcryptocom.fetch_markets|  s&    77?p (B?~~nfb9q#d)$ V	A!WF((=I
*D 00D(*F)+F%%fj9F&&v{;G#tH**62D++G4E!Tt'>'>x'HF//
CJ%%fh7F#~~f6JK $v7L M>>$*:*:6CX*YZL+7+CS&$FCZ%'FDHJ& ..#-h&#-3dkk&6IIi'+5+?3c #-3dkk&6IICORXX[^^aqqMM 0d&&vx80&0 0 	0
 &0 &0 70 H0 0 0 ,D2C0 0 &0 &0 $..<0  H!0" 8$$#0$ &.5D $ 0 0 I "&,,v"6++F3(!..t/?/?HY/Z["//0@0@0YZ  $005#//G!
  $#
  $#
  $#$  _0 0MV	n rO  Nsymbolsc                    | j                          d}i }|[d}t        |t              r.t        |      }|dkD  rt	        | j
                  dz         |d   }n|}| j                  |      }|d   |d<   | j                  | j                  ||            }| j                  |di       }| j                  |dg       }	| j                  |	|      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   r5   instrument_namerQ  r  )load_markets
isinstancerj  rm  r$   r5   r  v1PublicGetPublicGetTickersextendri  ro  parse_tickers)
rL  r  ru  r  requestr  symbolsLengthrv  rQ  r  s
             rN  fetch_tickerszcryptocom.fetch_tickers9  s     	F'4( #G 1$$TWW/s%stt  [[(F)/G%&33DKK4PQ2 (B7~~ffb1!!$00rO  r  c                     | j                          | j                  |      }| j                  |g|      }| j                  ||      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>`
        )r  r  r  
safe_value)rL  r  ru  tickerss       rN  fetch_tickerzcryptocom.fetch_tickero  sC     	V$$$fXv6w//rO  sincer  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S d}i }|| j                  |      }|d   |d<   |||d<   |||d<   | j	                  |d	      }| j                  |d	g      }|||d
<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
dg       }| j                  ||||      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>`
        Fr|   paginateNr5   r  
start_timer  untilend_timerQ  r  )r  handle_option_and_paramsfetch_paginated_call_dynamicr  safe_integeromit#v1PrivatePostPrivateGetOrderHistoryr  ri  ro  parse_orders)rL  r  r  r  ru  r  r  r  r  rv  r  orderss               rN  fetch_orderszcryptocom.fetch_orders~  s(    	88PZ[&44]FESXZ`aa[[(F)/G%&$)GL!$GG!!&'26G9-"'GJ;;DKKQW<XYP ~~h"5fb1  >>rO  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  |      }d|d   i}|||d<   |||d<   | j	                  |d      }| j                  |dg      }|||d	<   | j                  | j                  ||            }	| j                  |	d
i       }
| j                  |
dg       }| j                  ||||      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>`
        Fr   r  r  r5   start_tscountr  end_tsrQ  r  )r  r  r  r  r  r  v1PublicGetPublicGetTradesr  ri  ro  parse_trades)rL  r  r  r  ru  r  r  r  r  rv  rQ  tradess               rN  fetch_tradeszcryptocom.fetch_trades  s    	88PZ[&44]FESXZ`aaV$vd|
 "'GJ$GG!!&'26G9- %GH224;;w3OP* (B73  >>rO  r   c           	         | j                          d}| j                  |ddd      \  }}|r| j                  d|||||d      S | j                  |      }|d   | j	                  | j
                  ||      d}||dkD  rd}||d<   | j                         }	| j                  |      }
| j                  |d|	      }| j                  |dg      }|/||
d	z  z
  |d
<   || j                  ||
|z  d	z        |d<   n||d<   n||d<   | j                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  |||||      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
        Frx   r  r  r5   )r  	timeframer  r  i  r  r  rQ  r  )r  r  "fetch_paginated_call_deterministicr  rp  r   microsecondsparse_timeframer  r  sumv1PublicGetPublicGetCandlestickr  ri  ro  parse_ohlcvs)rL  r  r  r  r  ru  r  r  r  nowdurationr  rv  rQ  r  s                  rN  fetch_ohlcvzcryptocom.fetch_ohlcv  s    	88z[`a&::<QVX]_hjpruvvV$%d|))$//9iP
 s{$GG!''	2!!&'376G9-"'(T/"9GJ $(HHUHu4Dt4K$L!$)! %GH77GV8TU, (B7~~ffb1  vy%GGrO  c                 \   | j                          | j                  |      }d|d   i}|r||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j                  |d      }	| j                  |	d      }
| j                  |	||
      S )aM  
        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
        r  r5   depthrQ  r  r   t)	r  r  v1PublicGetPublicGetBookr  ri  ro  r  r  parse_order_book)rL  r  r  ru  r  r  rv  rQ  r  	orderBook	timestamps              rN  fetch_order_bookzcryptocom.fetch_order_bookE  s     	V$vd|
 $GG00Wf1MN& (B7~~ffb1OOD!,	%%i5	$$Y	BBrO  c                    | j                  |di       }| j                  |dg       }| j                  |d   dg       }d|i}t        dt	        |            D ]i  }||   }| j                  |d      }| j                  |      }	| j                         }
| j                  |d      |
d<   | j                  |d	      |
d
<   |
||	<   k | j                  |      S )NrQ  r  r   position_balancesr[  r  quantitytotalreserved_qtyused)	ri  ro  r  rl  rm  rp  rn  accountsafe_balance)rL  rv  responseResultr  positionBalancesrQ  ry  balance
currencyIdre  r  s              rN  parse_balancezcryptocom.parse_balancep  s    (B?~~nfb9??474GL)q#./0 	#A&q)G))'3DEJ**:6DllnG#//DGG"..wGGFO"F4L	#   ((rO  c                 f    | j                          | j                  |      }| j                  |      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>`
        )r  v1PrivatePostPrivateUserBalancer  )rL  ru  rv  s      rN  fetch_balancezcryptocom.fetch_balance  s4     	77?X !!(++rO  r5   c                     | j                          d}|| j                  |      }d|i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      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_idrQ  )r  r  "v1PrivatePostPrivateGetOrderDetailr  ri  parse_order)rL  r5   r  ru  r  r  rv  orders           rN  fetch_orderzcryptocom.fetch_order  s{     	[[(F
 ::4;;wPV;WXD x26v..rO  rf  siderc  r  c                    | j                  |      }|j                         }|d   |j                         | j                  ||      d}	|dk(  s
|dk(  s|dk(  r| j                  ||      |	d<   | j	                  | j
                  dd      }
|
|	d	<   d }d }| j                  d
||      \  }}| j                  d
|      \  }}|dk(  s|d|	d<   n
|dk(  rd|	d<   | j                  |dd      }|&|dk(  rd|	d<   n|dk(  rd|	d<   n|dk(  rd|	d<   n||	d<   | j                  |dd      }|s|dk(  rdg|	d<   d|	d<   | j                  |g d      }| j                  |d      }| j                  |d      }|d u}|d u}|d u}|r| j                  ||      |	d <   | j                  |      }|dk(  s
|dk(  s|dk(  rI|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"<   ned#|	d"<   n_|r+|dk(  s|dk(  rd|	d"<   nd$|	d"<   | j                  ||      |	d <   n2|r+|dk(  s|dk(  rd|	d"<   nd#|	d"<   | j                  ||      |	d <   n||	d"<   | j                  |g d%      }| j!                  |	|      S )&Nr5   )r  r  r  LIMIT
STOP_LIMITTAKE_PROFIT_LIMITr  r   r   	broker_idrP   rB   r   spot_marginrA   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  buyrf  TAKE_PROFIT	STOP_LOSSr  clientOrderIdr   r  r   r   r   )r  upperamount_to_precisionprice_to_precisionrp  r   handle_market_type_and_params$custom_handle_margin_mode_and_paramssafe_string_upper_2rr  safe_string_nrs  number_to_stringr0   	string_ltr  r  )rL  r  rf  r  rc  r  ru  r  uppercaseTyper  r   
marketTyper   r   r  r   r   r   	isTriggerisStopLossTriggerisTakeProfitTriggerpriceStrings                         rN  create_order_requestzcryptocom.create_order_request  s]   V$

%d|JJL00@

 W$-<*G]^qMq#66vuEGG!!$,,&A%

!??vW]^
F!FF}V\]
F("
(>%-GM"6!%+GM"..v}oV"e#+=(%+@(%+9(+6(>>&*e<+-$/=GK '9GO$))&2\]((A**63DE!-	*$6.d:#'#:#:6<#PGK //6K(m|.KQ^buQu5=((lC*=*6((lC*6*=5=((lC*7*5((lC*5*7(m|.K"."-#'#:#:6=#QGK  (m?R.R"5"/#'#:#:6?#SGK +GFO6  $Q  R{{7F++rO  c                     | j                          | j                  |      }| j                  ||||||      }| j                  |      }	| j	                  |	di       }
| j                  |
|      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>`
        rQ  )r  r  r,  v1PrivatePostPrivateCreateOrderri  r  )rL  r  rf  r  rc  r  ru  r  r  rv  rQ  s              rN  create_orderzcryptocom.create_order@  so    & 	V$++FD$vV77@ (B7//rO  r  c           	         | j                          g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |d      }	| j	                  |d      }
| j                  |di       }| j                  ||||	|
|      }|j                  |        | j                  |dd	      }||d
}| j                  | j                  ||            }| j	                  |dg       }| j                  |d      }|d|ig}| j                  |      S | j                  |      S )a[  
        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>`
        r   r  rf  r  rc  r  ru  contingency_typeLISTr1  
order_listrQ  list_idr  )r  rl  rm  rp  r  ri  create_advanced_order_requestr  #v1PrivatePostPrivateCreateOrderListr  r  )rL  r  ru  ordersRequestsry  rawOrdermarketIdrf  r  rc  r  orderParamsorderRequest
contigencyr  rv  rQ  listId	ocoOrderss                      rN  create_orderszcryptocom.create_orderse  si    	q#f+& 		0AayH''(;H##Hf5D##Hf5D__Xx8FOOHg6E..8R@K==hdTZ\acnoL!!,/		0 %%f.@&I
 *(
 ;;DKKQW<XYT 8R8!!&)4$f-.I$$Y//  ((rO  c                 \   | j                  |      }|j                         }|d   |j                         d}	|dk(  s
|dk(  s|dk(  r| j                  ||      |	d<   | j                  | j                  dd      }
|
|	d	<   | j                  |d
d      }|&|dk(  rd|	d<   n|dk(  rd|	d<   n|dk(  rd|	d<   n||	d<   | j                  |dd      }|s|dk(  rdg|	d<   d|	d<   | j                  |g d      }| j                  |d      }| j                  |d      }|d u}|d u}|d u}|r| j                  |      }|dk(  s
|dk(  s|dk(  rI|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<   nWt        j                  ||      rd|	d<   n;d|	d<   n5|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}| j                  |d d!d      \  }}| j                  |d"d#      }| j                  |d"      }|| j                  ||      }ny|re|t!        | j"                  d$z         | j                  |      }| j                  |      }t        j$                  ||      }| j                  ||      }n| j                  ||      }||	d#<   n| j'                  ||      |	d%<   | j                  |g d&      }| j)                  |	|      S )'Nr5   )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  rf  r  r  MARKETTrP   !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  rp  r   r"  rr  r#  rs  r$  r0   r%  r  safe_number_2r  cost_to_precisionr'   r5   
string_mulr  r  )rL  r  rf  r  rc  r  ru  r  r&  r  r   r   r  r   r   r   r(  r)  r*  r+  quoteAmountrC  r  amountStringcostRequests                            rN  r6  z'cryptocom.create_advanced_order_request  s   
 V$

%d|JJL
 W$-<*G]^qMq#66vuEGG!!$,,&A%..v}oV"e#+=(%+@(%+9(+6(>>&*e<+-$/=GK '9GO$))&2\]((A**63DE!-	*$6.d://6K(m|.KQ^buQu5=((lC*=*6((lC*6*=5=((lC*7*5((lC*5*7(m|.K"."- (m?R.R"5"/+GFOEM(!:Q\@\bo  tA  cAK04-8<8U8UV\^k  nQ  SW  9X5-v%%ffjADYYvv.F"44VTB2=&tww  2}  (}  ~  ~#'#8#8#@L"&"7"7">K")"4"4\;"OK"&"8"8"MK"44VVD"-GJ"&":":66"JGJ6  $Q  R{{7F++rO  c                     | j                          d}i }|| j                  |      }|d   |d<   | j                  | j                  ||            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:
        Nr5   r  )r  r  #v1PrivatePostPrivateCancelAllOrdersr  )rL  r  ru  r  r  s        rN  cancel_all_orderszcryptocom.cancel_all_orders  sY     	[[(F)/G%&77GV8TUUrO  c                     | j                          d}|| j                  |      }d|i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      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  rQ  )r  r  v1PrivatePostPrivateCancelOrderr  ri  r  )rL  r5   r  ru  r  r  rv  rQ  s           rN  cancel_orderzcryptocom.cancel_order$  sy     	[[(F
 77GV8TU (B7//rO  c                    |t        | j                  dz         | j                          | j                  |      }g }t	        dt        |            D ])  }||   }|d   t        |      d}|j                  |       + d|d}	| j                  | j                  |	|            }
| j                  |
dg       }| j                  ||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   r5   r  r  r2  r3  rQ  )r#   r5   r  r  rl  rm  strr  #v1PrivatePostPrivateCancelOrderListr  ro  r  )rL  idsr  ru  r  orderRequestsry  r5   r  r  rv  rQ  s               rN  cancel_orderszcryptocom.cancel_ordersF  s     >#DGG.Z$Z[[V$q#c(# 	(AQB#)$<GE   '	( !''
 ;;DKKQW<XY(B7  tVDDrO  c                    | j                          g }t        dt        |            D ]^  }||   }| j                  |d      }| j                  |d      }| j	                  |      }|d   t        |      d}	|j                  |	       ` d|d}
| j                  | j                  |
|            }| j                  |dg       }| j                  |ddd|      S )	a1  
        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>`
        r   r5   r  rR  r2  r3  rQ  N)r  rl  rm  rp  r  rS  r  rT  r  ro  r  )rL  r  ru  rV  ry  r  r5   r  r  	orderItemr  rv  rQ  s                rN  cancel_orders_for_symbolsz#cryptocom.cancel_orders_for_symbolse  s     	q#f+& 		,A1IE!!%.B%%eX6F[[(F#)$<GI   +		, !''
 ;;DKKQW<XY(B7  tT6BBrO  c                    | j                          d}i }|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dg       }	| j                  |	|||      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>`
        Nr5   r  rQ  r  )r  r  !v1PrivatePostPrivateGetOpenOrdersr  ri  ro  r  )
rL  r  r  r  ru  r  r  rv  r  r  s
             rN  fetch_open_orderszcryptocom.fetch_open_orders  s     	[[(F)/G%&99$++gv:VWL ~~h"5fb1  >>rO  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||d      S i }d}|| j                  |      }|d   |d<   |||d<   |||d	<   | j	                  |d
      }| j                  |d
g      }|||d<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
dg       }| j                  ||||      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>`
        Frw   r  r   Nr5   r  r  r  r  r  rQ  r  )r  r  r  r  r  r  v1PrivatePostPrivateGetTradesr  ri  ro  r  )rL  r  r  r  ru  r  r  r  r  rv  rQ  r  s               rN  fetch_my_tradeszcryptocom.fetch_my_trades  s)    	88R\]&44_feUZ\bdghh[[(F)/G%&$)GL!$GG!!&'26G9-"'GJ55dkk'66RS< (B73  >>rO  c                     d }d }d }|j                  d      dkD  r.|j                  d      \  }}|j                  d      }|d   }||gS |}||gS )N?r   =r   )findsplit)rL  addressStringaddresstagrawTagsplitteds         rN  parse_addresszcryptocom.parse_address  sl    c"Q&+11#6OGV||C(H1+C ~ $G~rO  re  rg  c                 t   | j                  ||      \  }}| j                          | j                  |      }|d   ||d}|||d<   d}| j                  |      \  }}| j	                  |      }	|	|	|d<   | j                  | j                  ||            }
| j                  |
d      }| j                  ||      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>`
        r5   )r{  rc  rg  Naddress_tagrT  rQ  )	handle_withdraw_tag_and_paramsr  safe_currencyhandle_network_code_and_paramsnetwork_code_to_id$v1PrivatePostPrivateCreateWithdrawalr  ri  parse_transaction)rL  re  rc  rg  rh  ru  r{  r  networkCoder  rv  rQ  s               rN  r   zcryptocom.withdraw  s     99#vFV%%d+ 

 ?%(GM""AA&IV++K8	 $-GL!<<T[[RX=YZ" (3%%fh77rO  c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }t        |      }|dk(  rt        | j                  dz         i }	t        d|      D ]  }
| j	                  ||
      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      \  }}| j                  |       | j                  |d      }| j                  ||      }|||||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
        r{  r5   rQ  deposit_address_listr   z7 fetchDepositAddressesByNetwork() generating address...rg  r\  )r[  r{  r\  rg  rh  )r  ro  %v1PrivatePostPrivateGetDepositAddressr  ri  ro  rm  r   r5   rl  rp  rn  rk  check_addressrq  )rL  re  ru  r{  r  rv  r  	addressesaddressesLengthrQ  ry  valuerf  r  responseCoderg  rh  r  r\  s                      rN  "fetch_deposit_addresses_by_networkz,cryptocom.fetch_deposit_addresses_by_network=  sa    	%%d+
 ==dkk'SY>Z[( ~~h"5NN4)?D	i.a*c cddq/* 	ANN9a0E ,,UI>M))%<J22:>L--m<LGSw'((	:I--iFG(""F7O	  rO  c                     | j                  |d      }| j                  |dg      }| j                  ||      }||v r||   S t        |j	                               }||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>`
        r\  r   )safe_string_upperr  r}  rj  rk  )rL  re  ru  r\  depositAddressesrk  s         rN  fetch_deposit_addresszcryptocom.fetch_deposit_addressx  sr     ((;6I;/BB4P&&#G,,(--/0D#DG,,rO  c                    | j                          d}i }|| j                  |      }|d   |d<   |||d<   |||d<   | j                  |d      }| j                  |dg      }|||d<   | j	                  | j                  ||            }| j                  |di       }	| j                  |	d	g       }
| j                  |
|||      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>`
        Nr5   r{  r  	page_sizer  r  rQ  deposit_list)	r  ro  r  r  %v1PrivatePostPrivateGetDepositHistoryr  ri  ro  parse_transactions)rL  re  r  r  ru  r{  r  r  rv  r  depositLists              rN  fetch_depositszcryptocom.fetch_deposits  s     	))$/H"*4.GJ"'GJ#(GK !!&'26G9- %GH==dkk'SY>Z[. ~~h"5nnT>2>&&{HeUKKrO  c                    | j                          d}i }|| j                  |      }|d   |d<   |||d<   |||d<   | j                  |d      }| j                  |dg      }|||d<   | j	                  | j                  ||            }| j                  |di       }	| j                  |	d	g       }
| j                  |
|||      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>`
        Nr5   r{  r  r  r  r  rQ  withdrawal_list)	r  ro  r  r  (v1PrivatePostPrivateGetWithdrawalHistoryr  ri  ro  r  )rL  re  r  r  ru  r{  r  r  rv  r  withdrawalLists              rN  fetch_withdrawalszcryptocom.fetch_withdrawals  s     	))$/H"*4.GJ"'GJ#(GK !!&'26G9- %GH@@WV\A]^2 ~~h"5.?D&&~xNNrO  tickerr  c                 `   | j                  |d      }| j                  |d      }| j                  ||d      }| j                  |d      }| j                  |d      }| j                  i d|d   d|d| j	                  |      d	| j                  |d
      d| j                  |d      d| j                  |d      dd d| j                  |d      dd dd dd d|d|dd dd d| j                  |d      dd | j                  |d      |dk(  r| j                  |d      nd |d|      S ) Nr  ry  _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quoteVolumer[  )r  rp  safe_marketsafe_tickerr  rs  )rL  r  r  r  r:  r  r   s          rN  parse_tickerzcryptocom.parse_ticker  s   B %%fc2	##FC0!!(FC8  1, !
fX&!
!
 Y/!
 D$$VS1	!

 4##FC0!
 4##FC0!
 !
 4##FC0!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $**637!!
" t#!
$ **637>Cun4++FD9SW)!
* + 	rO  tradec                 P   | j                  |dd      }| j                  |dd      }| j                  ||d      }| j                  |d      }| j                  |d      }| j	                  || j                  |dd	      || j                  |      |d
   | j                  |d      | j                  |dd      | j                  |d      | j                  |dd      | j                  |dd      d d | j                  |      | j                  t        j                  |            dd|      S )Nr  create_timery  r  r  fee_instrument_namer   dtrade_idr  r  sr  
taker_sideptraded_priceqtraded_quantityr{  r  )r[  r5   r  r  r  r  r  takerOrMakerr  rc  r  rf  r_  )safe_integer_2safe_string_2r  rp  
safe_trader  safe_string_lower_2r  rE  rn  rK  r0   
string_neg)rL  r  r  r  r:  feeCurrencyfeeCostStrings          rN  parse_tradezcryptocom.parse_trade8  s7   F ''sMB	%%eS2CD!!(FC8&&u.CD((7$$UC<"Y/X&%%eZ8,,UC@ 225,G''sNC((5FG 33K@))'*<*<]*KL 
" # 	rO  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr  or  r  r  r  )r  rs  )rL  ohlcvr  s      rN  parse_ohlcvzcryptocom.parse_ohlcvs  sn     eS)UC(UC(UC(UC(UC(
 	
rO  statusc                 8    dddddd}| j                  |||      S )Nr  canceledclosedrejectedexpired)ACTIVECANCELEDFILLEDREJECTEDEXPIREDrp  rL  r  statusess      rN  parse_order_statuszcryptocom.parse_order_status  s/    "" 
 &&99rO  r   c                 4    dddd}| j                  |||      S )Nr  r   r   )r  r  r  r  )rL  r   timeInForcess      rN  parse_time_in_forcezcryptocom.parse_time_in_force  s)     %#(!

 k;GGrO  r  c           
      d   | j                  |d      }|;|dk7  r6| j                  | j                  |d      | j                  |d      |dd      S | j                  |d      }| j                  |d      }| j                  ||      }| j	                  |d	      }d }|*d
}t        dt        |            D ]  }	||	   }
|
dk(  sd} n | j                  |d      }| j                  i d|d| j                  |d      d| j                  |d      d|d| j                  |      d| j                  |d      d| j                  | j                  |d            d|d| j                  |d      d| j                  | j                  |d            d|d| j                  |d      d| j                  |d      d| j                  |d       d!| j                  |d"      d#d d$| j                  |d%      | j                  |d&      | j                  |      | j                  |d'      d(g d)|      S )*Nre  r   r  
client_oidr  )r5   r  r[  r  r  r  r  Fr  Tr  r[  r5   r  r  r  lastTradeTimestampupdate_timer  r  rf  
order_typer   r  r  r  r  limit_pricerc  r  filledcumulative_quantity	remainingr  	avg_pricecumulative_valuecumulative_feer  )r  r_  r  )r  
safe_orderrp  safe_symbolr  rl  rm  r  r  r  r  rs  rn  )rL  r  r  re  r  r:  r  execInstr  ry  instr  s               rN  r  zcryptocom.parse_order  s   ^   /419??&&uj9!%!1!1%!F$	$   ##E=9##E+<=!!(F3??5+6H1c(m, {;&#H	
 &&u.CD  
E 
$""5*5 
 T--e\B 
 	 

 W- 
 !$"3"3E="I 
 d--d.>.>uh.OP 
 f 
 D**5,? 
 433D4D4DUO4\] 
  
 D**5&9 
 T%%e]; 
 d&&uj9 
 d&&u.CD 
  ! 
" t''{;# 
$ $$U,>? 33K@((0@A / 
0 1 	rO  c                 6    ddddd}| j                  |||      S )Npendingokfailed)r   r  23r  r  s      rN  parse_deposit_statuszcryptocom.parse_deposit_status  s,    	
 &&99rO  c                 <    dddddddd}| j                  |||      S )Nr  r  r  r  )r   r  r  r  456r  r  s      rN  parse_withdrawal_statusz!cryptocom.parse_withdrawal_status 	  s5    
 &&99rO  transactionr{  c                    d }| j                  |d      }d }d|v rd}| j                  |      }nd}| j                  |      }| j                  |d      }| j                  |      \  }}| j                  |d      }	| j	                  |	|      }
| j                  |d      }| j                  |d      }d }||
|d	}i d
|d| j                  |d      d| j                  |d      d|d| j                  |      dd d|d|dd d|d|dd d|d| j                  |d      d|
d|d| j                  |d      d | j                  |d      |dS )Nr  
client_wid
withdrawalr^  rg  r{  r  r_  r  r[  r5   txidr  r  r\  	addressToaddressFromrh  tagTotagFromrf  rc  updatedr  )internalcommentr_  )rp  r  r  rk  rn  r  rs  r  )rL  r  r{  rf  	rawStatusr  rf  rg  rh  r  re  r  feeCostr_  s                 rN  rs  zcryptocom.parse_transaction	  s   X $$[(;	;&D11)<FD..y9F((i@))-8%%k:>
&&z8<%%k=A	"";6#W5C
K
$"";5
 D$$[&9
 	

 Y/
 t
 w
 
 4
 3
 S
 t
 D
 d&&{H=
 
  f!
" t((mD#
$ ''\B)
 	
rO  c                    | j                  | j                  d      }| j                  |dd      }| j                  |d      }d}| j	                  ||      \  }}|!|dk7  rt        | j                  dz         ||gS |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   rB   FNcrossz only cross margin is supportedT)rp  r   rr  r  handle_margin_mode_and_paramsr)   r5   )rL  
methodNameru  r   isMarginr   s         rN  r!  z.cryptocom.custom_handle_margin_mode_and_paramsa	  s     &&t||]C>>&(E:68,
!??
FS
F!W$"477-N#NOO F## x'X-=$
F##rO  c                    | j                  |dg       }t        |      }|d d dd d di d}|t        d|      D ]  }||   }| j                  |d      }| j                  |d      }	| j	                  ||	      }
d d d| j                  |d      ddd	|d
   |
<   |dk(  se| j                  |d      |d   d<   d|d   d<    |S )NrS  )r_  r  )r[  r   r^  r   r   rT  re  rW  F)r^  r   r   r   r   r_  r  )ro  rm  rl  rp  rq  rs  )rL  r_  r{  networkListnetworkListLengthrQ  ry  networkInfor  currencyCodert  s              rN  parse_deposit_withdraw_feez$cryptocom.parse_deposit_withdraw_feeu	  s   " nnS."=,"
 " 
 "1/0 =)!n ,,[,G	#//&A"55iN'+4@(,(8(8FV(Wgl m3z";/ %)040@0@N^0_F:&u-7<F:&|4= rO  codesc                     | j                          | j                  |      }| j                  |d      }| j                  |d      }| j	                  ||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>`
        rQ  rR  rb  )r  rh  r  ro  parse_deposit_withdraw_fees)rL  r  ru  rv  r  rx  s         rN  fetch_deposit_withdraw_feesz%cryptocom.fetch_deposit_withdraw_fees	  sU     	??Gx2nnT>://UKPPrO  c                 z   | j                          i }d}|| j                  |      }|||d<   |||d<   | j                  |d      }| j                  |dg      }|||d<   | j	                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://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>`
        Nr  r  r  r  rQ  r  )	r  ro  r  r  #v1PrivatePostPrivateGetTransactionsr  ri  ro  parse_ledger)rL  re  r  r  ru  r  r{  r  rv  rQ  ledgers              rN  fetch_ledgerzcryptocom.fetch_ledger	  s     	))$/H$)GL!$GG!!&'26G9-"'GJ;;DKKQW<XY< (B73  5%@@rO  itemc                 ^   | j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }d }t	        j
                  |d      rd}t	        j                  |      }nd}| j                  || j                  |d      || j                  |d      | j                  |d	      | j                  |d
      | j                  | j                  |d            || j                  |      || j                  |      d d d d d dd|      S )Nevent_timestamp_msr  transaction_qtyr   outinr  
account_idr  trade_match_idjournal_typer  )r[  r5   	directionr  referenceIdreferenceAccountrf  r{  rc  r  r  beforeafterr  r_  )r  rp  rn  ro  r0   r%  
string_abssafe_ledger_entryparse_ledger_entry_typerK  r  )rL  r  r{  r  r  re  rc  r   s           rN  parse_ledger_entryzcryptocom.parse_ledger_entry	  sC   * %%d,@A	%%d,=>
&&z8<%%j(;!!$(9:	VS)I''/FI%%""44"''l;++D*= $ 0 07G H001A1A$1WX''/"Y/ '
& ' 	rO  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}| j                  |||      S )NTRADINGr  	TRADE_FEEr_  WITHDRAW_FEEWITHDRAWr  DEPOSITr^  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  )rL  rf  
ledgerTypes      rN  r'  z!cryptocom.parse_ledger_entry_type$
  s    
w

 E
 	

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

. 
D$77rO  c                     | j                          | j                  |      }| j                  |di       }| j                  |di       }| j                  |dg       }|j	                  |       | j                  ||      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
        rQ  master_accountsub_account_list)r  v1PrivatePostPrivateGetAccountsri  ro  r  parse_accounts)rL  ru  rv  rQ  masterAccountaccountss         rN  fetch_accountszcryptocom.fetch_accounts>
  sz     	77?@ (B7v/?D>>&*<bA&""8V44rO  c                 P    | j                  |d      | j                  |d      d |dS )Nuuidlabel)r5   rf  re  r[  r  )rL  r  s     rN  parse_accountzcryptocom.parse_accountn
  s4    6 ""7F3$$Wg6	
 	
rO  c                    | j                          d}|| j                  |      }d}| j                  d||      \  }}| j                  d|dg d       |dk(  rd}d|j	                         i}| j                  | j                  ||            }| j                  |di       }	| j                  |	d	g       }
| j                  |
|      }| j                  |d
      }| j                  ||||      S )a1  
        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   rf  )rD   rE   r  r  rE   r  instrument_typerQ  r  r  )r  r  r   check_required_argumentr  *v1PublicGetPublicGetExpiredSettlementPricer  ri  ro  parse_settlementssort_byfilter_by_symbol_since_limit)rL  r  r  r  ru  r  rf  r  rv  rQ  r  settlementssorteds                rN  fetch_settlement_historyz"cryptocom.fetch_settlement_history
  s     	[[(F99:RTZ\bcf$$%=tVMvw8Dtzz|
 BB4;;wX^C_`$ (B7~~ffb1,,T6:k;700NNrO  c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      || j	                  |      dS )Nxry  r  )r[  r  r  r  r  )r  rp  r  rs  r  )rL  r=  r  r  r:  s        rN  parse_settlementzcryptocom.parse_settlement
  sd     %%j#6	##J4&&x8%%j#6"Y/
 	
rO  c                     g }t        dt        |            D ]&  }|j                  | j                  ||   |             ( |S )Nr   )rl  rm  r  r_  )rL  rZ  r  rQ  ry  s        rN  rW  zcryptocom.parse_settlements
  sH     q#k*+ 	IAMM$//AGH	IrO  c           
         |t        | j                  dz         | j                          d}| j                  |dd      \  }}|r| j	                  d|||d|      S | j                  |      }|d   st        | j                  dz         |d   d	d
}|||d<   |||d<   | j                  |d      }| j                  |dg      }|||d<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
dg       }| j                  |
d      }g }t        dt        |            D ]_  }||   }| j                  |d      }|j!                  || j#                  ||      | j%                  |d      || j'                  |      d       a | j)                  |d      }| j+                  ||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>`
        z5 fetchFundingRateHistory() requires a symbol argumentFrh   r  8hrC   z7 fetchFundingRateHistory() supports swap contracts onlyr5   funding_hist)r  valuation_typer  r  r  r  rQ  r  r  r   r  r  )r[  r  fundingRater  r  r  r  )r#   r5   r  r  r  r  r%   r  r  v1PublicGetPublicGetValuationsr  ri  ro  rp  rl  rm  r  r  rs  r  rX  rY  )rL  r  r  r  ru  r  r  r  r  rv  rQ  r  r:  ratesry  entryr  r[  s                     rN  fetch_funding_rate_historyz$cryptocom.fetch_funding_rate_history
  s    >#DGG.e$eff88AZ\fg&::;TV\^cejlprxyyV$f~DGG&__``%d|,
 "'GJ$GG!!&'26G9- %GH66t{{7F7ST" (B7~~ffb1##F,=>q#d)$ 		AGE))%5ILL**8V<#//s;& LL3 		 e[1009I5RWXXrO  c                 $   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |dg       }| j                  | j	                  |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>`
        r  r5   rQ  r  r   )r  r   v1PrivatePostPrivateGetPositionsr  ri  ro  parse_position)rL  r  ru  r  r  rv  rQ  r  s           rN  fetch_positionzcryptocom.fetch_position)  s     	V$vd|
 88Wf9UV. (B7~~ffb1""4>>$#:FCCrO  c                    | j                          | j                  |      }i }d}|[d}t        |t              r.t	        |      }|dkD  rt        | j                  dz         |d   }n|}| j                  |      }|d   |d<   | j                  | j                  ||            }| j                  |di       }| j                  |dg       }	g }
t        dt	        |	            D ]N  }|	|   }| j                  |d      }| j                  |ddd	      }|
j                  | j!                  ||             P | j#                  |
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   r5   r  rQ  r  r  r  F)r  market_symbolsr  rj  rm  r$   r5   r  rk  r  ri  ro  rl  rp  r  r  rl  filter_by_array_positions)rL  r  ru  r  r  r  r  rv  r  	positionsrQ  ry  rh  r:  marketInners                  rN  fetch_positionszcryptocom.fetch_positionsS  sV    	%%g.F'4( #G 1$$TWW/u%uvv  [[(F)/G%&88Wf9UV. (B?NN>62>	q#i.) 	CAaLE''/@AH**8T4LKMM$--e[AB		C
 --fheLLrO  positionc                 6   | j                  |d      }| j                  ||d d      }| j                  ||d d      }| j                  |d      }| j                  |d      }| j	                  i d|dd d|d|d	| j                  |      d
d dt        j                  |d      rdnddt        j                  |      d|d   dd dd dd dd d| j                  |d      d| j                  |d      dd dd d | j                  |d      d d d d d d d      S )Nr  r  update_timestamp_msr  r[  r5   r  r  r  r   r  r   r  sell	contractsr  
entryPrice	markPricerD  r   
collateralopen_pos_costinitialMarginr  maintenanceMargininitialMarginPercentageopen_position_pnl)maintenanceMarginPercentageunrealizedPnlliquidationPricer   r  marginRatior   r   )
rp  r  r  r  safe_positionr  r0   	string_gtr%  rs  )rL  rt  r  r:  r  r  rc  s          rN  rl  zcryptocom.parse_position  s    ##H.?@!!(FD*E!!(FD*E%%h0EF	!!(J7!! #
H#
$#
 f#
 	#

 Y/#
 d#
 W..vs;E#
 ++F3#
 F>2#
 $#
 #
 #
 #
 $**8_E#
 T--h?#
   !#
" &t##
$ ,0!--h8KL $!#3#
  	rO  c                 "    | j                         S N)milliseconds)rL  s    rN  noncezcryptocom.nonce  s      ""rO  c                    d}||k\  rt        |      S t        |t               r|S d}d }t        |t              r|}n*| j                  |      }t        |j	                               }t        dt        |            D ]p  }||   }||z  }||   }	|	dk(  r|dz  }t        |	t              r6t        dt        |	            D ]  }
|| j                  |	|
   |dz         z  } c|t        |	      z  }r |S )N    r   Noner   )rS  r  rj  keysortrk  rl  rm  params_to_string)rL  objectlevelmaxLevelreturnString
paramsKeysr[  ry  rz  r{  r}  s              rN  r  zcryptocom.params_to_string  s   Hv;fc"M
fd#J\\&)Ffkkm,Jq#j/* 
	+AQ-CCL3KE&E4(q#e*- OA D$9$9%(EAI$NNLO E
*
	+ rO  c                 h   | j                          | j                  |      }|d   dd}| j                  |d      }| j                  |d      }|||d<   || j	                  |d   |      |d<   | j                  | j                  ||            }| j                  |d      }	| j                  |	|      S )aR  
        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>`
        r5   rB  )r  rf  rf  r  r  rQ  )	r  r  r  rp  r  !v1PrivatePostPrivateClosePositionr  ri  r  )
rL  r  r  ru  r  r  rf  r  rv  rQ  s
             rN  close_positionzcryptocom.close_position  s     	V$%d|
 %%ff5  1"GFO#66vh7GOGG99$++gv:VW (3//rO  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )az  
        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>`
        r  r5   rQ  )r  r  (v1PrivatePostPrivateGetInstrumentFeeRater  ri  parse_trading_fee)rL  r  ru  r  r  rv  r  s          rN  fetch_trading_feezcryptocom.fetch_trading_fee  ss     	V$vd|
 @@WV\A]^  ~~h"5%%dF33rO  c                     | j                          | j                  |      }| j                  |di       }| j                  |      S )ao  

        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
        rQ  )r  v1PrivatePostPrivateGetFeeRateri  parse_trading_fees)rL  ru  rv  rQ  s       rN  fetch_trading_feeszcryptocom.fetch_trading_fees%  sE     	66v>  (B7&&v..rO  c                    i }||d<   t        dt        | j                              D ]  }| j                  |   }| j                  |      }|d   }|rdnd}|rdnd}||| j	                  t        j                  | j                  ||      d            | j	                  t        j                  | j                  ||      d            d d d	}	|	||<    |S )
Nr[  r   rC   effective_deriv_taker_rate_bpseffective_spot_taker_rate_bpseffective_deriv_maker_rate_bpseffective_spot_maker_rate_bps10000r[  r  r   r   r  	tierBased)rl  rm  r  r  rK  r0   
string_divrp  )
rL  rv  rQ  ry  r  r  isSwaptakerFeeKeymakerFeeKey
tradingFees
             rN  r  zcryptocom.parse_trading_feesB  s     !vq#dll+, 	(A\\!_F[[(FF^F>D:JiK>D:JiK  **7+=+=d>N>NxYd>egn+op**7+=+=d>N>NxYd>egn+op"!J (F6N	( rO  r_  c                 (   | j                  |d      }| j                  ||      }||| j                  t        j                  | j                  |d      d            | j                  t        j                  | j                  |d      d            d d dS )Nr  effective_maker_rate_bpsr  effective_taker_rate_bpsr  )rp  r  rK  r0   r  )rL  r_  r  r:  r  s        rN  r  zcryptocom.parse_trading_fee`  s     ##C):;!!(F3&&w'9'9$:J:J3Pj:kmt'uv&&w'9'9$:J:J3Pj:kmt'uv
 	
rO  r   GETc           	      2   | j                  |d      }| j                  |d      }| j                  d   |   dz   |z   }	| j                  || j                  |            }
|dk(  r|
r,|	d| j	                  |
      z   z  }	n| j                          t        | j                               }| j                  i |      }t        |j                               }| j                  |d      }||z   | j                  z   |z   |z   }| j                  | j                  |      | j                  | j                        t         j"                        }t%        |      }| j'                  |||| j                  ||d      }|dk(  rd}d	}|j)                  ||      }d
di}|	|||dS )Nr   r   r   r  r   rb  )r5   methodru  api_keysigr  z{}z[]zContent-Typezapplication/json)r   r  bodyheaders)rp  r   r  extract_params	urlencoderg  rS  r  r  rj  rk  r  apiKeyhmacencodesecrethashlibsha256rm  jsonreplace)rL  pathr   r  ru  r  r  rf  accessr   queryr  requestParamsr  
strSortKeypayload	signatureparamsKeysLengthparamsStringarrayStrings                       rN  signzcryptocom.signs  s   Q'!!#q)iit$s*T1		&$"5"5d";<XsT^^E222++-

%E KKF3Mm0023J..}a@JUlT[[0:=EG		$++g"6DKK8PRYR`R`aI":99 ;;  D  1$#"||K> 2G fdwOOrO  reasonr   r  r  r  c
                     | j                  |d      }
|
dk7  rM| j                  dz   |z   }| j                  | j                  d   |
|       t	        | j                  dz   |z         y )Nre  r    rF  )rp  r5   throw_exactly_matched_exceptionr  r   )rL  re  r  r   r  r  r  rv  requestHeadersrequestBody	errorCodefeedbacks               rN  handle_errorszcryptocom.handle_errors  se    $$Xv6	ww}t+H001I9V^_# 455rO  r  )`__name__
__module____qualname__r   rJ  r   r  r   r   r  r   r   r  rS  r   r  r   r   r   r  r   r  rj  r  r   r  r   r  r  r  r   r   floatr   r,  r/  r   r@  r6  rM  rP  rW  r   rZ  r]  r`  rk  r   r   r
   r}  r  r  r  dictr  r  r  r  r  r  r  r  r	   rs  r!  r  r  r   r  r(  r'  r   rN  rR  r\  r_  rW  ri  rm  r   rs  rl  r  r  r  r   r  r   r  r  r  r  r  r  __classcell__)rM  s   @rN  r2   r2      s   n# n` ') iZ iV $& {$v, {z 04B 41W 417 41l 02 03 0f 0 *.Dt\^ J?3 J?c J? J?cghmcn J?X 6:UW 6?3 6?s 6?# 6?\`af\g 6?p 26DW[df AH# AHc AHQT AHkoptku AHF :>b )Cs )C3 )CY )CV) ) $& 6,( 6,p 26b 5/c 5/3 5/n os{} P,3 P,i P,y P,Z_ P,hk P,d gksu #03 #0i #0y #0RW #0`c #0J @B K)D$6 K)Z x|  EG ^,C ^,y ^,PY ^,ch ^,qt ^,@ /32 V V$ 37r  0s  0C  0D 04B E E> SU C5H0I C< /3TXac :? :?3 :?c :?hlmrhs :?x -1tRV_a @?c @? @?C @?D
 DHPR .8S .8% .8# .8Wb .8` DF 9s 9$~J^ 9v 79 -# -^ -& *.Dt\^ 5L3 5Lc 5L 5Lcghsct 5Ln -1tRV_a 7Oc 7O 7OC 7Ofjkvfw 7Or;4 ; ;6 ;z9 9v 9 9v
 
4 
(: :Hs H\ \v \ \|:
:S
T S
X S
Q\ S
j GI $(, ,\ <@ Q Q  (,$TZ\ :A :AC :As :Aaefqar :Ax3t 3x 3; 3j84 %' .54= .5`
B 6:[_hj /Os /O# /OUX /Ob
&  8<$]ajl DY DYC DYWZ DYL 24 (DS (DT 26b 8Mw 8MT(^ 8Mt-t -V -^#4 =A (0S (0	 (0PU (0T 57  4  4;N  4D )+ /{ /:<
T 
6 
EX 
& &eBSW %PN# s  c TX `c rO  r2   )7ccxt.base.exchanger   ccxt.abstract.cryptocomr   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   typingr   ccxt.base.errorsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   ccxt.base.decimal_to_precisionr/   ccxt.base.preciser0   r2    rO  rN  <module>r     s    ( /  b  b  b  b  b  b  b  * 0 - . . ' & . ) * ) + . * ) + 4 %A2+ A2rO  