
    eiϺ                       d dl mZ d dlmZ d dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" 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)AnyBalancesBool
CurrenciesCurrencyDepositAddressIntLedgerEntryLeverage
MarginModeMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)DDoSProtection)RateLimitExceeded)OnMaintenance)InvalidNonce)	TICK_SIZE)Precisec                   	    e Zd Zdef fdZi fdZi fdefdZi fdefdZ	di fde
fdZdd	efd
Zi fdee         fdZdedefdZd Zi fdedefdZdi fde
defdZddedefdZdi fdededefdZdddi fdededededee         f
dZddedefdZddi fdedededee         fdZ ddededefdZ!i fdede"fdZ#ddefdZ$dd e%d!ed"ed#e%d$ef
d%Z&dddi fde'dedefd&Z(i fde)fd'Z*de)fd(Z+i fd)ed*e,d+ed,ede-f
d-Z.dd	efd.Z/i fd)ede0fd/Z1dd	ede0fd0Z2dddi fd)e'dededee3         fd1Z4dddi fd)e'dededee3         fd2Z5di fd)ed*e,d3ed4e'de3f
d5Z6dd	ede3fd6Z7i fded7e,fd8Z8di fded9e9d:e:d*e,d;e;de<fd<Z=di fded9e9d:e:d*e,d;e;de<fd=Z>di fded9e9d:e:d*e,d;e;defd>Z?i dddd?fd!ed ed;e;d*e;d7e'd:efd@Z@i dAfd!ed edBeAfdCZBdi fded9e9d:e:d*e,d;e;de<fdDZCdi fded9e9d:e:d*e,d;e;defdEZDdFi fdGZEdddi fded9e9d:e:d*e,d;e;dHe;dIe;de<f fdJZFdKe'de'fdLZGi fdMeeH         fdNZIdi fded9e9d:e:d*e,d;e;defdOZJddi fdPeded9e9d:e:d*e;d;e;fdQZKdi fdPeded9e9d:e:d*e,d;e;fdRZLdi fdPede'de<fdSZMdddi fde'dededee<         fdTZNdddi fde'dededee<         fdUZOdddi fde'dededee<         fdVZPdddi fde'dededee<         fdWZQdddi fde'dededee<         fdXZRdddi fde'dededee<         fdYZSdi fdPede'fdZZTdi fde'fd[ZUdi fd\ee         de'fd]ZVd^ ZWdde<fd_ZXd`e'de'fdaZYd:e'de'fdbZZdKe'de'fdcZ[dde'fdeZ\dddi fde'dededee         fdfZ]dddi fdPede'dededee         f
dgZ^i fdede_fdhZ`ddiede_fdjZad9edefdkZbdi fdiede'fdlZcd9edefdmZddi fde'fdnZedi fdoefde'fdpZgi fdedehfdqZidi fdrejde'fdsZkddrededehfdtZli fdedemfduZnddvededemfdwZoi fded*e,demfdxZpi fded*e,demfdyZqi fdederfdzZsi fdedeer         fd{Ztdi fde
deer         fd|Zudd}edefd~Zvdde'dede'defdZwdddi fd)e'dedefdZxdded	edeyfdZzd9edefdZ{d)ejdededededefdZ|ddi ddfdZ} xZ~S )	coincatch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d/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddddddddddddddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdxdydzd{d|d}d~ddddi dddddddddddddddddddddddddddddddddddddddddddd	ii ddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddi dddddddddddddddddddddddddddddddddddddddddddddϜdМdydddddҜdddddd|                     dզ          |                     dզ          d֜iidddddddddddddddtddgdhdidjdkdldmdndodpdqdrdsdtdudd di dddddddddddddddddddddddddddddddd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dddddddd d!d"d#d$d%d&d'd(ddd)d*d+ddddddd,dddd ddddd-dddddddd.d/didd0d1d1dd2ddddd3dd4ddddd5d d d6d7id8	d9d:id:d;d dd<id6d4id=d9d>id9d>id?d d d?d@dAi dBi dCt
          dDt          dEt          dFt          dGt          dHt          dIt          dJt          dKt          dLt          dMt          dNt          dOt          dPt          dQt          dRt          dSt          i dTt          dUt          dVt          dWt          dXt          dYt          dZt          d[t          d\t          d]t          d^t          d_t          d`t          dat          dbt          dct          ddt          i det
          dft          dgt
          dht          dit          djt          dkt          dlt          dmt          dnt          dot          dpt          dqt          drt          dst          dtt          i dudvt           i          S (w  Nidr2   name	CoinCatch	countriesVG	rateLimit2   versionv1	certifiedFproThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelWithdrawclosePositioncreateConvertTradecreateDepositAddresscreateLimitBuyOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchBalancefetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFee)fetchTradingFeesfetchTransactionsfetchTransfersfetchWithdrawalsreduceMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModetransferwithdraw
timeframes1m3m5m15m30m1H2H4H6H12H1D3D1W1M)r   r   r   15301h2h4h6h12h1d3d1wr   urlszOhttps://github.com/user-attachments/assets/3d49065f-f05d-4573-88a2-1b5201ec6ff3zhttps://api.coincatch.com)publicprivatezhttps://www.coincatch.com/z)https://coincatch.github.io/github.io/en/z"https://www.coincatch.com/en/rate/z5https://partner.coincatch.cc/bg/92hy70391729607848548g?)urldiscount)logoapiwwwdocfeesreferralr   getzapi/spot/v1/public/time   zapi/spot/v1/public/currenciesg@zapi/spot/v1/market/tickerzapi/spot/v1/market/tickerszapi/spot/v1/market/fills   z api/spot/v1/market/fills-historyzapi/spot/v1/market/candlesz"api/spot/v1/market/history-candleszapi/spot/v1/market/depthzapi/spot/v1/market/merge-depthzapi/mix/v1/market/contractszapi/mix/v1/market/merge-depthzapi/mix/v1/market/depthzapi/mix/v1/market/tickerzapi/mix/v1/market/tickerszapi/mix/v1/market/fillszapi/mix/v1/market/fills-history)	zapi/mix/v1/market/candleszpi/mix/v1/market/indexzapi/mix/v1/market/funding-timez"api/mix/v1/market/history-fundRatez"api/mix/v1/market/current-fundRatezapi/mix/v1/market/open-interestzapi/mix/v1/market/mark-pricez!api/mix/v1/market/symbol-leveragez$api/mix/v1/market/queryPositionLeverz"api/spot/v1/wallet/deposit-address   z!pi/spot/v1/wallet/withdrawal-listz%api/spot/v1/wallet/withdrawal-list-v2zapi/spot/v1/wallet/deposit-listzapi/spot/v1/account/getInfozapi/spot/v1/account/assetsz#api/spot/v1/account/transferRecordszapi/mix/v1/account/accountzapi/mix/v1/account/accountsz%api/mix/v1/position/singlePosition-v2z"api/mix/v1/position/allPosition-v2zapi/mix/v1/account/accountBillz&api/mix/v1/account/accountBusinessBillzapi/mix/v1/order/currentz"api/mix/v1/order/marginCoinCurrentzapi/mix/v1/order/historyz#api/mix/v1/order/historyProductType)zapi/mix/v1/order/detailzapi/mix/v1/order/fillszapi/mix/v1/order/allFillszapi/mix/v1/plan/currentPlanzapi/mix/v1/plan/historyPlanzapi/spot/v1/wallet/transfer-v2z api/spot/v1/wallet/withdrawal-v2z&api/spot/v1/wallet/withdrawal-inner-v2zapi/spot/v1/account/billszapi/spot/v1/trade/orderszapi/spot/v1/trade/batch-orders
   )coststepzapi/spot/v1/trade/cancel-orderz!api/spot/v1/trade/cancel-order-v2z%api/spot/v1/trade/cancel-symbol-orderz%api/spot/v1/trade/cancel-batch-ordersz(api/spot/v1/trade/cancel-batch-orders-v2zapi/spot/v1/trade/orderInfozapi/spot/v1/trade/open-orderszapi/spot/v1/trade/historyzapi/spot/v1/trade/fillszapi/spot/v1/plan/placePlanzapi/spot/v1/plan/modifyPlanzapi/spot/v1/plan/cancelPlanzapi/spot/v1/plan/currentPlanzapi/spot/v1/plan/historyPlanz api/spot/v1/plan/batchCancelPlanzapi/mix/v1/account/open-countzapi/mix/v1/account/setLeveragezapi/mix/v1/account/setMarginz api/mix/v1/account/setMarginModez"api/mix/v1/account/setPositionModezapi/mix/v1/order/placeOrderzapi/mix/v1/order/batch-orderszapi/mix/v1/order/cancel-orderz$api/mix/v1/order/cancel-batch-ordersz%api/mix/v1/order/cancel-symbol-ordersz"api/mix/v1/order/cancel-all-orderszapi/mix/v1/plan/placePlanzapi/mix/v1/plan/modifyPlan)z api/mix/v1/plan/modifyPlanPresetzapi/mix/v1/plan/placeTPSLzapi/mix/v1/plan/placeTrailStopz"api/mix/v1/plan/placePositionsTPSLzapi/mix/v1/plan/modifyTPSLPlanzapi/mix/v1/plan/cancelPlanz api/mix/v1/plan/cancelSymbolPlanzapi/mix/v1/plan/cancelAllPlan)r   postrequiredCredentials)apiKeysecretpasswordr   tradingz0.001)	tierBased
percentagefeeSidemakertakeroptions47cfy1min5min15min30minr   r   r   r   1day3day1week)r   r   r   r   r   r   r   r   r   r   r   r   )rB   rD    BTCBITCOINERC20TRC20BEP20ARBONEArbitrumOneOPOptimismLTCBCHETCSOLNEO3STXstacksEGLDElrondNEARNEARProtocolACA
AcalaTokenKLAYKlaytnFTMFantomTERRATerraWAVESTAOSUISEIRUNE	THORChainZILSXPSolarFETAVAXzC-ChainXRPEOSDOGEDOGECOINCAP20MATICPolygonCSPRGLMRMoonbeamMINACFX
StratisEVMCelestiaChilizChainAptosOntologyICPCardanoFILCELODOTStellarLumensATOMCronosChain)r  r  STRATTIACHZAPTONTr  ADAr  r  r  XLMr   CRO)r   z
TRX(TRC20))brokerId!createMarketBuyOrderRequiresPricer   currencyIdsListForParseMarketbrokernetworksnetworksByIdfeatures)lastmarkindex)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax  i )r8  limitdaysBack	untilDayssymbolRequired)r8  triggerrA  rL  d   )r8  rI  rM  rA  
marketTyperL  rI    )	r   rX   rY   r   r   r   r   rj   r   extendsdefaultr>  )r:  price)rQ  rX   r   forDerivatives)linearinverse)rR  rB   rT  rD   rE   commonCurrencies
exceptions220014294000140002400034000540006400074000840009400114001240013400144001540016400174001840019400204003440017240912409134010240200403054040940704407244072540762407744080843001430024300443005430064300743008430094301043011430124311743118431224500645110)exactbroadprecisionMode)deep_extendsuperr2   describeparse_numberr)   r+   r"   r.   r%   r!   r#   r-   r'   r(   r,   r/   )self	__class__s    L/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/coincatch.pyr  zcoincatch.describe!   s   i 6 6 ? ? A A nD
+nD
KnD
 $nD
 	nD

 tnD
 nD
 4nD
  bbb %b 	b
 %b %b Tb "4b 'b tb b !%b  b %eb 'b  &t!b" '#b b$ '%b& /'b( $T)b* ,U+b, (-b. 0/b0 t1b2 3b4 75b6 &t7b8 (9b: ';b< &t=b> (?b@ "4AbB (CbD ,UEb b bF -eGbH %dIbJ  KbL MbN /ObP &uQbR #ESbT $UUbV )%WbX $UYbZ $U[b\ +E]b^ "4_b` &tabb  cbd +Eebf +Dgb b bh &uibj #Dkbl *4mbn $Uobp "5qbr tsbt  ubv %ewbx /ybz "4{b| }b~ !$b@  AbB dCbD +EEbF !%GbH "4Ib b bJ dKbL !$MbN uObP #DQbR  SbT 'UbV $TWbX !$YbZ *4[b\ (]b^ )%_b` uabb tcbd ebf Tgbh tibj "5kb bl %*%*"'$( $ #"!%#'! Cb b bnD
V  WnD
v i9:  4B<R #  wnD
R  117 4Q 5a	
 3A ;A 5a =a 3A 9! 6q 8 21 3A 4Q  21!" :1#$ 6723:;>?>?;<89=>@A5  ><a;Q @ :1	
 6q 5a >q 5a 6q @ =a 9! A! 3A =a  3A!" >q#$ 4523567878-  0+8!+:A+ A!+ 4Q	+
 3A+ 91b:Q:Q+ 9!+ <Q+ @+ @+ CA+ 6q+ 8+ 4Q+ 21+  5a!+" 6q#+ +$ 6q%+& 7'+( 7)+* ;A++, 8-+. 9!/+0 71+2 ;A3+4 =a5+6 6q7+8 8!R9P9P9+: 8;+< ?=+> @?+@ =aA+B 4QC+D 5aE+ +F =>56:;>?:;67<=9:U+ + +3E E?e eSnD
^ " $ $_nD
h %*&*#(!%!2!27!;!;!%!2!27!;!; 
inD
~ #59 %$&&"""$$$%"  #""##""""$""""  @ 26292W2 W2 W	2
 m2 *2 52 52 52 52 F2 82 H2 N2 <2  H!2" 8#2 2$ W%2& W'2( 5)2* 5+2, 5-2. K/20 5122 7324 5526 I728 592: 5;2< J=2> W?2@ YA2B FC2D JE2 2F # )%("% $ " *"(c2 2 2h %")! !q\ \nD
x
 $&+(,$($(%*- -
 -2).+06:#'#'"&#(	( ( #($)$)+/27/4#(1$ $6 r% ',!$$*%+*.& & ',#($)*/	# # ',!$#'$)&**/( ( $()-#m9 9v y  ) 504%*7 7$  &# # "#3 "#3 	  ## gW Wy
nD
h inD
j 4]4>4 04 0	4
 04 \4 04 Z4 \4 04 04 04 ]4 -4 ]4  -!4" ]#4 4$ -%4& Z'4( Z)4* Z+4, j-4. Z/40 Z142 Z344 ]546 Z748 ]94: ];4< Z=4> ]?4@ .A4B ZC4D ZE4 4 4F ]G4H \I4J ]K4L .M4N ZO4P ZQ4R ZS4T ZU4V ZW4X ZY4Z .[4\ .]4^ Z_4` Za4b .c4d Ze4 4j m7 7knD
Z Y[nD
 nD
 n n n	    c                    |                      |d          }|                      |dd          }|                     |ddg           }t          |          }	|/|	|k    r)t          t	          j        |	|z                      }
