
    E#i                        S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJ r   S SKJ!r!  S S	KJ"r"  S S
KJ#r#  S SKJ$r$  S SKJ%r%  S SKJ&r&  S SK'J(r(  S SK)J*r*   " S S\\5      r+g)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTransactionTransferEntry)List)ExchangeError)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)NullResponse)	TICK_SIZE)Precisec                   j  ^  \ rS rSrS\4U 4S jjrS0 S4S\S\S\4U 4S jjjrS r	0 4S\
\   4S	 jjr0 4S
 jrS\S\4S jrSkU 4S jjrS0 4S\S\S\4S jjrSSS0 4S\S\S\S\
\   4S jjrS0 4S\S\4S jjrSkS\S\S\4S jjrSS0 4S\S\S\S\
\   4S jjrS\S\4S jrSkS\S\S\4S jjrS\4S jr0 4S\ 4S jjr!S\ 4S jr"SSS0 4S\S\S\S\
\#   4S  jjr$SSS0 4S\S\S\S\
\#   4S! jjr%SkS"\S#\&S\#4S$ jjr'S%\S\4S& jr(S0 4S'\S\
\)   4S( jjr*0 4S\S\)4S) jjr+SkS#\&S\)4S* jjr,SSS0 4S\S\S\S\
\-   4S+ jjr.SkS,\S#\&S\-4S- jjr/S. r00 4S\S/\1S0\S1\S\24
S2 jjr3SkS3\S#\&S\24S4 jjr4S%\S\4S5 jr5S0 4S\S6\6S7\7S/\1S8\84
S9 jjr9S0 4S\S6\6S7\7S/\1S8\84
S: jjr:S0 4S\S6\6S7\7S/\1S8\84
S; jjr;S0 4S\S6\6S7\7S/\1S8\84
S< jjr<S6\64S= jr=0 4S\S7\7S>\14S? jjr>0 4S\S>\1S\?4S@ jjr@0 4S\S>\1S\?4SA jjrAS0 4SB\S\S\?4SC jjrBS0 4SB\S\S\?4SD jjrCSSS0 4S\S\S\S\
\?   4SE jjrDSSS0 4S\S\S\S\
\?   4SF jjrESSS0 4S\S\S\S\
\?   4SG jjrFSSS0 4S\S\S\S\
\?   4SH jjrGS0 4SB\S\S\?4SI jjrHS0 4S\S\
\?   4SJ jjrISS0 4SB\S\S6\6S7\7S/\8S8\84SK jjrJS0 4SL\
\   S\S\
\?   4SM jjrKSkSN\S\S\?4SO jjrLS%\S\4SP jrMS6\S\4SQ jrNS6\S\4SR jrO0 4S\S\
\P   4SS jjrQS0 4S\S\
\P   4ST jjrRSkSU\S\S\P4SV jjrSS0 4SW\TS\4SX jjrUS0 4S\S\V4SY jjrW0 4S\S\X4SZ jjrYSkS\S\X4S[ jjrZSSS0 4S\S\S\4S\ jjr[SkS\4S] jjr\SSS0 4S\S\S\4S^ jjr]SSS0 4SB\S\S\S\4S_ jjr^S0 4S\S7\7S\?4S` jjr_SaSb0 SS4Sc jr`S\TSd\Se\Sf\Sg\Sh\4Si jraSjrbU =rc$ )ldeepcoin   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_0 S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_E0 S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_E0 SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_E0 STS_SUS_SVS_SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_ESSSSSSSSSSSSSSe.E_SfSgShSiSjSkSlSmSnSoSpSqSr._SsStSuSuSv.SwSxSySzS{.S|._S}S~SSSSSSSSS.00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSSSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S.Sv._SSU R	                  S5      U R	                  S5      S.0_SSSSSSSS.SSSSSSS.SS.SSSSS.SSSS.S SSSS SS.S SSSSSS.S SSS S S SSSS.SS0S.	SS0SS0S.S._SSSSS._S[
        _SSSSSS.SSSSSSSS.0 SSS/0SSSS.SSSSS.SSSSSSS.S._S0 _S[        [        [        [        [        [        [        [        [        [        [        S.[        [        [        [        [        S.S.0E5      $ )Nidr'   nameDeepCoin	countriesSG	rateLimit   versionv1	certifiedFproThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelWithdrawclosePositioncreateConvertTradecreateDepositAddresscreateLimitBuyOrdercreateLimitOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLossOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterest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5m15m30m1H4H12H1D1W1M1Y)r   r   r   r   1h4h12h1d1wr   1yurlszOhttps://github.com/user-attachments/assets/671bd35c-770e-4935-9070-f8fb114f79c4zhttps://api.deepcoin.com)publicprivatezhttps://www.deepcoin.com/zhttps://www.deepcoin.com/docszhttps://s.deepcoin.com/UzkyODgyg?)urldiscount)logoapiwwwdocreferralr   get      )zdeepcoin/market/bookszdeepcoin/market/candleszdeepcoin/market/instrumentszdeepcoin/market/tickerszdeepcoin/market/index-candleszdeepcoin/market/tradesz"deepcoin/market/mark-price-candleszdeepcoin/market/step-marginzdeepcoin/account/balanceszdeepcoin/account/billszdeepcoin/account/positionszdeepcoin/trade/fillszdeepcoin/trade/orderByIDzdeepcoin/trade/finishOrderByIDzdeepcoin/trade/orders-historyz deepcoin/trade/v2/orders-pendingzdeepcoin/trade/funding-ratez-deepcoin/trade/fund-rate/current-funding-ratez deepcoin/trade/fund-rate/historyz%deepcoin/trade/trigger-orders-pendingz%deepcoin/trade/trigger-orders-historyz&deepcoin/copytrading/support-contractsz$deepcoin/copytrading/leader-positionz$deepcoin/copytrading/estimate-profitz#deepcoin/copytrading/history-profit)z"deepcoin/copytrading/follower-rankz"deepcoin/internal-transfer/supportz(deepcoin/internal-transfer/history-orderdeepcoin/rebate/configzdeepcoin/agents/usersz!deepcoin/agents/users/rebate-listzdeepcoin/agents/users/rebateszdeepcoin/asset/deposit-listzdeepcoin/asset/withdraw-listz"deepcoin/asset/recharge-chain-listzdeepcoin/listenkey/acquirezdeepcoin/listenkey/extendzdeepcoin/account/set-leveragezdeepcoin/trade/orderzdeepcoin/trade/replace-orderzdeepcoin/trade/cancel-orderz!deepcoin/trade/batch-cancel-orderz#deepcoin/trade/cancel-trigger-ordergUUUUUU?zdeepcoin/trade/swap/cancel-allzdeepcoin/trade/trigger-orderz#deepcoin/trade/batch-close-positionz!deepcoin/trade/replace-order-sltpz$deepcoin/trade/close-position-by-idsz$deepcoin/copytrading/leader-settingsz"deepcoin/copytrading/set-contractszdeepcoin/internal-transferr   zdeepcoin/asset/transfer)r   postfeestradingz0.0015z0.0010)takermakerfeatures)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricer   triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingmarketBuyRequiresPriced   <   )r   limitdaysBack	untilDayssymbolRequired)r   r   triggerr   r   )r   r   r   daysBackCanceledr   r   r   r   r   ,  )	r   rO   rP   rv   r|   r{   r~   r_   rw   extends)linearinverse)r8   r:   requiredCredentials)apiKeysecretpasswordprecisionModeoptionsi  ERC20TRC20)ETHUSDTUSDCARBITRUMz
BSC(BEP20)SOLBitcoinCardano)r   r   ARBBSCr   BTCADAtypesGTCr   r   )r   r   r   SPOTSWAP)r8   r:   r   r            
   )r8   fundrebater   r   demo)
recvWindowdefaultNetworksnetworksnetworksByIdrt   r   exchangeTypeaccountsByTypecommonCurrencies
exceptions)2431364449194195199100010unsupportedActionlocalIDNotExist)zno availablezfield is requiredznot in acceptable rangez%subscription cluster does not "exist"zmust be equal or lesser than)exactbroad)deep_extendsuperr'   describeparse_numberr$   r!   r   r   r    r"   r   )self	__class__s    G/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/deepcoin.pyr  deepcoin.describe   s9
   h > @ [C
*[C
J[C
 $[C
 	[C

 t[C
 [C
 4[C
  ccc $c 	c
 %c %c Uc "4c 'c tc c !%c  c %ec 'c  &t!c" #D#c$ '%c& ''c( /)c* $T+c, ,T-c. (/c0 01c2 t3c4 5c6 77c8 &t9c: (;c< &u=c> (?c@ ,UAcB -eCcD %dEcF TGcH  IcJ KcL /McN &tOcP #DQcR $TScT )%UcV $UWcX $UYcZ +E[c\ "5]c^ &t_c` (acb  ccd +Eecf +Egch &uicj #Dkcl *4mcn $Tocp "4qcr tsct  ucv %ewcx /ycz "5{c| }c~ !$c@  AcB dCcD $UEcF +EGcH !$IcJ "4KcL eMcN !$OcP uQcR #DScT  UcV 'WcX $UYcZ !$[c\ *4]c^ (_c` )%acb uccd uecf gch Uicj tkcl $)$)%*"'$( % #"!&#( !Ec[C
X Y[C
r i89 36< #s[C
L 123478349:23>?78	3Q0! 5a /	
 3A 9! 8 ;A 6q H ;A @ @ A! ?  ?!" >q#$ ?@>?DE2312=>9:7889>?6756;>7. 7 6q	
 <Q >u 9! 7 >q <Q ? ? =a 5a 1!  21!A2@M[C
N !..x8!..x8O[C
Z $&*(,$($)%*-
 -2)-+/ ).(-).1
 &*7 $(#'"&#(	( #'$)277$: %)&+!$$&%)*.& #'&+!$#'$)*.( $(&+!$$(,0%)#'$)*.	*  #u=@ "6 "6 	G[[C
j " $k[C
t Yu[C
v ""##$ %$%' $$! ff-! !   #"""	!  #A(w[C
H
 I
[C
J
 '++$&''%/)3'1 %1):/9=G4>K
[C
 [ [	    N
methodNamemarketc                    > U R                  US5      nU R                  US5      nU R                  US5      nUc  Ub  U R                  USU05      n[        [        U ]  XX45      $ )NinstTypetype)safe_stringomitextendr  r'   handle_market_type_and_params)r  r  r  paramsdefaultValuer  r  r  s          r  r"  &deepcoin.handle_market_type_and_paramsw  sk    ##FJ76:./Lx3[[&();<FXtB:W]llr  c                 `    U R                  U R                  S0 5      nU R                  X!U5      $ )Nr   )	safe_dictr   r  )r  r  exchangeTypess      r  convert_to_instrument_type#deepcoin.convert_to_instrument_type  s+    t||^RHT::r  c                    SS/nU R                  U R                  S5      nUb  U R                  USU5      nOU R                  U R                  SU5      n/ n/ n[        S[	        U5      5       H&  nUR                  U R                  X&   U5      5        M(     Un[        S[	        U5      5       H  nU R                  XTU   5      nM     U$ )z

https://www.deepcoin.com/docs/DeepCoinMarket/getBaseInfo

retrieves data on all markets for okcoin
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
r8   r:   rt   r   r   )r'  r   	safe_listrangelenappendfetch_markets_by_typearray_concat)r  r#  r   fetchMarketsOptionpromisesresultis          r  fetch_marketsdeepcoin.fetch_markets  s      !^^DLL.I)NN#5wFENN4<<GEq#e*%AOOD66uxHI &q#h-(A&&v{;F )r  c                     SU R                  U5      0nU R                  U R                  X25      5      nU R                  US/ 5      nU R	                  U5      $ )Nr  data)r)  "publicGetDeepcoinMarketInstrumentsr!  r,  parse_markets)r  r  r#  requestresponsedataResponses         r  r0  deepcoin.fetch_markets_by_type  sY    77=
 ::4;;w;WX< ~~h;!!,//r  c                    U R                  US5      nU R                  US5      nUS:H  nUS:H  nU R                  US5      nU R                  USS5      nS nS n	U R                  U5      n
U R                  U5      nU
S-   U-   nS nU(       a)  US	:g  nU(       a  UOUnU R                  U5      n	US
-   U	-   nU R                  U R                  US0 5      nU R                  USS5      n[
        R                  " US5      nU R                  US5      nU R                  US5      nU R                  [
        R                  " UU5      5      nU R                  US5      nU R                  U0 SU_SU_SU
_SU_SU	_SU_SU_SU_SU_SU_SU=(       a    [
        R                  " US5      _SU_SS_SS_SUS:H  _S U_S!U_U(       a  U(       + OS U(       a  U R                  US"5      OS S S S S S U R                  US#5      U R                  US$5      S%.U R                  S5      U R                  U5      S&.U R                  US'5      US&.S S S&.S S S&.S(.US).
E5      $ )*NinstIdr  r8   r:   baseCcyquoteCcy /USD:r   lever1maxMktSzmaxLmtSzstater+   symbolbasequotesettlebaseIdquoteIdsettleIdr  r9   r;   Fr<   activelivecontractr   ctVallotSztickSz)amountr   )minmaxminSz)leveragerZ  r   cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTypecreated	precisionlimitsinfo)r  safe_string_lowersafe_currency_codesafe_dict_2r   r%   
string_maxr  r!  	string_gtsafe_number)r  r  r+   r  r8   r:   rQ  rR  rS  rP  rN  rO  rM  isLinearr   maxLeveragemaxMarketSizemaxLimitSize	maxAmountrL  s                       r  parse_marketdeepcoin.parse_market  s   \ fh/%%fj9!!&)4""6:r:&&v.''0e#5(H"*wH,,X6Fc\F*F		4B?&&vw<((c:((<''
;%%g&8&8&UV	  1{{4 0"
"0"
f0"
 D0"
 U	0"

 f0"
 f0"
 w0"
 0"
 D0"
 D0"
 dD 1 1+s C0"
 D0"
 e0"
 e0"
 evo0"
  !0"
" h#0"
$ *.H4AED,,VW=4"**67;))&(;  ,,S1,,[9
  ++FG<$
  
  $ _0"
 0 0	r  c                 
  > [         [        U ]  X5      n[        UR	                  5       5      n[        S[        U5      5       H2  nX4   nX   nUS   (       d  M  US   US   -   nU/U R                  U'   M4     U R                  $ )Nr   r:   rQ  rR  )	r  r'   set_marketslistkeysr-  r.  markets_by_idmarkets)	r  r{  
currenciessymbolsr5  rM  r  additionalIdr  s	           r  rw  deepcoin.set_markets8  s    $3GHw||~&q#g,'AZF_Ff~~%h/&2CC4:8""<0 ( ||r  rM  r   c           	          U R                  5         U R                  U5      nUc  SnUS   US.nU R                  U R                  XS5      5      nU R	                  US0 5      nU R                  XqSSSSS	5      $ )
a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.deepcoin.com/docs/DeepCoinMarket/marketBooks

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Ni  r+   )rA  szr9  bidsasksr   r   )load_marketsr  publicGetDeepcoinMarketBooksr!  r'  parse_order_book)r  rM  r   r#  r  r<  r=  r9  s           r  fetch_order_bookdeepcoin.fetch_order_bookC  s     	V$=ETl
 44T[[5QR" ~~h3$$T4ANNr  r   sincec           	         U R                  5         SnSnU R                  USSS5      u  puU(       a(  U R                  USS05      nU R                  SXXBXV5      $ U R	                  U5      nU R                  US5      n	U R                  US5      nU R                  U R                  X"5      n
US   U
S	.nUb  XKS'   U R                  US5      nUb  XS'   U R                  US5      nU R                  USS5      nU(       ae  U R                  US5      nUbP  U R                  U5      nUc  UOUnX>U-  S-  -   nUb  [        UU5      nU R                  5       n[        UU5      US'   S
nU	S:X  a!  U R                  U R                  X5      5      nOGU	S:X  a!  U R                  U R                  X5      5      nO U R                  U R                  X5      5      nU R!                  US/ 5      nU R#                  UXX45      $ )aR  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.deepcoin.com/docs/DeepCoinMarket/getKlineData
https://www.deepcoin.com/docs/DeepCoinMarket/getIndexKlineData
https://www.deepcoin.com/docs/DeepCoinMarket/getMarkKlineData

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest candle to fetch
:param str [params.price]: "mark" or "index" for mark price and index price candles
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r   Frw   paginatecalculateUntilTr   r+   )rA  barNr   untilafteri  r   r   r9  )r  handle_option_and_paramsr!  "fetch_paginated_call_deterministicr  r  r   r   safe_integer	safe_boolparse_timeframer[  milliseconds'publicGetDeepcoinMarketMarkPriceCandles#publicGetDeepcoinMarketIndexCandlespublicGetDeepcoinMarketCandlesr,  parse_ohlcvs)r  rM  	timeframer  r   r#  maxLimitr  r  r   r  r<  r  r  durationnumberOfCandlesendTimenowr=  r9  s                       r  fetch_ohlcvdeepcoin.fetch_ohlcvj  s   $ 	88z[`a[[*:D)ABF::<X]jp{{V$  167+t	ETl
 $G!!&'2$GYYvw/F0@%HYYv'78F   //	:/4}(5o#="EE$!'51G'')#&w#4 F?CCDKKPWD`aHg??G@\]H::4;;w;WXH6 ~~h3  v%GGr  r}  c                 @   U R                  5         U R                  U5      nU R                  U5      nSnU R                  SX25      u  pBSU R	                  U5      0nU R                  U R                  XR5      5      nU R                  US/ 5      nU R                  Xq5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://www.deepcoin.com/docs/DeepCoinMarket/getMarketTickers

: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
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r  r9  )	r  market_symbolsget_market_from_symbolsr"  r)  publicGetDeepcoinMarketTickersr!  r,  parse_tickers)r  r}  r#  r  
marketTyper<  r=  tickerss           r  fetch_tickersdeepcoin.fetch_tickers  s     	%%g.--g6
!??PV_
77
C
 66t{{77ST..626!!'33r  tickerc           	         U R                  US5      nU R                  US5      nU R                  XBS5      nUS   nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	US	   (       a  US
   (       a  U	n
Un	U
nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU R	                  U5      _SU_SU_SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU_SU_SU_SS _SS _SS _SS _U	US S US .EU5      $ )!NtsrA  -rM  r   open24h	volCcy24hvol24hr:   r   high24hlow24h	timestampdatetimehighlowbidbidPx	bidVolumebidSzaskaskPx	askVolumeaskSzvwapopenclosepreviousClosechange
percentageaverage)
baseVolumequoteVolume	markPrice
indexPricerh  )r  r  safe_marketsafe_tickeriso8601)r  r  r  r  marketIdrM  r   r  r  r  tempr  r  s                r  parse_tickerdeepcoin.parse_ticker  s   * %%fd3	##FH5!!(C8!/	2&&v{;%%fh7
&>fY/D$JK	2vx0 !
f!
!
 Y/!
 D	!

 3!
 4##FG4!
 ))&':!
 4##FG4!
 ))&':!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&-!
. / 	r  c                    U R                  5         U R                  U5      nSUS   0nUb  X6S'   U R                  U5      nXvS'   U R                  U R	                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )a  
get the list of most recent trades for a particular symbol

https://www.deepcoin.com/docs/DeepCoinMarket/getTrades

: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(default 100, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
rA  r+   r   productGroupr9  )r  r  get_product_group_from_marketpublicGetDeepcoinMarketTradesr!  r,  parse_trades)
r  rM  r  r   r#  r  r<  r  r=  r9  s
             r  fetch_tradesdeepcoin.fetch_trades  s     	V$fTl
 $G99&A".55dkk'6RS~~h3  u<<r  c                 >    SnUS   (       a  US   (       a  SnU$ SnU$ )NSpotr:   r   SwapUSwap )r  r  r  s      r  r  &deepcoin.get_product_group_from_market-  s0    &>h&   &r  tradec                 8   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nS nU R                  US5      nUb(  U R                  US5      n	U R                  U	5      n
UU
S.nU R	                  UUU R                  U5      US   U R                  US	5      U R                  US
5      S U R                  U5      UU R                  USS5      U R                  USS5      S US.U5      $ )NrA  r  sideexecTypefeefeeCcyr_  currencyrM  tradeIdordIdfillPxpxfillSzr  )rh  r  r  rM  r+   orderr  takerOrMakerr  r   rZ  r_  r  )r  r  r  rj  
safe_trader  parse_taker_or_makersafe_string_2)r  r  r  r  r  r  r  r  feeCostfeeCurrencyIdfeeCurrencyCodes              r  parse_tradedeepcoin.parse_trade6  s>   @ ##E84!!(3%%eT2	v.##E:6""5%0 ,,UH=M"55mDO+C "Y/X&""5)4%%eW5 55h?''x>(($? 
  	r  r  c                 0    SSS.nU R                  X!U5      $ )Nr   r   )TMr  )r  r  r   s      r  r  deepcoin.parse_taker_or_makert  s$    
 ::r  c                     U R                  5         SnU R                  SSX5      u  p!SU R                  U5      0nU R                  U R	                  X15      5      nU R                  U5      $ )a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://www.deepcoin.com/docs/DeepCoinAccount/getAccountBalance

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: "spot" or "swap", the market type for the balance
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
r8   r[   Nr  )r  r"  r)  !privateGetDeepcoinAccountBalancesr!  parse_balance)r  r#  r  r<  r=  s        r  fetch_balancedeepcoin.fetch_balance{  sq     	
!??PTV\i
77
C
 99$++g:VW!!(++r  c                    US S S.nU R                  US/ 5      n[        S[        U5      5       H}  nX4   nU R                  US5      nU R	                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US	5      US
'   XU'   M     U R                  U5      $ )N)rh  r  r  r9  r   ccybaltotal	frozenBalusedavailBalfree)r,  r-  r.  r  rj  accountsafe_balance)	r  r=  r4  balancesr5  balancerM  coder  s	            r  r  deepcoin.parse_balance  s      

 >>(FB7q#h-(AkG%%gu5F**62DllnG#//?GG"..wDGFO"..w
CGFO"4L )   ((r  r  c                    U R                  5         SnU R                  USSS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 0 nSnUb  U R                  U5      nUS   US	'   Ub  X&S
'   Ub  X6S'   U R	                  US5      nUb  XS'   U R                  US5      nU R                  U R                  Xd5      5      n	U R                  U	S0 5      n
U R                  U
S/ 5      nSS0nU R                  XX#U5      $ )a  
fetch all deposits made to an account

https://www.deepcoin.com/docs/assets/deposit

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Frg   r  r  Nr   2   r+   coin	startTimesizer  r  r9  r  deposit)r  r  fetch_paginated_call_cursorr  r  r   "privateGetDeepcoinAssetDepositListr!  r'  r,  parse_transactionsr  r  r  r   r#  r  r<  r  r  r=  r9  itemstransactionParamss                r  fetch_depositsdeepcoin.fetch_deposits  s-    	88R\^cd33OTRWagimoprtuu}}T*H&tnGFO#(K #FO!!&'2!&IYYvw/F::4;;w;WX~~h3tVR0I#
 &&uFWXXr  c                    U R                  5         SnU R                  USSS5      u  pTU(       a  U R                  SXX4SSSS5	      $ 0 nSnUb  U R                  U5      nUS   US	'   Ub  X&S
'   Ub  X6S'   U R	                  US5      nUb  XS'   U R                  US5      nU R                  U R                  Xd5      5      n	U R                  U	S0 5      n
U R                  U
S/ 5      nSS0nU R                  XX#U5      $ )aQ  
fetch all withdrawals made from an account

https://www.deepcoin.com/docs/assets/withdraw

: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 boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Frg   r  r  Nr   r  r+   r  r  r  r  r  r9  r  
withdrawal)r  r  r  r  r  r   #privateGetDeepcoinAssetWithdrawListr!  r'  r,  r  r  s                r  fetch_withdrawalsdeepcoin.fetch_withdrawals  s-    	88R\^cd33OTRWagimoprtuu}}T*H&tnGFO#(K #FO!!&'2!&IYYvw/F;;DKK<XY~~h3tVR0L#
 &&uFWXXr  transactionr  c                    U R                  US5      nU R                  US5      nU R                  XB5      nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  U5      n	U R                  U R                  US5      5      n
0 SU_SS _S	U_SU_S
U	_SS _SS _SU R                  US5      _SS _SS _SS _SU
_SS _SS _SU_SU_SU R                  U5      _S S S S S.S.E$ )NtxHashr  rZ  
createTime	chainNamestatusrh  r+   r  networkaddressFrom	addressToaddresstagFromtagTotagr  updatedtxidr  r  )r  r_  )internalcommentr  )r  rj  rn  safe_timestampnetwork_id_to_codeparse_transaction_statusr  )r  r!  r  r/  
currencyIdr  rZ  r  	networkIdr'  r&  s              r  parse_transactiondeepcoin.parse_transaction  s    X6%%k6:
&&z<!!+x8''\B	$$[+>	)))4..t/?/?X/VW
K
$
 
 f	

 w
 4
 
 t''Y?
 t
 T
 4
 f
 D
 t
 D
  !
