
    !:h[                       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      Z8y)    )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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d/Z2dddi fd(e'dededee3   fd0Z4dddi fd(e'dededee3   fd1Z5di fd(ed)e,d2ede3fd3Z6dd	ede3fd4Z7i fded5e,fd6Z8di fded7e9d8e:d)e,d9e;de<fd:Z=di fded7e9d8e:d)e,d9e;de<fd;Z>di fded7e9d8e:d)e,d9e;defd<Z?i dddd=fd eded9e;d)e;d5e'd8efd>Z@i d?fd eded@eAfdAZBdi fded7e9d8e:d)e,d9e;de<fdBZCdi fded7e9d8e:d)e,d9e;defdCZDdDi fdEZEdddi fded7e9d8e:d)e,d9e;dFe;dGe;de<f fdHZFdIe'de'fdJZGi fdKeeH   fdLZIdi fded7e9d8e:d)e,d9e;defdMZJddi fdNeded7e9d8e:d)e;d9e;fdOZKdi fdNeded7e9d8e:d)e,d9e;fdPZLdi fdNede'de<fdQZMdddi fde'dededee<   fdRZNdddi fde'dededee<   fdSZOdddi fde'dededee<   fdTZPdddi fde'dededee<   fdUZQdddi fde'dededee<   fdVZRdddi fde'dededee<   fdWZSdi fdNede'fdXZTdi fde'fdYZUdi fdZee   de'fd[ZVd\ ZWdde<fd]ZXd^e'de'fd_ZYd8e'de'fd`ZZdIe'de'fdaZ[dbe'fdcZ\dddi fde'dededee   fddZ]dddi fdNede'dededee   f
deZ^i fdede_fdfZ`ddgede_fdhZad7edefdiZbdi fdgede'fdjZcd7edefdkZddi fde'fdlZedi fdmefde'fdnZgi fdedehfdoZidi fdpede'fdqZjddpededehfdrZki fdedelfdsZmddtededelfduZni fded)e,delfdvZoi fded)e,delfdwZpi fdefdxZqi fdedeer   fdyZsdi fde
deer   fdzZtdd{edefd|Zudd}e'ded~e'defdZvdddi fd(e'dedefdZwdded	edexfdZyd7edefdZzd(e{dededededefdZ|ddi ddfdZ} xZ~S )	coincatchreturnc                 l   | j                  t        t        |          i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.d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| j	                  dի      | j	                  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(ddddd
ddddd)dd*d+d,d-d.ddddddd/dddd ddddd0dddddddd1d2didd3d4d4dd5ddddd6dd7ddddd8d d d9d:id;	d<d=id=d>d dd?id9d7id@d<dAid<dAidBd d dBdCdDi dEi dFt
        dGt        dHt        dIt        dJt        dKt        dLt        dMt        dNt        dOt        dPt        dQt        dRt        dSt        dTt        dUt        dVt        i dWt        dXt        dYt        dZt        d[t        d\t        d]t        d^t        d_t        d`t        dat        dbt        dct        ddt        det        dft        dgt        i dht
        dit        djt
        dkt        dlt        dmt        dnt        dot        dpt        dqt        drt        dst        dtt        dut        dvt        dwt        i dxdyt         i      S (z  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ARBArbitrumOneOPTIMISM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AVAX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TIAr  APTONTr  ADAr  r  r  XLMr!  CROr#  r(  r)  )r   z
TRX(TRC20)r   r  r  r	  r  	CFXeSpacer  r  r  r   r"  )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 )r9  limitdaysBack	untilDayssymbolRequired)r9  triggerrB  rM  d   )r9  rJ  rN  rB  
marketTyperM  rJ    )	r   rX   rY   r   r   r   r   rj   r   extendsdefaultr?  )r;  price)rR  rX   r   forDerivatives)linearinverse)rS  rB   rU  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    H/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coincatch.pyr  zcoincatch.describe!   s   i ? A yD
+yD
KyD
 $yD
 	yD

 tyD
 yD
 4y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( $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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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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l %*%*"'$( $ #"!%#'! CbyD
V WyD
v i9: 4B<R #wy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+ 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!R9P9+: 8;+< ?=+> @?+@ =aA+B 4QC+D 5aE+F =>56:;>?:;67<=9:U+3E?eSyD
^ " $_yD
h %*&*#(!%!2!27!;!%!2!27!;
iyD
~ #59 %$&&"""$$$%" #""##""""$""""@ 26292W2 W2 W	2
 =2 
2 52 52 52 52 F2 82 H2 N2 <2  H!2" 8#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F # )%#0"% $ " *"(c2h %")#(!'"%$!& ")#0%*#(!qgyD
N $&+(,$($(%*-
 -2).+06:#'#'"&#(	( #($)$)+/27/4#(1$6 r% ',!$$*%+*.& ',#($)*/	# ',!$#'$)&**/( $()-#m9v y  ) 504%*7$  &# "#3 "#3 	 ##gWOyD
~ yD
@ 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& 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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j m7AyD
p YqyD
 y y	    c                     | j                  |d      }| j                  |dd      }| j                  |ddg       }t        |      }	|+|	|kD  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  3!!&+K6{<$#6		,*= >?M-''Kr  c                 H    | j                  |      }| j                  |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2r  c                 T   | j                  |      }| j                  |dg       }i }g }t        dt        |            D ];  }||   }| j	                  |d      }|j                  |       | j                  |      }	| j                  |d      }
i }t        dt        |
            D ]  }|
|   }| j	                  |d      }| j                  |      }||| j                  |d      dd| j                  |d	      ddd
d| j	                  |d      dk(  | j	                  |d      dk(  | j                  |d      d|d	||<    | j                  || j                  |d      |	dddddddddddddd
||d      ||	<   > | j                  | 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minrH  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_code_to_id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_currencies<  s    ::6B~~h3@ q#d)$ 6	A1gG))':>J  ,**:6D~~gx8H#%N1c(m, "1+ ,,Wg>	"55i@#* $(#3#3G=O#P#'$
 $(#3#3G=P#Q#'%	 ##//HFR $ 0 0. IV S++G]C!%#%-y)	0  77 !..wA!   $# 
  $#!	 +-9 F4L?6	n >>$,,(GHP<IDLL89r  Ncodesc                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )ah  
        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  sG     	::6B~~h3//eZHHr  currencyc                    | j                  |dg       }t        |      }|d d dd d di d}t        d|      D ]  }||   }| j                  |d      }| j                  |d      }	| j	                  ||	      }
d d d| j                  |d      ddd	|d
   |
<   |dk(  se| j                  |d      |d   d<   d|d   d<    |S )Nr  )r  r   )r  r   r  r/  r   r  r  r  Fr  r/  r   r   r  r   )r  r  r  r  network_id_to_coder  )r  r  r  r  chainsLengthr  r  r  r  currencyCoder  s              r  parse_deposit_withdraw_feez$coincatch.parse_deposit_withdraw_fee  s   , Xr26{"
 " 
 q,' 	9A1IE((8I++Hf=L11)\JK#'t<$($4$4UM$JZ_`/F:{+ q ,0,<,<UM,Rz"5)38z"<0	9 r  c                    | j                  |      }| j                  | j                  d      | j                          | j                  |dg       }i }d}| j	                  |dd|      \  }}g }d|d<   | j                  | j                  ||            }| j                  |dg       }d|d<   | j                  | j                  ||            }| j                  |dg       }g }	t        dt        |            D ]_  }
||
   }| j                  |d	g       }t        dt        |            D ]-  }||   }d	|gi}|	j                  | j                  ||             / a | j                  ||	      }| j                  ||      }| j                  |      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P!!#nnXvr:";;FNTacnoV!(88Wf9UVH NN8VR8	!(88Wf9UVL NN8VR8	q#i.) 	CAq\F!%8Lb!Q1c"456 C+A.(6( "((VS)ABC	C ''	3DE##K=!!'**r  r  c                     | j                  |d      }| j                  | j                  d      }| j                  |d      }| j                  |d      }| j                  |d      }d }d}d }	d}
d }d }d }|d u }|r;| j                  |      }| j                  |d      }| j                  |d      }|d	z  }nzd
}
| j	                  |d      |d<   | j	                  |d      |d<   | j                  |dg       }| j                  |d      }| j                  |      }	d|	z   }||k(  }||k(  }|rd}n|rd}| j                  |      }| j                  |      }|dz   |z   |z   }| j                  |d      }|r|dk(  nd }| j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }t        j                  | j                  |      |      }| 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'| j	                  |d(      d|d|d| j	                  |d      d| j	                  |d      d)| j                  |d)      d*| j                  |d*      d+| j                  |d+      d,d d-d d.d d/d d0| j                  |      | j                  |      d1d2| j	                  |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   :rV  rW  /symbolStatusnormalvolumePlace
pricePlacepriceEndStepr5   basequoter  r  subTyperC   FrE   rF   contractr  settleIdcontractSizesizeMultiplierr   r   r   expiryexpiryDatetimestrike
optionTyper  )amountrT  r  minTradeNumr  )r  rT  rC  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_marketm  sv   b ##FH5nnTYY	:~~k62!!&*5""6;7	4!66x@N%%nh?F&&~yAGHD ,,V^DDM ,,V^DDM!%8Lb!Q''(:A>H,,X6F6\F(*H(*I"#&&v.''0e#f,''?/;,(*&&v}= $ 4 4[ A%%fl;
''?&11$2F2Fz2RT`a)) 6+
(6+
f6+
 D6+
 U	6+

 f6+
 w6+
 f6+
 D6+
 w6+
 F6+
 ve46+
 J6+
 e6+
 e6+
 F
6+
  f!6+
" #6+
$ D,,V5EF%6+
& h'6+
( y)6+
* T%%dG4+6+
, T%%dG4-6+
. $..|</6+
0 k:16+
2 t''i836+
4 d56+
6 d76+
8 d96+
: $;6+
< ++,AB**+?@=6+
D ++FMB
  
  
  E6+
h ti6+
j Fk6+
 6 6	r  c                     d }d }| j                  | j                  dg       }t        dt        |            D ]?  }||   }|j	                  |      }|dkD  s|j                  |d      }|dk(  r|}|}n|}|} n ||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q#k*+ 	A$QJ!z2JB!))*b9?'F$G#F(G	 
 r  r  c                    | j                          | j                  |      }d|d   i}d}|d   r"| j                  | j                  ||            }nK|d   r"| j	                  | j                  ||            }n$t        | j                  dz   dz   |d   z   d	z         | j                  |d