||
z  S |S )Nr   r   r   	orderListorderDataList)safe_integersafe_list_2lenintmathceil)r  r   methodpathparamsconfigr   r   ordersordersLengthnumberOfStepss              r  calculate_rate_limiter_costz%coincatch.calculate_rate_limiter_cost  s      00  33!!&+KK6{{<$#6#6	,*= > >??M-''Kr  c                 X    |                      |          }|                     |d          S )a[  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://coincatch.github.io/github.io/en/spot/#get-server-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        data)publicGetApiSpotV1PublicTimer  )r  r  responses      r  
fetch_timezcoincatch.fetch_time  s/     44V<<   6222r  c                    |                      |          }|                     |dg           }i }g }t          dt          |                    D ]}}||         }|                     |d          }|                    |           |                     |          }	|                     |d          }
i }t          dt          |
                    D ]}|
|         }|                     |d          }|                     |          }|||                     |d          dd|                     |d	          ddd
d|                     |d          dk    |                     |d          dk    |                     |d          d|d	||<   | 	                    || 
                    |d          |	dddddddddddddd
||d          ||	<   |                     | j        d          
|| j        d<   |S )a  
        fetches all available currencies on an exchange

        https://coincatch.github.io/github.io/en/spot/#get-coin-list

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r   coinNamechainschainminDepositAmountNminrG  minWithdrawAmountdepositr   rechargeabletruewithdrawablewithdrawFee)	r5   networklimitsactiver  r   fee	precisioninfocoinId)r5   	numericIdcoder  typer6   r  r  r   r  r  r.  r  r,  )"publicGetApiSpotV1PublicCurrencies	safe_listranger  safe_stringappendsafe_currency_codenetwork_id_to_codesafe_numbersafe_currency_structurer  r   )r  r  r  r  resultcurrenciesIdsicurrecy
currencyIdr  r.  parsedNetworksjr  	networkIdnetworkCodes                   r  fetch_currencieszcoincatch.fetch_currencies1  ss    ::6BB~~h33@ q#d))$$ 6	 6	A1gG))':>>J  ,,,**:66D~~gx88H#%N1c(mm,,  "1+ ,,Wg>>	"55i@@#* $(#3#3G=O#P#P#'$ $
 $(#3#3G=P#Q#Q#'% %	 	 ##//HHFR $ 0 0. I IV S++G]CC!%#%/ /{++(  77 !..wAA!   $#   
  $#! !	 	 +-9 9  F4LL0 >>$,(GHHP<IDL89r  Ncodesc                     |                                   |                     |          }|                     |dg           }|                     ||d          S )af  
        fetch deposit and withdraw fees

        https://coincatch.github.io/github.io/en/spot/#get-coin-list

        :param str[] [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>`
        r  r  )load_marketsr  r  parse_deposit_withdraw_fees)r  r  r  r  r  s        r  fetch_deposit_withdraw_feesz%coincatch.fetch_deposit_withdraw_fees  sV     	::6BB~~h33//eZHHHr  currencyc                    |                      |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  )r  r   )r  r   r  r.  r   r  r  r  Fr  r.  r   r   r  r   )r  r  r  r  r  r  )r  r  r  r  chainsLengthr  r  r  r  currencyCoder  s              r  parse_deposit_withdraw_feez$coincatch.parse_deposit_withdraw_fee  s;   , Xr226{{" 
 "  
 
 q,'' 	9 	9A1IE((88I++Hf==L11)\JJK#'t<<$($4$4UM$J$JZ_``/ /F:{+ q  ,0,<,<UM,R,Rz"5)38z"<0r  c                    |                      |          }|                     | j        d          |                                  |                     |dg           }i }d}|                     |dd|          \  }}g }d|d<   |                     |                     ||                    }|                     |dg           }d|d<   |                     |                     ||                    }|                     |dg           }g }	t          dt          |                    D ]w}
||
         }|                     |d	g           }t          dt          |                    D ]8}||         }d	|gi}|		                    |                     ||                     9x| 
                    ||	          }| 
                    ||          }|                     |          S )
aj  
        retrieves data on all markets for the exchange

        https://coincatch.github.io/github.io/en/spot/#get-all-tickers
        https://coincatch.github.io/github.io/en/mix/#get-all-symbols

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r,  Nr  r~   productTypeumcbldmcblr   supportMarginCoins)publicGetApiSpotV1MarketTickersr  r   r  handle_option_and_params publicGetApiMixV1MarketContractsextendr  r  r  array_concatparse_markets)r  r  r  spotMarketsrequestr  swapMarkets	swapUMCBL	swapDMCBLswapDMCBLExtendedr  marketr  r  settleobjmarketss                    r  fetch_marketszcoincatch.fetch_markets  s    77??8 >>$,(GHHP!!###nnXvr::";;FNTacnooV!(88Wf9U9UVVH NN8VR88	!(88Wf9U9UVVL NN8VR88	q#i..)) 	C 	CAq\F!%8Lb!Q!Q1c"45566 C C+A.(6( "((VS)A)ABBBBC ''	3DEE##K==!!'***r  r  c                    |                      |d          }|                     | j        d          }|                     |d          }|                      |d          }|                      |d          }d }d}d }	d}
d }d }d }|d u }|rG|                     |          }|                      |d          }|                      |d          }|d	z  }nd
}
|                     |d          |d<   |                     |d          |d<   |                     |dg           }|                      |d          }|                     |          }	d|	z   }||k    }||k    }|rd}n|rd}|                     |          }|                     |          }|dz   |z   |z   }|                      |d          }|r|dk    nd }|                      |d          }|                     |          }|                      |d          }|                      |d          }t          j	        |                     |          |          }| 
                    i d|d|d|d|d|d|d|d|
d|d|d |rd!n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 d0|                     |          |                     |          d1d2|                     |d3          d d4d d d4d d d4d d d4d5d6d d7|          S )8Nsymbolr   rB   baseCoin	quoteCoinr   baseIdquoteId_SPBLrD   takerFeeRater   makerFeeRater   r  r   :rU  rV  /symbolStatusnormalvolumePlace
pricePlacepriceEndStepr5   basequoter  r  subTyperC   FrE   rF   contractr  settleIdcontractSizesizeMultiplierr   r   r   expiryexpiryDatetimestrike
optionTyper  )amountrS  r  minTradeNumr  )r  rS  rB  r   createdr  )r  	safe_dictr   parse_spot_market_idr  r  r  parse_precisionr0   
string_mulsafe_market_structure	safe_boolr  )r  r  marketIdtradingFeesr   r  r  r  suffixr  r  isLinear	isInverser	  isSpotparsedMarketIdr  r  r  r  r  r  r  amountPrecisionStringr  r  pricePrecisionStrings                              r  parse_marketzcoincatch.parse_marketb  s   b ##FH55nnTY	::~~k622!!&*55""6;77	4 	$!66x@@N%%nh??F&&~yAAGHHD ,,V^DDDM ,,V^DDDM!%8Lb!Q!Q''(:A>>H,,X66F6\F(*H(*I $" $#&&v..''00e#f,''??/;E,(**&&v}== $ 4 4[ A A%%fl;;
''??&1$2F2Fz2R2RT`aa)) 6+
(6+
f6+
 D6+
 U	6+

 f6+
 w6+
 f6+
 D6+
 w6+
 F6+
 v/ee46+
 J6+
 e6+
 e6+
 F
6+
  f!6+
" #6+
 6+
$ D,,V5EFF%6+
& h'6+
( y)6+
* T%%dG44+6+
, T%%dG44-6+
. $..|<</6+
0 k::16+
2 t''i8836+
4 d56+
6 d76+
8 d96+
: $;6+
< ++,ABB**+?@@ =6+
D ++FMBB 
   
   
    E6+
h ti6+
j Fk6+
 6+
 6 6 6	r  c                 $   d }d }|                      | j        dg           }t          dt          |                    D ]L}||         }|                    |          }|dk    r'|                    |d          }|dk    r|}|}n|}|} nM||d}	|	S )Nr,  r   r   )r  r  )r  r   r  r  findreplace)
r  r  r  r  currencyIdsr  r  
entryIndexrestIdr  s
             r  r  zcoincatch.parse_spot_market_id  s    nnT\3RTVWWq#k**++ 	 	A$QJ!z22JB!))*b99??'F$GG#F(G  
 
 r  r  c                    |                                   |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }nX|d         r*|                     |                     ||                    }n&t          | j        dz   dz   |d         z   d	z             |                     |d
i           }|                     ||          S )a(  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://coincatch.github.io/github.io/en/spot/#get-single-ticker
        https://coincatch.github.io/github.io/en/mix/#get-single-symbol-ticker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        r  r5   NrB   rD    z#fetchTicker() is not supported for r   type of marketsr  )	r  r  publicGetApiSpotV1MarketTickerr  publicGetApiMixV1MarketTickerr*   r5   r  parse_tickerr  r  r  r  r  r  r  s          r  fetch_tickerzcoincatch.fetch_ticker  s     	V$$fTl
 &> ;	|::4;;wPV;W;WXXHH2 F^ !	|99$++gv:V:VWWHH@ tw}/TTW]^dWeehzz{{{~~h33  v...r  symbolsc                 @   d}|                                   |                     |ddd          }|                     |          }d}|                     ||||          \  }}d}|dk    r|                     |          }nt|dk    rKd}|                     ||d|          \  }}d|i}|                     |                     ||                    }n#t          | j	        dz   |z   d	z   |z   d
z             | 
                    |dg           }	|                     |	|          S )a2  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://coincatch.github.io/github.io/en/spot/#get-all-tickers
        https://coincatch.github.io/github.io/en/mix/#get-all-symbol-ticker

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'spot' or 'swap'(default 'spot')
        :param str [params.productType]: 'umcbl' or 'dmcbl'(default 'umcbl') - USDT perpetual contract or Universal margin perpetual contract
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        r   NTrB   rD   r  r  r-  () is not supported for r.  r  )r  market_symbolsget_market_from_symbolshandle_market_type_and_paramsr  r  publicGetApiMixV1MarketTickersr  r*   r5   r  parse_tickers)
r  r4  r  
methodNamer  rO  r  r  r  r  s
             r  fetch_tickerszcoincatch.fetch_tickers[  sN    $
%%gtT4@@--g66
!??
FTZ\fgg
F;;FCCHH8 6!!!K"&"?"?
Tacn"o"oK{G ::4;;wPV;W;WXXHHF tw}z9<VVYccfxxyyy~~h33!!$000r  c                    |                      |dd          }|                     |dd          }|                    d          dk     r|dz  }|                     ||          }|                     |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t          j        |                     |d d!          d"          d#d |                     |d$d%          |                     |d&d'          |                     |d(          d |d)|          S )*Nts	timestampr  r   _r   r  closer1  datetimehighhigh24hlowlow24hbidbuyOnebestBid	bidVolumebidSzasksellOnebestAsk	askVolumeaskSzvwapopenopenUtc0openUtcpreviousClosechanger   	changeUtcchgUtc100averagebaseVol
baseVolumequoteVolquoteVolume
indexPrice)r]  r_  r`  	markPricer  )	safe_integer_2r  r'  safe_market_customsafe_string_2safe_tickeriso8601r0   r  )r  tickerr  r@  r  r1  s         r  r1  zcoincatch.parse_ticker  sf   \ ''kBB	##FHb99==!!H((6::!!&'6:: !
fX&!
!
 Y//!
 D$$VY77	!

 4##FH55!
 4%%fh	BB!
 ))&'::!
 4%%fiCC!
 ))&'::!
 D!
 D&&vz9EE!
 T!
 D!
 T!
 d!
  ',T-?-?U]-^-^`eff!!
" t#!
$ ,,VYMM--fj-PP**6<@@-!
 !
 !
. /  	r  rI  c                 j   |                                   d}|                     |          }d|d         i}|||d<   d}|                     ||d          \  }}|||d<   d}|d         r*|                     |                     ||                    }n[|d         r*|                     |                     ||                    }n)t          | j        d	z   |z   d
z   |d         z   dz             |                     |di           }	| 	                    |	d          }
| 
                    |	||
dd          S )ae  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://coincatch.github.io/github.io/en/spot/#get-merged-depth-data
        https://coincatch.github.io/github.io/en/mix/#get-merged-depth-data

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return(maximum and default value is 100)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.precision]: 'scale0'(default), 'scale1', 'scale2' or 'scale3' - price accuracy, according to the selected accuracy step size to return the cumulative depth
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        r   r  r5   NrI  r  rB   rD   r-  r6  r  r.  r  r?  bidsasks)r  r  r  "publicGetApiSpotV1MarketMergeDepthr  !publicGetApiMixV1MarketMergeDepthr*   r5   r  r  parse_order_book)r  r  rI  r  r<  r  r  r  r  r  r@  s              r  fetch_order_bookzcoincatch.fetch_order_book  s_    	%
V$$fTl
 $GG	 99&*kZZ	6 #,GK &> 	~>>t{{7TZ?[?[\\HH  F^ 	~==dkk'SY>Z>Z[[HHtw}z9<VVY_`fYggj||}}}~~h33%%dD11	$$T69ffMMMr  r   	timeframesincec                    d}|                                   |                     |          }d|d         i}d}	|                     ||d          \  }	}|d         }
| j        d         |
         }|                     |||          }d}|}||	|}|||d	<   d}|d
         rl||d<   |||d<   |	|	|d<   |                     |                     ||                    }|                     |dg           }|                     |||||          S |d         r||d<   |	| 	                                }	| | 
                    |          }|	||z  dz  z
  }||d<   |	|d<   d}|                     ||d          \  }}|dk    rd|d<   |                     |                     ||                    }|                     |||||          S t          | j        dz   |z   dz   |d         z   dz             )a  

        https://coincatch.github.io/github.io/en/spot/#get-candle-data
        https://coincatch.github.io/github.io/en/mix/#get-candle-data

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch(default 100)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param str [params.price]: "mark" for mark price candles
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   r  r5   Nuntilr  r   rP  rI  rB   periodafterbeforer  rD   granularity	startTimeendTimerS  r2  zmarket mark index	kLineTyper-  r6  r.  )r  r  r  r   r  publicGetApiSpotV1MarketCandlesr  r  parse_ohlcvsmillisecondsparse_timeframepublicGetApiMixV1MarketCandlesr*   r5   )r  r  ro  rp  rI  r  r<  r  r  rr  rO  r   encodedTimeframemaxLimitrequestedLimitr  r  duration	priceTypes                      r  fetch_ohlcvzcoincatch.fetch_ohlcv9  s`     "
V$$fTl
 55fj'RRvF^
\,/
;
++J	9MM5#4%N%-GG&> ;	~ 0GH #(  $)!;;DKKQW<X<XYYH* >>(FB77D$$T69eUKKKF^ 	~%5GM"}))++}//	::H!4t!;<#(GK !&GI!I $ = =fjRY Z ZIvF""':$::4;;wPV;W;WXXH $$Xvy%OOOtw}z9<VVY_`fYggj||}}}r  c           
         |                      |dd          |                     |dd          |                     |dd          |                     |dd          |                     |d	d
          |                     |dd          gS )Nr?  r   rS  r   rD  r   rF     rB  r   r\     )rb  safe_number_2)r  ohlcvr  s      r  parse_ohlcvzcoincatch.parse_ohlcv  s    tQ//ufa00ufa00ueQ//ugq11ui33
 	