" Y/#
$  )
 	
r  r&  c                 0    SSS.nU R                  X!U5      $ )Npendingok)
confirmingsucceedr  r  r&  statusess      r  r4  !deepcoin.parse_transaction_status,  s$    #
 &99r  codesc                    U R                  5         Uc  [        U R                  S-   5      e[        U5      nUS:w  a  [	        U R                  S-   5      eUS   nU R                  U5      nUS   SS.nU R                  U R                  Xb5      5      nU R                  US0 5      nU R                  US/ 5      n	S	U0n
U R                  XS
U
5      $ )af  
fetch deposit addresses for multiple currencies and chain types

https://www.deepcoin.com/docs/assets/chainlist

:param str[]|None codes: list of unified currency codes, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `address structures <https://docs.ccxt.com/#/?id=address-structure>`
z= fetchDepositAddresses requires a list with one currency coder   r   r+   en)currency_idlangr9  rx  r  F)r  r   r+   r.  r"   r  (privateGetDeepcoinAssetRechargeChainListr!  r'  r,  parse_deposit_addresses)r  rA  r#  lengthr  r  r<  r=  r9  rx  additionalParamss              r  fetch_deposit_addresses deepcoin.fetch_deposit_addresses3  s     	=#DGG.m$mnnUQ;tww)hhiiQx==&#D>
 @@WA]^6 ~~h3~~dFB/"
 ++D@PQQr  c                    U R                  5         U R                  US5      nU R                  U R                  S0 5      nU R                  XA5      nU(       a  UOUnUb  U R	                  US5      nU R                  U/U5      n[        U5      nU R                  US0 5      nUb*  US:  a$  [        SU5       H  n	Xi   n
U
S   U:X  d  M  U
nM     U$ )a  
fetch the deposit address for a currency associated with self account

https://www.deepcoin.com/docs/assets/chainlist

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: unified network code for deposit chain
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r'  r   r   r   )r  r  r'  r   r   rJ  r.  r-  )r  r  r#  r'  r   defaultNetwork
addressessrH  r*  r5  entrys              r  fetch_deposit_addressdeepcoin.fetch_deposit_addressk  s     	""695..7H"M))/@$'.YYvy1F114&&A
Z..Q3fqj1f%"#w.#G & r  c                     U R                  US5      nU R                  US5      nU R                  U5        US U R                  U5      UU R                  US5      S.$ )Nchainr*  memo)rh  r  r'  r*  r-  )r  check_addressr3  )r  r=  r  rS  r*  s        r  parse_deposit_addressdeepcoin.parse_deposit_address  sg    &   73""8Y77#..u5##Hf5
 	
r  c                    U R                  5         SnU R                  SSXE5      u  pTSU R                  U5      0nSnUb  U R                  U5      nUS   US'   Ub  X&S'   Ub  X6S'   U R	                  US	5      nUb  XS
'   U R                  US	5      nU R                  U R                  Xd5      5      n	U R                  U	S/ 5      n
U R                  XX#5      $ )a  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://www.deepcoin.com/docs/DeepCoinAccount/getAccountBills

:param str [code]: unified currency code
:param int [since]: timestamp in ms of the earliest ledger entry
:param int [limit]: max number of ledger entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest ledger entry
:param str [params.type]: 'spot' or 'swap', the market type for the ledger(default 'spot')
:returns dict[]: a list of `ledger structures <https://docs.ccxt.com/#/?id=ledger>`
r8   ro   Nr  r+   r  r  r   r  beforer9  )
r  r"  r)  r  r  r   privateGetDeepcoinAccountBillsr!  r,  parse_ledger)r  r  r  r   r#  r  r<  r  r  r=  r9  s              r  fetch_ledgerdeepcoin.fetch_ledger  s     	
!??tU[h
77
C
 }}T*H%d^GEN$G$G!!&'2 %HYYvw/F66t{{77ST6 ~~h3  >>r  itemc                    U R                  US5      nU R                  US5      n[        R                  " U5      n[        R                  " US5      (       a  SOSnU R                  US5      nU R                  Xr5      nU R                  US5      nU R                  UU R                  US5      US S S U R                  U5      US	   UUU R                  U5      S U R                  US