i       }| j                  ||      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XH2 F^99$++gv:VWH@ tww}/TTW]^dWeehzz{{~~h3  v..r  symbolsc                    d}| j                          | j                  |ddd      }| j                  |      }d}| j                  ||||      \  }}d}|dk(  r| j	                  |      }nh|dk(  r?d}| j                  ||d|      \  }}d|i}| j                  | j                  ||            }n$t        | j                  dz   |z   d	z   |z   d
z         | j                  |dg       }	| j                  |	|      S )a4  
        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 r0  r  )r  market_symbolsget_market_from_symbolshandle_market_type_and_paramsr  r  publicGetApiMixV1MarketTickersr  r*   r5   r  parse_tickers)
r  r6  r  
methodNamer  rP  r  r  r  r  s
             r  fetch_tickerszcoincatch.fetch_tickersf  s"    $
%%gtT4@--g6
!??
FTZ\fg
F;;FCH8 6!!K"&"?"?
Tacn"oK{G ::4;;wPV;WXHF tww}z9<VVYccfxxyy~~h3!!$00r  c                    | j                  |dd      }| j                  |dd      }|j                  d      dk  r|dz  }| j                  ||      }| j	                  |dd	      }| j                  i d|d   d|d
| j                  |      d| j                  |d      d| j                  |d      d| j	                  |dd      d| j                  |d      d| j	                  |dd      d| j                  |d      dd d| j	                  |dd      d|d	|dd dd dt        j                  | j	                  |d d!      d"      d#d | j	                  |d$d%      | j	                  |d&d'      | j                  |d(      d |d)|      S )*Nts	timestampr  r   _r   r  closer2  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_  ra  rb  	markPricer  )	safe_integer_2r  r)  safe_market_customsafe_string_2safe_tickeriso8601r0   r  )r  tickerr  rB  r  r2  s         r  r3  zcoincatch.parse_ticker  s!   \ ''kB	##FHb9==!H((6:!!&'6: !
fX&!
!
 Y/!
 D$$VY7	!

 4##FH5!
 4%%fh	B!
 ))&':!
 4%%fiC!
 ))&':!
 D!
 D&&vz9E!
 T!
 D!
 T!
 d!
  ',,T-?-?U]-^`ef!!
" t#!
$ ,,VYM--fj-P**6<@-!
. / 	r  rJ  c                    | j                          d}| j                  |      }d|d   i}|||d<   d}| j                  ||d      \  }}|||d<   d}|d   r"| j                  | j	                  ||            }nN|d   r"| j                  | j	                  ||            }n't        | j                  d	z   |z   d
z   |d   z   dz         | j                  |di       }	| j                  |	d      }
| j                  |	||
dd      S )ag  
        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   NrJ  r  rB   rD   r/  r8  r  r0  r  rA  bidsasks)r  r  r  "publicGetApiSpotV1MarketMergeDepthr  !publicGetApiMixV1MarketMergeDepthr*   r5   r  r  parse_order_book)r  r  rJ  r  r>  r  r  r  r  r  rB  s              r  fetch_order_bookzcoincatch.fetch_order_book  s-    	%
V$fTl
 $GG	 99&*kZ	6 #,GK &>>>t{{7TZ?[\H  F^==dkk'SY>Z[Htww}z9<VVY_`fYggj||}}~~h3%%dD1	$$T69ffMMr  r   sincec                 H   d}| j                          | j                  |      }d|d   i}d}	| j                  ||d      \  }	}|d   }
| j                  d   |
   }| j	                  |||      }d}|}||	|}|||d	<   d}|d
   r\||d<   |||d<   |	|	|d<   | j                  | j                  ||            }| j                  |dg       }| j                  |||||      S |d   r||d<   |	| j                         }	|| j                  |      }|	||z  dz  z
  }||d<   |	|d<   d}| j                  ||d      \  }}|dk(  rd|d<   | j                  | j                  ||            }| j                  |||||      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   rQ  rJ  rB   periodafterbeforer  rD   granularity	startTimeendTimerT  r3  zmarket mark index	kLineTyper/  r8  r0  )r  r  r  r   r  publicGetApiSpotV1MarketCandlesr  r  parse_ohlcvsmillisecondsparse_timeframepublicGetApiMixV1MarketCandlesr*   r5   )r  r  	timeframerq  rJ  r  r>  r  r  rs  rP  r   encodedTimeframemaxLimitrequestedLimitr  r  duration	priceTypes                      r  fetch_ohlcvzcoincatch.fetch_ohlcvD  s%     "
V$fTl
 55fj'RvF^
\\,/
;
++J	9M5#4%N%-GG&> 0GH #(  $)!;;DKKQW<XYH* >>(FB7D$$T69eUKKF^%5GM"}))+}//	:H!4t!;<#(GK !&GI!I $ = =fjRY ZIvF"':$::4;;wPV;WXH $$Xvy%OOtww}z9<VVY_`fYggj||}}r  c           
          | j                  |dd      | j                  |dd      | j                  |dd      | j                  |dd      | j                  |d	d
      | j                  |dd      gS )NrA  r   rU  r   rF  r   rH     rD  r   r^     )rd  safe_number_2)r  ohlcvr  s      r  parse_ohlcvzcoincatch.parse_ohlcv  sx    tQ/ufa0ufa0ueQ/ugq1ui3
 	
r  c                     d}| j                          | j                  |      }d|d   i}d}| j                  ||d      \  }}d}	|}
|||	}
|||d<   |||d<   |
|
|d	<   d}|d
   r"| j                  | j	                  ||            }nN|d   r"| j                  | j	                  ||            }n't        | j                  dz   |z   dz   |d   z   dz         | j                  |dg       }| j                  ||||      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   Nrs  rQ  rx  ry  rJ  rB   rD   r/  r8  r  r0  r  )
r  r  r  $publicGetApiSpotV1MarketFillsHistoryr  #publicGetApiMixV1MarketFillsHistoryr*   r5   r  parse_trades)r  r  rq  rJ  r  r>  r  r  rs  r  requestLimitr  r  s                r  fetch_tradeszcoincatch.fetch_trades  sD    #
V$fTl
 55fj'Rv5#4#L ',$ %*	"#+GG&>@@WV\A]^H$ F^??GU[@\]H( tww}z9<VVY_`fYggj||}}~~h3  vue<<r  tradec                    | j                  |d      }| j                  ||      }| j                  |g d      }| j                  |dd      }d }|t	        j
                  |      }| j                  |d      }|
|d   |d   }| j                  |dd      }| j                  | j                  |d	d
      | j                  |d      || j                  |      |d   | j                  |d      | j                  |      | j                  |d      | j                  |dd      | j                  |g d      | j                  |dd      ||d|d|      S )Nr  )fillTimerB  cTimer   r  feeCcyr  	tradeSidesidetradeIdfillIdorderId	orderTypetakerMakerFlag	fillPricerT  )fillQuantitysizesizeQtyfillTotalAmount
fillAmountr   r  )r5   orderrB  rE  r  r  r  takerOrMakerrT  r  r   r  r  )r  re  safe_integer_nrf  r0   
string_abssafe_string_lower_2
safe_traderh  parse_order_sidesafe_string_n)	r  r  r  r  rB  r   feeCostfeeCurrencyr  s	            r  parse_tradezcoincatch.parse_trade  st   r ##E84((6:''/QR	!!%7((.G&&uh7fX&6&B *K''{FC$$UIx@%%eY7"Y/X&$$UK8))$/ ,,U4DE''{GD((0ST&&u.?N' ! 
" # 	r  c                 &   | j                          | j                  |      }|d   }|j                  d      }|| j                  |d      d}| j	                  | j                  ||            }| j                  |di       }| j                  ||      S )an  
        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   rC  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_rateQ  s     	V$$<s#++E15
 >>t{{7TZ?[\ ~~h3&&tV44r  c                     | j                  |d      }| j                  ||      }| j                  |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  rc  rb  interestRateestimatedSettlePricerB  rE  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r  re  r  )r  r  r  r  r  s        r  r  zcoincatch.parse_funding_rater  s   ##Hh7((6:&&x?