r  c                 ^   d}|                                   |                     |          }d|d         i}d}|                     ||d          \  }}d}	|}
|||	}
|||d<   |||d<   |
|
|d	<   d}|d
         r*|                     |                     ||                    }n[|d         r*|                     |                     ||                    }n)t          | j        dz   |z   dz   |d         z   dz             |                     |dg           }| 	                    ||||          S )a  
        get the list of most recent trades for a particular symbol

        https://coincatch.github.io/github.io/en/spot/#get-recent-trades
        https://coincatch.github.io/github.io/en/mix/#get-fills

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest entry to fetch
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        r   r  r5   Nrr  rP  rw  rx  rI  rB   rD   r-  r6  r  r.  r  )
r  r  r  $publicGetApiSpotV1MarketFillsHistoryr  #publicGetApiMixV1MarketFillsHistoryr*   r5   r  parse_trades)r  r  rp  rI  r  r<  r  r  rr  r  requestLimitr  r  s                r  fetch_tradeszcoincatch.fetch_trades  ss    #
V$$fTl
 55fj'RRv5#4#L ',$ %*	"#+GG&> (	~@@WV\A]A]^^HH$ F^ 	~??GU[@\@\]]HH( tw}z9<VVY_`fYggj||}}}~~h33  vue<<<r  tradec                 .   |                      |d          }|                     ||          }|                     |g d          }|                     |dd          }d }|t	          j        |          }|                      |d          }||d         |d         }|                     |dd          }|                     |                     |d	d
          |                      |d          ||                     |          |d         |                      |d          | 	                    |          |                      |d          |                     |dd          | 
                    |g d          |                     |dd          ||d|d|          S )Nr  )fillTimer@  cTimer   r  feeCcyr  	tradeSidesidetradeIdfillIdorderId	orderTypetakerMakerFlag	fillPricerS  )fillQuantitysizesizeQtyfillTotalAmount
fillAmountr   r  )r5   orderr@  rC  r  r  r  takerOrMakerrS  r  r   r  r  )r  rc  safe_integer_nrd  r0   
string_abssafe_string_lower_2
safe_traderf  parse_order_sidesafe_string_n)	r  r  r  r  r@  r   feeCostfeeCurrencyr  s	            r  parse_tradezcoincatch.parse_trade  s   r ##E844((6::''/Q/Q/QRR	!!%77(..G&&uh77fX&6&B *K''{FCC$$UIx@@%%eY77"Y//X&$$UK88))$// ,,U4DEE''{GDD((0S0S0STT&&u.?NN'  ! 
  
" #  	r  c                 l   |                                   |                     |          }|d         }|                    d          }||                     |d          d}|                     |                     ||                    }|                     |di           }|                     ||          S )al  
        fetch the current funding rate

        https://coincatch.github.io/github.io/en/mix/#get-current-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        r5   rA  r   )r  r  r  )r  r  splitr  &publicGetApiMixV1MarketCurrentFundRater  r  parse_funding_rate)	r  r  r  r  r  partsr  r  r  s	            r  fetch_funding_ratezcoincatch.fetch_funding_rateF  s     	V$$$<s##++E155
 
 >>t{{7TZ?[?[\\ ~~h33&&tV444r  c                     |                      |d          }|                     ||          }|                     |d          }i d|d|d         dd dd dd dd dd d	d d|d
d dd dd dd dd dd dd dd S )Nr  fundingRater  ra  r`  interestRateestimatedSettlePricer@  rC  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r  rc  r  )r  r
  r  r  r  s        r  r  zcoincatch.parse_funding_rateg  s   ##Hh77((6::&&x??
H
fX&
 
 $	

 D
 #D
 
 
 ;
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  r  r<  
optionNamer  requestPropertyc                 N    |                      ||||          \  }}||||<   ||gS N)r  )	r  r  r<  r  r  r  defaultValuerF   paramsOmiteds	            r   handle_option_params_and_requestz*coincatch.handle_option_params_and_request  s=    #<<VZQ[]ijj'-GO$&&r  c           
         |t          | j        dz             |                                  d}|                     |          }d|d         i}|}||}|||d<   |                     |                     ||                    }	|                     |	dg           }
g }t          dt          |
                    D ]}|
|         }| 	                    |d	          }|
                    ||                     |                     |d          |dd
          |                     |d          ||                     |          d           |                     |d          }|                     |||          S )a  
        fetches historical funding rate prices

        https://coincatch.github.io/github.io/en/mix/#get-history-funding-rate

        :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 entries to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.pageNo]: the page number to fetch
        :param bool [params.nextPage]: whether to query the next page(default False)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentrN  r  r5   pageSizer  r   
settleTimerD   r  )r  r  r  r@  rC  r@  )r$   r5   r  r  &publicGetApiMixV1MarketHistoryFundRater  r  r  r  r  r  safe_symbolr  r  rf  sort_byfilter_by_since_limit)r  r  rp  rI  r  maxEntriesPerRequestr  r  r  r  r  ratesr  entryr@  sorteds                   r  fetch_funding_rate_historyz$coincatch.fetch_funding_rate_history  s    >#DG.e$efff"V$$fTl
 1N%"0GJ>>t{{7TZ?[?[\\ ~~h33q#d))$$ 		 		AGE))%>>ILL**4+;+;E8+L+LfVZ\bcc#//}EE& LL33      e[11))&%???r  c                    |                                   d}d}|                     |d|          \  }}d}|dk    r|                     |          }nt|dk    rKd}|                     ||d|          \  }}d|i}|                     |                     ||                    }n#t          | j        dz   |z   dz   |z   d	z             |                     |d
g           }| 	                    |          S )a5  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://coincatch.github.io/github.io/en/spot/#get-account-assets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'spot' or 'swap' - the type of the market to fetch balance for(default 'spot')
        :param str [params.productType]: *swap only* 'umcbl' or 'dmcbl'(default 'umcbl')
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        rf   NrB   rD   r  r  r-  r6  r.  r  )
r  r9   privateGetApiSpotV1AccountAssetsr  !privateGetApiMixV1AccountAccountsr  r*   r5   r  parse_balance)r  r  r<  rO  r  r  r  r  s           r  fetch_balancezcoincatch.fetch_balance  s    	#

!??
DRXYY
F$ <<VDDHH6!!!K"&"?"?
Tacn"o"oK{G8 ==dkk'SY>Z>Z[[HHtw}z9<VVYccfxxyyy~~h33!!$'''r  c                    d|i}t          dt          |                    D ]}|                     ||i           }|                     |dd          }|                     |          }|                                 }|                     |d          |d<   |                     |dd          }|                     |d	d
          }	t          j        ||	          |d<   |                     |d          |d<   |||<   | 	                    |          S )Nr  r   r  
marginCoin	availablefreelocklockedfrozen0usedequitytotal)
r  r  r  rd  r  accountr  r0   
string_addsafe_balance)
r  balancesr  r  balanceEntryr  r  r  r  r  s
             r  r  zcoincatch.parse_balance  s   F H
 q#h--(( 
	# 
	#A>>(Ar::L++L*lSSJ**:66DllnnG"..|[IIGFO''fhGGF%%lHcBBF%0@@GFO#//hGGGG"F4LL  (((r  r  r  fromAccount	toAccountc                    |                                   |                     |          }|dk    r|dk    rd}nd}|dk    r|dk    rd}nd}|d         |                     ||          ||d}d}|                     |dd	          \  }}|||d
<   |                     |                     ||                    }	|                     |	|          S )a  
        transfer currency internally between wallets on the same account

        https://coincatch.github.io/github.io/en/spot/#transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: 'spot' or 'swap' or 'mix_usdt' or 'mix_usd' - account to transfer from
        :param str toAccount: 'spot' or 'swap' or 'mix_usdt' or 'mix_usd' - account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: a unique id for the transfer
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        rD   USDTmix_usdtmix_usdr5   )coinr  fromTypetoTypeNr   clientOrderId	clientOid)r  r  currency_to_precisionr  $privatePostApiSpotV1WalletTransferV2r  parse_transfer)
r  r  r  r  r  r  r  r  r  r  s
             r  r   zcoincatch.transfer8  s    	==&&&  v~~('v~~&		%	TN00v>>#	
 
 " $ = =fjRa b bv$#0GK <<T[[RX=Y=YZZ ""8X666r  c           
          |                      |d          }d }|dk    rd}|                     |di           }|                      |d          d d |                     d |          d d d ||d	S )Nmsgsuccessokr  
transferId)	r5   r@  rC  r  r  r  r  statusr  )r  r  r  )r  r   r  r  r  r  s         r  r  zcoincatch.parse_transferj  s    x//)F~~h33""466//h??

 

 
	
r  c                    |                                   |                     |          }d|d         i}d}|                     |          \  }}||                     |          }|t	          | j        dz             |                     ||          |d<   |                     |                     ||                    }| 	                    |di           }| 
                    ||          }|S )a  
        fetch the deposit address for a currency associated with self account

        https://coincatch.github.io/github.io/en/spot/#get-coin-address

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: network for fetch deposit address
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        r  r5   NzM fetchDepositAddress() requires a network parameter or a default network coder  r  )r  r  handle_network_code_and_paramsdefault_network_coder$   r5   network_code_to_id'privateGetApiSpotV1WalletDepositAddressr  r  parse_deposit_address)	r  r  r  r  r  r  r  r  depositAddresss	            r  fetch_deposit_addresszcoincatch.fetch_deposit_address|  s     	==&&HTN
  "AA&IIV33D99K#DG.}$}~~~22;EE??GU[@\@\]] ~~h3333D(CCr  c                    |                      |d          }|                     |           |                      |d          }|                      | j        d         ||          }|                      |d          }|d         ||||dS )Naddressr  r/  tagr  )r  r  r  r  r  )r  check_addressr   )r  r  r  r  r  r  r  s          r  r  zcoincatch.parse_deposit_address  s     "">9==7###$$^W==	""4<#?IVV~u55 ("
 
 	
r  c                 ~   d}|                                   i }d}| |                     |          }|d         |d<   |||d<   d}|                     ||d          \  }}|||d<   |                     |                     ||                    }	|                     |	dg           }
|                     |
|||          S )	a-  
        fetch all deposits made to an account

        https://coincatch.github.io/github.io/en/spot/#get-deposit-list

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
        :param int [limit]: the maximum number of transfer structures to retrieve(not used by exchange)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch transfers for(default time now)
        :param int [params.pageNo]: pageNo default 1
        :param int [params.pageSize]: pageSize(default 20, max 100)
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        rq   Nr5   r  rw  rr  rx  r  )r  r  r  $privateGetApiSpotV1WalletDepositListr  r  parse_transactionsr  r  rp  rI  r  r<  r  r  rr  r  r  s              r  fetch_depositszcoincatch.fetch_deposits  s     %
!}}T**H&tnGFO#(GK 55fj'RRv!&GI<<T[[RX=Y=YZZ8 ~~h33&&tXueDDDr  c                    d}|                                   i }d}| |                     |          }|d         |d<   |||d<   |||d<   d}|                     ||d          \  }}|||d<   |                     |                     ||                    }	|                     |	d	g           }
|                     |
|||          S )
a  
        fetch all withdrawals made from an account

        https://coincatch.github.io/github.io/en/spot/#get-withdraw-list-v2

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
        :param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch transfers for(default time now)
        :param str [params.clientOid]: clientOid
        :param str [params.orderId]: The response orderId
        :param str [params.idLessThan]: Requests the content on the page before self ID(older data), the value input should be the orderId of the corresponding interface.
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        r   Nr5   r  rw  rI  rr  rx  r  )r  r  r  )privateGetApiSpotV1WalletWithdrawalListV2r  r  r  r  s              r  fetch_withdrawalszcoincatch.fetch_withdrawals  s      (
!}}T**H&tnGFO#(GK $GG55fj'RRv!&GIAA$++gW]B^B^__ ~~h33&&tXueDDDr  r  r  c                    |                      ||          \  }}|                                  |                     |          }|d         ||d}|||d<   d}|                     |          \  }}||                     |          |d<   |                     |                     ||                    }	|                     |	di           }
|                     |
|          S )as  
        make a withdrawal

        https://coincatch.github.io/github.io/en/spot/#withdraw

        :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
        :param str params['network']: network for withdraw(mandatory)
        :param str [params.remark]: remark
        :param str [params.clientOid]: custom id
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        r5   )r  r  r  Nr  r  r  )	handle_withdraw_tag_and_paramsr  r  r  r   &privatePostApiSpotV1WalletWithdrawalV2r  r  parse_transaction)r  r  r  r  r  r  r  r  r  r  r  s              r  r   zcoincatch.withdraw  s      99#vFFV==&&TN
 

 ? GEN"AA&IIV"#66{CCGG>>t{{7TZ?[?[\\ ~~h33%%dH555r  c                 >   |                      |d          }|dk    rd}|                      |d          }|                      |d          }|                     ||          }|                     |d          }|                     |d          }|                      |d          }	|                      | j        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S )Nr  r  r  txIdr  r  r  r  r/  	toAddressfromAddressr  r  r  r  r  r5   r  txidr@  rC  r  r  	addressToaddressFromtagTotagFromr  updated)internalcommentr  )r  r  r  r  r   rd  rf  )r  transactionr  r  r  r  r  r@  r  r  r  r  r  r  r  r  r  s                    r  r  zcoincatch.parse_transactionI  sV   D !!+x88YFV44V44&&tX66%%k7;;	!!+x88$$['::	""4<#?IVV$$[+>>	&&{MBB{E22V44"";66  C
K
$$$[$	BB
 D
 	

 Y//
 w
 t
 
 ;
 3
 T
 t
 D
 f
 
  f!
" t#
$ )
 
 
 	
r  r   c                     |                                   d}|                     |          }|d         st          | j        dz   |z   dz             ||d<   d|d<   |                     |dd	|d
|          S )a  
        create a market buy order by providing the symbol and cost

        https://coincatch.github.io/github.io/en/spot/#place-order

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rS   rB   r-  z() supports spot orders onlyr<  Fr+  r  buyN)r  r  r*   r5   create_order)r  r  r   r  r<  r  s         r  !create_market_buy_order_with_costz+coincatch.create_market_buy_order_with_cost  s     	3
V$$f~ 	\tw}z9<ZZ[[[)|6;23  5$fMMMr  r  r  rS  c                 V   |                                   |                     |dd          |d<   |                     |          }|d         r|                     ||||||          S |d         r|                     ||||||          S t          | j        dz   |d         z   dz             )a  
        create a trade order

        https://coincatch.github.io/github.io/en/spot/#place-order
        https://coincatch.github.io/github.io/en/spot/#place-plan-order
        https://coincatch.github.io/github.io/en/mix/#place-order
        https://coincatch.github.io/github.io/en/mix/#place-plan-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'LIMIT_MAKER' for spot, 'market' or 'limit' or 'STOP' for swap
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.hedged]: *swap markets only* must be set to True if position mode is hedged(default False)
        :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
        :param float [params.triggerPrice]: the price that the order is to be triggered
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'PO'
        :param str [params.clientOrderId]: a unique id for the order - is mandatory for swap
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r<  rX   rB   rD   z$ createOrder() is not supported for r  r.  )r  r  r  create_spot_ordercreate_swap_orderr*   r5   )r  r  r  r  r  rS  r  r  s           r  r$  zcoincatch.create_order  s    . 	#//mTT|V$$&> 	w))&$feVTTTF^ 	w))&$feVTTTtw)OORXY_R``cuuvvvr  c                    |                                   |                     |dd          |d<   |                     ||||||          }|                     |d          du}d}	|r|                     |          }	n|                     |          }	|                     |	di           }
|                     |          }|                     |
|          S )a  
        create a trade order on spot market

        https://coincatch.github.io/github.io/en/spot/#place-order
        https://coincatch.github.io/github.io/en/spot/#place-plan-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that 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 float [params.cost]: *market buy only* the quote quantity that can be used alternative for the amount
        :param float [params.triggerPrice]: the price that the order is to be triggered at
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'PO'
        :param str [params.clientOrderId]: a unique id for the order(max length 40)
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r<  createSpotOrderr9  Nr  )r  r  create_spot_order_request!privatePostApiSpotV1PlanPlacePlanprivatePostApiSpotV1TradeOrdersr  r  parse_order)r  r  r  r  r  rS  r  r  
isPlanOrerr  r  r  s               r  r'  zcoincatch.create_spot_order  s    ( 	#//FWXX|66vtT6SXZ`aa%%g~>>dJ
 	E==gFFHH ;;GDDH~~h33V$$f---r  c                 B   d}|                      |d|          \  }}|                     |          }|d         ||d}	|dk    }