5      S S S.U5      $ )Nr  balChg0outinr  r  billIdr  r  )rh  r+   	directionr  referenceAccountreferenceIdr  r  rZ  r  r  rY  r  r&  r  )	r  r  r%   
string_abs	string_ltsafe_currencysafe_ledger_entryparse_ledger_entry_typer  )	r  r^  r  r  r  rZ  re  r5  r  s	            r  parse_ledger_entrydeepcoin.parse_ledger_entry  s    %%dD1	!!$1##F+$..vs;;E	%%dE2
%%j;f-%%""42" $006 ("Y/%%dE2'
  ! 	r  c                 6    SSSSSS.nU R                  X!U5      $ )Nr  r   r  )rI  2345r  )r  r  
ledgerTypes      r  rl   deepcoin.parse_ledger_entry_type  s-    

 
$77r  rZ  fromAccount	toAccountc                    SnU R                  USS5      u  peU(       a  UOU R                  US5      nUc  [        U R                  S-   5      eU R	                  5         U R                  U5      nU R                  U R                  S0 5      nU R                  XU5      n	U R                  XU5      n
US   U R                  X5      U	U
US.nU R                  U R                  X5      5      nU R                  US	0 5      nU R                  X5      nU R                  U R                  S0 5      nU R                  US
S5      nU(       a  X>S'   XNS'   X.S'   U$ )aY  
transfer currency internally between wallets on the same account

https://www.deepcoin.com/docs/assets/transfer

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from('spot', 'inverse', 'linear', 'fund', 'rebate' or 'demo')
:param str toAccount: account to transfer to('spot', 'inverse', 'linear', 'fund', 'rebate' or 'demo')
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.userId]: user id
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr   userIduidz' transfer() requires a userId parameterr  r+   )rD  rZ  from_idto_idrz  r9  fillResponseFromRequestTrv  rw  rZ  )r  r  r   r+   r  r  r'  r   currency_to_precision privatePostDeepcoinAssetTransferr!  parse_transferr  )r  r  rZ  rv  rw  r#  ry  r  r  fromIdtoIdr<  r=  r9  r   transferOptionsr}  s                    r  r   deepcoin.transfer  sS    66vz8T!t'7'7'F>#DGG.W$WXX==&6FK!!.{K9E#D>00>
 88W9UV ~~h3&&t6..z2F"&..B[]a"b"&1]#$-[!!'Xr  r   c                     U R                  US5      nU R                  S U5      nUS S S US S S U R                  U5      S.	$ )NretCode)	rh  r+   r  r  r  rZ  rv  rw  r&  )r  rj  parse_transfer_status)r  r   r  r&  currencyCodes        r  r  deepcoin.parse_transferG  sX     !!(I6..tX>$008

 
	
r  c                     US:X  a  gg)Nra  r;  failedr  )r  r&  s     r  r  deepcoin.parse_transfer_status]  s    S=r  r  r  r   c                 &   U R                  5         U R                  U5      nU R                  US5      nU R                  XX4XV5      n	Sn
Ub  U R	                  U	5      n
OU R                  U	5      n
U R                  U
S0 5      nU R                  X5      $ )a}  
create a trade order