H
fX&
 
 $	

 D
 #D
 
 
 ;
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  r  r>  
optionNamer  requestPropertyc                 F    | j                  ||||      \  }}||||<   ||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'-GO$&&r  c           
      l   |t        | j                  dz         | j                          d}| j                  |      }d|d   i}|}||}|||d<   | j	                  | j                  ||            }	| j                  |	dg       }
g }t        dt        |
            D ]q  }|
|   }| j                  |d	      }|j                  || j                  | j                  |d      |dd
      | j                  |d      || j                  |      d       s | j                  |d      }| j!                  |||      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 argumentrO  r  r5   pageSizer  r   
settleTimerD   r  )r  r  r  rB  rE  rB  )r$   r5   r  r  &publicGetApiMixV1MarketHistoryFundRater  r  r  r  r  r  safe_symbolr  r  rh  sort_byfilter_by_since_limit)r  r  rq  rJ  r  maxEntriesPerRequestr  r  r  r  r  ratesr  entryrB  sorteds                   r  fetch_funding_rate_historyz$coincatch.fetch_funding_rate_history  sW    >#DGG.e$eff"V$fTl
 1N%"0GJ>>t{{7TZ?[\ ~~h3q#d)$ 		AGE))%>ILL**4+;+;E8+LfVZ\bc#//}E& LL3 		 e[1))&%??r  c                    | j                          d}d}| j                  |d|      \  }}d}|dk(  r| j                  |      }nh|dk(  r?d}| j                  ||d|      \  }}d|i}| j	                  | j                  ||            }n$t        | j                  dz   |z   dz   |z   d	z         | j                  |d
g       }| j                  |      S )a7  
        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/  r8  r0  r  )
r  r;   privateGetApiSpotV1AccountAssetsr  !privateGetApiMixV1AccountAccountsr  r*   r5   r  parse_balance)r  r  r>  rP  r  r  r  r  s           r  fetch_balancezcoincatch.fetch_balance  s     	#

!??
DRXY
F$ <<VDH6!!K"&"?"?
Tacn"oK{G8 ==dkk'SY>Z[Htww}z9<VVYccfxxyy~~h3!!$''r  c                    d|i}t        dt        |            D ]  }| j                  ||i       }| j                  |dd      }| j	                  |      }| j                         }| j                  |d      |d<   | j                  |dd      }| j                  |d	d
      }	t        j                  ||	      |d<   | j                  |d      |d<   |||<    | j                  |      S )Nr  r   r  
marginCoin	availablefreelocklockedfrozen0usedequitytotal)
r  r  r  rf  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SJ**:6DllnG"..|[IGFO''fhGF%%lHcBF%00@GFO#//hGGG"F4L
	#   ((r  r  r  fromAccount	toAccountc                 X   | j                          | j                  |      }|dk(  r
|dk(  rd}nd}|dk(  r
|dk(  rd}nd}|d   | j                  ||      ||d}d}| j                  |dd	      \  }}|||d
<   | j	                  | j                  ||            }	| j                  |	|      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.transferC  s     	==&& v~('v~&	%	TN00v>#	
 " $ = =fjRa bv$#0GK <<T[[RX=YZ ""8X66r  c           
          | j                  |d      }d }|dk(  rd}| j                  |di       }| j                  |d      d d | j                  d |      d d d ||d	S )Nmsgsuccessokr  
transferId)	r5   rB  rE  r  r  r  r  statusr  )r  r  r  )r  r   r  r  r  r  s         r  r  zcoincatch.parse_transferu  sw    x/)F~~h3""46//h?

 
	
r  c                    | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|| j                  |      }|t	        | j
                  dz         | j                  ||      |d<   | j                  | j                  ||            }| j                  |di       }| j                  ||      }|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   r  '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V33D9K#DGG.}$}~~22;E??GU[@\] ~~h333D(Cr  c                     | j                  |d      }| j                  |       | j                  |d      }| j                  | j                  d   ||      }| j                  |d      }|d   ||||dS )Naddressr  r0  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~u5 ("
 	
r  c                 @   d}| j                          i }d}|| j                  |      }|d   |d<   |||d<   d}| j                  ||d      \  }}|||d<   | j                  | j	                  ||            }	| j                  |	dg       }
| j                  |
|||      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  rx  rs  ry  r  )r  r  r  $privateGetApiSpotV1WalletDepositListr  r  parse_transactionsr  r  rq  rJ  r  r>  r  r  rs  r  r  s              r  fetch_depositszcoincatch.fetch_deposits  s     %
!}}T*H&tnGFO#(GK 55fj'Rv!&GI<<T[[RX=YZ8 ~~h3&&tXueDDr  c                 N   d}| j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   d}| j                  ||d      \  }}|||d<   | j                  | j	                  ||            }	| j                  |	d	g       }
| j                  |
|||      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  rx  rJ  rs  ry  r  )r  r  r  )privateGetApiSpotV1WalletWithdrawalListV2r  r  r  r  s              r  fetch_withdrawalszcoincatch.fetch_withdrawals  s      (
!}}T*H&tnGFO#(GK $GG55fj'Rv!&GIAA$++gW]B^_ ~~h3&&tXueDDr  r  c                 r   | j                  ||      \  }}| j                          | j                  |      }|d   ||d}|||d<   d}| j                  |      \  }}|| j	                  |      |d<   | j                  | j                  ||            }	| j                  |	di       }
| j                  |
|      S )au  
        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V==&TN

 ? GEN"AA&IV"#66{CGG>>t{{7TZ?[\ ~~h3%%dH55r  c                    | j                  |d      }|dk(  rd}| j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  | j                  d	   |	|	      }
| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }d }|||d}i d|d| j                  |dd      d|d|d| j                  |      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  r0  	toAddressfromAddressr  r  r  r  r  r5   r  txidrB  rE  r  r  	addressToaddressFromtagTotagFromr  updated)internalcommentr  )r  r  r  r  r   rf  rh  )r  transactionr  r  r  r  r  rB  r  r  r  r  r  r  r  r  r  s                    r  r  zcoincatch.parse_transactionT  s   D !!+x8YFV4V4&&tX6%%k7;	!!+x8$$[':	""4<<#?IV$$[+>	&&{MB{E2V4"";6 C
K
$$$[$	B
 D
 	

 Y/
 w
 t
 
 ;
 3
 T
 t
 D
 f
 
  f!
" t#
$ )
 	
r  r   c                     | j                          d}| j                  |      }|d   st        | j                  dz   |z   dz         ||d<   d|d<   | j	                  |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  sx     	3
V$f~tww}z9<ZZ[[)|6;23  5$fMMr  r  r  rT  c                    | j                          | j                  |dd      |d<   | j                  |      }|d   r| j                  ||||||      S |d   r| j	                  ||||||      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 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  r0  )r  r  r  create_spot_ordercreate_swap_orderr*   r5   )r  r  r  r  r  rT  r  r  s           r  r%  zcoincatch.create_order  s    , 	#//mT|V$&>))&$feVTTF^))&$feVTTtww)OORXY_R``cuuvvr  c                 \   | j                          | j                  |dd      |d<   | j                  ||||||      }| j                  |d      du}d}	|r| j                  |      }	n| j	                  |      }	| j                  |	di       }
| j                  |      }| j                  |
|      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>  createSpotOrderr:  Nr  )r  r  create_spot_order_request!privatePostApiSpotV1PlanPlacePlanprivatePostApiSpotV1TradeOrdersr  r  parse_order)r  r  r  r  r  rT  r  r  
isPlanOrerr  r  r  s               r  r(  zcoincatch.create_spot_order  s    ( 	#//FWX|66vtT6SXZ`a%%g~>dJ
==gFH ;;GDH~~h3V$f--r  c                    d}| j                  |d|      \  }}| j                  |      }|d   ||d}	|dk(  }
| j                  |||
      }|d   }|d   }d}| j                  |d	      \  }}d}| j                  |d
      \  }}|
xr |dk(  }|s |t        | j                  dz   |z   dz         |r| j                  |||||      }|d	   }|d   }|,|dk(  r||	d<   |r|n| j                  |      |	d<   |r|nd|	d<   nZ||	d
<   |||	d<   d}| j                  |d      \  }}|||	d<   |dk(  r||	d<   d}|
rd}nd}||	d<   |
r|n| j                  |      |	d<   | j                  |	|      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   r:  r$  r/  z3 supports cost parameter for market buy orders onlyrJ  rT  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  rT  r  r>  r  r  isMarketOrdertimeInForceAndParamsr@  r   r:  isMarketBuycostAndParamsr  r9  s                      r  r,  z#coincatch.create_spot_order_request	  s   " .
!55flJW
FV$Tl

 )#FFzSY[hi%h/*=9//?f #77Of#7$"2tww}z9<qqrr ??