|                     |||
          }|d         }|d         }d}|                      |d	          \  }}d}|                      |d
          \  }}|
o|dk    }|s|t          | j        dz   |z   dz             |r)|                     |||||          }|d	         }|d         }|1|dk    r||	d<   |r|n|                     |          |	d<   |r|nd|	d<   nc||	d
<   |||	d<   d}|                      |d          \  }}|||	d<   |dk    r||	d<   d}|
rd}nd}||	d<   |
r|n|                     |          |	d<   |                     |	|          S )a@  
 @ignore
        helper function to build request
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that 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 float [params.triggerPrice]: the price that the order is to be triggered at
        :param float [params.cost]: *market buy only* the quote quantity that can be used alternative for the amount
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately
        :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'PO'(default 'GTC')
        :param str [params.clientOrderId]: a unique id for the order(max length 40)
        :returns dict: request to be sent to the exchange
        createSpotOrderRequestr<  r5   )r  r  r  r  r  r?  Nr   r9  r#  r-  z3 supports cost parameter for market buy orders onlyrI  rS  quantityr  forcetimeInForceValuer  r  executePricemarket_price
fill_pricetriggerTyper  )handle_param_stringr  "handle_time_in_force_and_post_onlyr*   r5   handle_requires_price_and_costnumber_to_stringr  )r  r  r  r  r  rS  r  r<  r  r  isMarketOrdertimeInForceAndParamsr?  r   r9  isMarketBuycostAndParamsr  r8  s                      r  r+  z#coincatch.create_spot_order_request  s@   " .
!55flJWW
FV$$Tl
 

 )#FFzSY[hii%h/*=9//??f #77OOf#7 	s$"2tw}z9<qqrrr 	- ??
FTY[acghhM (D"8,Fw#( *5"X$$4;P;PQW;X;XGJ.9G{{xGG&2GN#&.9*+!%M$($<$<V_$U$U!M6('4$w*/'#K +,*%0GM"&3Vdd9N9Nv9V9VGFO{{7F+++r  r#  c                 ~   d|                      |          z   dz   }d}|                     |||d          \  }}d }	||                     |          }	d }
||                     |          }
|rE|+|)t          | j        dz   |z   dz   |z   dz   |z   dz             |t          j        |	|
          }n|r|n|	}||d}|S )	NcreateMarketOrderRequiresPriceTr-  z*() requires the price argument for market zT orders to calculate the total cost to spend(amount * price), alternatively set the zK option or param to False and pass the cost to spend in the amount argument)r   r  )
capitalizer  r<  r(   r5   r0   r  )r  r<  r  rS  r  r   r  r  requiresPriceamountStringpriceStringr  s               r  r;  z(coincatch.handle_requires_price_and_cost:	  s$   #dood&;&;;>RR
 $ = =fjR\^b c cv 0088L//66K 	2DL"47S=:#=@l#los#s  wM  $M  PZ  $Z  ]j  $j  k  k  k),DD144\D
 
 r  Fr=  c                     d }|                      ||d          \  }}d}|                     ||dk    |          \  }}|rd}|                     |          }||d}|S )Nr?  F	post_onlyr6  )r?  r  )r  handle_post_onlyencode_time_in_force)r  r<  r  r=  r?  postOnlyr  s          r  r:  z,coincatch.handle_time_in_force_and_post_onlyQ	  s    ";;FJP]^^V00{@Z\bcc& 	K//<<&
 
 r  c                    |                      |dd          |d<   |                                  |                     |          }|                     ||||||          }|                      |d          }	|                     |d          }d}
|	dk    r|                     |          }
n1|	dk    r|                     |          }
n|                     |          }
|                     |
di           }| 	                    ||          S )aZ  
        create a trade order on swap market

        https://coincatch.github.io/github.io/en/mix/#place-order
        https://coincatch.github.io/github.io/en/mix/#place-plan-order
        https://coincatch.github.io/github.io/en/mix/#place-stop-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.hedged]: must be set to True if position mode is hedged(default False)
        :param bool [params.postOnly]: *non-trigger orders only* if True, the order will only be posted to the order book and not executed immediately
        :param bool [params.reduceOnly]: True or False whether the order is reduce only
        :param str [params.timeInForce]: *non-trigger orders only* 'GTC', 'FOK', 'IOC' or 'PO'
        :param str [params.clientOrderId]: a unique id for the order
        :param float [params.triggerPrice]: the price that the order is to be triggered at
        :param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        r<  createSwapOrderendpointTypeNrM  tpslr  )
r  r  r  create_swap_order_requestomit privatePostApiMixV1PlanPlacePlan privatePostApiMixV1PlanPlaceTPSL"privatePostApiMixV1OrderPlaceOrderr  r.  )r  r  r  r  r  rS  r  r  r  rO  r  r  s               r  r(  zcoincatch.create_swap_order_	  s   8  $//FWXX|V$$00tVUTZ[[''@@))G^449$$<<WEEHHV##<<WEEHH>>wGGH ~~h33f---r  c                    d}|                      |d|          \  }}|                     |          }|d         |d         |                     ||          d}	|                     ||d|	d          \  }	}|dk    }
|                     ||||||          }|                     |d	          }||dk    rI|                     |||
          }|d         }|d         }|||	d<   ||                     ||          |	d<   |dk    r||	d<   d}d}|dk    s|dk    s|dk    s|dk    s|dk    s|dk    rd}|dk    r|dk    rd}|sr|                     ||d|          \  }}| 	                    |d          }|r(||r|dk    rd}n2|dk    rd}n)|dk    rd}n |dk    rd}n|
                                dz   }|r|                     |d          }||	d<   |                     |	|          S ) ap  
 @ignore
        helper function to build request
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.hedged]: must be set to True if position mode is hedged(default False)
        :param bool [params.postOnly]: *non-trigger orders only* if True, the order will only be posted to the order book and not executed immediately
        :param bool [params.reduceOnly]: True or False whether the order is reduce only
        :param str [params.timeInForce]: *non-trigger orders only* 'GTC', 'FOK', 'IOC' or 'PO'
        :param str [params.clientOrderId]: a unique id for the order
        :param float [params.triggerPrice]: the price that the order is to be triggered at
        :param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :returns dict: request to be sent to the exchange
        createSwapOrderRequestr<  r5   r  )r  r  r  r  r  r  rO  Nstandardr  r?  r4  rS  rP  r  F
buy_singlesell_single	open_long
open_short
close_longclose_shortTr@  
reduceOnlyr#  sell_singler  )r9  r  amount_to_precisionr  (handle_trigger_stop_loss_and_take_profitr  r:  price_to_precisionr  r  lowerrR  r  )r  r  r  r  r  rS  r  r<  r  r  r=  rO  r>  r?  sideIsExchangeSpecificr@  r_  s                    r  rQ  z#coincatch.create_swap_order_request	  s   0 .
!55flJWW
FV$$Tl ,,,VV<<
 

 ??
Tcelnyzz)>>vtTSXZdflmm''?? lj&@&@#'#J#J:W]_l#m#m )(3F.}=K&.9*+ #'#:#:65#I#I F""#'GK %*"F$$$-*?*?T[EXEX^bfr^r^rx|  AM  yM  yM  SW  [h  Sh  Sh)-&L((t}/D/D!F) 4!%!>!>vzS[]c!d!d!^^FLAA
 4".J.5==#0DD!V^^#/D5==#.DD!V^^#/D::<<)3D 96<88"GFO{{7F+++r  rX   c                 Z   i }d}|                      |d          }	|                      |d          }
d }|                     |d          }|                     |d          }|                     |dd          }|d u}|                      |d          }|                      |d	          }|
d u}|	d u}|d u}|r|s|                      |d          }
|
d u}|d u}|r|s|                      |d          }	|	d u}|o|}|d u}|d
k    }|s|s|dk    rZ|rA|rd|d<   nd|d<   |                     ||          |d<   |                     ||          |d<   d}|dk    rd }|r|
|d<   |r|	|d<   n|s|s|r|s#t	          | j        dz   |z   dz   |z   dz             d}d}|dk    rd}||d<   |r,|t          | j        dz   |z   dz             |}||d<   d|d<   n|r|
}d |d<   n|	}d!|d<   |                     ||          |d<   |||d"<   |                     |g d#          }|                     ||          S )$NrX  r<  r=  
takeProfitstopLossr9  	stopPricetrailingPercenttrailingTriggerPricer  rZ   r6  r8  r7  r5  rM  rY   presetTakeProfitPricepresetStopLossPricer-  z() supports does not support z type of stop loss and take profit orders(only market type is supported for stop loss and take profit orders). To create a market order with stop loss or take profit attached use createOrderWithTakeProfitAndStopLoss()rP  longr#  shortholdSidezG() requires the trailingTriggerPrice parameter for trailing stop orders	rangeRatemoving_planplanTypeprofit_plan	loss_planrO  )ri  rh  r<  r=  r9  rj  rk  rl  )	r  r  rd  rd  r*   r5   r$   rR  r  )r  r  r  r  rS  r<  r  r  rO  r<  r=  requestTriggerPricerh  ri  r9  	isTriggerrk  rl  
hasTPPrice
hasSLPricehasTakeProfithasStopLosshasBothTPAndSLisTrailingPercentOrderr=  rq  s                             r  rc  z2coincatch.handle_trigger_stop_loss_and_take_profit	  sv   !((AA**63DEE#'^^FL99
>>&*55))&.+NN!-	**63DEE#//8NOO%T1
#4/
#4/ 	7 	7"..z>JJO)5Jt+ 	5z 	5 ,,X~FFM't3J#2
"1"=) #	[Y #	[:9_+_+_ )  U-;GM**-9GM*.2.E.Efe.T.TGN+*.*A*A&,*W*W'(^++# C3B/0 ?1>-. 	[: 	[)? 	[  F"47S=:#=@_#_bf#f  jE  $E  F  F  F!LHu}}""*GJ% 2'/+DGcMJ,F  JS  -S  T  T  T&:#'6$&3
## 2&5#&3
##&3#&1
#&*&=&=fFY&Z&ZGN##&2GN#6  $j  $j  $j  k  k{{7F+++r  rh  ri  c	           
         d}	|                                   |                     |          }
|
d         st          | j        dz   |	z   dz             |	|d<   t	          t
          |                               ||||||||          S )aM  
        *swap markets only* create an order with a stop loss or take profit attached(type 3)
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency or the number of contracts
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param float [takeProfit]: the take profit price, in units of the quote currency
        :param float [stopLoss]: the stop loss price, in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rZ   rD   r-  z%() is supported for swap markets onlyr<  )r  r  r*   r5   r  r2   +create_order_with_take_profit_and_stop_loss)r  r  r  r  r  rS  rh  ri  r  r<  r  r  s              r  r  z5coincatch.create_order_with_take_profit_and_stop_loss$
  s     <