https://www.deepcoin.com/docs/DeepCoinTrade/order
https://www.deepcoin.com/docs/DeepCoinTrade/triggerOrder

: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
:param str [params.timeInForce]: *non trigger orders only* 'GTC'(Good Till Cancel), 'IOC'(Immediate Or Cancel) or 'PO'(Post Only)
:param bool [params.postOnly]: *non trigger orders only* True to place a post only order
:param bool [params.reduceOnly]: *non trigger orders only* a mark to reduce the position size for margin, swap and future orders
:param float [params.triggerPrice]: the price a trigger order is triggered at
:param float [params.stopLoss.triggerPrice]: the price that a stop loss order is triggered at
:param float [params.takeProfit.triggerPrice]: the price that a take profit order is triggered at
:param str [params.positionSide]: if position mode is one-way: set to 'net', if position mode is hedge-mode: set to 'long' or 'short'
:param bool [params.hedged]: *swap only* True for hedged mode, False for one way mode
:param str [params.marginMode]: *swap only*'cross' or 'isolated', the default is 'cash' for spot and 'cross' for swap
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   Nr9  )r  r  r  create_order_request$privatePostDeepcoinTradeTriggerOrderprivatePostDeepcoinTradeOrderr'  parse_order)r  rM  r  r  rZ  r   r#  r  r   r<  r=  r9  s               r  create_orderdeepcoin.create_orderb  s    2 	V$''?++F$V#@@IH  99'BH~~h3--r  c                    U R                  U5      nU R                  US5      nUSLn	U R                  US5      n
U
b%  US   (       a  Ub  [        U R                  S-   5      eU	(       a  U R	                  XX4XV5      $ U R                  XX4XV5      $ )z8
@ignore
       helper function to build request
       r   Nr_  r8   zO createOrder() accepts a cost parameter for spot non-trigger market orders only)r  r  r   r+   create_trigger_order_requestcreate_regular_order_request)r  rM  r  r  rZ  r   r#  r  r   isTriggerOrderr_  s              r  r  deepcoin.create_order_request  s    
 V$''?&d2/&>l&> +|!|}}44V4QV__44V4QV__r  c                    U R                  U5      nUnU R                  X&5      u  pUS   UUS.n	U R                  US5      n