FTY[acghM (D"8,Fw#( *5$4;P;PQW;XGJ.9{xGG&2GN#&.9*+!%M$($<$<V_$U!M6('4$w*/'#K,*%0GM"&3d9N9Nv9VGFO{{7F++r  r$  c                 b   d| j                  |      z   dz   }d}| j                  |||d      \  }}d }	|| j                  |      }	d }
|| j                  |      }
|rG|,|*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  rT  r  r   r  r  requiresPriceamountStringpriceStringr  s               r  r<  z(coincatch.handle_requires_price_and_costD	  s   #dood&;;>RR
 $ = =fjR\^b cv 008L//6KDL"477S=:#=@l#los#s  wM  $M  PZ  $Z  ]j  $j  k  k)),D4\D
 r  Fr>  c                     d }| j                  ||d      \  }}d}| j                  ||dk(  |      \  }}|rd}| j                  |      }||d}|S )Nr@  F	post_onlyr7  )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_only[	  sq    ";;FJP]^V00{@Z\bc&K//<&
 r  c                    | j                  |dd      |d<   | j                          | j                  |      }| j                  ||||||      }| j                  |d      }	| j	                  |d      }d}
|	dk(  r| j                  |      }
n(|	dk(  r| j                  |      }
n| j                  |      }
| j                  |
di       }| j                  ||      S )a  
        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.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endpointTypeNrN  tpslr  )
r  r  r  create_swap_order_requestomit privatePostApiMixV1PlanPlacePlan privatePostApiMixV1PlanPlaceTPSL"privatePostApiMixV1OrderPlaceOrderr  r/  )r  r  r  r  r  rT  r  r  r  rP  r  r  s               r  r)  zcoincatch.create_swap_orderi	  s    6  $//FWX|V$00tVUTZ[''@))G^49$<<WEHV#<<WEH>>wGH ~~h3f--r  c                    d}| j                  |d|      \  }}| j                  |      }|d   |d   | j                  ||      d}	| j                  ||d|	d      \  }	}|dk(  }
| j	                  ||||||      }| j                  |d	      }||d
k(  r;| j                  |||
      }|d   }|d   }|||	d<   || j                  ||      |	d<   |dk7  rr||	d<   d}| j                  ||d|      \  }}d}| j                  |d|      \  }}|r"|r|dk(  rd}n+|dk(  r&d}n#|dk(  rd}n|dk(  rd}n|j                         dz   }||	d<   | j                  |	|      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 bool [params.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  rP  standardr  r@  r5  rT  rQ  r  FrA  
reduceOnlyr$  close_shortsell
close_long	open_long
open_short_singler  )r:  r  amount_to_precisionr  (handle_trigger_stop_loss_and_take_profitr  r;  price_to_precisionr  handle_param_boollowerr  )r  r  r  r  r  rT  r  r>  r  r  r>  rP  r?  r@  rA  rZ  s                   r  rR  z#coincatch.create_swap_order_request	  s   0 .
!55flJW
FV$Tl ,,,VV<

 ??
Tcelnyz)>>vtTSXZdflm''? lj&@#'#J#J:W]_l#m )(3F.}=K&.9*+ #'#:#:65#I F"#'GK  F!::6:xY_`NFF$J!%!7!7j!YJu},+u}*+zz|i/"GFO{{7F++r  rX   c                    i }d}| j                  |d      }	| j                  |d      }
d }| j                  |d      }| j                  |d      }| j                  |dd      }|d u}| j                  |d      }| j                  |d	      }|
d u}|	d u}|d u}|r|s| j                  |d      }
|
d u}|d u}|r|s| j                  |d      }	|	d u}|xr |}|d u}|d
k(  }|s|s|dk(  rQ|r9|rd|d<   nd|d<   | j                  ||      |d<   | j                  ||      |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<   | j                  ||      |d<   |||d"<   | j                  |g d#      }| j                  ||      S )$NrY  r=  r>  
takeProfitstopLossr:  	stopPricetrailingPercenttrailingTriggerPricer  rZ   r7  r9  r8  r6  rN  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()rQ  longr$  shortholdSidezG() requires the trailingTriggerPrice parameter for trailing stop orders	rangeRatemoving_planplanTypeprofit_plan	loss_planrP  )rh  rg  r=  r>  r:  ri  rj  rk  )	r  r  rf  rc  r*   r5   r$   rS  r  )r  r  r  r  rT  r>  r  r  rP  r=  r>  requestTriggerPricetakeProfitParamsstopLossParamsr:  	isTriggerrj  rk  
hasTPPrice
hasSLPricehasTPParamshasSLParamshasBothTPAndSLisTrailingPercentOrderr>  rp  s                             r  rb  z2coincatch.handle_trigger_stop_loss_and_take_profit	  s   !((A**63DE#'>>&,?
;))&.+N!-	**63DE#//8NO%T1
#4/
't3z"../?PO)5J%T1z ,,^^LM't3J#2
"1"=)Y:9_+_ -;GM*-9GM*.2.E.Efe.TGN+*.*A*A&,*W'(^+#3B/01>-.:)? "477S=:#=@_#_bf#f  jE  $E  F  F!LHu}""*GJ%'/+DGGcMJ,F  JS  -S  T  T&:#'6$&3
#&5#&3
#&3#&1
#&*&=&=fFY&ZGN##&2GN#6  $j  k{{7F++r  rg  rh  c	           
          d}	| j                          | j                  |      }
|
d   st        | j                  dz   |	z   dz         |	|d<   t        t
        |   ||||||||      S )aO  
        *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  rT  rg  rh  r  r>  r  r  s              r  r  z5coincatch.create_order_with_take_profit_and_stop_loss&
  s     <
V$f~tww}z9<ccdd)|YQRXZ^`dflnsu  BJ  LR  S  	Sr  r@  c                 6    ddddd}| j                  |||      S )Nr  iokfokrJ  )GTCr5  r6  r7  r  )r  r@  timeInForceMaps      r  rL  zcoincatch.encode_time_in_force;
  s,    	
 [IIr  r  c           	         | j                          d}||d<   g }g }t        dt        |            D ]  }||   }| j                  |d      }|j	                  |       | j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d	i       }| j                  ||	|
|||      }| j                  |d
      }|t        | j                  dz   |z   dz         | j                  |d      }|| j                         |d<   |j	                  |       	 | j                  |      }t        |      }|dk7  rt        | j                  dz         | j                  |d      }| j                  |      }d|d   i}|d   }d}d}d}|dk(  r)||d<   | j                  | j                  ||            }d}nZ|d   r1|d   |d<   ||d<   | j!                  | j                  ||            }d}n$t        | j                  dz   |z   dz   |z   dz         | j                  |di       }| j#                  ||g       }| j%                  |      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  rT  r  r:  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  	orderInfor8  r0  r  )r  r  r  r  r  r  r  create_order_requestr*   r5   uuiduniquer%   r  $privatePostApiSpotV1TradeBatchOrdersr  #privatePostApiMixV1OrderBatchOrdersr  parse_orders)r  r  r  r>  ordersRequestsr6  r  rawOrderr  r  r  r  rT  orderParamsorderRequestr:  r  symbolsLengthordersSymbolr  r  rP  r  responseOrderspropertyNamer  s                             r  create_orderszcoincatch.create_ordersD
  s    	#
)|q#f+& 	0AayH%%h9FNN6"##Hf5D##Hf5D%%h9F$$Xw7E..8R@K44VT4QVXcdL++KHL'"477S=:#=@d#dee ,,\?KM$04		_-!!,/!	0" ++g&GATWW'eeff''3\*fTl
 F^
 #1GK @@WV\A]^H< (LF^$*:$6GL!'5GO$??GU[@\]H2 'Ltww}z9<VVYccfxxyy~~h3lB?  00r  c                    | j                  |dd      }||d<   | j                  |      }|d   r| j                  ||||||      S |d   r| j                  ||||||      S t	        | j
                  dz   |z   dz   |d   z   dz         )	Nr>  createOrderRequestrB   rD   r/  r8  r  r0  )r  r  r,  rR  r*   r5   )	r  r  r  r  r  rT  r  r>  r  s	            r  r  zcoincatch.create_order_request
  s    %%fl<PQ
)|V$&>11&$feU[\\F^11&$feU[\\tww}z9<VVY_`fYggj||}}r  r5   c           	          d}||d<   | j                          | j                  |      }	|	d   r| j                  |||||||      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/  r8  r  r0  )r  r  edit_spot_orderr*   r5   )
r  r5   r  r  r  r  rT  r  r>  r  s
             r  