V$$f~ 	etw}z9<ccddd)|Y%%QQRXZ^`dflnsu  BJ  LR  S  S  	Sr  r?  c                 >    ddddd}|                      |||          S )Nr  iokfokrI  )GTCr4  r5  r6  r  )r  r?  timeInForceMaps      r  rK  zcoincatch.encode_time_in_force9
  s4    	
 
 [IIIr  r  c           	         |                                   d}||d<   g }g }t          dt          |                    D ]8}||         }|                     |d          }|                    |           |                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d	i           }|                     ||	|
|||          }|                     |d
          }|t          | j	        dz   |z   dz             |                     |d          }|| 
                                |d<   |                    |           :|                     |          }t          |          }|dk    rt          | j	        dz             |                     |d          }|                     |          }d|d         i}|d         }d}d}d}|dk    r1||d<   |                     |                     ||                    }d}ng|d         r<|d         |d<   ||d<   |                     |                     ||                    }d}n#t          | j	        dz   |z   dz   |z   dz             |                     |di           }|                     ||g           }|                     |          S )a  
        create a list of trade orders(all orders should be of the same symbol)

        https://coincatch.github.io/github.io/en/spot/#batch-order

        :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(max 50 entries)
        :param dict [params]: extra parameters specific to the api endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        rY   r<  r   r  r  r  r  rS  r  r9  Nr-  z"() does not support trigger ordersr  r   z< createOrders() requires all orders to be of the same symbolr5   rB   r  
resultListrD   r  r  r  	orderInfor6  r.  r  )r  r  r  r  r  r  r  create_order_requestr*   r5   uuiduniquer%   r  $privatePostApiSpotV1TradeBatchOrdersr  #privatePostApiMixV1OrderBatchOrdersr  parse_orders)r  r  r  r<  ordersRequestsr4  r  rawOrderr  r  r  r  rS  orderParamsorderRequestr9  r  symbolsLengthordersSymbolr  r  rO  r  responseOrderspropertyNamer  s                             r  create_orderszcoincatch.create_ordersB
  s    	#
)|q#f++&& 	0 	0AayH%%h99FNN6"""##Hf55D##Hf55D%%h99F$$Xw77E..8R@@K44VT4QVXcddL++KHHL'"47S=:#=@d#deee ,,\?KKM$04		_-!!,////++g&&GATW'eefff''33\**fTl
 F^
 #1GK @@WV\A]A]^^H< (LLF^ 	z$*:$6GL!'5GO$??GU[@\@\]]H2 'LLtw}z9<VVYccfxxyyy~~h33lB??  000r  c                 >   |                      |dd          }||d<   |                     |          }|d         r|                     ||||||          S |d         r|                     ||||||          S t	          | j        dz   |z   dz   |d         z   dz             )	Nr<  createOrderRequestrB   rD   r-  r6  r  r.  )r  r  r+  rQ  r*   r5   )	r  r  r  r  r  rS  r  r<  r  s	            r  r  zcoincatch.create_order_request
  s    %%fl<PQQ
)|V$$&> 	~11&$feU[\\\F^ 	~11&$feU[\\\tw}z9<VVY_`fYggj||}}}r  r5   c           	          d}||d<   |                                   |                     |          }	|	d         r|                     |||||||          S t          | j        dz   |z   dz   |	d         z   dz             )a  
        edit a trade trigger, stop-looss or take-profit order

        https://coincatch.github.io/github.io/en/spot/#modify-plan-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        	editOrderr<  rB   r-  r6  r  r.  )r  r  edit_spot_orderr*   r5   )
r  r5   r  r  r  r  rS  r  r<  r  s
             r  
edit_orderzcoincatch.edit_order
  s     !
)|V$$&> 	~''FD$vVVV tw}z9<VVY_`fYggj||}}}r  c                 ^   |                                   d}|                     |d|          \  }}|                     |          }	|	d         s#t          | j        dz   |	d         z   dz             d|i}
|                     |d          }|||
d
<   n$|t          | j        dz   |z   dz             ||
d<   d	}|                     |d          \  }}|dk    o|dk    }|s|t          | j        dz   |z   dz             |D|r*|                     |||||          }|d         }|d         }n|                     |          |
d<   |||
d<   |dk    r|||
d<   | 	                    | 
                    |
|                    }|                     |di           }|                     ||	          S )a  
 @ignore
        edit a trade order

        https://coincatch.github.io/github.io/en/spot/#modify-plan-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: a unique id for the order that can be used alternative for the id
        :param str params['triggerPrice']: *mandatory* the price that the order is to be triggered at
        :param float [params.cost]: *market buy only* the quote quantity that can be used alternative for the amount
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        editSpotOrderr<  rB   z" editSpotOrder() does not support r  z ordersr  r  Nr  r-  z() requires id or clientOrderIdr  r   r  r#  z5() supports cost parameter for market buy orders onlyr  r  rI  rS  r  )r  r9  r  r*   r5   r  r%   r;  r<  "privatePostApiSpotV1PlanModifyPlanr  r  r.  )r  r5   r  r  r  r  rS  r  r<  r  r  r  r   r?  r@  r  r  s                    r  r  zcoincatch.edit_spot_order
  s   & 	$
!55flJWW
FV$$f~ 	ltw)MMPVW]P^^ajjkkk
 ((AA$#0GK  ZTWs]Z7:[[\\\!#GI//??fx'<dem 	u$"2tw}z9<ssttt @ $ C CJPVX]_egk l l$V,&x0"&"7"7"?"?"GFOGOO%"3$GG::4;;wPV;W;WXX ~~h33f---r  c                    d}|                                   i }|                     |d          }|||d<   d}||                     |          }d}|                     ||||          \  }}d}	d}
|dk    r|                     |                     ||                    }	|                     |	d          }|+t          j        |	          }	|                     |	dg           }| 	                    |di           }
n|dk    r|#t          | j        d	z   |z   d
z   |z   dz             |d         |d<   ||                     |d          }||d<   |                     |                     ||                    }	| 	                    |	di           }
n#t          | j        d	z   |z   dz   |z   dz             |                     |
|          S )a   
        fetches information on an order made by the user(non-trigger orders only)

        https://coincatch.github.io/github.io/en/spot/#get-order-details
        https://coincatch.github.io/github.io/en/mix/#get-order-details

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in(is mandatory for swap)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'spot' or 'swap' - the type of the market to fetch entry for(default 'spot')
        :param str [params.clientOrderId]: a unique id for the order that can be used alternative for the id
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        r   r  Nr  rB   r  r   rD   r-  z"() requires a symbol argument for r.  r5   r  r  r6  )r  r  r  r9  "privatePostApiSpotV1TradeOrderInfor  r  jsonloadsr  r$   r5   rR  privateGetApiMixV1OrderDetailr*   r.  )r  r5   r  r  r<  r  r  r  rO  r  r  r  s               r  fetch_orderzcoincatch.fetch_order  s    "
((AA !#GI[[((F
!??
FTZ\fgg
F>>t{{7TZ?[?[\\HT >>(F33D|:h//~~h;;NN4B//EE6!!~'#
(BEi(ilv(v  zL  )L  M  M  M &tGH(6?;;'4$99$++gv:V:VWWHF NN8VR88EEtw}z9<VVYccfxxyyyv...r  c                 b   d}|                                   d}||                     |          }d}|                     ||||          \  }}||d<   |dk    r|                     ||||          S |dk    r|                     ||||          S t          | j        dz   |z   dz   |z   dz             )	a  
        fetch all unfilled currently open orders

        https://coincatch.github.io/github.io/en/spot/#get-order-list
        https://coincatch.github.io/github.io/en/spot/#get-current-plan-orders
        https://coincatch.github.io/github.io/en/mix/#get-open-order
        https://coincatch.github.io/github.io/en/mix/#get-all-open-order
        https://coincatch.github.io/github.io/en/mix/#get-plan-order-tpsl-list

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching trigger orders(default False)
        :param str [params.type]: 'spot' or 'swap' - the type of the market to fetch entries for(default 'spot')
        :param str [params.productType]: *swap only* 'umcbl' or 'dmcbl' - the product type of the market to fetch entries for(default 'umcbl')
        :param str [params.marginCoin]: *swap only* the margin coin of the market to fetch entries for
        :param str [params.isPlan]: *swap trigger only* 'plan' or 'profit_loss'('plan'(default) for trigger(plan) orders, 'profit_loss' for stop-loss and take-profit orders)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r   NrB   r<  rD   r-  r6  r.  )r  r  r9  fetch_open_spot_ordersfetch_open_swap_ordersr*   r5   r  r  rp  rI  r  r<  r  rO  s           r  fetch_open_orderszcoincatch.fetch_open_orders  s    * '
[[((F
!??
FTZ\fgg
F)|..vueVLLL6!!..vueVLLLtw}z9<VVYccfxxyyyr  c                    |                                   d}|                     |d|          \  }}i }d}| |                     |          }|d         |d<   d}|                     ||dd|          \  }}d}	|r~|t	          | j        d	z   |z   d
z             |||d<   |                     |                     ||                    }
|                     |
di           }| 	                    |dg           }	n@| 
                    |                     ||                    }
| 	                    |
dg           }	|                     |	|||          S )aQ  
 @ignore
        fetch all unfilled currently open orders for spot markets

        https://coincatch.github.io/github.io/en/spot/#get-order-list
        https://coincatch.github.io/github.io/en/spot/#get-current-plan-orders

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching trigger orders(default False)
        :param str [params.lastEndId]: *for trigger orders only* the last order id to fetch entries after
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        fetchOpenSpotOrdersr<  Nr5   r  FrM  stopr-  z0() requires a symbol argument for trigger ordersr  r  r  )r  r9  r  handle_option_and_params_2r$   r5   #privatePostApiSpotV1PlanCurrentPlanr  r  r  #privatePostApiSpotV1TradeOpenOrdersr  )r  r  rp  rI  r  r<  r  r  rx  r  r  r  s               r  r  z coincatch.fetch_open_spot_orders  ss     	*
!55flJWW
F[[((F &tGH	 ;;FJPY[aclmm	6 C	:~'#
(BEw(wxxx &+
#??GU[@\@\]]H< >>(FB77D^^D+r::FF??GU[@\@\]]H: ^^Hfb99F  >>>r  c                 X   |                                   d}|                     |d|          \  }}d}|                     ||dd|          \  }}d}|                     ||d|          \  }}|                     |d          }d}	d}
||                     |          }	d	|	d
         i}|s|8|||d<   |||d<   |                     |                     ||                    }
n|                     |                     ||                    }
np|rt          | j
        dz   |z   dz             |d}d|i}d}|                     |d|          }|||d<   |                     |                     ||                    }
|                     |
dg           }|                     ||	||          S )a  
 @ignore
        fetch all unfilled currently open orders for swap markets

        https://coincatch.github.io/github.io/en/mix/#get-open-order
        https://coincatch.github.io/github.io/en/mix/#get-all-open-order
        https://coincatch.github.io/github.io/en/mix/#get-plan-order-tpsl-list

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching trigger orders(default False)
        :param str [params.isPlan]: 'plan' or 'profit_loss'('plan'(default) for trigger(plan) orders, 'profit_loss' for stop-loss and take-profit orders)
        :param str [params.productType]: 'umcbl' or 'dmcbl' - the product type of the market to fetch entries for(default 'umcbl')
        :param str [params.marginCoin]: the margin coin of the market to fetch entries for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        fetchOpenSwapOrdersr<  FrM  r  NisPlanr  r  r5   r-  z5() requires a symbol argument for swap trigger ordersr  r  r  )r  r9  r  r  handle_optionr  !privateGetApiMixV1PlanCurrentPlanr  privateGetApiMixV1OrderCurrentr$   r5   (privateGetApiMixV1OrderMarginCoinCurrentr  r  )r  r  rp  rI  r  r<  rx  planr  r  r  r  r  r  s                 r  r  z coincatch.fetch_open_swap_orders  s   & 	*
!55flJWW
F	 ;;FJPY[aclmm	644VZSWXXf((]CC[[((F&,G  ']t/*-8GM*#(,GH%B  AA$++gW]B^B^__>>t{{7TZ?[?[\\ /	c#DGcMJ$>Ax$xyyy"%{G #J++JjQQJ%(2%H DDT[[QXZ`EaEabbH~~h33  vue<<<r  c                 b   d}|                                   d}||                     |          }d}|                     ||||          \  }}||d<   |dk    r|                     ||||          S |dk    r|                     ||||          S t          | j        dz   |z   dz   |z   dz             )	a  
        fetches information on multiple canceled and closed orders made by the user

        https://coincatch.github.io/github.io/en/spot/#get-order-list
        https://coincatch.github.io/github.io/en/spot/#get-history-plan-orders
        https://coincatch.github.io/github.io/en/mix/#get-history-orders
        https://coincatch.github.io/github.io/en/mix/#get-producttype-history-orders
        https://coincatch.github.io/github.io/en/mix/#get-history-plan-orders-tpsl

        :param str symbol: *is mandatory* unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for
        :param boolean [params.trigger]: True if fetching trigger orders(default False)
        :param str [params.isPlan]: *swap only* 'plan' or 'profit_loss'('plan'(default) for trigger(plan) orders, 'profit_loss' for stop-loss and take-profit orders)
        :param str [params.type]: 'spot' or 'swap' - the type of the market to fetch entries for(default 'spot')
        :param str [params.productType]: *swap only* 'umcbl' or 'dmcbl' - the product type of the market to fetch entries for(default 'umcbl')
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        rg   NrB   r<  rD   r-  r6  r.  )r  r  r9  %fetch_canceled_and_closed_spot_orders%fetch_canceled_and_closed_swap_ordersr*   r5   r  s           r   fetch_canceled_and_closed_ordersz*coincatch.fetch_canceled_and_closed_orders  s    * 4
[[((F
!??
FTZ\fgg
F)|==feUTZ[[[6!!==feUTZ[[[tw}z9<VVYccfxxyyyr  c                    d}|                      |d|          \  }}|t          | j        dz   |z   dz             d}|                                  |                     |          }d|d         i}|}	d	}
|                     ||d
d|
          \  }
}d}|
rd}|                     ||d|          \  }}|}d}|                                 }|
|||z
  }|}n|||z
  }n||z   }||d<   ||d<   |	|}	|	|d<   |                     | 	                    ||                    }| 
                    |di           }|                     |dg           }nd|||d<   |}	|	|	|d<   |                     | 	                    ||                    }t          j        |          }|                     |dg           }|                     ||||          S )a  
 @ignore
        fetches information on multiple canceled and closed orders made by the user on spot markets

        https://coincatch.github.io/github.io/en/spot/#get-order-history
        https://coincatch.github.io/github.io/en/spot/#get-history-plan-orders

        :param str symbol: *is mandatory* unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: *for trigger orders only* the latest time in ms to fetch orders for
        :param boolean [params.trigger]: True if fetching trigger orders(default False)
        :param str [params.lastEndId]: *for trigger orders only* the last order id to fetch entries after
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
         fetchCanceledAndClosedSpotOrdersr<  Nr-  .() requires a symbol argument for spot marketsrH  r  r5   FrM  r  rr      X rw  rx  r  r  r  rt  rI  )r9  r$   r5   r  r  r  r  r|  #privatePostApiSpotV1PlanHistoryPlanr  r  r   privatePostApiSpotV1TradeHistoryr  r  r  )r  r  rp  rI  r  r<  r  r  r  r  rx  r  rr  requestSinceintervalnowr  r  parsedResponses                      r  r  z/coincatch.fetch_canceled_and_closed_spot_orders  s4   " 8
!55flJWW
F>#DGcMJ$>Aq$qrrrV$$fTl
 	 ;;FJPY[aclmm	6 g	@E 99&*gW\]]ME6 L/H##%%CL$8"X~"$x/(#/GK !&GI#'".GJ??GU[@\@\]]H< >>(FB77D^^D+r::FF #( ''#/ <<T[[RX=Y=YZZHX "Z11N^^NFB??F  >>>r  c                 
   d}|                      |d|          \  }}|}d}|                     ||d|          \  }}|                                 }d}	|