U
b  XS'   U R                  US5      nU R	                  US0 5      nU R                  US5      nUb'  U R                  US/5      nU R                  X5      U	S'   U R	                  US	0 5      nU R                  US5      nUb'  U R                  US	/5      nU R                  X5      U	S
'   US:H  nUb4  U(       a  [        U R                  S-   5      eU R                  X5      U	S'   OU(       d  [        U R                  S-   5      eUS   (       a  U R                  US5      nUbL  U(       d  [        U R                  S-   5      eU R                  US5      nU R                  UU5      U	S'   SU	S'   OU R                  X5      U	S'   SU	S'   X9S'   SU	S'   OU R                  X5      U	S'   SnU R                  SUU5      u  nnUU	S'   SnU R                  USSU5      u  nnUU	S'   SnU R                  USS5      nU(       a  US:X  a  S nOUS!:X  a  S"nOUS:X  a  S"nOUS!:X  a  S nUU	S#'   U R                  X5      $ )$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 you want to trade in units of the 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 float [params.cost]: *spot only* the cost of the order in units of the quote currency, for market orders only
       :param str [params.clientOrderId]: a unique id for the order
       :param str [params.timeInForce]: 'GTC'(Good Till Cancel), 'IOC'(Immediate Or Cancel) or 'PO'(Post Only)
       :param bool [params.postOnly]: True to place a post only order
       :param bool [params.reduceOnly]: a mark to reduce the position size for margin and swap orders
       :param float [params.stopLossPrice]: the price that a stop loss order is triggered at
       :param float [params.takeProfitPrice]: the price that a take profit order is triggered at
       :param str [params.marginMode]: *swap only* 'cross' or 'isolated', the default is 'cash' for spot and 'cross' for swap
       :param str [params.mrgPosition]: *swap only* 'merge' or 'split', the default is 'merge'
       r+   )rA  r  ordTypeclientOrderIdNclOrdIdstopLossr   slTriggerPx
takeProfittpTriggerPxr  zB createOrder() does not require a price argument for market ordersr  z9 createOrder() requires a price argument for limit ordersr8   r_  zC createOrder() accepts a cost parameter for spot market orders onlyr  	quote_ccytgtCcybase_ccyr  cashtdModecrossrO   mergemrgPosition
reduceOnlyFbuyshortselllongposSide)r  'handle_type_post_only_and_time_in_forcer  r   r'  price_to_precisionr   r+   cost_to_precisionamount_to_precisionhandle_margin_mode_and_paramsr  r  r!  )r  rM  r  r  rZ  r   r#  r  	orderTyper<  r  r  r   r  r   isMarketOrderr_  r   r  r  r  s                        r  r  %deepcoin.create_regular_order_request  s   ( V$	 HHV	Tl  
" ((A$!.IYYv7F>>&*b9((>B$YYv
|4F%)%<%<V%SGM"^^FL"=
**:~F&YYv~6F%)%<%<V%UGM") +o!opp 33FBGDMTWW'bbcc&>##FF3D$$TWW/t%tuu662 $ 6 6vt D$/! $ 8 8 H$.!"FO &GH 44VDGDM J!%!C!CMSY[e!fJ *GH!K"&"?"?Wdfq"rK%0GM"GeDJ5=%GV^$G5=$GV^%G!(GI{{7++r  c                    U R                  U5      nUS   U R                  US   5      U R                  X5      UUS.nU R                  US5      n	U R	                  X5      US'   Ub  U R	                  X5      US'   OUS:X  a  [        U R                  S-   5      eSn
U R                  S	Xj5      u  pS
nU
S:X  a  SnU R                  USS5      nU R                  US5      nXS'   XS'   US   (       a6  U(       a  US:X  a  SUS'   O#US:X  a  SUS'   OUS:X  a  SUS'   OUS:X  a  SUS'   SnU R                  US	SU5      u  pXS'   U R                  X5      $ )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 you want to trade in units of the base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param bool [params.reduceOnly]: a mark to reduce the position size for margin orders
       :param str [params.marginMode]: *swap only* 'cross' or 'isolated', the default is 'cash' for spot and 'cross' for swap
       r+   r  )rA  r  r  r  r  r   r   r   zA createOrder() requires a price argument for limit trigger ordersr  rO   r   isolatedr   r  FisCrossMarginr  r:   r  r  r  r  r  r  r  )r  
capitalizer  r  r  r   r+   r  r  r   r  r!  )r  rM  r  r  rZ  r   r#  r  r<  r   r   r  r  r  s                 r  r  %deepcoin.create_trigger_order_request	  s    V$Tl OOF6N;**6: 
 ''? #'"9"9&"O#66vEGGW_#DGG.q$qrr
!??vb
#M^^FL%@
6<0#0 &&>5=)0GI&V^)/GI&5=)/GI&V^)0GI&";;FMS`bmn!,{{7++r  c                     SnU R                  US:H  US:H  U5      u  p2U(       a  SnU R                  U5      nU R                  US5      nUb  US:X  a  SnX/$ )NFr  	post_onlyr   r   ioc)handle_post_onlyhandle_time_in_forcer   )r  r  r#  postOnlyr   s        r  r  0deepcoin.handle_type_post_only_and_time_in_forceN  sk    001A4;CVX^_D//76=1#+*>D~r  r_  c                 V    U R                  USU05      nU R                  USUSSU5      $ )a  
create a market order by providing the symbol, side and cost
:param str symbol: unified symbol of the market to create an order in
:param str side: 'buy' or 'sell'
: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>`
r_  r  r   Nr!  r  )r  rM  r  r_  r#  s        r  create_market_order_with_cost&deepcoin.create_market_order_with_costY  s3     Vfd^4  4D&IIr  c                 V    U R                  USU05      nU R                  USSSSU5      $ )an  
create a market buy order by providing the symbol and cost
: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>`
r_  r  r  r   Nr  r  rM  r_  r#  s       r  !create_market_buy_order_with_cost*deepcoin.create_market_buy_order_with_coste  s3     Vfd^4  5!T6JJr  c                 V    U R                  USU05      nU R                  USSSSU5      $ )ao  
create a market sell order by providing the symbol and cost
: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>`
r_  r  r  r   Nr  r  s       r  "create_market_sell_order_with_cost+deepcoin.create_market_sell_order_with_costp  s3     Vfd^4  61dFKKr  r+   c                 8   U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nUS   US.nU R	                  U R                  XS5      5      nU R                  US/ 5      nU R                  US0 5      nU R                  X5      $ )as  
fetches information on a closed order made by the user

https://www.deepcoin.com/docs/DeepCoinTrade/finishOrderByID

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
. fetchClosedOrder() requires a symbol argumentr+   rA  r  r9  r   )	r  r   r+   r  &privateGetDeepcoinTradeFinishOrderByIDr!  r,  r'  r  )	r  r+   rM  r#  r  r<  r=  r9  rO  s	            r  fetch_closed_orderdeepcoin.fetch_closed_order{  s     	>#DGG.^$^__V$Tl
 >>t{{7?[\^ ~~h3tQ+..r  c                 \   U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nUS   US.nU R	                  U R                  XS5      5      nU R                  US/ 5      n[        U5      nUS:X  a  gU R                  US0 5      n	U R                  X5      $ )aI  
fetch an open order by it's id

https://www.deepcoin.com/docs/DeepCoinTrade/orderByID

:param str id: order id
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r+   r  r9  r   )
r  r   r+   r   privateGetDeepcoinTradeOrderByIDr!  r,  r.  r'  r  )
r  r+   rM  r#  r  r<  r=  r9  rH  rO  s
             r  fetch_open_orderdeepcoin.fetch_open_order  s     	>#DGG.^$^__V$Tl
 88W9UV~~h3TQ;tQ+..r  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ U R                  USS5      nSnU R	                  USU5      u  ptSn0 n	Ub  U R                  U5      nUS   U	S'   S	n
U R                  XxXJ5      u  pU R                  U
5      U	S
'   Ub  X9S'   SnU(       ar  US:w  a  [        U R                  S-   U-   S-   5      eUc  [        U R                  S-   5      eU R                  US5      nU R                  U R                  X5      5      nO U R                  U R                  X5      5      nU R                  US/ 5      nU R!                  XX#5      $ )a  

https://www.deepcoin.com/docs/DeepCoinTrade/ordersHistory
https://www.deepcoin.com/docs/DeepCoinTrade/triggerOrdersHistory

fetches information on multiple canceled and closed orders made by the user
:param str [symbol]: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: whether to fetch trigger/algo orders(default False)
:param str [params.type]: *non trigger orders only* 'spot' or 'swap', the market type for the orders
:param str [params.state]: *non trigger orders only* 'canceled' or 'filled', the order state to filter by
:param str [params.OrderType]: *trigger orders only* 'limit' or 'market'
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Fr\   r  r   r  Nr+   rA  r8   r  r    z"() does not support trigger orderszM fetchCanceledAndClosedOrders() requires a symbol argument for trigger ordersr9  )r  r  fetch_paginated_call_dynamicr  handle_param_stringr  r"  r)  r   r+   r   r   +privateGetDeepcoinTradeTriggerOrdersHistoryr!  $privateGetDeepcoinTradeOrdersHistoryr,  parse_orders)r  rM  r  r   r#  r  r   r  r  r<  r  r=  r9  s                r   fetch_canceled_and_closed_orders)deepcoin.fetch_canceled_and_closed_orders  s   $ 	88A_akl445SU[dirr..E:3
!55flJW
[[(F &tGH
!??
TZg
"==jI
$G;; 3!;>b!bcc~'  3B  )B  C  CYYvy1F8 GGT[HdeH` @@WA]^H~~h3  u<<r  c                 z    SnU R                  USU05      nU R                  USS05      nU R                  XX45      $ )aH  
fetches information on multiple canceled orders made by the user

https://www.deepcoin.com/docs/DeepCoinTrade/ordersHistory