edit_orderzcoincatch.edit_order
  s     !
)|V$&>''FD$vVV tww}z9<VVY_`fYggj||}}r  c                    | j                          d}| j                  |d|      \  }}| j                  |      }	|	d   s!t        | j                  dz   |	d   z   dz         d|i}
| j                  |d      }|||
d
<   n%|t        | j                  dz   |z   dz         ||
d<   d	}| j                  |d      \  }}|dk(  xr |dk(  }|s |t        | j                  dz   |z   dz         |6|r | j                  |||||      }|d   }|d   }n| j                  |      |
d<   |||
d<   |dk(  r|||
d<   | j                  | j                  |
|            }| j                  |di       }| j                  ||	      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  rJ  rT  r  )r  r:  r  r*   r5   r  r%   r<  r=  "privatePostApiSpotV1PlanModifyPlanr  r  r/  )r  r5   r  r  r  r  rT  r  r>  r  r  r  r   r@  rA  r  r  s                    r  r  zcoincatch.edit_spot_order
  s   & 	$
!55flJW
FV$f~tww)MMPVW]P^^ajjkk
 ((A$#0GK ZTWWs]Z7:[[\\!#GI//?fx'<dem$"2tww}z9<sstt $ C CJPVX]_egk l$V,&x0"&"7"7"?"GFOGO%"3$GG::4;;wPV;WX ~~h3f--r  c                    d}| j                          i }| j                  |d      }|||d<   d}|| j                  |      }d}| j                  ||||      \  }}d}	d}
|dk(  rq| j	                  | j                  ||            }	| j                  |	d      }|(t        j                  |	      }	| j                  |	dg       }| j                  |di       }
n|dk(  r||$t        | j                  d	z   |z   d
z   |z   dz         |d   |d<   || j                  |d      }||d<   | j                  | j                  ||            }	| j                  |	di       }
n$t        | j                  d	z   |z   dz   |z   dz         | j                  |
|      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 r0  r5   r  r  r8  )r  r  r  r;  "privatePostApiSpotV1TradeOrderInfor  r  jsonloadsr  r$   r5   rS  privateGetApiMixV1OrderDetailr*   r/  )r  r5   r  r  r>  r  r  r  rP  r  r  r  s               r  fetch_orderzcoincatch.fetch_order  s    "
((A !#GI[[(F
!??
FTZ\fg
F>>t{{7TZ?[\HT >>(F3D|::h/~~h;NN4B/E6!~'#
(BEi(ilv(v  zL  )L  M  M &tGH(6?;'4$99$++gv:VWHF NN8VR8Etww}z9<VVYccfxxyyv..r  c                 8   d}| j                          d}|| j                  |      }d}| j                  ||||      \  }}||d<   |dk(  r| j                  ||||      S |dk(  r| j	                  ||||      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/  r8  r0  )r  r  r;  fetch_open_spot_ordersfetch_open_swap_ordersr*   r5   r  r  rq  rJ  r  r>  r  rP  s           r  fetch_open_orderszcoincatch.fetch_open_orders  s    * '
[[(F
!??
FTZ\fg
F)|..vueVLL6!..vueVLLtww}z9<VVYccfxxyyr  c                 :   | j                          d}| j                  |d|      \  }}i }d}|| j                  |      }|d   |d<   d}| j                  ||dd|      \  }}d}	|ro|t	        | j
                  d	z   |z   d
z         |||d<   | j                  | j                  ||            }
| j                  |
di       }| j                  |dg       }	n4| j                  | j                  ||            }
| j                  |
dg       }	| j                  |	|||      S )aS  
 @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  FrN  stopr/  z0() requires a symbol argument for trigger ordersr  r  r  )r  r:  r  handle_option_and_params_2r$   r5   #privatePostApiSpotV1PlanCurrentPlanr  r  r  #privatePostApiSpotV1TradeOpenOrdersr  )r  r  rq  rJ  r  r>  r  r  ry  r  r  r  s               r  r  z coincatch.fetch_open_spot_orders  sC     	*
!55flJW
F[[(F &tGH	 ;;FJPY[aclm	6~'#
(BEw(wxx &+
#??GU[@\]H< >>(FB7D^^D+r:F??GU[@\]H: ^^Hfb9F  >>r  c                    | j                          d}| j                  |d|      \  }}d}| j                  ||dd|      \  }}d}| j                  ||d|      \  }}| j	                  |d      }d}	d}
|n| j                  |      }	d	|	d
   i}|s|0|||d<   |||d<   | j                  | j                  ||            }
n| j                  | j                  ||            }
ne|rt        | j                  dz   |z   dz         |d}d|i}d}| j	                  |d|      }|||d<   | j                  | j                  ||            }
| j                  |
dg       }| j                  ||	||      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>  FrN  r  NisPlanr  r  r5   r/  z5() requires a symbol argument for swap trigger ordersr  r  r  )r  r:  r  r  handle_optionr  !privateGetApiMixV1PlanCurrentPlanr  privateGetApiMixV1OrderCurrentr$   r5   (privateGetApiMixV1OrderMarginCoinCurrentr  r  )r  r  rq  rJ  r  r>  ry  planr  r  r  r  r  r  s                 r  r  z coincatch.fetch_open_swap_orders  s   & 	*
!55flJW
F	 ;;FJPY[aclm	644VZSWXf((]C[[(F&,G t/*-8GM*#(,GH%B  AA$++gW]B^_>>t{{7TZ?[\#DGGcMJ$>Ax$xyy"%{G #J++JjQJ%(2%H DDT[[QXZ`EabH~~h3  vue<<r  c                 8   d}| j                          d}|| j                  |      }d}| j                  ||||      \  }}||d<   |dk(  r| j                  ||||      S |dk(  r| j	                  ||||      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/  r8  r0  )r  r  r;  %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
F)|==feUTZ[[6!==feUTZ[[tww}z9<VVYccfxxyyr  c                 "   d}| j                  |d|      \  }}|t        | j                  dz   |z   dz         d}| j                          | j	                  |      }d|d   i}|}	d	}
| j                  ||d
d|
      \  }
}d}|
rd}| j                  ||d|      \  }}|}d}| j                         }|
|||z
  }|}n|||z
  }n||z   }||d<   ||d<   |	|}	|	|d<   | j                  | j                  ||            }| j                  |di       }| j                  |dg       }nY|||d<   |}	|	|	|d<   | j                  | j                  ||            }t        j                  |      }| j                  |dg       }| j                  ||||      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 marketsrI  r  r5   FrN  r  rs      X rx  ry  r  r  r  ru  rJ  )r:  r$   r5   r  r  r  r  r}  #privatePostApiSpotV1PlanHistoryPlanr  r  r   privatePostApiSpotV1TradeHistoryr  r  r  )r  r  rq  rJ  r  r>  r  r  r  r  ry  r  rs  requestSinceintervalnowr  r  parsedResponses                      r  r  z/coincatch.fetch_canceled_and_closed_spot_orders  s   " 8
!55flJW
F>#DGGcMJ$>Aq$qrrV$fTl
 	 ;;FJPY[aclm	6E 99&*gW\]ME6 L/H##%CL$8"X~"$x/(#/GK !&GI#'".GJ??GU[@\]H< >>(FB7D^^D+r:F #( ''#/ <<T[[RX=YZHX "ZZ1N^^NFB?F  >>r  c                 n   d}| j                  |d|      \  }}|}d}| j                  ||d|      \  }}| j                         }d}	|
|||	z
  }|}n|||	z
  }n||	z   }||d}
|||
d<   d}|| j                  |      }|d   |
d	<   | j	                  |d
      }d}| j                  ||dd|      \  }}d}| j                  ||d|      \  }}d}d}|s|C|||
d<   |||
d
<   | j                  | j                  |
|            }| j                  |dg       }n|;| j                  |      }|d   |
d	<   | j                  | j                  |
|            }n*|d}||
d
<   | j                  | j                  |
|            }| j                  |di       }| j                  |dg       }| j                  ||      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>  Nrs  r  )rx  ry  r  r5   r  r  FrN  r  r  r  r  r  )r:  r  r}  r  r  r  !privateGetApiMixV1PlanHistoryPlanr  r  privateGetApiMixV1OrderHistory)privateGetApiMixV1OrderHistoryProductTyper  r  )r  r  rq  rJ  r  r>  r  rs  r  r  r  r  r  ry  r  r  r  r  s                     r  r  z/coincatch.fetch_canceled_and_closed_swap_ordersH  s8   & 8
!55flJW
F55fj'SXYv! ,M 4>LE 8+LH$E%
 "'GJ[[(F &tGH((]C	 ;;FJPY[aclm	644VZSWXf4+$(!&)4&==dkk'SY>Z[HH ^^Hfb9F!V,$*4L!>>t{{7TZ?[\&")K)4&II$++V]_eJfgR >>(FB7D^^D+r:F  00r  c                    d}|t        | j                  dz   |z   dz         | j                          | j                  |      }i }d}| j	                  |d      \  }}| |t        | j                  dz   |z   dz         |||d<   n||d<   |d	   }d
}	| j                  ||dd|	      \  }	}d}
|	r|dk7  r|d   |d<   |dk(  rF|	r"| j                  | j                  ||            }
n| j                  | j                  ||            }
n|dk(  rd}| j                  ||d|      \  }}|d   |d<   |	s|G|t        | j                  dz   |z   dz         ||d<   | j                  | j                  ||            }
nF| j                  | j                  ||            }
n$t        | j                  dz   |z   dz   |z   dz         | j                  |
di       }| j                  ||      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  FrN  r  rB   r5   r  rD   rs  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)r8  r0  r  )r$   r5   r  r  r:  r  "privatePostApiSpotV1PlanCancelPlanr  &privatePostApiSpotV1TradeCancelOrderV2r  !privatePostApiMixV1PlanCancelPlan#privatePostApiMixV1OrderCancelOrderr*   r  r/  )r  r5   r  r  r>  r  r  r  rP  rN  r  rs  r  s                r  cancel_orderzcoincatch.cancel_order  s:   $ #
>#DGGcMJ$>A`$`aaV$! $ 8 8 QvJ]2#DGGcMJ$>Ax$xyy$#0GK !#GIF^
99&*iY_ahi:/ &tGHBB4;;wX^C_`FFt{{SZ\bGcd6! H#<<VZQ[]efHf$*:$6GL!X1#+DGGcMJ,F  JR  -R  S  S&.
#AA$++gW]B^_CCDKKPWY_D`atww}z9<VVYccfxxyy~~h3f--r  c                 P   d}| j                          d}|| j                  |      }i }d}| j                  ||||      \  }}d}| j                  ||dd|      \  }}d}|dk(  r|rQ|	|d   g|d<   | j	                  | j                  ||            }| j                  |d	g       }	| j                  |	|      S |t        | j                  d
z   |z   dz         |d   |d<   | j                  | j                  ||            }n|dk(  rcd}
|	|d   |d<   n| j                  |d|
      }