|||	z
  }|}n|||	z
  }n||	z   }||d}
|||
d<   d}| |                     |          }|d         |
d	<   |                     |d
          }d}|                     ||dd|          \  }}d}|                     ||d|          \  }}d}d}|s|O|||
d<   |||
d
<   |                     |                     |
|                    }|                     |dg           }n|J|                     |          }|d         |
d	<   | 	                    |                     |
|                    }n2|d}||
d
<   | 
                    |                     |
|                    }|                     |di           }|                     |dg           }|                     ||          S )a  
 @ignore
        fetches information on multiple canceled and closed orders made by the user on swap markets

        https://coincatch.github.io/github.io/en/mix/#get-history-orders
        https://coincatch.github.io/github.io/en/mix/#get-producttype-history-orders
        https://coincatch.github.io/github.io/en/mix/#get-history-plan-orders-tpsl

        :param str [symbol]: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for
        :param boolean [params.trigger]: True if fetching trigger orders(default False)
        :param str [params.isPlan]: *swap only* 'plan' or 'profit_loss'('plan'(default) for trigger(plan) orders, 'profit_loss' for stop-loss and take-profit orders)
        :param str [params.productType]: *swap only* 'umcbl' or 'dmcbl' - the product type of the market to fetch entries for(default 'umcbl')
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
         fetchCanceledAndClosedSwapOrdersr<  Nrr  r  )rw  rx  r  r5   r  r  FrM  r  r  r  r  r  )r9  r  r|  r  r  r  !privateGetApiMixV1PlanHistoryPlanr  r  privateGetApiMixV1OrderHistory)privateGetApiMixV1OrderHistoryProductTyper  r  )r  r  rp  rI  r  r<  r  rr  r  r  r  r  r  rx  r  r  r  r  s                     r  r  z/coincatch.fetch_canceled_and_closed_swap_ordersF  s   & 8
!55flJWW
F55fj'SXYYv!! ,M 4>LEE 8+LLH$E%
 
 "'GJ[[((F &tGH((]CC	 ;;FJPY[aclmm	644VZSWXXf ]	;4+$(!&)4&==dkk'SY>Z>Z[[HH ^^Hfb99FF!V,,$*4L!>>t{{7TZ?[?[\\&")K)4&II$++V]_eJfJfggR >>(FB77D^^D+r::F  000r  c                 N   d}|t          | j        dz   |z   dz             |                                  |                     |          }i }d}|                     |d          \  }}||t          | j        dz   |z   dz             |||d<   n||d<   |d	         }d
}	|                     ||dd|	          \  }	}d}
|	r|dk    r|d         |d<   |dk    rV|	r*|                     |                     ||                    }
n|                     |                     ||                    }
n|dk    rd}| 	                    ||d|          \  }}|d         |d<   |	s|N|t          | j        dz   |z   dz             ||d<   | 
                    |                     ||                    }
nM|                     |                     ||                    }
n#t          | j        dz   |z   dz   |z   dz             |                     |
di           }|                     ||          S )a  
        cancels an open order

        https://coincatch.github.io/github.io/en/spot/#cancel-order-v2
        https://coincatch.github.io/github.io/en/spot/#cancel-plan-order
        https://coincatch.github.io/github.io/en/mix/#cancel-order
        https://coincatch.github.io/github.io/en/mix/#cancel-plan-order-tpsl

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.clientOrderId]: a unique id for the order that can be used alternative for the id
        :param bool [params.trigger]: True for canceling a trigger order(default False)
        :param bool [params.stop]: *swap only* an alternative for trigger param
        :param str [params.planType]: *swap trigger only* the type of the plan order to cancel: 'profit_plan' - profit order, 'loss_plan' - loss order, 'normal_plan' - plan order, 'pos_profit' - position profit, 'pos_loss' - position loss, 'moving_plan' - Trailing TP/SL, 'track_plan' - Trailing Stop
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        rJ   Nr-  () requires a symbol argumentr  z5() requires an id argument or clientOrderId parameterr  r  r  FrM  r  rB   r5   r  rD   rt  r  r    () requires a planType parameter for swap trigger orders("profit_plan" - profit order, "loss_plan" - loss order, "normal_plan" - plan order, "pos_profit" - position profit, "pos_loss" - position loss, "moving_plan" - Trailing TP/SL, "track_plan" - Trailing Stop)r6  r.  r  )r$   r5   r  r  r9  r  "privatePostApiSpotV1PlanCancelPlanr  &privatePostApiSpotV1TradeCancelOrderV2r  !privatePostApiMixV1PlanCancelPlan#privatePostApiMixV1OrderCancelOrderr*   r  r.  )r  r5   r  r  r<  r  r  r  rO  rM  r  rt  r  s                r  cancel_orderzcoincatch.cancel_order  s   $ #
>#DGcMJ$>A`$`aaaV$$! $ 8 8 Q QvJ]2#DGcMJ$>Ax$xyyy$#0GK  !#GIF^
99&*iY_ahii 	-:// &tGH eBB4;;wX^C_C_``FFt{{SZ\bGcGcdd6!! H#<<VZQ[]effHf$*:$6GL! bX1#+DGcMJ,F  JR  -R  S  S  S&.
#AA$++gW]B^B^__CCDKKPWY_D`D`aatw}z9<VVYccfxxyyy~~h33f---r  c                 &   d}|                                   d}||                     |          }i }d}|                     ||||          \  }}d}|                     ||dd|          \  }}d}|dk    r|rd||d         g|d<   |                     |                     ||                    }|                     |d	g           }	|                     |	|          S |t          | j	        d
z   |z   dz             |d         |d<   | 
                    |                     ||                    }n|dk    rd}
||d         |d<   n|                     |d|
          }
|
|d<   d}|                     ||d|          \  }}|s|z|t          | j	        d
z   |z   dz             ||d<   |*|                     |                     ||                    }n|                     |                     ||                    }n|5|d         |d<   |                     |                     ||                    }nsd}|
dk    rd}n:|                     ||d|          \  }}|t          | j	        d
z   |z   dz             ||d<   |                     |                     ||                    }|                     |          }|                     ||          S t%          | j	        d
z   |z   dz   |z   dz             |                     |          }||d<   |gS )a  
        cancels all open orders

        https://coincatch.github.io/github.io/en/spot/#cancel-all-orders
        https://coincatch.github.io/github.io/en/spot/#batch-cancel-plan-orders
        https://coincatch.github.io/github.io/en/mix/#batch-cancel-order
        https://coincatch.github.io/github.io/en/mix/#cancel-order-by-symbol
        https://coincatch.github.io/github.io/en/mix/#cancel-plan-order-tpsl-by-symbol
        https://coincatch.github.io/github.io/en/mix/#cancel-all-trigger-order-tpsl

        :param str [symbol]: unified symbol of the market the orders were made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: 'spot' or 'swap' - the type of the market to cancel orders for(default 'spot')
        :param bool [params.trigger]: True for canceling a trigger orders(default False)
        :param str [params.productType]: *swap only(if symbol is not provided* 'umcbl' or 'dmcbl' - the product type of the market to cancel orders for(default 'umcbl')
        :param str [params.marginCoin]: *mandatory for swap non-trigger dmcb(if symbol is not provided)* the margin coin of the market to cancel orders for
        :param str [params.planType]: *swap trigger only* the type of the plan order to cancel: 'profit_plan' - profit order, 'loss_plan' - loss order, 'normal_plan' - plan order, 'pos_profit' - position profit, 'pos_loss' - position loss, 'moving_plan' - Trailing TP/SL, 'track_plan' - Trailing Stop
        :returns dict: response from the exchange
        rH   NrB   FrM  r  r5   r4  r  r-  z9() requires a symbol argument for spot non-trigger ordersr  rD   r  r  rt  r  r  r  r  z9() requires a marginCoin parameter for dmcbl product typer6  r.  r  )r  r  r9  r  'privatePostApiSpotV1PlanBatchCancelPlanr  r  r  r$   r5   *privatePostApiSpotV1TradeCancelSymbolOrderr  r  'privatePostApiMixV1PlanCancelSymbolPlan$privatePostApiMixV1PlanCancelAllPlan*privatePostApiMixV1OrderCancelSymbolOrders'privatePostApiMixV1OrderCancelAllOrders+get_result_from_batch_canceling_swap_ordersr*   
safe_order)r  r  r  r<  r  r  rO  rM  r  r  r  rt  r  r  r  s                  r  cancel_all_orderszcoincatch.cancel_all_orders  s   ( '
[[((F
!??
FTZ\fgg
F99&*iY_ahii  i%*0,GI&GGT[]cHdHdee ~~h;;((v666>+DGcMJ,F  JE  -E  F  F  F$*4L!  JJ4;;W^`fKgKghh6!!!K!$*4L!!"00]KXX)4& H#<<VZQ[]effHf fX1#+DGcMJ,F  JR  -R  S  S  S&.
#%#KKDKKX_agLhLhiiHH#HHU\^dIeIeffHH#(.z(:%JJ4;;W^`fKgKghh"&
'))!'JJ)-)F)Fvz[gis)t)t&J!)/#
0J  NI  1I  J  J  J(2%GGT[]cHdHdee EEhOOF$$VV444tw}z9<VVYccfxxyyy)) fwr  idsc                 >   d}|t          | j        dz   |z   dz             |                                  |                     |          }d|d         i}|d         }|                     |d          }|||d	<   |                     |d          }n$|t          | j        dz   |z   d
z             ||d<   d}	d}
|dk    rW|                     |                     |                    }	|                     |	di           }|                     |dg           }
ns|dk    rJ|d         |d<   | 	                    |                     ||                    }	| 
                    |	          }
n#t          | j        dz   |z   dz   |z   dz             |                     |
|          S )a  
        cancel multiple non-trigger orders

        https://coincatch.github.io/github.io/en/spot/#cancel-order-in-batch-v2-single-instruments

        :param str[] ids: order ids
        :param str symbol: *is mandatory* unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str[] [params.clientOrderIds]: client order ids
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        rK   Nr-  r  r  r5   r  clientOrderIds
clientOidsz;() requires either ids argument or clientOrderIds parameterorderIdsrB   r  r  rD   r  r  r6  r.  )r$   r5   r  r  r  rR  ,privatePostApiSpotV1TradeCancelBatchOrdersV2r  r  )privatePostApiMixV1OrderCancelBatchOrdersr  r*   r  )r  r  r  r  r<  r  r  rO  r  r  r  r  s               r  cancel_orderszcoincatch.cancel_orders  s    $
>#DGcMJ$>A`$`aaaV$$fTl
 F^
0@AA%$2GL!YYv'788FF[#DGcMJ$>A~$~"%GJHHU\I]I]^^H0 >>(FB77D^^D,;;FF6!!$*:$6GL!EEdkkRY[aFbFbccH EEhOOFFtw}z9<VVYccfxxyyy  000r  c                     |                      |di           }g }|                     |dg           }t          dt          |                    D ]#}||         }d|i}|                    |           $|S )Nr  	order_idsr   r  )r  
safe_valuer  r  r  )r  r  r  r  r  r  r  
resultItems           r  r  z5coincatch.get_result_from_batch_canceling_swap_orders  s    ~~h33??4b99q#h--(( 	& 	&AqkG7J MM*%%%%r  c                 d   |                      |d          }|                      |d          }|                     |||          }|                     |d          }|                     |                     |dd                    }|                     |                      |d                    }||}|                      |d          }|                     |                     |d                    }	|                     |d	d
          }
|                      |d          d u}|dk    o|	dk    }|d         r|r|sd }
|                     |dd          }|                      |d          }d }d }d }||                     |          }nA|r|                     |          nd }t          j
        |                      |d                    }|                     |                     |d                    }d }||dk    }|                     |                      |d                    }|                     |                      |d                    }|                     |                     |dd                    }|                      |d          }|dk    r|}n|dk    r|}|                     i d|                      |d          d|                     |dd          d|                     |          d |d!d d"|                     |d#          d|                     |          d|d         d$|d|d|	d|d%|r|n|                      |d&          d'|