:param str symbol: unified market symbol of the market the orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: 'spot' or 'swap', the market type for the orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r]   r  rL  canceledr!  r  r  rM  r  r   r#  r  s         r  fetch_canceled_ordersdeepcoin.fetch_canceled_ordersW  sF     +
VlJ%?@Vgz%:;44VERRr  c                 z    SnU R                  USU05      nU R                  USS05      nU R                  XX45      $ )aF  
fetches information on multiple closed orders made by the user

https://www.deepcoin.com/docs/DeepCoinTrade/ordersHistory

:param str symbol: unified market symbol of the market the orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: 'spot' or 'swap', the market type for the orders
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r_   r  rL  filledr  r  s         r  fetch_closed_ordersdeepcoin.fetch_closed_ordersi  sF     )
VlJ%?@Vgx%8944VERRr  c                     U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nU R	                  USS5      nSUS   0nUb  X7S'   U R                  USS	5      nSn	U(       aJ  U R                  US5      nU R                  US
   5      US'   U R                  U R                  Xt5      5      n	O$XgS'   U R                  U R                  Xt5      5      n	U R                  U	S/ 5      n
U R                  XX#SS05      $ )a  
fetch all unfilled currently open orders

https://www.deepcoin.com/docs/DeepCoinTrade/ordersPendingV2
https://www.deepcoin.com/docs/DeepCoinTrade/triggerOrdersPending

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: whether to fetch trigger/algo orders(default False)
:param int [params.index]: *non trigger orders only* pagination index, default is 1
:param str [params.orderType]: *trigger orders only* 'limit' or 'market'
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz- fetchOpenOrders() requires a symbol argumentr   r   rA  r+   r   r   Fr  r  r9  r&  r  )r  r   r+   r  r  r  r   r)  +privateGetDeepcoinTradeTriggerOrdersPendingr!  &privateGetDeepcoinTradeV2OrdersPendingr,  r  )r  rM  r  r   r#  r  r   r<  r   r=  r9  s              r  fetch_open_ordersdeepcoin.fetch_open_orders{  s     	>#DGG.]$]^^V$!!&'15fTl
 $G..E:YYvy1F"&"A"A&."QGJ@ GGT[HdeH$G^ BB4;;wC_`H~~h3  uh=OPPr  c                    U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nUS   US.nSnU R	                  USS5      nU(       a3  U R                  US5      nU R                  U R                  XS5      5      nO U R                  U R                  XS5      5      nU R                  US0 5      nU R                  X5      $ )a  
cancels an open order

https://www.deepcoin.com/docs/DeepCoinTrade/cancelOrder

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: whether the order is a trigger/algo order(default False)
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz) cancelOrder() requires a symbol argumentr+   r  r   Fr9  )r  r   r+   r  r  r   *privatePostDeepcoinTradeCancelTriggerOrderr!  #privatePostDeepcoinTradeCancelOrderr'  r  )	r  r+   rM  r#  r  r<  r=  r   r9  s	            r  cancel_orderdeepcoin.cancel_order  s     	>#DGG.Y$YZZV$Tl
 ..E:YYvy1FFFt{{SZGcdH??G@\]H~~h3--r  c                     U R                  5         Uc  [        U R                  S-   5      eU R                  U5      nUS   (       a  [	        U R                  S-   5      eU R                  U5      nU R                  US5      nSnUb  U R                  US5      nUS:X  a  SnSnU R                  US	S
U5      u  prUS   UUU(       a  SOSS.nU R                  U R                  X5      5      n	U R                  U	S/ 5      n
U R                  X5      $ )a8  
cancel all open orders in a market

https://www.deepcoin.com/docs/DeepCoinTrade/cancelAllOrder

:param str symbol: unified market symbol of the market to cancel orders in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: *swap only* 'cross' or 'isolated', the default is 'cash' for spot and 'cross' for swap
:param bool [params.merged]: *swap only* True for merged positions, False for split positions(default True)
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
z- cancelAllOrders() requires a symbol argumentr8   z4 cancelAllOrders() is not supported for spot marketsr   r   r  r   Tr>   mergedr+   )InstrumentIDProductGroupIsCrossMarginIsMergeModer9  )r  r   r+   r  r"   r  r  r   r  %privatePostDeepcoinTradeSwapCancelAllr!  r,  r  )r  rM  r#  r  r  r   encodedMarginModer  r<  r=  r9  s              r  cancel_all_ordersdeepcoin.cancel_all_orders  s    	>#DGG.]$]^^V$&>tww)__``99&A%%fl;
!YYv|4FZ'$%!66v?PRZ\bc"4L(. &1A	
 ==dkk'>Z[~~h3  ..r  c                    U R                  5         SU0nSn	Ub8  U R                  U5      n	U	S   (       a  [        U R                  S-   5      eU	S   nU R	                  US5      n
U R	                  US5      nU
SL=(       d    USLnSnU(       a  Uc  Ub  [        U R                  S-   5      eU
b,  U(       a  U R                  X*5      OU R                  U
5      US	'   Ub,  U(       a  U R                  X+5      OU R                  U5      US
'   U R                  USS/5      nU R                  U R                  X5      5      nO~Ub,  Ub  U R                  X&5      US'   OU R                  U5      US'   Ub,  Ub  U R                  X%5      US'   OU R                  U5      US'   U R                  U R                  X5      5      nU R                  US0 5      nU R                  U5      $ )a  
edit a trade order

https://www.deepcoin.com/docs/DeepCoinTrade/replaceOrder
https://www.deepcoin.com/docs/DeepCoinTrade/replaceTPSL

:param str id: cancel order id
:param str [symbol]: unified symbol of the market to create an order in(not used in deepcoin editOrder)
:param str [type]: 'market' or 'limit'(not used in deepcoin editOrder)
:param str [side]: 'buy' or 'sell'(not used in deepcoin editOrder)
: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 float [params.stopLossPrice]: the price that a stop loss order is triggered at
:param float [params.takeProfitPrice]: the price that a take profit order is triggered at
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`

OrderSysIDNr8   z. editOrder() is not supported for spot marketsrM  r   r   z editOrder() with stopLossPrice or takeProfitPrice cannot have price or amount. Either use stopLossPrice/takeProfitPrice or price/amount to edit order.r  r  r   volumer9  )r  r  r"   r+   rn  r   r  number_to_stringr   (privatePostDeepcoinTradeReplaceOrderSltpr!  r  $privatePostDeepcoinTradeReplaceOrderr'  r  )r  r+   rM  r  r  rZ  r   r#  r<  r  r   r   isTPSLr=  r9  s                  r  
edit_orderdeepcoin.edit_order1  s
   $ 	"
 [[(Ff~"477-]#]^^H%F((A**63DEt+M1L!v'9   ,E  "E  F  F([a)@)@)Wgkg|g|  ~K  hL&*]c)@)@)Yimi~i~  @O  jP&YYv9J'KLFDDT[[QXEabH %'+'>'>v'MGG$'+'<'<U'CGG$!%(,(@(@(PGH%(,(=(=f(EGH%@@WA]^H~~h3%%r  idsc                 "   U R                  5         SnUb3  U R                  U5      nUS   (       a  [        U R                  S-   5      eSU0nU R	                  U R                  XS5      5      nU R                  US/ 5      nU R                  Xt5      $ )a  
cancel multiple orders
:param str[] ids: order ids
:param str [symbol]: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr8   z1 cancelOrders() is not supported for spot marketsOrderSysIDsr9  )r  r  r"   r+   (privatePostDeepcoinTradeBatchCancelOrderr!  r,  r  )r  r  rM  r#  r  r<  r=  r9  s           r  cancel_ordersdeepcoin.cancel_ordersi  s     	[[(Ff~"477-`#`aa3
 @@WA]^~~h3  ..r  r  c                    U R                  US5      nU R                  X25      nU R                  US5      nU R                  USS5      n[        U5      S:  a  U R	                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUS:X  a  S nU R                  US5      n	S n
U	b5  U R                  US	5      nU R                  U5      U R                  U	5      S
.n
U R                  0 SU R                  US5      _SU R                  US5      _SU R                  U5      _SU_SS _SU R                  US5      _SU R                  U5      _SUS   _SU R                  U5      _SU R                  U5      _SU R                  US5      _SU R                  USS5      _SU_SU R                  US5      _SU R                  US 5      _S!S _S"U R                  U R                  US#5      5      _U R                  US$S%5      U R                  US&S'5      S S U
S U(       a  US(:H  OS US).EU5      $ )*NrA  cTimerD     rL  r  avgPxr  r  r  r+   r  r  r  r  r  lastTradeTimestamplastUpdateTimestampuTimer&  rM  r  r   r  r   r  ordPxr  rZ  r  r  	accFillSz	remainingr   	triggerPxr  tpTriggerPricer  slTriggerPricer  )r   r   r_  tradesr  r  r  rh  )r  r  r  r.  r2  r  rj  
safe_orderr  parse_order_statusparse_order_typeparse_order_time_in_forcer  	omit_zero)r  r  r  r  r  timestampStringrL  r  r  r  r  r  s               r  r  deepcoin.parse_order~  s   F ##E84!!(3%%eW5	**5'2>"$++E7;I  0$$UI6	""5'2b=G((9$&&ue4G))'2 33MBC   
$""5'2 
T--eY? 
 Y/ 
 	 

 !$ 
 "4#4#4UG#D 
 d--e4 
 fX& 
 D)))4 
 499)D 
 D$$UF3 
 T''tW= 
 w 
 d&&ud3 
 d&&uk: 
  ! 