|
|d<   d}| j                  ||d|      \  }}|s|k|t        | j                  d
z   |z   dz         ||d<   |"| j                  | j                  ||            }n| j                  | j                  ||            }n|*|d   |d<   | j                  | j                  ||            }ngd}|
dk(  rd}n7| j                  ||d|      \  }}|t        | j                  d
z   |z   dz         ||d<   | j!                  | j                  ||            }| j#                  |      }| j                  ||      S t%        | j                  d
z   |z   dz   |z   dz         | j'                  |      }||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   FrN  r  r5   r6  r  r/  z9() requires a symbol argument for spot non-trigger ordersr  rD   r  r  rs  r  r  r  r  z9() requires a marginCoin parameter for dmcbl product typer8  r0  r  )r  r  r;  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  rP  rN  r  r  r  rs  r  r  r  s                  r  cancel_all_orderszcoincatch.cancel_all_orders  sI   ( '
[[(F
!??
FTZ\fg
F99&*iY_ahi%*0,GI&GGT[]cHde ~~h;((v66>+DGGcMJ,F  JE  -E  F  F$*4L!  JJ4;;W^`fKgh6!!K!$*4L!"00]KX)4& H#<<VZQ[]efHfX1#+DGGcMJ,F  JR  -R  S  S&.
#%#KKDKKX_agLhiH#HHU\^dIefH#(.z(:%JJ4;;W^`fKgh"&
')!'J)-)F)Fvz[gis)t&J!)/#
0J  NI  1I  J  J(2%GGT[]cHde EEhOF$$VV44tww}z9<VVYccfxxyy) fwr  idsc                    d}|t        | j                  dz   |z   dz         | j                          | j                  |      }d|d   i}|d   }| j	                  |d      }|||d	<   | j                  |d      }n%|t        | j                  dz   |z   d
z         ||d<   d}	d}
|dk(  rG| j                  | j                  |            }	| j                  |	di       }| j	                  |dg       }
nd|dk(  r;|d   |d<   | j                  | j                  ||            }	| j                  |	      }
n$t        | j                  dz   |z   dz   |z   dz         | j                  |
|      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  r8  r0  )r$   r5   r  r  r  rS  ,privatePostApiSpotV1TradeCancelBatchOrdersV2r  r  )privatePostApiMixV1OrderCancelBatchOrdersr  r*   r  )r  r  r  r  r>  r  r  rP  r  r  r  r  s               r  cancel_orderszcoincatch.cancel_orders  s    $
>#DGGcMJ$>A`$`aaV$fTl
 F^
0@A%$2GL!YYv'78F[#DGGcMJ$>A~$~"%GJHHU\I]^H0 >>(FB7D^^D,;F6!$*:$6GL!EEdkkRY[aFbcH EEhOFtww}z9<VVYccfxxyy  00r  c                     | j                  |di       }g }| j                  |dg       }t        dt        |            D ]  }||   }d|i}|j	                  |        |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  so    ~~h3??4b9q#h-( 	&AqkG7J MM*%	& r  c                 ,   | j                  |d      }| j                  |d      }| j                  |||      }| j                  |d      }| j                  | j	                  |dd            }| j                  | j                  |d            }||}| j                  |d      }| j                  | j                  |d            }	| j	                  |d	d
      }