d(|                     |d)d*          d+d d||||                     |d,d-          d ||d.||                     |d/          ||d0	|          S )1Nr  r  r  rS  r5  priceAvgr  r  r2  r  r8  r  r#  rB   r  state	feeDetailr  r?  r6  r9  rm  presetTakeLossPricert  rv  ru  r5   r  r  r  rC  r@  lastTradeTimestamplastUpdateTimestampuTimer  r[  r  r  filledr  	filledQty	remainingr  filledAmount)r  r   r_  )	r=  r<  r   tradesr  r   r_  rL  r  )r  rc  r  	omit_zerord  r  safe_string_lowerparse_fee_detail_stringr  r0   r  parse_order_time_in_forcer  rf  parse_order_statusr  )r  r  r  r  r  r@  rS  r  r  r  r  rx  r?  r  feeDetailStringr   r  r  r?  rL  r9  r=  r<  rt  s                           r  r.  zcoincatch.parse_order  sp   X ##E844%%e\::
((6:FF%%eW55	t11%.QQRR>>$"2"25*"E"EFF=E{33$$T%;%;E6%J%JKK##E:v>>$$UM::$F	x'<dem6N 	 	y 	F##E8W==**5+>>&//@@DDAKU$11*===QUK()9)9%)G)GHHG44T5K5KES`5a5abb""d*H~~d&6&6un&M&MNN..)9)9%AX)Y)YZZt'9'9%AXZo'p'pqq##E:66{""(MM&&*O  
$""5)44 
T//TT 
 Y// 
 	 

 !$ 
 "4#4#4UG#D#D 
 d--f55 
 fX& 
 D 
 ; 
 D 
 U 
 8Uxx1A1A%1U1U 
 f 
 d((LL 
  ! 
" L# 
$  /*&&u.?PP'  ..== ; 
  
  
< =  	r  r  c           
      H    dddddddddd	}|                      |||          S )NrS  closedcanceled)	not_triggerinitnewpartially_filled	full_fillr  cancelr  	cancelledr  )r  r  satusess      r  r  zcoincatch.parse_order_status  sC    ! &! "#

 

 888r  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}|                      |||          S )Nr#  r`  r[  r\  r]  r^  reduce_close_longreduce_close_shortoffset_close_longoffset_close_shortburst_close_longburst_close_shortdelivery_close_longdelivery_close_shortrY  rZ  r  )r  r  sidess      r  r  zcoincatch.parse_order_side  s    
5
F
 
 &	

 &
 5
  
 !%
  
 !%
 
  
 "6
 #E
 %
  6!
$ tT222r  c                 >    ddddd}|                      |||          S )Nr  r6  r4  r5  )r  rI  r  r  r  )r  r?  timeInForcess      r  r  z#coincatch.parse_order_time_in_force  s4    	
 
 k;GGGr  r  c                    g }|                      |          }|rt          |                                          }t          dt	          |                    D ]}|                     ||          }|| j        v rl|                     |          }|                     ||i           }t          j
        |                     |d                    }	|                    ||	d           |S )Nr   totalFee)r  r  )
parse_jsonlistkeysr  r  r  currencies_by_idr  r  r0   r  r  )
r  r  r  r  r  r  r  r  feeEntryr  s
             r  r  z!coincatch.parse_fee_detail_string  s    OOO44	 		(())D1c$ii(( 	 	!--dA66
!666#66zBBH#~~iRHHH$/0@0@:0V0VWWFMM$,"(# #    r  c                    d}|                      |d|          \  }}|                                  d}d}i }|)|                     |          }|d         }|d         |d<   n>|                     ||||          \  }}|dk    rt	          | j        dz   |z   d	z             d}	|}
|dk    r7d
}||}
|
|
|d<   |                     |                     ||                    }	n|dk    r|||d<   nd|d<   d}|                     ||d          \  }}|||d<   n| 	                                |d<   |*| 
                    |                     ||                    }	nkd}|                     |d|          }||d<   |                     |                     ||                    }	n#t          | j        dz   |z   dz   |z   dz             |                     |	dg           }|                     ||||          S )a  
        fetch all trades made by the user

        https://coincatch.github.io/github.io/en/spot/#get-transaction-details
        https://coincatch.github.io/github.io/en/mix/#get-order-fill-detail
        https://coincatch.github.io/github.io/en/mix/#get-producttype-order-fill-detail

        :param str symbol: *is mandatory* unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: *swap markets only* the latest time in ms to fetch trades for, only supports the last 30 days timeframe
        :param str [params.lastEndId]: *swap markets only* query the data after self tradeId
        :returns Trade[]: a list of `trade structures <https://github.com/ccxt/ccxt/wiki/Manual#trade-structure>`
        r   r<  NrB   r  r5   r  r-  r  rH  rI  rD   rw  r   rr  rx  r  r  r6  r.  r  )r9  r  r  r9  r$   r5   privatePostApiSpotV1TradeFillsr  r  r|  privateGetApiMixV1OrderFillsr  privateGetApiMixV1OrderAllFillsr*   r  r  )r  r  rp  rI  r  r<  r  rO  r  r  r  maxSpotLimitrr  r  r  s                  r  fetch_my_tradeszcoincatch.fetch_my_trades  s`     %
!55flJWW
F
[[((FJ &tGH!%!C!CJPVX^`j!k!kJV##'#
(BEu(uvvvL +'#/ 4 ::4;;wPV;W;WXXHH6!! &+{##&'{#E 99&*gVVME6 %*	""%)%6%6%8%8	"!4  <<T[[RX=Y=YZZ%"00]KXX)4&6  ??GU[@\@\]]tw}z9<VVYccfxxyyy~~h33  vue<<<r  c           	          d}|t          | j        dz   |z   dz             ||d}|                     ||||                     ||                    S )a%  
        fetch all the trades made from a single order

        https://coincatch.github.io/github.io/en/spot/#get-transaction-details

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        r   Nr-  r  )r  r<  )r$   r5   r"  r  )r  r5   r  rp  rI  r  r<  r  s           r  fetch_order_tradeszcoincatch.fetch_order_trades~  si     (
>#DGcMJ$>A`$`aaa$
 
 ##FE5$++gv:V:VWWWr  c                 "   |                                   |                     |          }|d         |d         d}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches the margin mode of the trading pair

        https://coincatch.github.io/github.io/en/mix/#get-single-account

        :param str symbol: unified symbol of the market to fetch the margin mode for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin mode structure <https://docs.ccxt.com/?id=margin-mode-structure>`
        r5   r  r  r  r  )r  r   privateGetApiMixV1AccountAccountr  r  parse_margin_moder2  s          r  fetch_margin_modezcoincatch.fetch_margin_mode  s     	V$$Tl ,
 
 88Wf9U9UVV: ~~h33%%dF333r  r8  c                     |                      |d          }||                     d |          |                     |          dS )Nr8  )r  r  r8  )r  r  parse_margin_mode_type)r  r8  r  
marginTypes       r  r(  zcoincatch.parse_margin_mode  sM    ++JEE
&&tV4455jAA
 
 	
r  c                 :    ddd}|                      |||          S )Ncrossisolated)crossedfixedr  r  r  typess      r  r+  z coincatch.parse_margin_mode_type  s.    
 
 tT222r  c                    |t          | j        dz             |                                }|                                  |                     |          }|d         dk    r#t          | j        dz   |d         z   dz             |d         |d         |                     |          d	}|                     |                     ||                    }|S )
ar  
        set margin mode to 'cross' or 'isolated'

        https://coincatch.github.io/github.io/en/mix/#change-margin-mode

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentr  rD   z& setMarginMode() is not supported for r.  r5   r  )r  r  r8  )	r$   r5   re  r  r  r*   encode_margin_mode_type'privatePostApiMixV1AccountSetMarginModer  )r  r8  r  r  r  r  r  s          r  set_margin_modezcoincatch.set_margin_mode  s     >#DG.[$[\\\%%''
V$$&>V##tw)QQTZ[aTbbewwxxxTl ,66zBB
 

 ??GU[@\@\]]  r  c                 :    ddd}|                      |||          S )Nr0  r1  )r.  r/  r  r2  s      r  r5  z!coincatch.encode_margin_mode_type  s.    
 
 tT222r  c                    |t          | j        dz             |                                  |                     |          }|d         dk    r#t	          | j        dz   |d         z   dz             |d         |d         d	}|                     |                     ||                    }|                     |d
i           }|                     |d          }||dk    dS )a  
        fetchs the position mode, hedged or one way

        https://coincatch.github.io/github.io/en/mix/#get-single-account

        :param str symbol: unified symbol of the market to fetch entry for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        Nz/ fetchPositionMode() requires a symbol argumentr  rD   z* fetchPositionMode() is not supported for r.  r5   r  r&  r  holdModedouble_hold)r  r@  )	r$   r5   r  r  r*   r'  r  r  r  )r  r  r  r  r  r  r  r:  s           r  fetch_position_modezcoincatch.fetch_position_mode  s     >#DG._$_```V$$&>V##tw)UUX^_eXffi{{|||Tl ,
 
 88Wf9U9UVV~~h33##D*55-/
 
 	
r  r@  c                    d}d}|                                   |                     |d          }||y|                     |          }|d         dk    r#t          | j        dz   |d         z   dz             |d	         }|                    d
          }	|                     |	d|          }n|                     |d|          }||rdndd}
|                     | 	                    |
|                    S )a  
        set hedged to True or False for a market

        https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Set%20Position%20Mode

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: unified symbol of the market to fetch entry for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.productType]: 'umcbl' or 'dmcbl'(default 'umcbl' if symbol is not provided)
        :returns dict: response from the exchange
        r   r  r  Nr  rD   z( setPositionMode() is not supported for r.  r5   rA  r   r;  single_hold)r  r:  )
r  r  r  r*   r5   r  r  r  )privatePostApiMixV1AccountSetPositionModer  )r  r@  r  r  r<  defaultProductTyper  r  r  r  r  s              r  set_position_modezcoincatch.set_position_mode  s%    '
$&&v}==!V,,&>V++&tw1['[^dek^l'l  pB  (B  C  C  C!$< s++"44UA{KK"00]L^__&)/B]
 
 ==dkk'SY>Z>Z[[[r  c                    |                                   |                     |          }|d         dk    r#t          | j        dz   |d         z   dz             |d         |d         d}|                     |                     ||                    }|                     |di           }|                     ||          S )	ac  
        fetch the set leverage for a market

        https://coincatch.github.io/github.io/en/mix/#get-single-account

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        r  rD   z& fetchLeverage() is not supported for r.  r5   r  r&  r  )r  r  r*   r5   r'  r  r  parse_leverager2  s          r  fetch_leveragezcoincatch.fetch_leverageJ  s     	V$$&>V##tw)QQTZ[aTbbewwxxxTl ,
 
 88Wf9U9UVV~~h33""4000r  rB  c                    d}|t          | j        dz   |z   dz             |                                  |                     |          }|d         dk    r)t	          | j        dz   |z   dz   |d         z   dz             |d	         |d
         |d}d}|                     ||d          \  }}|||d<   |                     |                     ||                    }|                     |di           }	| 	                    |	|          S )a  
        set the level of leverage for a market

        https://hashkeyglobal-apidoc.readme.io/reference/change-futures-leverage-trade

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.side]: *for isolated margin mode with hedged position mode only* 'long' or 'short'
        :returns dict: response from the exchange
        r   Nr-  r  r  rD   r6  r.  r5   r  )r  r  rB  r  rq  r  )
r$   r5   r  r  r*   r  %privatePostApiMixV1AccountSetLeverager  r  rC  )
r  rB  r  r  r<  r  r  r  r  r  s
             r  set_leveragezcoincatch.set_leverage`  s/    #
>#DGcMJ$>A`$`aaaV$$&>V##tw}z9<VVY_`fYggj||}}}Tl , 
 

 44VZPPf"&GJ==dkk'SY>Z>Z[[  ~~h33""4000r  c                 d   |                      |d          }|                     ||          }|                     |                     |d                    }|                     |dd          }|                     |dd          }|                     |d          }|dk    r|}|}||d         |||d	S )
Nr  r8  fixedLongLeveragelongLeveragefixedShortLeverageshortLeveragecrossMarginLeverager.  )r  r  r8  rJ  rL  )r  rc  r+  r  rb  r  )r  rB  r  r  r8  rJ  rL  rM  s           r  rC  zcoincatch.parse_leverage  s    F ##Hh77((6::001G1GR^1_1_``
**85H.YY++H6JO\\"//:OPP  .L/MX&$(*
 
 	
r  c                    d}|                      |d|          \  }}|                                  |                     |          }|d         dk    r)t          | j        dz   |z   dz   |d         z   dz             |                     ||          }|d         |d	         |d
}d }|                     ||d          \  }}|||d<   |                     |                     ||                    }	|dk    rt          j
        |          }|                     |                     |	|          |                     |          |d          S )NmodifyMarginHelperr<  r  rD   r-  r6  r.  r5   r  )r  r  r  r  rq  reduce)r  r  )r9  r  r  r*   r5   rb  r  #privatePostApiMixV1AccountSetMarginr  r0   r  parse_margin_modificationr  )
r  r  r  r  r  r<  r  r  r  r  s
             r  modify_margin_helperzcoincatch.modify_margin_helper  sr   )
!55flJWW
FV$$&>V##tw}z9<VVY_`fYggj||}}}))&&99Tl ,
 

 44VZPPf"&GJ;;DKKQW<X<XYY
 8'//F{{499(FKK''//N
 N
   	r  r  c                 t    |                      |d          }|dk    rdnd}||d         d d d d |d         |d d d
S )Nr  r  r  failedr  r  )
r  r  r  r8  r  r  r  r  r@  rC  r  )r  r  r  r  r  s        r  rR  z#coincatch.parse_margin_modification  sb     tU++**X&7O
 
 	
r  c                 >    d|d<   |                      || d|          S )a  
        remove margin from a position

        https://coincatch.github.io/github.io/en/mix/#change-margin

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.side]: *for isolated margin mode with hedged position mode only* 'long' or 'short'
        :returns dict: a `margin structure <https://docs.ccxt.com/?id=margin-structure>`
        r   r<  rP  rS  r  r  r  r  s       r  reduce_marginzcoincatch.reduce_margin  s*      .|((&(FKKKr  c                 <    d|d<   |                      ||d|          S )a  
        add margin

        https://coincatch.github.io/github.io/en/mix/#change-margin

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.side]: *for isolated margin mode with hedged position mode only* 'long' or 'short'
        :returns dict: a `margin structure <https://docs.ccxt.com/?id=margin-structure>`
        rG   r<  addrW  rX  s       r  
add_marginzcoincatch.add_margin  s(      +|((GGGr  c                 2   d}d}|                      ||d          \  }}|                     ||          }t          |          }|dk    r8t          dt          |                    D ]}||         }|d         |k    r|c S |                     |di           S )a  
        fetch data on a single open contract trade position

        https://coincatch.github.io/github.io/en/mix/#get-symbol-position

        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
 @param {str}  [params.side] 'long' or 'short' *for non-hedged position mode only* (default 'long')
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        r   ro  r  r   r   )r  fetch_positions_for_symbolr  r  r  )	r  r  r  r<  r  	positionsarrayLengthr  positions	            r  fetch_positionzcoincatch.fetch_position  s     %
44VZPPf33FFCC	)nn??1c)nn-- $ $$Q<F#t++#OOO ,~~iB///r  c                 $   |                                   |                     |          }|d         |d         d}|                     |                     ||                    }|                     |dg           }|                     ||g          S )a  
        fetch open positions for a single market

        https://coincatch.github.io/github.io/en/mix/#get-symbol-position

        fetch all open positions for specific symbol
        :param str symbol: unified market symbol
        :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>`
        r5   r  r&  r  )r  r  *privateGetApiMixV1PositionSinglePositionV2r  r  parse_positionsr2  s          r  r^  z$coincatch.fetch_positions_for_symbol'  s     	V$$Tl ,
 
 BB4;;wX^C_C_``@ ~~h33##D6(333r  c                 F   d}|                                   d}||                     |          }g }t          dt          |                    D ]J}||         }|                    d          }	|                     |	d          }
|                    |
           K|                     |          }t          |          }|dk    rt          | j	        dz   |z   dz             |d         }n| 
                    ||d	|          \  }}d	|i}|d
k    r>d}| 
                    ||d          \  }}| |                     |          }|d         |d<   |                     |                     ||                    }|                     |dg           }|                     ||          S )av  
        fetch all open positions

        https://coincatch.github.io/github.io/en/mix/#get-all-position

        :param str[] [symbols]: list of unified market symbols(all symbols must belong to the same product type)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.productType]: 'umcbl' or 'dmcbl'(default 'umcbl' if symbols are not provided)
        :param str [params.marginCoin]: the settle currency of the positions, needs to match the productType
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        r   r  Nr   rA  r   r-  zJ() requires all symbols to belong to the same product type(umcbl or dmcbl)r  r  r  r5   r  )r  
market_idsr  r  r  r  r  r  r&   r5   r  r  'privateGetApiMixV1PositionAllPositionV2r  r  re  )r  r4  r  r<  r  	marketIdsproductTypesr  r  r  marketProductTyper`  r  r  r  r  r  s                    r  fetch_positionszcoincatch.fetch_positions[  s    &
00IL1c)nn-- 7 7$Q< s++$($4$4UA$>$>!##$56666;;|44Ll++KQ#
 :  >J  !J  K  K  K*1o"&"?"?
Tacn"o"oK;
 '!!"J!%!>!>vzS_!`!`J%==44(0%??GU[@\@\]]B ~~h33##D'222r  ra  c                 j   |                      |d          }|                      |d          }|                     |||          }|                     |d          }|                      |d          }d }|                      |d          }|dk    rd}n|dk    r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 |                     t          j
        |
d!                    |	d |                     |d"          |                     |d#          d d d d |d$          S )%Nr  r  r  r8  r:  r;  Tr>  FrC   keepMarginRater5   r@  rC  	contractsr  r  r  rq  notionalrB  unrealizedPnlunrealizedPLrealizedPnlachievedProfits
collateral
entryPriceaverageOpenPricera  marketPriceliquidationPricer@  rZ  marginRatior  )maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentagerz  r  	lastPricer<  r=  r   r  )r  rc  r  r  safe_positionrf  r  r+  r  r0   r  )r  ra  r  r  r  r@  r8  isHedgedr:  rC   rn  s              r  parse_positionzcoincatch.parse_position  s   4 ##Hh77##Hl;;((68DD%%h88	%%h==
##Hj99}$$HH&&H!!(H55))(4DEE!! #
fX&#
$#
 #
 Y//	#

 ))(G<<#
 D#
 D**8Z@@#
 #
 ))(J??#
 T--hGG#
 4++H6GHH#
 $#
 $**85GHH#
 ))(MBB#
  0 0;M N N#
  $55jAA!#
" h##
$ "&+/+<+<W=OP^`e=f=f+g+g#'+++HmDD#'#4#4Xw#G#G!#9#
 #
 #
   	r  r  r  c                 "   	 |                      ||          }nv# t          $ ri}|                     | j        |g           }|	|d         }n8t	          dt          |                    D ]}||         }|d         |k    r|} nY d }~nd }~ww xY w|S )Nr   r  )safe_market	Exceptionr  markets_by_idr  r  )r  r  r  r  emarketsWithCurrentIdr  marketWithCurrentIds           r  rc  zcoincatch.safe_market_custom  s    	%%h77FF 	 	 	 $(>>$2DhPR#S#S -a0q#&:";";<<  A*>q*A'*:6(BB!4 C	 s    
BABBc                    d}|                                   i }d}|                     |d||          \  }}d}d}	||                     |          }	|dk    rf|	|                     |	d          }
|
|d<   |||d<   |                     |                     ||                    }|                     |dg           }n|dk    r|||d	<   nd
|d	<   d}|                     ||d          \  }}|||d<   n|                                 |d<   |||d<   d}|| 	                    |d|          }n|dk    rd}nd}| 
                    |d|          \  }}||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }n t          | j        dz   |z   dz   |z             |                     ||	||          S )a  
        fetch the history of changes, actions done by the user or operations that altered balance of the user

        https://coincatch.github.io/github.io/en/spot/#get-bills
        https://coincatch.github.io/github.io/en/mix/#get-business-account-bill

        :param str [code]: unified currency code
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entrys to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: *swap only* the latest time in ms to fetch entries for
        :param str [params.type]: 'spot' or 'swap'(default 'spot')
        :param str [params.after]: *spot only* billId, return the data less than self billId
        :param str [params.before]: *spot only* billId, return the data greater than or equals to self billId
        :param str [params.groupType]: *spot only*
        :param str [params.bizType]: *spot only*
        :param str [params.productType]: *swap only* 'umcbl' or 'dmcbl'(default 'umcbl' or 'dmcbl' if code is provided and code is not equal to 'USDT')
        :param str [params.business]: *swap only*
        :param str [params.lastEndId]: *swap only*
        :param bool [params.next]: *swap only*
        :returns dict: a `ledger structure <https://docs.ccxt.com/?id=ledger-entry-structure>`
        ry   rB   Nr  r  rI  r  rD   rw  r   rr  rx  r  r  r  r  r  r  r-  z () does not support market type )r  r9  r  r   privatePostApiSpotV1AccountBillsr  r  r  r|  r  r9  ,privateGetApiMixV1AccountAccountBusinessBillr  r*   r5   parse_ledger)r  r  rp  rI  r  r<  r  rO  r  r  r  r  rr  r  r  s                  r  fetch_ledgerzcoincatch.fetch_ledger  sR   . #

!??
DRXZdee
F}}T**H# ,,X{CC	$-! #( <<T[[RX=Y=YZZH, ^^Hfb99FF6!! ',$$'($E 99&*gVVME6 %*	""%)%6%6%8%8	" &+
#!K|"00]KXX%%"&":":6=R]"^"^K%0GM"HHU\^dIeIeffHb >>(FB77D^^D(B77FFtw}z9<^^akklll  5%@@@r  itemc                 L   |                      |d          }|                     |dd          }d }|                     |d          }|                     |||          }|                     |dd          }d}t	          j        |d          rd	}t	          j        |d
          }t	          j        |                     |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  r  r  r  r2  r  inr  outz-1r  r   feeCoinr  r5   billIdr  r@  rC  r  	directionreferenceIdreferenceAccountr  bizTypebusinessr  ru  rt  balancer  r  )r  rd  r  rc  r0   	string_ltr  r  safe_ledger_entryrf  parse_ledger_entry_typer  r  )
r  r  r  r@  r  r  r  rF  r  r  s
             r  parse_ledger_entryzcoincatch.parse_ledger_entry  s.   8 %%dG44	%%dJEE##D(33((68DD))$
HEE	\3// 	BI"-lDAAL&t'9'9$v'N'NOO((y99
 
 %% '
$$$T8T::'
D'
 '
 Y//	'

 t'
 '
 4'
 '
 D001I1I$PY[e1f1fgg'
 //(CC'
 fX&'
 l'
 d'
 T%%dI66'
 d'
  3!'
" #  	r  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dd}|                      |||          S )Nr  r   
withdrawalr#  r  r`  zdeduction of handling feer  ztransfer-inr   ztransfer inztransfer outzrebate rewardsrebatezairdrop rewardszusdt contract rewardszmix contract rewardszsystem lockz	user lockr[  r\  r]  )r^  trans_from_exchangetrans_to_exchangecontract_settle_feeburst_long_loss_queryburst_short_loss_queryr  r2  s      r  r  z!coincatch.parse_ledger_entry_type  s   
y

 7
 G	

 (
 :
 :
 J
 h
 x
 $X
 #H
 =
 
 
  '!
" '#
$ ##-!+#(%,&-/
 
 
2 tT222r  reasonr   r  headersbodyc
                    |sd S |                      |d          }
| j        dz   |z   }|                      |d          }|
dk    p|
d u }|                    d          dk    r|                     |di           }|                     |dd	g           }|                     |          sEd
}|                     |di           }|                      |d          }|                      |d          }
|sS|                     | j        d         ||           |                     | j        d         |
|           t          |          d S )Nr  r-  r  r  batchr   r  failure
fail_infosF	errorCodeerrorMsgr  r  )
r  r5   r'  r  r  is_emptythrow_exactly_matched_exceptionrX  throw_broadly_matched_exceptionr!   )r  r  r  r   r  r  r  r  requestHeadersrequestBodymessagefeedbackmessageCoder  r  r  
firstEntrys                    r  handle_errorszcoincatch.handle_errors  sU    	4""8U337S=4'&&x88i'=W_88G!!>>(FB77D&&tYbIIG==)) C!^^GQ;;
"..z;GG**:zBB 	*001I;X`aaa001I7T\]]])))tr  r   GETc           
      |   d|z   }|dk    r0|                      |          }t          |          dk    r|d|z   z  }|dk    r|                                  |                     |                                           }	d}
|dk    r|                     |          }|}
|	|z   |z   |
z   }|                     |                     |          |                     | j                  t          j
        d          }| j        ||	| j        d|                     | j        d	d
          d}| j        d         |         |z   }||||dS )Nr  r  r   ?r   r   base64zapplication/jsonr*  r   )z
ACCESS-KEYzACCESS-SIGNzACCESS-TIMESTAMPzACCESS-PASSPHRASEzContent-TypezX-CHANNEL-API-CODEr   )r   r  r  r  )	urlencoder  check_required_credentialsr<  r|  r  hmacencoder   hashlibsha256r   r   r  r   r   )r  r  r   r  r  r  r  endpointqueryr@  r  payload	signaturer   s                 r  signzcoincatch.sign  sM   :U??NN6**E5zzQC%K')++-----d.?.?.A.ABBIFyy((&(83f<G		$++g"6"6DK8P8PRYR`bjkkI"k($-%)] 2&*&6&6t|ZQX&Y&Y G is#h.fdwOOOr  r  )NN)__name__
__module____qualname__r   r  r  r   r  r   r  r   r  r	   r  r    r   r  dictr$  r  strr   r3  r   r=  r1  r   rn  r  r  r  r   r  r  r   r  r  objectr  r   r  r   r  r  floatr   r   r  r
   r  r  r   r  r  r   r  r%  r   r   r   r   r$  r'  r+  r;  r   r:  r(  rQ  rc  r  rK  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r.  r  r  r  r  r"  r$  r   r)  r(  r+  r7  r5  r<  boolrA  r   rD  r  rG  rC  r   rS  rR  rY  r\  r   rb  r^  rl  r  rc  r  r   r  r  r  r  __classcell__)r  s   @r  r2   r2      s       o# o o o o o ob MO 	 	 	 	 !# 3 3s 3 3 3 3( ') e eZ e e e eN <@ I I I I I I0 0 0 0 0 0d $& G+ G+$v, G+ G+ G+ G+RQ4 QF Q Q Q Qf  , 02 N/ N/3 N/f N/ N/ N/ N/` 04B \1 \1W \17 \1 \1 \1 \1|K K6 KV K K K KZ :>b 1N 1Ns 1N3 1NY 1N 1N 1N 1Nf 9=4^bkm ]~ ]~# ]~# ]~S ]~X[ ]~rvw{r| ]~ ]~ ]~ ]~~
 
 
4 
 
 
 
 6:UW K= K=3 K=s K=# K=\`af\g K= K= K= K=ZU U Uv U U U U Un 68 5 5 5K 5 5 5 5B
 
6 
 
 
 
0' 'v '3 '\_ 'jp '  DG ' ' ' ' 8<$]ajl 7@ 7@ 7@C 7@WZ 7@ 7@ 7@ 7@r $& F( F(( F( F( F( F(P0) 0) 0) 0) 0)d [] 07 07S 07% 07c 07c 07an 07 07 07 07d
 
 
 
 
 
$ 79 ( (# (^ ( ( ( (T
 
h 
R` 
 
 
 
. *.Dt\^ 9E 9E3 9Ec 9E 9Ecghsct 9E 9E 9E 9Ev -1tRV_a #E #Ec #E #EC #Efjkvfw #E #E #E #EJ KOWY *6 *6S *6% *6# *6C *6^i *6 *6 *6 *6XL
 L
x L
; L
 L
 L
 L
\ RT N N N5 N N N N( gksu w w3 wi wy wRW w`c wz w w w wB lpxz *. *. *.9 *.I *.W\ *.eh *.  @E *. *. *. *.X tx  AC @, @, @,9 @,I @,_d @,mp @,  HL @, @, @, @,D NP^brv  EI  W\   d X[ lo   B   QT    . RTkp  S $ dh     lpxz 6. 6. 6.9 6.I 6.W\ 6.eh 6.  @E 6. 6. 6. 6.p tx  AC H, H, H,9 H,I H,_d H,mp H,  HL H, H, H, H,T ^ksu A, A, A, A,F FJ  ^b  tx  AC S S# SY S^g Sqv S  @C S  X[ S  nq S  HM S S S S S S*J J J J J J @B p1 p1D$6 p1 p1 p1 p1d os{} 	~ 	~3 	~i 	~y 	~Z_ 	~hk 	~  CG 	~ 	~ 	~ 	~ `drv  @B ~ ~S ~# ~Y ~i ~Y\ ~lo ~ ~ ~ ~4 sw  @B @. @.# @.s @.) @.9 @.^c @.lo @. @. @. @.D 26b z/ z/c z/3 z/U z/ z/ z/ z/x /3TXac "z "z "z3 "zc "zhlmrhs "z "z "z "zH 48dY]fh _? _?S _? _?SV _?mqrwmx _? _? _? _?B 48dY]fh {= {=S {= {=SV {=mqrwmx {= {= {= {=z >BPTcgpr "z "zs "z# "z]` "zw{  }B  xC "z "z "z "zH CGUYhluw G? G?C G?s G?be G?  }A  BG  }H G? G? G? G?R CGUYhluw R1 R1C R1s R1be R1  }A  BG  }H R1 R1 R1 R1h 37r 9. 9.s 9.C 9. 9. 9. 9.v /32 r r r r r rh ;?r O1 O1c O1C O1 O1 O1 O1b
 
 
O O O O O Ob9 9 9 9 9 93S 3S 3 3 3 3*HS HS H H H Hs    " -1tRV_a H= H=c H= H=C H=fjkpfq H= H= H= H=T 9=4^bkm X XS X# XS XX[ Xrvw|r} X X X X, 57 .4 .4 .4: .4 .4 .4 .4`
 
D 
* 
 
 
 
33 33 3 3 3 3 >B" ' '# 's ' ' ' 'R3C 3C 3 3 3 3 15R 
 
# 
 
 
 
8 =A )\ )\ )\c )\ )\ )\ )\V 24 1 1S 1 1 1 1 1, 9=R -1 -1S -1# -1 -1 -1 -1^2
 2
t 2
V 2
x 2
 2
 2
 2
h FH  3 L^    :
 
d 
F 
N` 
 
 
 
$ @B L LC L LFX L L L L =? H H He HCU H H H H 24 0 0S 0 0 0 0 0. >@ 24 24 24DN 24 24 24 24h 26b J3 J3w J3T(^ J3 J3 J3 J3XD Dt DV D D D DL 3  QT `f    " (,$TZ\ hA hA hAC hAs hA hA hA hAT; ;t ;x ;; ; ; ; ;z3C 3C 3 3 3 38# s  c TX `c    * &eBSW P P P P P P P Pr  r2   )9ccxt.base.exchanger   ccxt.abstract.coincatchr   r  r  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr    ccxt.base.errorsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   ccxt.base.decimal_to_precisionr/   ccxt.base.preciser0   r2    r  r  <module>r     s(   ( ' ' ' ' ' / / / / / /    n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) + + + + + + . . . . . . * * * * * * ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %OPP OPP OPP OPP OPP+ OPP OPP OPP OPP OPPr  