" DNN4+;+;E;+OP# 
$  $11%HXY!//}FVW6?k1T3 
4 5 	r  c                 4    SSSSS.nU R                  X!U5      $ )Nr  closedr  )rU  r  r  partially_filledr  r>  s      r  r  deepcoin.parse_order_status  s*    " &	
 &99r  c                 6    SSSSSS.nU R                  X!U5      $ )Nr   r  )r   r  r  r  TPSLr  )r  r  r   s      r  r  deepcoin.parse_order_type  s-     
 T22r  c                 4    SSSSS.nU R                  X!U5      $ )Nr   r   r   )r  r  r   r  r  )r  r  timeInForcess      r  r  "deepcoin.parse_order_time_in_force	  s*    	
 D99r  c                    U R                  5         U R                  U5      nU R                  US   5      nUUS   S.nU R                  U R	                  XR5      5      nU R                  US/ 5      nU R                  XsS   /5      $ )ao  
fetch open positions for a single market

https://www.deepcoin.com/docs/DeepCoinAccount/accountPositions

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>`
r  r+   )r  rA  r9  rM  )r  r  r)  "privateGetDeepcoinAccountPositionsr!  r,  parse_positions)r  rM  r#  r  instrumentTyper<  r=  r9  s           r  fetch_positions_for_symbol#deepcoin.fetch_positions_for_symbol	  s     	V$88H&Tl
 ::4;;w;WX~~h3##D(+;*<==r  c                 z   U R                  5         U R                  USSS5      nSnSnUb#  U R                  US5      nU R                  U5      nU R	                  SXBU5      u  p2U R                  U5      nSU0nU R                  U R                  Xr5      5      nU R                  US/ 5      n	U R                  X5      $ )a@  
fetch all open positions

https://www.deepcoin.com/docs/DeepCoinAccount/accountPositions

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
NTr:   r   r   r  r9  )
r  r  r  r  r"  r)  r.  r!  r,  r/  )
r  r}  r#  r  r  firstSymbolr0  r<  r=  r9  s
             r  fetch_positionsdeepcoin.fetch_positions"	  s     	%%gtT4@
**7A6K[[-F!??@PRXblm
88D
 ::4;;w;WX2 ~~h3##D22r  positionc                 r   U R                  US5      nU R                  X25      nU R                  US5      nU R                  0 SUS   _SU R                  US5      _SU_SU R	                  U5      _SU R                  US	5      _S
S _SU R                  US5      _SS _SU R                  U R                  US5      5      _SS _SS _SS _SU R                  US5      _SS _SU R                  US5      _SU R                  US5      _SS_U R                  US5      S S S S U R                  US5      S S S S US.E5      $ )NrA  r  rM  r+   posIdr  r  	contractsposr`  r  r  notionalr^  rH  unrealizedPnlrealizedPnl
collateral
entryPricer  r  liquidationPriceliqPxr   mgnModer   T	useMarginr  )maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentagemarginRatior  	lastPricer   r   r  rh  )r  r  r  safe_positionr  r   )r  r7  r  r  r  s        r  parse_positiondeepcoin.parse_positionT	  s   & ##Hh7!!(3%%h8	!! #
fX&#
$""8W5#
 #
 Y/	#

 ))(E:#
 D#
 D$$Xy9#
 #
 t'7'7''JK#
 T#
 4#
 $#
 $**8W=#
 #
  0 07 C#
  $**8Y?!#
" d##
$ "&!1!1(K!H+/!'+#'#4#4Xw#G!#9#
  	r  r^  c                    Uc  [        U R                  S-   5      eUS:  a  [        U R                  S-   5      eU R                  5         U R	                  U5      nSnU R                  SX55      u  pSUS:w  a  US:w  a  [        U R                  S-   5      eSnU R                  USS	U5      u  pcUS:w  a  US
:w  a  [        U R                  S-   5      eUUUS   US.nU R                  U R                  Xs5      5      nU$ )a  
set the level of leverage for a market

https://www.deepcoin.com/docs/DeepCoinAccount/accountSetLeverage

: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.marginMode]: 'cross' or 'isolated'(default is cross)
:param str [params.mrgPosition]: 'merge' or 'split', default is merge
:returns dict: response from the exchange
z) setLeverage() requires a symbol argumentr   z+ setLeverage() leverage should be minimum 1r  r   r  zT setLeverage() requires a marginMode parameter that must be either cross or isolatedr  r  splitzB setLeverage() mrgPosition parameter must be either merge or splitr+   )rH  rC  rA  r  )	r   r+   r   r  r  r  r  %privatePostDeepcoinAccountSetLeverager!  )	r  r^  rM  r#  r  r   r  r<  r=  s	            r  set_leveragedeepcoin.set_leverage	  s    >#DGG.Y$YZZ a<TWW'TTUUV$
!??vb
'!
j(@TWW'}}~~";;FMS`bmn'!kW&<TWW'kkll!Tl&	
 ==dkk'>Z[ r  c                    U R                  5         U R                  USSSS5      nSnSnUb#  U R                  US5      nU R                  U5      nU R	                  SXBU5      u  p2SnUS:X  a  S	nOUS:w  a  [        U R                  S
-   5      eSU0nU R                  U R                  Xr5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  X5      $ )a  
fetch the funding rate for multiple markets

https://www.deepcoin.com/docs/DeepCoinTrade/currentFundRate

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.subType]: "linear" or "inverse"
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
r:   Tr   Nr   rm   r  r   r  zG fetchFundingRates() subType parameter must be either linear or inverser  r9  current_fund_rates)r  r  r  r  handle_sub_type_and_paramsr   r+   1privateGetDeepcoinTradeFundRateCurrentFundingRater!  r'  r,  parse_funding_rates)r  r}  r#  subTypefirstMarketr4  r  r<  r=  r9  ratess              r  fetch_funding_ratesdeepcoin.fetch_funding_rates	  s     	%%gvtT4H"**7A6K++k2K99:M{dkliH TWW'ppqq
 II$++V]Jfg& ~~h3t%92>''77r  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eUS   U R	                  U5      S.nU R                  U R                  XB5      5      nU R                  US0 5      nU R                  US/ 5      nU R                  US0 5      nU R                  X5      $ )a3  
fetch the current funding rate

https://www.deepcoin.com/docs/DeepCoinTrade/currentFundRate