| j                  |d      d u}|dk(  xr |	dk(  }|d   r|r|sd }
| j	                  |dd      }| j                  |d      }d }d }d }|| j                  |      }n:|r| j                  |      nd }t        j                  | j                  |d            }| j                  | j                  |d            }d }||dk(  }| j                  | j                  |d            }| j                  | j                  |d            }| j                  | j	                  |dd            }| j                  |d      }|dk(  r|}n|dk(  r|}| j                  i d| j                  |d      d| j	                  |dd      d| j                  |      d |d!d d"| j                  |d#      d| j                  |      d|d   d$|d|d|	d|d%|r|n| j                  |d&      d'|
d(| j	                  |d)d*      d+d d|||| j	                  |d,d-      d ||d.|| j                  |d/      ||d0	|      S )1Nr  r  r  rT  r6  priceAvgr  r  r3  r  r9  r  r$  rB   r  state	feeDetailr  r@  r7  r:  rl  presetTakeLossPricers  ru  rt  r5   r  r  r  rE  rB  lastTradeTimestamplastUpdateTimestampuTimer  r]  r  r  filledr  	filledQty	remainingr  filledAmount)r  r   rZ  )	r>  r=  r   tradesr  r   rZ  rM  r  )r  re  r  	omit_zerorf  r  safe_string_lowerparse_fee_detail_stringr  r0   r  parse_order_time_in_forcer  rh  parse_order_statusr  )r  r  r  r  r  rB  rT  r  r  r  r  ry  r@  r  feeDetailStringr   r  r  r@  rM  r:  r>  r=  rs  s                           r  r/  zcoincatch.parse_order  s   X ##E84%%e\:
((6:F%%eW5	t11%.QR>>$"2"25*"EF=E{3$$T%;%;E6%JK##E:v>$$UM:$F	x'<dem6NyF##E8W=**5+>&//@DAK$11*=QUK(()9)9%)GHG44T5K5KES`5ab""d*H~~d&6&6un&MN..)9)9%AX)YZt'9'9%AXZo'pq##E:6{"(M&*O  
$""5)4 
T//T 
 Y/ 
 	 

 !$ 
 "4#4#4UG#D 
 d--f5 
 fX& 
 D 
 ; 
 D 
 U 
 8x1A1A%1U 
 f 
 d((L 
  ! 
" L# 
$  /*&&u.?P' ..= ; 
< = 	r  r  c           
      @    dddddddddd	}| j                  |||      S )NrU  closedcanceled)	not_triggerinitnewpartially_filled	full_fillr  cancelr  	cancelledr  )r  r  satusess      r  r  zcoincatch.parse_order_status  s;    ! &! "#

 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}| j                  |||      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_short
buy_singlesell_singler  )r  r  sidess      r  r  zcoincatch.parse_order_side  s    
5
F
 
 &	

 &
 5
  
 !%
  
 !%
 
  
 "6
 #E
 %
  6!
$ tT22r  c                 6    ddddd}| j                  |||      S )Nr  r7  r5  r6  )r  rJ  r  r  r  )r  r@  timeInForcess      r  r  z#coincatch.parse_order_time_in_force  s,    	
 k;GGr  r  c                    g }| j                  |      }|rt        |j                               }t        dt	        |            D ]  }| j                  ||      }|| j                  v s$| j                  |      }| j                  ||i       }t        j                  | j                  |d            }	|j                  ||	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		()D1c$i( 	!--dA6
!6!66#66zBH#~~iRHH$//0@0@:0VWFMM$,"(# 	 r  c                 d   d}| j                  |d|      \  }}| j                          d}d}i }|| j                  |      }|d   }|d   |d<   n:| j                  ||||      \  }}|dk(  rt	        | j
                  dz   |z   d	z         d}	|}
|dk(  r/d
}||}
|
|
|d<   | j                  | j                  ||            }	n|dk(  r|||d<   nd|d<   d}| j                  ||d      \  }}|||d<   n| j                         |d<   |"| j                  | j                  ||            }	n`d}| j                  |d|      }||d<   | j                  | j                  ||            }	n$t        | j
                  dz   |z   dz   |z   dz         | j                  |	dg       }| j                  ||||      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  rI  rJ  rD   rx  r   rs  ry  r  r  r8  r0  r  )r:  r  r  r;  r$   r5   privatePostApiSpotV1TradeFillsr  r  r}  privateGetApiMixV1OrderFillsr  privateGetApiMixV1OrderAllFillsr*   r  r  )r  r  rq  rJ  r  r>  r  rP  r  r  r  maxSpotLimitrs  r  r  s                  r  fetch_my_tradeszcoincatch.fetch_my_trades  s     %
!55flJW
F
[[(FJ &tGH!%!C!CJPVX^`j!kJV#'#
(BEu(uvvL +'#/ 4 ::4;;wPV;WXH6! &+{#&'{#E 99&*gVME6 %*	"%)%6%6%8	"!4  <<T[[RX=YZ%"00]KX)4&6  ??GU[@\]tww}z9<VVYccfxxyy~~h3  vue<<r  c           	          d}|t        | j                  dz   |z   dz         ||d}| j                  |||| j                  ||            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   r/  r  )r  r>  )r$   r5   r%  r  )r  r5   r  rq  rJ  r  r>  r  s           r  fetch_order_tradeszcoincatch.fetch_order_trades  s]     (
>#DGGcMJ$>A`$`aa$
 ##FE5$++gv:VWWr  c                     | j                          | j                  |      }|d   |d   d}| j                  | j                  ||            }| j	                  |di       }| j                  ||      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_moder4  s          r  fetch_margin_modezcoincatch.fetch_margin_mode  sx     	V$Tl ,
 88Wf9UV: ~~h3%%dF33r  r9  c                 p    | j                  |d      }|| j                  d |      | j                  |      dS )Nr9  )r  r  r9  )r  r  parse_margin_mode_type)r  r9  r  
marginTypes       r  r+  zcoincatch.parse_margin_mode  s?    ++JE
&&tV455jA
 	
r  c                 2    ddd}| j                  |||      S )Ncrossisolated)crossedfixedr  r  r  typess      r  r.  z coincatch.parse_margin_mode_type  s&    
 tT22r  c                 f   |t        | j                  dz         |j                         }| j                          | j	                  |      }|d   dk7  r!t        | j                  dz   |d   z   dz         |d   |d   | j                  |      d}| j                  | j                  ||            }|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
        z+ setMarginMode() requires a symbol argumentr  rD   z& setMarginMode() is not supported for r0  r5   r  )r  r  r9  )	r$   r5   re  r  r  r*   encode_margin_mode_type'privatePostApiMixV1AccountSetMarginModer  )r  r9  r  r  r  r  r  s          r  set_margin_modezcoincatch.set_margin_mode  s     >#DGG.[$[\\%%'
V$&>V#tww)QQTZ[aTbbewwxxTl ,66zB

 ??GU[@\]  r  c                 2    ddd}| j                  |||      S )Nr3  r4  )r1  r2  r  r5  s      r  r8  z!coincatch.encode_margin_mode_type  s&    
 tT22r  c                 |   |t        | j                  dz         | j                          | j                  |      }|d   dk7  r!t	        | j                  dz   |d   z   dz         |d   |d   d}| j                  | j                  ||            }| j                  |d	i       }| j                  |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
        z/ fetchPositionMode() requires a symbol argumentr  rD   z* fetchPositionMode() is not supported for r0  r5   r  r)  r  holdModedouble_hold)r  rA  )	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     >#DGG._$_``V$&>V#tww)UUX^_eXffi{{||Tl ,
 88Wf9UV~~h3##D*5-/
 	
r  rA  c                    d}d}| j                          | j                  |d      }|y|d| j                  |      }|d   dk7  r!t        | j                  dz   |d   z   dz         |d   }|j                  d	      }	| j                  |	d
|      }n| j                  |d|      }||rdndd}
| j                  | j                  |
|            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  r  rD   z( setPositionMode() is not supported for r0  r5   rC  r   r>  single_hold)r  r=  )
r  r  r  r*   r5   r  r  r  )privatePostApiMixV1AccountSetPositionModer  )r  rA  r  r  r>  defaultProductTyper  r  r  r  r  s              r  set_position_modezcoincatch.set_position_mode!  s     '
$&&v}=!V,&>V+&tww1['[^dek^l'l  pB  (B  C  C!$< s+"44UA{K"00]L^_&)/]
 ==dkk'SY>Z[[r  c                 8   | j                          | j                  |      }|d   dk7  r!t        | j                  dz   |d   z   dz         |d   |d   d}| j	                  | j                  ||            }| j                  |di       }| j                  ||      S )	ae  
        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 r0  r5   r  r)  r  )r  r  r*   r5   r*  r  r  parse_leverager4  s          r  fetch_leveragezcoincatch.fetch_leverageL  s     	V$&>V#tww)QQTZ[aTbbewwxxTl ,
 88Wf9UV~~h3""400r  rC  c                    d}|t        | j                  dz   |z   dz         | j                          | j                  |      }|d   dk7  r't	        | j                  dz   |z   dz   |d   z   dz         |d	   |d
   |d}d}| j                  ||d      \  }}|||d<   | j                  | j                  ||            }| j                  |di       }	| j                  |	|      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   r8  r0  r5   r  )r  r  rC  r  rp  r  )
r$   r5   r  r  r*   r  %privatePostApiMixV1AccountSetLeverager  r  rF  )
r  rC  r  r  r>  r  r  r  r  r  s
             r  set_leveragezcoincatch.set_leverageb  s    #
>#DGGcMJ$>A`$`aaV$&>V#tww}z9<VVY_`fYggj||}}Tl , 

 44VZPf"&GJ==dkk'SY>Z[  ~~h3""400r  c                 $   | j                  |d      }| j                  ||      }| j                  | j                  |d            }| j	                  |dd      }| j	                  |dd      }| j                  |d      }|dk(  r|}|}||d   |||d	S )
Nr  r9  fixedLongLeveragelongLeveragefixedShortLeverageshortLeveragecrossMarginLeverager1  )r  r  r9  rM  rO  )r  re  r.  r  rd  r  )r  rC  r  r  r9  rM  rO  rP  s           r  rF  zcoincatch.parse_leverage  s    F ##Hh7((6:001G1GR^1_`
**85H.Y++H6JO\"//:OP .L/MX&$(*
 	
r  c                 *   d}| j                  |d|      \  }}| j                          | j                  |      }|d   dk7  r't        | j                  dz   |z   dz   |d   z   dz         | j                  ||      }|d   |d	   |d
}d }| j                  ||d      \  }}|||d<   | j                  | j                  ||            }	|dk(  rt        j                  |      }| j                  | j                  |	|      | j                  |      |d      S )NmodifyMarginHelperr>  r  rD   r/  r8  r0  r5   r  )r  r  r  r  rp  reduce)r  r  )r:  r  r  r*   r5   ra  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  s=   )
!55flJW
FV$&>V#tww}z9<VVY_`fYggj||}}))&&9Tl ,

 44VZPf"&GJ;;DKKQW<XY
 8''/F{{499(FK''/N
  	r  r  c                 ^    | j                  |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  r9  r  r  r  r  rB  rE  r  )r  r  r  r  r  s        r  rU  z#coincatch.parse_margin_modification  sU     tU+*X&7O
 	
r  c                 6    d|d<   | j                  || 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=reduce-margin-structure>`
        r   r>  rS  rV  r  r  r  r  s       r  reduce_marginzcoincatch.reduce_margin  s'      .|((&(FKKr  c                 4    d|d<   | j                  ||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=add-margin-structure>`
        rG   r>  addrZ  r[  s       r  
add_marginzcoincatch.add_margin  s%      +|((GGr  c                     d}d}| j                  ||d      \  }}| j                  ||      }t        |      }|dkD  r+t        dt        |            D ]  }||   }|d   |k(  s|c S  |d   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   rn  r  r   r   )r  fetch_positions_for_symbolr  r  )	r  r  r  r>  r  	positionsarrayLengthr  positions	            r  fetch_positionzcoincatch.fetch_position  s     %
44VZPf33FFC	)n?1c)n- $$Q<F#t+#O$ |r  c                     | j                          | j                  |      }|d   |d   d}| j                  | j                  ||            }| j	                  |dg       }| j                  ||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_positionsr4  s          r  ra  z$coincatch.fetch_positions_for_symbol)  s|     	V$Tl ,
 BB4;;wX^C_`@ ~~h3##D6(33r  c                    d}| j                          d}|| j                  |      }g }t        dt        |            D ];  }||   }|j	                  d      }	| j                  |	d      }
|j                  |
       = | j                  |      }t        |      }|dkD  rt        | j                  dz   |z   dz         |d   }n| j                  ||d	|      \  }}d	|i}|d
k(  r3d}| j                  ||d      \  }}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j                  |dg       }| j                  ||      S )ax  
        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   rC  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  rh  )r  r6  r  r>  r  	marketIdsproductTypesr  r  r  marketProductTyperc  r  r  r  r  r  s                    r  fetch_positionszcoincatch.fetch_positions]  s    &
0IL1c)n- 7$Q< s+$($4$4UA$>!##$56	7
  ;;|4Ll+KQ#
 :  >J  !J  K  K*1o"&"?"?
Tacn"oK;
 '!"J!%!>!>vzS_!`J%==4(0%??GU[@\]B ~~h3##D'22r  rd  c                    | j                  |d      }| j                  |d      }| j                  |||      }| j                  |d      }| j                  |d      }d }| j                  |d      }|dk(  rd}n|dk(  rd	}| j                  |d
      }	| j                  |d      }
| j	                  i d|d   dd d|d| j                  |      d| j                  |d      dd d| j                  |d      d|	d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |      d |d | j                  t        j                  |
d!            |	d | j                  |d"      | j                  |d#      d d d d |d$      S )%Nr  r  r  r9  r=  r>  TrA  FrC   keepMarginRater5   rB  rE  	contractsr  r  r  rp  notionalrC  unrealizedPnlunrealizedPLrealizedPnlachievedProfits
collateral
entryPriceaverageOpenPricerc  marketPriceliquidationPricerA  r\  marginRatior  )maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentager}  r  	lastPricer=  r>  r   r  )r  re  r  r  safe_positionrh  r  r.  r  r0   r  )r  rd  r  r  r  rB  r9  isHedgedr=  rC   rq  s              r  parse_positionzcoincatch.parse_position  sv   4 ##Hh7##Hl;((68D%%h8	%%h=
##Hj9}$H&H!!(H5))(4DE!! #
fX&#
$#
 #
 Y/	#

 ))(G<#
 D#
 D**8Z@#
 #
 ))(J?#
 T--hG#
 4++H6GH#
 $#
 $**85GH#
 ))(MB#
  0 0;M N#
  $55jA!#
" h##
$ "&+/+<+<W=O=OP^`e=f+g#'+++HmD#'#4#4Xw#G!#9#
  	r  r  r  c                     	 | j                  ||      }|S # t        $ r[}| j                  | j                  |g       }||d   }n+t	        dt        |            D ]  }||   }|d   |k(  s|} n Y d }~|S d }~ww xY w)Nr   r  )safe_market	Exceptionr  markets_by_idr  r  )r  r  r  r  emarketsWithCurrentIdr  marketWithCurrentIds           r  re  zcoincatch.safe_market_custom  s    	%%h7F   	 $(>>$2D2DhPR#S -a0q#&:";< A*>q*A'*:6(B!4	
 	s    	A:A
A5*A55A:c                 J   d}| j                          i }d}| j                  |d||      \  }}d}d}	|| j                  |      }	|dk(  rU|	| j                  |	d      }
|
|d<   |||d<   | j	                  | j                  ||            }| j                  |dg       }n|dk(  r|||d	<   nd
|d	<   d}| j                  ||d      \  }}|||d<   n| j                         |d<   |||d<   d}|| j                  |d|      }n
|dk(  rd}nd}| j                  |d|      \  }}||d<   | j                  | j                  ||            }| j                  |di       }| j                  |dg       }n!t        | j                  dz   |z   dz   |z         | j                  ||	||      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>`
        ry   rB   Nr  r  rJ  r  rD   rx  r   rs  ry  r  r  r  r  r  r  r/  z () does not support market type )r  r;  r  r   privatePostApiSpotV1AccountBillsr  r  r  r}  r  r:  ,privateGetApiMixV1AccountAccountBusinessBillr  r*   r5   parse_ledger)r  r  rq  rJ  r  r>  r  rP  r  r  r  r  rs  r  r  s                  r  fetch_ledgerzcoincatch.fetch_ledger   s   . #

!??
DRXZde
F}}T*H# ,,X{C	$-! #( <<T[[RX=YZH, ^^Hfb9F6! ',$'($E 99&*gVME6 %*	"%)%6%6%8	" &+
#!K|"00]KX%%"&":":6=R]"^K%0GM"HHU\^dIefHb >>(FB7D^^D(B7Ftww}z9<^^akkll  5%@@r  itemc                    | j                  |d      }| j                  |dd      }d }| j                  |d      }| j                  |||      }| j                  |dd      }d}t	        j
                  |d      rd	}t	        j                  |d
      }t	        j                  | j                  |dd            | j                  |d      d}	| j                  i d| j                  |dd      d|d|d| j                  |      dd d|dd dd d| j                  | j                  |dd            d| j                  ||      d|d   d|dd d| j                  |d      dd d|	|      S )!Nr  r  r  r  r3  r  inr  outz-1r  r   feeCoinr  r5   billIdr  rB  rE  r  	directionreferenceIdreferenceAccountr  bizTypebusinessr  rv  ru  balancer  r  )r  rf  r  re  r0   	string_ltr  r  safe_ledger_entryrh  parse_ledger_entry_typer  r  )
r  r  r  rB  r  r  r  rG  r  r  s
             r  parse_ledger_entryzcoincatch.parse_ledger_entry  s   8 %%dG4	%%dJE##D(3((68D))$
HE	\3/I"--lDAL&&t'9'9$v'NO((y9
 %% '
$$$T8T:'
D'
 '
 Y/	'

 t'
 '
 4'
 '
 D001I1I$PY[e1fg'
 //(C'
 fX&'
 l'
 d'
 T%%dI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}| j                  |||      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  r5  s      r  r  z!coincatch.parse_ledger_entry_type  s   
y

 7
 G	

 (
 :
 :
 J
 h
 x
 $X
 #H
 =
 
 
  '!
" '#
$ ##-!+#(%,&-/
2 tT22r  reasonr   r  headersbodyc
                 0   |sy | j                  |d      }
| j                  dz   |z   }| j                  |d      }|
dk(  xs |
d u }|j                  d      dk\  rq| j                  |di       }| j	                  |dd	g       }| j                  |      s9d
}| j                  |di       }| j                  |d      }| j                  |d      }
|sK| j                  | j                  d   ||       | j                  | j                  d   |
|       t        |      y )Nr  r/  r  r  batchr   r  failure
fail_infosF	errorCodeerrorMsgr  r  )
r  r5   r)  r  r  is_emptythrow_exactly_matched_exceptionrY  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  s   ""8U377S=4'&&x8i'=W_88G!>>(FB7D&&tYbIG==)!^^GQ;
"..z;G**:zB001I;X`a001I7T\]))r  r   GETc           
      R   d|z   }|dk(  r'| j                  |      }t        |      dk7  r|d|z   z  }|dk(  r| j                          | j                  | j	                               }	d}
|dk7  r| j                  |      }|}
|	|z   |z   |
z   }| j                  | j                  |      | j                  | j                        t        j                  d      }| j                  ||	| j                  d| j                  | 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queryrB  r  payload	signaturer   s                 r  signzcoincatch.sign  s)   :U?NN6*E5zQC%K')++---d.?.?.ABIFyy(&(83f<G		$++g"6DKK8PRYR`R`bjkI"kk($-%)]] 2&*&6&6t||ZQX&YG iis#h.fdwOOr  r  )NN)__name__
__module____qualname__r   r  r  r   r  r   r  r   r  r	   r  r    r   r  dictr&  r  strr   r5  r   r?  r3  r   rp  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)  rR  rb  r  rL  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/  r  r  r  r  r%  r'  r   r,  r+  r.  r:  r8  r?  boolrD  r   rG  rJ  rF  r   rV  rU  r\  r_  re  r   ra  ro  r  re  r  r   r  r  r  r  r  __classcell__)r  s   @r  r2   r2      s   z# zx MO 	 !# 3s 3( ') eZ eN <@ I I0 0d $& G+$v, G+RQ4 QF Qf, 02 N/3 N/f N/` 04B \1W \17 \1|K6 KV KZ :>b 1Ns 1N3 1NY 1Nf 26DW[df ]~# ]~c ]~QT ]~koptku ]~~
 
4 
 6:UW K=3 K=s K=# K=\`af\g K=ZU Uv U Un 68 5 5K 5B
6 
0'v '3 '\_ 'jp '  DG ' 8<$]ajl 7@ 7@C 7@WZ 7@r $& F(( F(P0) 0)d [] 07S 07% 07c 07c 07an 07d
 
$ 79 (# (^ (T
h 
R` 
. *.Dt\^ 9E3 9Ec 9E 9Ecghsct 9Ev -1tRV_a #Ec #E #EC #Efjkvfw #EJ DHPR *6S *6% *6# *6Wb *6XL
x L
; L
\ RT N N5 N( gksu w3 wi wy wRW w`c wz w@ 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 5. 5.9 5.I 5.W\ 5.eh 5.  @E 5.n tx  AC A, A,9 A,I A,_d A,mp A,  HL A,F ^ksu A,F FJ  ^b  tx  AC S# SY S^g Sqv S  @C S  X[ S  nq S  HM S*J J J @B p1D$6 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/c z/3 z/U z/x /3TXac "z "z3 "zc "zhlmrhs "zH 48dY]fh _?S _? _?SV _?mqrwmx _?B 48dY]fh {=S {= {=SV {=mqrwmx {=z >BPTcgpr "zs "z# "z]` "zw{  }B  xC "zH CGUYhluw G?C G?s G?be G?  }A  BG  }H G?R CGUYhluw R1C R1s R1be R1  }A  BG  }H R1h 37r 9.s 9.C 9.v /32 r rh ;?r O1c O1C O1b
O Ob9 9 93S 3S 3*HS HS Hs " -1tRV_a H=c H= H=C H=fjkpfq H=T 9=4^bkm XS X# XS XX[ Xrvw|r} X, 57 .4 .4: .4`
D 
* 
33 33 3 >B" '# 's 'R3C 3C 3 15R 
# 
8 =A )\ )\c )\V 24 1S 1 1, 9=R -1S -1# -1^2
t 2
V 2
x 2
h FH 3 L^ :
d 
F 
N` 
$ @B LC L LFX L =? H He HCU H 24 S . >@ 24 24DN 24h 26b J3w J3T(^ J3XDt DV DL3  QT `f " (,$TZ\ hA hAC hAs hAT;t ;x ;; ;z3C 3C 38# s  c TX `c * &eBSW 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  * 0 - . ' & . ) * ) + . * ) 4 %QPP+ QPPr  