: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>`
r:   z2 fetchFundingRate() is only valid for swap marketsr+   )rA  r  r9  rT  r   )
r  r  r   r+   r  rV  r!  r'  r,  parse_funding_rate)	r  rM  r#  r  r<  r=  r9  rZ  rO  s	            r  fetch_funding_ratedeepcoin.fetch_funding_rate	  s     	V$f~*^ ^__Tl::6B
 II$++V]Jfg ~~h3t%92>ua,&&u55r  c                     U R                  USS5      nU R                  X25      n0 SU_SU_SS _SS _SS _SS _S	S _S
S _SU R                  US5      _SS _SS _SS _SS _SS _SS _SS _SS _SS 0E$ )NinstrumentIdinstrumentIDrh  rM  r  r  interestRateestimatedSettlePricer  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolrn  )r  rV  r  r  rM  s        r  r^  deepcoin.parse_funding_rate
  s    %%hO!!(3
H
f
 
 $	

 D
 #D
 
 
 4++HmD
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                 F   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X6S'   U R	                  U R                  Xd5      5      nU R                  US0 5      nU R                  US/ 5      n	U R                  XX#5      $ )a  
fetches historical funding rate prices

https://www.deepcoin.com/docs/DeepCoinTrade/fundingRateHistory

:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: timestamp in ms of the earliest funding rate to fetch
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.page]: pagination page number
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
z5 fetchFundingRateHistory() requires a symbol argumentrA  r+   r  r9  rows)	r   r+   r  r  &privateGetDeepcoinTradeFundRateHistoryr!  r'  r,  parse_funding_rate_histories)
r  rM  r  r   r#  r  r<  r=  r9  rs  s
             r  fetch_funding_rate_history#deepcoin.fetch_funding_rate_history3
  s     >#DGG.e$effV$fTl
 #FO>>t{{7?[\. ~~h3~~dFB/00uLLr  c                     U R                  US5      nU R                  USS5      nU R                  XBS S5      nUUS   U R                  US5      UU R	                  U5      S.$ )N
CreateTimerc  rb  r:   rM  rate)rh  rM  rf  r  r  )r2  r  r  rn  r  )r  rh  r  r  rc  s        r  parse_funding_rate_history#deepcoin.parse_funding_rate_historyd
  sr     ''l;	))$O!!,fEX&++D&9"Y/
 	
r  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ SnUb  U R                  U5      nSnU R	                  SXdU5      u  ptSU R                  U5      0nUb  US   US'   Ub  X(S	'   Ub  X8S
'   U R                  US5      n	U	b  U R                  US5      nXS'   U R                  U R                  X5      5      n
U R                  U
S/ 5      nU R                  XX#5      $ )aH  
fetch all trades made by the user

https://www.deepcoin.com/docs/DeepCoinTrade/tradeFills

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest trade to fetch
:param str [params.type]: 'spot' or 'swap', the market type for the trades(default is 'spot')
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Frv   r  Nr8   r  r+   rA  beginr   r  endr9  )r  r  r  r  r"  r)  r  r   privateGetDeepcoinTradeFillsr!  r,  r  )r  rM  r  r   r#  r  r  r  r<  r  r=  r9  s               r  fetch_my_tradesdeepcoin.fetch_my_tradesx
  s5    	88R\]44_fUZcc[[(F
!??QWakl
77
C
  &tGH$G$G!!&'2YYvw/F"EN44T[[5QR4 ~~h3  u<<r  c                     U R                  5         U R                  US5      nUc  Uc  [        U R                  S-   5      eU R	                  SU0U5      nU R                  X#XE5      $ )a  
fetch all the trades made from a single order

https://www.deepcoin.com/docs/DeepCoinTrade/tradeFills

: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
:param str [params.type]: 'spot' or 'swap', the market type for the trades
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
r  zK fetchOrderTrades requires a symbol argument or a market type in the paramsr  )r  r  r   r+   r!  r  )r  r+   rM  r  r   r#  r  s          r  fetch_order_tradesdeepcoin.fetch_order_trades
  sh     	%%ff5
>j0#DGG.{${||gr]F3##F5AAr  c                    U R                  5         U R                  U5      nU R                  U5      nU R                  US5      nU R	                  US5      nUS   US.nSn	Uc$  Uc!  U R                  U R                  X5      5      n	O;Ub  U R                  US5      nU/US'   U R                  U R                  X5      5      n	U R	                  U	S/ 5      n
U R                  X5      $ )aF  
closes open positions for a market

https://www.deepcoin.com/docs/DeepCoinTrade/batchClosePosition
https://www.deepcoin.com/docs/DeepCoinTrade/closePositionByIds

:param str symbol: Unified CCXT market symbol
:param str [side]: not used by deepcoin
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str|None [params.positionId]: the id of the position you would like to close
:param str[]|None [params.positionIds]: list of position ids to close(for batch closing)
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`

positionIdpositionIdsr+   )rA  r  Nr9  )
r  r  r  r  r,  *privatePostDeepcoinTradeBatchClosePositionr!  r   *privatePostDeepcoinTradeClosePositionByIdsr  )r  rM  r  r#  r  r  r  r  r<  r=  r9  s              r  close_positiondeepcoin.close_position
  s     	V$99&A%%fl;
nnV];Tl(
 +"5FFt{{SZGcdH%6<8*4&FFt{{SZGcdH~~h3--r  r   GETc                 2   UnUS:X  a)  U R                  U5      n[        U5      (       a  USU-   -  nU R                  S   U   S-   U-   n	US:X  a  U R                  5         U R	                  5       n
U R                  U
5      nX-   S-   U-   nU R                  UU R                  SS.nUS:w  a  U R                  U5      nSUS	'   X-  nU R                  U R                  U5      U R                  U R                  5      [        R                  S
5      nXS'   XXeS.$ )Nr  ?r   rE  r   200103)zDC-ACCESS-KEYzDC-ACCESS-TIMESTAMPzDC-ACCESS-PASSPHRASEappidzapplication/jsonzContent-Typebase64zDC-ACCESS-SIGN)r   methodbodyheaders)	urlencoder.  r   check_required_credentialsr  r  r   r   jsonhmacencoder   hashlibsha256)r  pathr   r  r#  r  r  requestPathqueryr   r  dateTimepayload	signatures                 r  signdeepcoin.sign
  s   U?NN6*E5zzsU{*iis#c)K7)++-))+I||I.H'#-;G!%'/(,!	G yy(*<'		$++g"6DKK8PRYR`R`bjkI(1$%dOOr  reasonr   r  r  r  c
                    U R                  US0 5      n
U R                  US5      nU R                  US5      nU R                  U
S5      nU R                  U
S5      nU R                  U
S5      nUb  US:X  a  Ub  UnU R                  U
S5      nUbA  [        S	[	        U5      5       H(  nU R                  UU0 5      nU R                  US5      nM*     U R
                  S
-   U-   nUc  Ub  UnU R                  U
S5      nUc  Ub  UnUS:w  d  US:w  d	  Ub  US:w  a  U R                  U R                  S   UU5        U R                  U R                  S   UU5        U R                  U R                  S   UU5        U R                  U R                  S   UU5        [        U5      eU R                  U
S/ 5      nSU
;   a  Uc  [        U5      eg )Nr9  msgr  sCodesMsg	errorCoderD  	errorListr   r  r  r1   ra  r  r  rx  )r'  r  r,  r-  r.  r+   throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   r#   )r  r  r  r   r  r  r  r=  requestHeadersrequestBodyr9  r  messageCoder  r  r  r  r5  rO  feedbackr  rx  s                         r  handle_errorsdeepcoin.handle_errors  s   ~~h3x/&&x8  w/f-$$T;7	O#)$2BCNN45	 1c)n-y!R8 ,,UK@	 . 77S=4'M	 5E""43M 3ECK[C/U5F5TW<001I;X`a001I5RZ[001I3PXY001I3PXY))>>$3D$T\"8,,r  r  )N)d__name__
__module____qualname____firstlineno__r   r  strr   r"  r)  r   r6  r0  dictrt  rw  r	   r   r  rx  r  r   r   r  r   r  r   r  r  r  r   r  r   r  r  r   r  r  r   r7  r4  r   rJ  rP  rV  r
   r\  rm  rl  floatr   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  r  r   r1  r5  rL  intrQ  r   r[  r   r_  r^  rv  r{  r  r  r  r  r  __static_attributes____classcell__)r  s   @r  r'   r'      s   \# \|
 OS[]lp m mV mux m m; $& $v, 0 24 #0Jv4 vF vp	 :>b %Os %O3 %OY %ON 26DW[df VH# VHc VHQT VHkoptku VHp 04B 4W 47 4,:4 : :6 :x 6:UW =3 =s =# =\`af\g =2F s < <v < <|;S ; $& ,( ,&) )@ *.Dt\^ &Y3 &Yc &Y &Ycghsct &YP -1tRV_a &Yc &Y &YC &Yfjkvfw &YP,
T ,
X ,
Q\ ,
\:s :s : 8<B 6RW 6R4P^K_ 6Rp 79 # ^ 8
 
N 
< (,$TZ\ <? <?C <?s <?aefqar <?|#t #x #; #J8 [] 3S 3% 3c 3c 3an 3j
t 
x 
= 
,C C 
 gksu 2.3 2.i 2.y 2.RW 2.`c 2.h os{} `3 `i `y `Z_ `hk `$ w{  DF _,3 _,i _,y _,bg _,ps _,B w{  DF C,3 C,i C,y C,bg C,ps C,J	I 	 _a 
JC 
Jy 
JPU 
J RT 	K 	K5 	KX] 	K SU 	L 	LE 	LY^ 	L 9=R D/S D/# D/E D/L 7;2 /3 / /% /6 >BPTcgpr y=s y=# y=]` y=w{  }B  xC y=v 37TX\eg SC Ss SRU Slpqvlw S$ 154VZce S# SS SPS Sjnotju S$ /3TXac qQ qQ3 qQc qQhlmrhs qQf 37r .s .C .e .< /32 #/ #/$u+ #/J `drv  @B 6&S 6&# 6&Y 6&i 6&Y\ 6&lo 6&p ;?r /c /C /dSXk /*p pv p pd: : :3S 3S 3:c :c : >@ > >DN >, 26b 03w 03T(^ 03d3t 3V 3x 3j 9=R 2S 2# 2h 6:" 087 08 08d 68 $6 $6K $6L
6 
[ 
< 8<$]ajl /M /MC /MWZ /Mb
v 
( -1tRV_a A=c A= A=C A=F 9=4^bkm BS B# BS BX[ B* =A  .S  .	  .PU  .D &eBSW P4# s  c TX `c  r  r'   ),ccxt.base.exchanger   ccxt.abstract.deepcoinr   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   typingr   ccxt.base.errorsr   r   r   r   r    r!   r"   r#   ccxt.base.decimal_to_precisionr$   ccxt.base.preciser%   r'   r  r  r  <module>r     se    ( .  r  r  r  r  r  r  * . ' . ) * ) ) 4 %S,x S,r  