
    ei                    0   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ 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+  G d dee          Z,dS )    )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                       e Zd Zdef fdZdi dfdededef fdZd Zi fde	e         fdZ
i fd	Zdedefd
Zdi 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di fdedefdZdidededefdZddi fdededede	e         fdZdedefdZdidededefdZdefdZi fdefdZ defdZ!dddi fdededede	e"         fdZ#dddi fdededede	e"         fd Z$did!ed"e%de"fd#Z&d$edefd%Z'di fd&ede	e(         fd'Z)i fdede(fd(Z*did"e%de(fd)Z+dddi fdededede	e,         fd*Z-did+ed"e%de,fd,Z.d- Z/i fded.e0d/ed0ede1f
d1Z2did2ed"e%de1fd3Z3d$edefd4Z4di fded5e5d6e6d.e0d7e7f
d8Z8di fded5e5d6e6d.e0d7e7f
d9Z9di fded5e5d6e6d.e0d7e7f
d:Z:di fded5e5d6e6d.e0d7e7f
d;Z;d5e5fd<Z<i fded6e6d=e0fd>Z=i fded=e0de>fd?Z?i fded=e0de>fd@Z@di fdAedede>fdBZAdi fdAedede>fdCZBdddi fdededede	e>         fdDZCdddi fdededede	e>         fdEZDdddi fdededede	e>         fdFZEdddi fdededede	e>         fdGZFdi fdAedede>fdHZGdi fdede	e>         fdIZHddi fdAeded5e5d6e6d.e7d7e7fdJZIdi fdKe	e         dede	e>         fdLZJdidMedede>fdNZKd$edefdOZLd5edefdPZMd5edefdQZNi fdede	eO         fdRZPdi fdede	eO         fdSZQdidTededeOfdUZRdi fdVeSdefdWZTdi fdedeUfdXZVi fdedeWfdYZXdidedeWfdZZYdddi fdededefd[ZZdidefd\Z[dddi fdededefd]Z\dddi fdAedededefd^Z]di fded6e6de>fd_Z^d`dai ddfdbZ_deSdceddedeedfedgefdhZ` xZaS )jdeepcoinreturnc                 `   |                      t          t          |                                           i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcddddddddddddddddddedfdgdhdidjdkdldmdndodpdqdrdsdtdududvdwdxdydzd{d|d}d~ddddddddddddii dddddddddddddddddddddddddddddddddddddddddddd	i ddddddddddddddddddddddddddddddddddvdd|                     d          |                     d          diddddddddddddddddddddddddddd dddd ddd ddddddd ddd d d ddddddid	ddiddiddddddddt
          ddddddddddddddȜi dddgidddd͜dddddМddddddd՜d֜di dt          t          t          t          t          t          t          t          t          t          t          dٜt          t          t          t          t          dڜdۜi          S )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/ddf3e178-c3b6-409d-8f9f-af8b7cf80454z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/trade/funding-ratez-deepcoin/trade/fund-rate/current-funding-ratez deepcoin/trade/fund-rate/historyz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/trigger-orders-pendingz%deepcoin/trade/trigger-orders-historyz&deepcoin/copytrading/support-contractsz$deepcoin/copytrading/leader-positionz$deepcoin/copytrading/estimate-profitz#deepcoin/copytrading/history-profitz"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   rN   rO   ru   r{   rz   r}   r^   rv   extends)linearinverse)r7   r9   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)r7   r9   r   r            
   )r7   fundrebater   r   demo)
recvWindowdefaultNetworksnetworksnetworksByIdrs   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    Y/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/deepcoin.pyr  zdeepcoin.describe   s/   h 5 5 > > @ @ [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( /)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 c 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 c 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 c 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 cl $)$)%*"'$( % #"!&#( !Ec c c[C
X  Y[C
r i89  36< #  s[C
L 123478349:23>?7878IJ<=  3Q0! 5a /	
 3A 9! 8 ;A @ @ A! ? ? >q =a  =a!" CA#$ 3412=>9:7889>?67565  87. 7 6q	
 <Q >u 9! 7 >q <Q ? ? =a 5a 1!  21!;/ /!@ @M[C
N !..x88!..x88 O[C
Z $&*(,$($)%*- -
 -2)-+/ ).(-).1 1
 &*7 7 $(#'"&#(	( ( #'$)277$ $: %)&+!$$&%)*.& & #'&+!$#'$)*.( ( $(&+!$$(,0%)#'$)*.	* 	*  #u= =@ "6 "6 	 G G[[C
j " $ $k[C
t Yu[C
v ""##$ $ %$%' $$ ! ff-! !     #"""	! !  # #A( (w[C
H
 I
[C
J
 '++$&''%/)3'1  %1):/9=G4>  K
[C
 [C
 [ [ [	    N
methodNamemarketc                    |                      |d          }|                     |d          }|                      |d          }|||                     |d|i          }t          t          |                               ||||          S )NinstTypetype)safe_stringomitextendr  r'   handle_market_type_and_params)r  r  r  paramsdefaultValuer  r  r  s          r  r   z&deepcoin.handle_market_type_and_paramsx  s    ##FJ776:..//Lx3[[&();<<FXt$$BB:vW]_klllr  c                 h    |                      | j        di           }|                     |||          S )Nr   )	safe_dictr   r  )r  r  exchangeTypess      r  convert_to_instrument_typez#deepcoin.convert_to_instrument_type  s1    t|^RHHtT:::r  c                   K   ddg}|                      | j        d          }||                     |d|          }n|                     | j        d|          }g }g }t          dt	          |                    D ]1}|                    |                     ||         |                     2t          j        |  d{V }t          dt	          |                    D ]}| 	                    |||                   }|S )a  

        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
        r7   r9   rs   Nr   r   )
r$  r   	safe_listrangelenappendfetch_markets_by_typeasynciogatherarray_concat)r  r!  r   fetchMarketsOptionpromisesresultis          r  fetch_marketszdeepcoin.fetch_markets  s       !^^DL.II)NN#5wFFEENN4<GGEq#e**%% 	J 	JAOOD66uQxHHIIII 2222222q#h--(( 	< 	<A&&vx{;;FFr  c                    K   d|                      |          i}|                     |                     ||                     d {V }|                     |dg           }|                     |          S )Nr  data)r&  "publicGetDeepcoinMarketInstrumentsr  r(  parse_markets)r  r  r!  requestresponsedataResponses         r  r,  zdeepcoin.fetch_markets_by_type  s      77==
 @@WV\A]A]^^^^^^^^< ~~h;;!!,///r  c                    |                      |d          }|                     |d          }|dk    }|dk    }|                      |d          }|                      |dd          }d }d }	|                     |          }
|                     |          }|
dz   |z   }d }|r)|d	k    }|r|n|}|                     |          }	|d
z   |	z   }|                     | j        |di           }|                      |dd          }t          j        |d          }|                      |d          }|                      |d          }|                     t          j        ||                    }|                      |d          }|                     |i d|d|d|
d|d|	d|d|d|d|d|d|ot          j	        |d          d|ddddd|dk    d |d!||r| nd |r| 
                    |d"          nd d d d d d | 
                    |d#          | 
                    |d$          d%|                     d          |                     |          d&| 
                    |d'          |d&d d d&d d d&d(|d)
          S )*NinstIdr  r7   r9   baseCcyquoteCcy /USD:r   lever1maxMktSzmaxLmtSzstater*   symbolbasequotesettlebaseIdquoteIdsettleIdr  r8   r:   Fr;   activelivecontractr   ctVallotSztickSz)amountr   )minmaxminSz)leveragerV  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  r7   r9   rM  rN  rO  rL  rJ  rK  rI  isLinearr   maxLeveragemaxMarketSizemaxLimitSize	maxAmountrH  s                       r  parse_marketzdeepcoin.parse_market  s   \ fh//%%fj99!!&)44""6:r::&&v..''00e# 	+5(H"*6wwH,,X66Fc\F*F	4B??&&vw<<(c::((<<''
;;%%g&8&U&UVV	  11{{4 0"
"0"
f0"
 D0"
 U	0"

 f0"
 f0"
 w0"
 0"
 D0"
 D0"
 dD 1+s C C0"
 D0"
 e0"
 e0"
 evo0"
  !0"
" h#0"
$ *.7H4AEOD,,VW===4"**67;;))&(;;   ,,S11,,[99 
  ++FG<<$ 
   
    $ _0"
 0"
 0"
 0 0 0	r  c                 N   t          t          |                               ||          }t          |                                          }t          dt          |                    D ]6}||         }||         }|d         r|d         |d         z   }|g| j        |<   7| j        S )Nr   r9   rM  rN  )	r  r'   set_marketslistkeysr)  r*  markets_by_idmarkets)	r  rv  
currenciessymbolsr3  rI  r  additionalIdr  s	           r  rr  zdeepcoin.set_markets9  s    $''33GZHHw||~~&&q#g,,'' 	< 	<AQZFV_Ff~ <%h/&2CC4:8"<0|r  rI  r   c           	      D  K   |                                   d{V  |                     |          }|d}|d         |d}|                     |                     ||                     d{V }|                     |di           }|                     ||ddddd	          S )
a4  
        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*   )r=  szr6  bidsasksr   r   )load_marketsr  publicGetDeepcoinMarketBooksr  r$  parse_order_book)r  rI  r   r!  r  r9  r:  r6  s           r  fetch_order_bookzdeepcoin.fetch_order_bookD  s       !!!!!!!!!V$$=ETl
 
 ::4;;wPV;W;WXXXXXXXX" ~~h33$$T64ANNNr  r   sincec           	        K   |                                   d{V  d}d}|                     |ddd          \  }}|r9|                     |ddi          }|                     d||||||           d{V S |                     |          }|                     |d          }	|                     |d          }|                     | j        ||          }
|d	         |
d
}|||d<   |                     |d          }|||d<   |                     |d          }| 	                    |dd          }|rw|                     |d          }|_| 
                    |          }||n|}|||z  dz  z   }|t          ||          }|                                 }t          ||          |d<   d}|	dk    r0|                     |                     ||                     d{V }ne|	dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     |||||          S )a  
        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
        Nr   Frv   paginatecalculateUntilTr   r*   )r=  barr   untilafteri  r   r   r6  )r~  handle_option_and_paramsr  "fetch_paginated_call_deterministicr  r  r  r   safe_integer	safe_boolparse_timeframerW  milliseconds'publicGetDeepcoinMarketMarkPriceCandles#publicGetDeepcoinMarketIndexCandlespublicGetDeepcoinMarketCandlesr(  parse_ohlcvs)r  rI  	timeframer  r   r!  maxLimitr  r  r   r  r9  r  r  durationnumberOfCandlesendTimenowr:  r6  s                       r  fetch_ohlcvzdeepcoin.fetch_ohlcvk  s     $ !!!!!!!!!88z[`aa& 	B[[*:D)ABBF@@vW\^cenpv  yA  B  B  B  B  B  B  B  B  BV$$  1167++t	9EETl
 
 $GG!!&'22$GGYYvw//F0@%HH 	5YYv'788F   //	::/4}((58o#="EE$!'511G''))#&w#4#4 F??!II$++V]_eJfJfggggggggHHg!EEdkkRY[aFbFbccccccccHH!@@WV\A]A]^^^^^^^^H6 ~~h33  vy%GGGr  rx  c                   K   |                                   d{V  |                     |          }|                     |          }d}|                     d||          \  }}d|                     |          i}|                     |                     ||                     d{V }|                     |dg           }|                     ||          S )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  r6  )	r~  market_symbolsget_market_from_symbolsr   r&  publicGetDeepcoinMarketTickersr  r(  parse_tickers)r  rx  r!  r  
marketTyper9  r:  tickerss           r  fetch_tickerszdeepcoin.fetch_tickers  s       !!!!!!!!!%%g..--g66
!??PVX^__
F77
CC
 <<T[[RX=Y=YZZZZZZZZ..6266!!'7333r  tickerc           	      4   |                      |d          }|                     |d          }|                     ||d          }|d         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|d	         r|d
         r|	}
|}	|
}|                     |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 |          S )!Ntsr=  -rI  r   open24h	volCcy24hvol24hr9   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
indexPricerd  )r  r  safe_marketsafe_tickeriso8601)r  r  r  r  marketIdrI  r   r  r  r  tempr  r  s                r  parse_tickerzdeepcoin.parse_ticker  sJ   * %%fd33	##FH55!!(FC88!//	22&&v{;;%%fh77
&> 	fY/ 	D$JK	22vx00 !
f!
!
 Y//!
 D	!

 3!
 4##FG44!
 ))&'::!
 4##FG44!
 ))&'::!
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&-!
 !
 !
. /  	r  c                 v  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |          }||d<   |                     |                     ||                     d{V }|                     |dg           }	|                     |	|||          S )a2  
        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>`
        Nr=  r*   r   productGroupr6  )r~  r  get_product_group_from_marketpublicGetDeepcoinMarketTradesr  r(  parse_trades)
r  rI  r  r   r!  r  r9  r  r:  r6  s
             r  fetch_tradeszdeepcoin.fetch_trades  s       !!!!!!!!!V$$fTl
 $GG99&AA".;;DKKQW<X<XYYYYYYYY~~h33  vue<<<r  c                 4    d}|d         r|d         rd}nd}|S )NSpotr9   r   SwapUSwap )r  r  r  s      r  r  z&deepcoin.get_product_group_from_market.  s2    &> 	&h &&%r  tradec                    |                      |d          }|                     ||          }|                     |d          }|                      |d          }|                      |d          }d }|                      |d          }|0|                      |d          }	|                     |	          }
||
d}|                     |||                     |          |d         |                      |d	          |                      |d
          d |                     |          ||                     |dd          |                     |dd          d |d|          S )Nr=  r  sideexecTypefeefeeCcyr[  currencyrI  tradeIdordIdfillPxpxfillSzr{  )rd  r  r  rI  r*   orderr  takerOrMakerr  r   rV  r[  r  )r  r  r  rf  
safe_trader  parse_taker_or_makersafe_string_2)r  r  r  r  r  r  r  r  feeCostfeeCurrencyIdfeeCurrencyCodes              r  parse_tradezdeepcoin.parse_trade7  sy   @ ##E844!!(F33%%eT22	v..##E:66""5%00 ,,UH==M"55mDDO+ C "Y//X&""5)44%%eW55 55h??''x>>(($?? 
  
   	r  r  c                 :    ddd}|                      |||          S )Nr   r   )TMr  )r  r  r   s      r  r  zdeepcoin.parse_taker_or_makeru  s.    
 
 x:::r  c                 *  K   |                                   d{V  d}|                     dd||          \  }}d|                     |          i}|                     |                     ||                     d{V }|                     |          S )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>`
        NrZ   r  )r~  r   r&  !privateGetDeepcoinAccountBalancesr  parse_balance)r  r!  r  r9  r:  s        r  fetch_balancezdeepcoin.fetch_balance|  s       !!!!!!!!!
!??PTV\^hii
F77
CC
 ??GU[@\@\]]]]]]]]!!(+++r  c                    |d d d}|                      |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d	          |d
<   |||<   |                     |          S )N)rd  r  r  r6  r   ccybaltotal	frozenBalusedavailBalfree)r(  r)  r*  r  rf  accountsafe_balance)	r  r:  r2  balancesr3  balancerI  coder  s	            r  r  zdeepcoin.parse_balance  s      
 

 >>(FB77q#h--(( 	# 	#AqkG%%gu55F**622DllnnG#//??GG"..wDDGFO"..w
CCGFO"F4LL  (((r  r  c                   K   |                                   d{V  d}|                     |ddd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     |d          }|||d<   |                     |d          }|                     |                     ||                     d{V }	|                     |	di           }
| 	                    |
dg           }ddi}| 
                    |||||          S )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>`
        NFrf   r  r  r   2   r*   coin	startTimesizer  r  r6  r  deposit)r~  r  fetch_paginated_call_cursorr  r  r  "privateGetDeepcoinAssetDepositListr  r$  r(  parse_transactionsr  r  r  r   r!  r  r9  r  r  r:  r6  itemstransactionParamss                r  fetch_depositszdeepcoin.fetch_deposits  s      !!!!!!!!!88R\^cdd& 	|99/4QVX]_egmosuvxz{{{{{{{{{}}T**H&tnGFO#(GK #GFO!!&'22!&GIYYvw//F@@WV\A]A]^^^^^^^^~~h33tVR00I#
 &&uhuFWXXXr  c                   K   |                                   d{V  d}|                     |ddd          \  }}|r#|                     d||||dddd	  	         d{V S i }d}| |                     |          }|d         |d	<   |||d
<   |||d<   |                     |d          }|||d<   |                     |d          }|                     |                     ||                     d{V }	|                     |	di           }
| 	                    |
dg           }ddi}| 
                    |||||          S )a  
        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>`
        NFrf   r  r  r   r  r*   r   r  r  r  r  r6  r  
withdrawal)r~  r  r  r  r  r  #privateGetDeepcoinAssetWithdrawListr  r$  r(  r  r  s                r  fetch_withdrawalszdeepcoin.fetch_withdrawals  s      !!!!!!!!!88R\^cdd& 	|99/4QVX]_egmosuvxz{{{{{{{{{}}T**H&tnGFO#(GK #GFO!!&'22!&GIYYvw//FAA$++gW]B^B^________~~h33tVR00L#
 &&uhuFWXXXr  transactionr  c                 P   |                      |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S )NtxHashr   rV  
createTime	chainNamestatusrd  r*   r  networkaddressFrom	addressToaddresstagFromtagTotagr  updatedtxidr  r  )r  r[  )internalcommentr  )r  rf  rj  safe_timestampnetwork_id_to_codeparse_transaction_statusr  )r  r  r  r  
currencyIdr  rV  r  	networkIdr  r  s              r  parse_transactionzdeepcoin.parse_transaction  s    X66%%k6::
&&z8<<!!+x88''\BB	$$[+>>	)))44..t/?/?X/V/VWW
K
$
 
 f	

 w
 4
 
 t''Y??
 t
 T
 4
 f
 D
 t
 D
  !
" Y//#
$   )
 
 
 	
r  r  c                 :    ddd}|                      |||          S )Npendingok)
confirmingsucceedr  r  r  statusess      r  r"  z!deepcoin.parse_transaction_status-  s.    #
 
 &&999r  codesc                   K   |                                   d{V  |t          | j        dz             t          |          }|dk    rt	          | j        dz             |d         }|                     |          }|d         dd}|                     |                     ||                     d{V }|                     |di           }| 	                    |d	g           }	d
|i}
| 
                    |	|d|
          S )a  
        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>`
        Nz= fetchDepositAddresses requires a list with one currency coder   r   r*   en)currency_idlangr6  rs  r  F)r~  r   r*   r*  r"   r  (privateGetDeepcoinAssetRechargeChainListr  r$  r(  parse_deposit_addresses)r  r-  r!  lengthr  r  r9  r:  r6  rs  additionalParamss              r  fetch_deposit_addressesz deepcoin.fetch_deposit_addresses4  s.      !!!!!!!!!=#DG.m$mnnnUQ;;tw)hhiiiQx==&&#D>
 
 FFt{{SZ\bGcGcdddddddd6 ~~h33~~dFB//"
 ++D%@PQQQr  c                   K   |                                   d{V  |                     |d          }|                     | j        di           }|                     ||          }|r|n|}||                     |d          }|                     |g|           d{V }t          |          }|                     |di           }|/|dk    r)t          d|          D ]}	||	         }
|
d         |k    r|
}|S )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>`
        Nr  r   r   r   )r~  r  r$  r   r  r6  r*  r)  )r  r  r!  r  r   defaultNetwork
addressessr4  r  r3  entrys              r  fetch_deposit_addresszdeepcoin.fetch_deposit_addressl  s)      !!!!!!!!!""6955..7H"MM))/4@@$8''.YYvy11F77GGGGGGGG
Z..Q33fqjj1f%% $ $"1#w..#Gr  c                     |                      |d          }|                      |d          }|                     |           |d |                     |          ||                      |d          dS )Nchainr  memo)rd  r  r  r  r  )r  check_addressr!  )r  r:  r  r=  r  s        r  parse_deposit_addresszdeepcoin.parse_deposit_address  s~    &   733""8Y777###..u55##Hf55
 
 	
r  c                 (  K   |                                   d{V  d}|                     dd||          \  }}d|                     |          i}d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |d	          }|||d
<   |                     |d	          }|                     |                     ||                     d{V }	|                     |	dg           }
| 	                    |
|||          S )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-entry-structure>`
        Nr7   rn   r  r*   r  r  r   r  beforer6  )
r~  r   r&  r  r  r  privateGetDeepcoinAccountBillsr  r(  parse_ledger)r  r  r  r   r!  r  r9  r  r  r:  r6  s              r  fetch_ledgerzdeepcoin.fetch_ledger  sS      !!!!!!!!!
!??tU[]ghh
F77
CC
 }}T**H%d^GEN$GG$GG!!&'22 %GHYYvw//F<<T[[RX=Y=YZZZZZZZZ6 ~~h33  x>>>r  itemc                 ,   |                      |d          }|                     |d          }t          j        |          }t          j        |d          rdnd}|                     |d          }|                     ||          }|                     |d          }|                     ||                     |d          |d d d |                     |          |d	         |||                     |          d |                     |d
          d d d|          S )Nr  balChg0outinr  r  billIdr  r  )rd  r*   	directionr  referenceAccountreferenceIdr  r  rV  r  r  rB  r  r  r  )	r  r  r%   
string_abs	string_ltsafe_currencysafe_ledger_entryparse_ledger_entry_typer  )	r  rF  r  r  r  rV  rM  r#  r  s	            r  parse_ledger_entryzdeepcoin.parse_ledger_entry  s+    %%dD11	!!$11#F++$.vs;;EEE	%%dE22
%%j(;;f--%%""422" $0066 ("Y//%%dE22'
 '
  !  	r  c                 @    dddddd}|                      |||          S )Nr  r   r  )rE  2345r  )r  r  
ledgerTypes      r  rT  z deepcoin.parse_ledger_entry_type	  s7    
 

 
D$777r  rV  fromAccount	toAccountc                   K   d}|                      |dd          \  }}|r|n|                     |d          }|t          | j        dz             |                                  d{V  |                     |          }|                     | j        di           }|                     |||          }	|                     |||          }
|d         |                     ||          |	|
|d}| 	                    | 
                    ||                     d{V }|                     |d	i           }|                     ||          }|                     | j        di           }|                     |d
d          }|r||d<   ||d<   ||d<   |S )a  
        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*   )r0  rV  from_idto_idr`  r6  fillResponseFromRequestTr\  r]  rV  )r  r  r   r*   r~  r  r$  r   currency_to_precision privatePostDeepcoinAssetTransferr  parse_transferr  )r  r  rV  r\  r]  r!  r_  r  r   fromIdtoIdr9  r:  r6  r   transferOptionsrc  s                    r  r   zdeepcoin.transfer  s      66vz8TT!Ft'7'7'F'F>#DG.W$WXXX!!!!!!!!!==&&6FKK!!.+{KK	9EE#D>00v>>
 
 >>t{{7TZ?[?[\\\\\\\\ ~~h33&&tX66..z2FF"&..B[]a"b"b" 	(&1H]#$-H[!!'HXr  r   c                     |                      |d          }|                     d |          }|d d d |d d d |                     |          d	S )NretCode)	rd  r*   r  r  r  rV  r\  r]  r  )r  rf  parse_transfer_status)r  r   r  r  currencyCodes        r  rf  zdeepcoin.parse_transferH  sf     !!(I66..tX>>$0088

 

 
	
r  c                     |dk    rdS dS )NrI  r(  failedr  )r  r  s     r  rl  zdeepcoin.parse_transfer_status^  s    S==4xr  r  r  r   c                   K   |                                   d{V  |                     |          }|                     |d          }|                     ||||||          }	d}
||                     |	           d{V }
n|                     |	           d{V }
|                     |
di           }|                     ||          S )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>`
        Nr   r6  )r~  r  r  create_order_request$privatePostDeepcoinTradeTriggerOrderprivatePostDeepcoinTradeOrderr$  parse_order)r  rI  r  r  rV  r   r!  r  r   r9  r:  r6  s               r  create_orderzdeepcoin.create_orderc  s      2 !!!!!!!!!V$$''??++FD$vVV#!FFwOOOOOOOOHH  "??HHHHHHHHH~~h33f---r  c                 >   |                      |          }|                     |d          }|du}	|                     |d          }
|
!|d         r|t          | j        dz             |	r|                     ||||||          S |                     ||||||          S )z;
 @ignore
        helper function to build request
        r   Nr[  r7   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  rI  r  r  rV  r   r!  r  r   isTriggerOrderr[  s              r  rq  zdeepcoin.create_order_request  s    
 V$$''??&d2//&> ~l&> +|!|}}} 	`44VT4QVX^___44VT4QVX^___r  c                    |                      |          }|}|                     ||          \  }}|d         ||d}	|                     |d          }
|
|
|	d<   |                     |d          }|                     |di           }|                     |d          }|0|                     |dg          }|                     ||          |	d<   |                     |d	i           }|                     |d          }|0|                     |d	g          }|                     ||          |	d
<   |dk    }|3|rt          | j        dz             |                     ||          |	d<   n|st          | j        dz             |d         r|                     |d          }|N|st          | j        dz             |                     |d          }|                     ||          |	d<   d|	d<   n| 	                    ||          |	d<   d|	d<   ||	d<   d|	d<   n| 	                    ||          |	d<   d}| 
                    d||          \  }}||	d<   d}|                     |dd|          \  }}||	d<   d}|                     |dd          }|r|dk    rd }n|d!k    rd"}n|dk    rd"}n|d!k    rd }||	d#<   |                     |	|          S )$a  
 @ignore
        helper function to build request
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much 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*   )r=  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 ordersr7   r[  zC createOrder() accepts a cost parameter for spot market orders onlyr{  	quote_ccytgtCcybase_ccyr  cashtdModecrossrN   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  rI  r  r  rV  r   r!  r  	orderTyper9  r|  r~  r   r  r   isMarketOrderr[  r   r  r  r  s                        r  rx  z%deepcoin.create_regular_order_request  sZ   ( V$$	 HHvVV	6Tl  
 
" ((AA$!.GIYYv77F>>&*b99((>BB$YYv
|44F%)%<%<V]%S%SGM"^^FL"==
**:~FF&YYv~66F%)%<%<V_%U%UGM") q +o!oppp 33FEBBGDMM 	dTW'bbccc&> !	)##FF33D$ v$TW/t%tuuu6622 $ 6 6vt D D$/!! $ 8 8 H H$.!"GFO &GH 44VVDDGDM J!%!C!CMSY[e!f!fJ *GH!K"&"?"?Wdfq"r"rK%0GM"GeDDJ 	&5==%GGV^^$G5==$GGV^^%G!(GI{{7F+++r  c                    |                      |          }|d         |                     |d                   |                     ||          ||d}|                     |d          }	|                     ||	          |d<   ||                     ||          |d<   n|dk    rt          | j        dz             d	}
|                     d
||
          \  }
}d}|
dk    rd}|                     |dd          }| 	                    |d          }||d<   |
|d<   |d         r1|r|dk    rd|d<   n#|dk    rd|d<   n|dk    rd|d<   n|dk    rd|d<   d}| 
                    |d
d|          \  }}||d<   |                     ||          S )a  
 @ignore
        helper function to build request
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much 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  )r=  r  r{  r  r  r   Nr   r   zA createOrder() requires a price argument for limit trigger ordersr  rN   r   isolatedr   r  FisCrossMarginr  r9   r  r  r  r  r  r  r  )r  
capitalizer  r  r  r   r*   r  r  r  r  r  )r  rI  r  r  rV  r   r!  r  r9  r   r   r  r  r  s                 r  rw  z%deepcoin.create_trigger_order_request
  s    V$$Tl OOF6N;;**66:: 
 
 ''?? #'"9"9&,"O"O#66vuEEGGW__#DG.q$qrrr
!??vWabb
F##M^^FL%@@
6<00#0 &&> 
	1 	15==)0GI&&V^^)/GI&5==)/GI&&V^^)0GI&";;FMS`bmnnV!,{{7F+++r  c                     d}|                      |dk    |dk    |          \  }}|rd}|                     |          }|                     |d          }||dk    rd}||gS )NFr  	post_onlyr   r   ioc)handle_post_onlyhandle_time_in_forcer  )r  r  r!  postOnlyr   s        r  r  z0deepcoin.handle_type_post_only_and_time_in_forceO  s    001A4;CVX^__& 	D//776=11#+*>*>Df~r  r[  c                 v   K   |                      |d|i          }|                     |d|dd|           d{V S )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  ru  )r  rI  r  r[  r!  s        r  create_market_order_with_costz&deepcoin.create_market_order_with_costZ  sO       Vfd^44&&vxq$OOOOOOOOOr  c                 v   K   |                      |d|i          }|                     |dddd|           d{V S )a  
        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  rI  r[  r!  s       r  !create_market_buy_order_with_costz*deepcoin.create_market_buy_order_with_costf  sO       Vfd^44&&vx4PPPPPPPPPr  c                 v   K   |                      |d|i          }|                     |dddd|           d{V S )a  
        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_costz+deepcoin.create_market_sell_order_with_costq  sO       Vfd^44&&vxD&QQQQQQQQQr  r*   c                   K   |                                   d{V  |t          | j        dz             |                     |          }|d         |d}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )a  
        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>`
        N. fetchClosedOrder() requires a symbol argumentr*   r=  r  r6  r   )	r~  r   r*   r  &privateGetDeepcoinTradeFinishOrderByIDr  r(  r$  rt  )	r  r*   rI  r!  r  r9  r:  r6  r:  s	            r  fetch_closed_orderzdeepcoin.fetch_closed_order|  s       !!!!!!!!!>#DG.^$^___V$$Tl
 
 DDT[[QXZ`EaEabbbbbbbb^ ~~h33tQ++v...r  c                   K   |                                   d{V  |t          | j        dz             |                     |          }|d         |d}|                     |                     ||                     d{V }|                     |dg           }t          |          }|dk    rdS |                     |di           }	| 	                    |	|          S )a  
        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  r6  r   )
r~  r   r*   r   privateGetDeepcoinTradeOrderByIDr  r(  r*  r$  rt  )
r  r*   rI  r!  r  r9  r:  r6  r4  r:  s
             r  fetch_open_orderzdeepcoin.fetch_open_order  s       !!!!!!!!!>#DG.^$^___V$$Tl
 
 >>t{{7TZ?[?[\\\\\\\\~~h33TQ;;4tQ++v...r  c                   K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S |                     |dd          }d}|                     |d|          \  }}d}i }	| |                     |          }|d         |	d<   d	}
|                     ||||
          \  }
}|                     |
          |	d
<   |||	d<   d}|r|dk    rt          | j	        dz   |z   dz             |t          | j	        dz             |                     |d          }|                     |                     |	|                     d{V }n/|                     |                     |	|                     d{V }|                     |dg           }|                     ||||          S )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>`
        NFr[   r  r   r  r*   r=  r7   r  r    z"() does not support trigger orderszM fetchCanceledAndClosedOrders() requires a symbol argument for trigger ordersr6  )r~  r  fetch_paginated_call_dynamicr  handle_param_stringr  r   r&  r   r*   r   r  +privateGetDeepcoinTradeTriggerOrdersHistoryr  $privateGetDeepcoinTradeOrdersHistoryr(  parse_orders)r  rI  r  r   r!  r  r   r  r  r9  r  r:  r6  s                r   fetch_canceled_and_closed_ordersz)deepcoin.fetch_canceled_and_closed_orders  sT     $ !!!!!!!!!88A_akll& 	y::;Y[achjoqwxxxxxxxxx..E::3
!55flJWW
F[[((F &tGH
!??
FTZ\fgg
F"==jII
$GG Q	e;;; 3!;>b!bccc~'  3B  )B  C  C  CYYvy11F8 "MMdkkZaciNjNjkkkkkkkkHH` "FFt{{SZ\bGcGcddddddddH~~h33  vue<<<r  c                    K   d}|                      |d|i          }|                      |ddi          }|                     ||||           d{V S )a  
        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  rH  canceledNr  r  r  rI  r  r   r!  r  s         r  fetch_canceled_orderszdeepcoin.fetch_canceled_ordersX  sj       +
VlJ%?@@Vgz%:;;::65%QWXXXXXXXXXr  c                    K   d}|                      |d|i          }|                      |ddi          }|                     ||||           d{V S )a  
        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  rH  filledNr  r  s         r  fetch_closed_orderszdeepcoin.fetch_closed_ordersj  sj       )
VlJ%?@@Vgx%899::65%QWXXXXXXXXXr  c                   K   |                                   d{V  |t          | j        dz             |                     |          }|                     |dd          }d|d         i}|||d<   |                     |dd	          }d}	|rd|                     |d          }|                     |d
                   |d<   |                     | 	                    ||                     d{V }	n4||d<   | 
                    | 	                    ||                     d{V }	|                     |	dg           }
|                     |
|||ddi          S )ar  
        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   r=  r*   r   r   Fr  r  r6  r  r  )r~  r   r*   r  r  r  r  r&  +privateGetDeepcoinTradeTriggerOrdersPendingr  &privateGetDeepcoinTradeV2OrdersPendingr(  r  )r  rI  r  r   r!  r  r   r9  r   r:  r6  s              r  fetch_open_orderszdeepcoin.fetch_open_orders|  s       !!!!!!!!!>#DG.]$]^^^V$$!!&'155fTl
 $GG..E:: S	gYYvy11F"&"A"A&."Q"QGJ@ "MMdkkZaciNjNjkkkkkkkkHH$GG^ "HHU\^dIeIeffffffffH~~h33  vueh=OPPPr  c                 &  K   |                                   d{V  |t          | j        dz             |                     |          }|d         |d}d}|                     |dd          }|rF|                     |d          }|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    |di           }| 
                    ||          S )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   Fr6  )r~  r   r*   r  r  r  *privatePostDeepcoinTradeCancelTriggerOrderr  #privatePostDeepcoinTradeCancelOrderr$  rt  )	r  r*   rI  r!  r  r9  r:  r   r6  s	            r  cancel_orderzdeepcoin.cancel_order  s=      !!!!!!!!!>#DG.Y$YZZZV$$Tl
 
 ..E:: 	dYYvy11F!LLT[[Y`bhMiMijjjjjjjjHH!EEdkkRY[aFbFbccccccccH~~h33f---r  c                   K   |                                   d{V  |t          | j        dz             |                     |          }|d         rt	          | j        dz             |                     |          }|                     |d          }d}||                     |d          }|dk    rd}d	}|                     |d
d|          \  }}|d         |||rdndd}| 	                    | 
                    ||                     d{V }	|                     |	dg           }
|                     |
|          S )av  
        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>`
        Nz- cancelAllOrders() requires a symbol argumentr7   z4 cancelAllOrders() is not supported for spot marketsr   r   r  r   Tr=   mergedr*   )InstrumentIDProductGroupIsCrossMarginIsMergeModer6  )r~  r   r*   r  r"   r  r  r  r  %privatePostDeepcoinTradeSwapCancelAllr  r(  r  )r  rI  r!  r  r  r   encodedMarginModer  r9  r:  r6  s              r  cancel_all_orderszdeepcoin.cancel_all_orders  s      !!!!!!!!!>#DG.]$]^^^V$$&> 	atw)__```99&AA%%fl;;
!YYv|44FZ''$%!66v?PRZ\bcc"4L(. &-11A	
 
 CCDKKPWY_D`D`aaaaaaaa~~h33  v...r  c                 N  K   |                                   d{V  d|i}d}	|<|                     |          }	|	d         rt          | j        dz             |	d         }|                     |d          }
|                     |d          }|
dup|du}d}|r||t          | j        dz             |
0|r|                     ||
          n|                     |
          |d	<   |0|r|                     ||          n|                     |          |d
<   |                     |ddg          }| 	                    | 
                    ||                     d{V }n|4||                     ||          |d<   n|                     |          |d<   |4||                     ||          |d<   n|                     |          |d<   |                     | 
                    ||                     d{V }|                     |di           }|                     |          S )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>`
        N
OrderSysIDr7   z. editOrder() is not supported for spot marketsrI  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   volumer6  )r~  r  r"   r*   rj  r   r  number_to_stringr  (privatePostDeepcoinTradeReplaceOrderSltpr  r  $privatePostDeepcoinTradeReplaceOrderr$  rt  )r  r*   rI  r  r  rV  r   r!  r9  r  r   r   isTPSLr:  r6  s                  r  
edit_orderzdeepcoin.edit_order2  s     $ !!!!!!!!!"
 [[((Ff~ _"47-]#]^^^H%F((AA**63DEEt+M1L 	e!v'9   ,E  "E  F  F  F([a  *L)@)@)W)W)Wgkg|g|  ~K  hL  hL&*]c  *P)@)@)Y)Y)Yimi~i~  @O  jP  jP&YYv9J'KLLF!JJ4;;W^`fKgKghhhhhhhhHH %'+'>'>vu'M'MGG$$'+'<'<U'C'CGG$!%(,(@(@(P(PGH%%(,(=(=f(E(EGH%!FFt{{SZ\bGcGcddddddddH~~h33%%%r  idsc                 j  K   |                                   d{V  d}|4|                     |          }|d         rt          | j        dz             d|i}|                     |                     ||                     d{V }|                     |dg           }|                     ||          S )aF  
        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>`
        Nr7   z1 cancelOrders() is not supported for spot marketsOrderSysIDsr6  )r~  r  r"   r*   (privatePostDeepcoinTradeBatchCancelOrderr  r(  r  )r  r  rI  r!  r  r9  r:  r6  s           r  cancel_orderszdeepcoin.cancel_ordersj  s       !!!!!!!!![[((Ff~ b"47-`#`aaa3
 FFt{{SZ\bGcGcdddddddd~~h33  v...r  r  c                 h   |                      |d          }|                     ||          }|                     |d          }|                      |dd          }t          |          dk     r|                     |d          }|                      |d          }|                      |d          }|                      |d          }|dk    rd }|                      |d          }	d }
|	A|                      |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 |r|d(k    nd |d)|          S )*Nr=  cTimer@     rH  r{  avgPxr  r  r  r*   r  r|  r}  r  r  lastTradeTimestamplastUpdateTimestampuTimer  rI  r  r   r  r   r  ordPxr  rV  r{  r  	accFillSz	remainingr   	triggerPxr  tpTriggerPricer  slTriggerPricer  )r   r   r[  tradesr  r  r  rd  )r  r  r  r*  r   r  rf  
safe_orderr  parse_order_statusparse_order_typeparse_order_time_in_forcer  	omit_zero)r  r  r  r  r  timestampStringrH  r  r  r  r  r  s               r  rt  zdeepcoin.parse_order  sD   F ##E844!!(F33%%eW55	**5'2>>"$$++E7;;I  00$$UI66	""5'22b==G((99$&&ue44G))'22 33MBB C   
$""5'22 
T--eY?? 
 Y// 
 	 

 !$ 
 "4#4#4UG#D#D 
 d--e44 
 fX& 
 D)))44 
 499)DD 
 D$$UF33 
 T''tW== 
 w 
 d&&ud33 
 d&&uk:: 
  ! 
" DNN4+;+;E;+O+OPP# 
$  $11%HXYY!//}FVWW6?Ik11T3 
  
  
4 5  	r  c                 >    ddddd}|                      |||          S )Nr  closedr  )rQ  r  r  partially_filledr  r+  s      r  r  zdeepcoin.parse_order_status  s4    " &	
 
 &&999r  c                 @    dddddd}|                      |||          S )Nr   r  )r   r  r  r  TPSLr  )r  r  r   s      r  r  zdeepcoin.parse_order_type  s7     
 
 tT222r  c                 >    ddddd}|                      |||          S )Nr   r   r   )r  r  r   r  r  )r  r  timeInForcess      r  r  z"deepcoin.parse_order_time_in_force	  s4    	
 
 dD999r  c                 v  K   |                                   d{V  |                     |          }|                     |d                   }||d         d}|                     |                     ||                     d{V }|                     |dg           }|                     ||d         g          S )a  
        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>`
        Nr  r*   )r  r=  r6  rI  )r~  r  r&  "privateGetDeepcoinAccountPositionsr  r(  parse_positions)r  rI  r!  r  instrumentTyper9  r:  r6  s           r  fetch_positions_for_symbolz#deepcoin.fetch_positions_for_symbol	  s       !!!!!!!!!V$$88HH&Tl
 
 @@WV\A]A]^^^^^^^^~~h33##D6(+;*<===r  c                   K   |                                   d{V  |                     |ddd          }d}d}|+|                     |d          }|                     |          }|                     d|||          \  }}|                     |          }d|i}|                     |                     ||                     d{V }|                     |dg           }	| 	                    |	|          S )an  
        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>`
        NTr9   r   r   r  r6  )
r~  r  r  r  r   r&  r  r  r(  r  )
r  rx  r!  r  r  firstSymbolr  r9  r:  r6  s
             r  fetch_positionszdeepcoin.fetch_positions#	  s      !!!!!!!!!%%gtT4@@
**7A66K[[--F!??@PRXZ`blmm
F88DD
 @@WV\A]A]^^^^^^^^2 ~~h33##D'222r  positionc                    |                      |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          S )Nr=  r  rI  r*   posIdr  r  	contractsposr\  r  r  notionalrZ  rD  unrealizedPnlrealizedPnl
collateral
entryPricer  r  liquidationPriceliqPxr   mgnModer   T	useMarginr  )maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentagemarginRatior  	lastPricer   r   r  rd  )r  r  r  safe_positionr  r  )r  r  r  r  r  s        r  parse_positionzdeepcoin.parse_positionU	  s   & ##Hh77!!(F33%%h88	!! #
fX&#
$""8W55#
 #
 Y//	#

 ))(E::#
 D#
 D$$Xy99#
 #
 t'7'7''J'JKK#
 T#
 4#
 $#
 $**8W==#
 #
  0 07 C C#
  $**8Y??!#
" d##
$ "&!1!1(K!H!H+/!'+#'#4#4Xw#G#G!#9#
 #
 #
   	r  rZ  c                 J  K   |t          | j        dz             |dk     rt          | j        dz             |                                  d{V  |                     |          }d}|                     d||          \  }}|dk    r|dk    rt          | j        dz             d	}|                     |dd
|          \  }}|d	k    r|dk    rt          | j        dz             |||d         |d}|                     |                     ||                     d{V }|S )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
        Nz) 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*   )rD  r  r=  r  )	r   r*   r   r~  r  r  r  %privatePostDeepcoinAccountSetLeverager  )	r  rZ  rI  r!  r  r   r  r9  r:  s	            r  set_leveragezdeepcoin.set_leverage	  sp      >#DG.Y$YZZZ a<<TW'TTUUU!!!!!!!!!V$$
!??vWabb
F'!!
j(@(@TW'}}~~~";;FMS`bmnnV'!!kW&<&<TW'kklll!Tl&	
 
 CCDKKPWY_D`D`aaaaaaaa r  c                 B  K   |                                   d{V  |                     |dddd          }d}d}|+|                     |d          }|                     |          }|                     d|||          \  }}d}|dk    rd	}n|dk    rt          | j        d
z             d|i}|                     |                     ||                     d{V }| 	                    |di           }	| 
                    |	dg           }
|                     |
|          S )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
        Nr9   Tr   r   rl   r  r   r  zG fetchFundingRates() subType parameter must be either linear or inverser  r6  current_fund_rates)r~  r  r  r  handle_sub_type_and_paramsr   r*   0publicGetDeepcoinTradeFundRateCurrentFundingRater  r$  r(  parse_funding_rates)r  rx  r!  subTypefirstMarketr   r  r9  r:  r6  ratess              r  fetch_funding_rateszdeepcoin.fetch_funding_rates	  s[      !!!!!!!!!%%gvtT4HH"**7A66K++k22K99:M{\bdklliHH  TW'ppqqq
 NNt{{[bdjOkOkllllllll& ~~h33t%92>>''w777r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             |d         |                     |          d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |di           }| 	                    ||          S )	aa  
        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>`
        Nr9   z2 fetchFundingRate() is only valid for swap marketsr*   )r=  r  r6  r  r   )
r~  r  r   r*   r  r  r  r$  r(  parse_funding_rate)	r  rI  r!  r  r9  r:  r6  r#  r:  s	            r  fetch_funding_ratezdeepcoin.fetch_funding_rate	  s      !!!!!!!!!V$$f~ 	`*^ ^___Tl::6BB
 
 NNt{{[bdjOkOkllllllll ~~h33t%92>>ua,,&&uf555r  c                     |                      |dd          }|                     ||          }i d|d|dd dd dd dd d	d d
d d|                     |d          dd dd dd dd dd dd dd dd dd iS )NinstrumentIdinstrumentIDrd  rI  r  r  interestRateestimatedSettlePricer  r  fundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  safe_symbolrj  )r  rR  r  r  rI  s        r  r&  zdeepcoin.parse_funding_rate
  s#    %%hOO!!(F33
H
f
 
 $	

 D
 #D
 
 
 4++HmDD
 
 t
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )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>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr=  r*   r  r6  rows)	r   r*   r~  r  %publicGetDeepcoinTradeFundRateHistoryr  r$  r(  parse_funding_rate_histories)
r  rI  r  r   r!  r  r9  r:  r6  r9  s
             r  fetch_funding_rate_historyz#deepcoin.fetch_funding_rate_history4
  s       >#DG.e$efff!!!!!!!!!V$$fTl
 #GFOCCDKKPWY_D`D`aaaaaaaa. ~~h33~~dFB//00vueLLLr  c                     |                      |d          }|                     |dd          }|                     ||d d          }||d         |                     |d          ||                     |          dS )N
CreateTimer*  r)  r9   rI  rate)rd  rI  r-  r  r  )r   r  r  rj  r  )r  rd  r  r  r*  s        r  parse_funding_rate_historyz#deepcoin.parse_funding_rate_historye
  s     ''l;;	))$OO!!,fEEX&++D&99"Y//
 
 	
r  c                   K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S d}||                     |          }d}|                     d|||          \  }}d|                     |          i}||d         |d<   |||d	<   |||d
<   |                     |d          }	|	|                     |d          }|	|d<   |                     | 	                    ||                     d{V }
| 
                    |
dg           }|                     ||||          S )a  
        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>`
        NFru   r  r7   r  r*   r=  beginr   r  endr6  )r~  r  r  r  r   r&  r  r  privateGetDeepcoinTradeFillsr  r(  r  )r  rI  r  r   r!  r  r  r  r9  r  r:  r6  s               r  fetch_my_tradeszdeepcoin.fetch_my_tradesy
  s      !!!!!!!!!88R\]]& 	j::?FTY[`bhiiiiiiiii[[((F
!??QWY_akll
F77
CC
  &tGH$GG$GG!!&'22YYvw//F"GEN::4;;wPV;W;WXXXXXXXX4 ~~h33  vue<<<r  c                   K   |                                   d{V  |                     |d          }||t          | j        dz             |                     d|i|          }|                     ||||           d{V S )ah  
        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>`
        Nr  zK fetchOrderTrades requires a symbol argument or a market type in the paramsr  )r~  r  r   r*   r  rE  )r  r*   rI  r  r   r!  r  s          r  fetch_order_tradeszdeepcoin.fetch_order_trades
  s       !!!!!!!!!%%ff55
>j0#DG.{${|||gr]F33))&%GGGGGGGGGr  c                 \  K   |                                   d{V  |                     |          }|                     |          }|                     |d          }|                     |d          }|d         |d}d}	|2|0|                     |                     ||                     d{V }	nM||                     |d          }|g|d<   |                     |                     ||                     d{V }	|                     |	dg           }
| 	                    |
|          S )a  
        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>`
        N
positionIdpositionIdsr*   )r=  r  r6  )
r~  r  r  r  r(  *privatePostDeepcoinTradeBatchClosePositionr  r  *privatePostDeepcoinTradeClosePositionByIdsrt  )r  rI  r  r!  r  r  rI  rJ  r9  r:  r6  s              r  close_positionzdeepcoin.close_position
  s\      !!!!!!!!!V$$99&AA%%fl;;
nnV];;Tl(
 
 +"5!LLT[[Y`bhMiMijjjjjjjjHH%6<88*4&!LLT[[Y`bhMiMijjjjjjjjH~~h33f---r  r   GETc                 V   |}|dk    r,|                      |          }t          |          r|d|z   z  }| j        d         |         dz   |z   }	|dk    r|                                  |                                 }
|                     |
          }||z   dz   |z   }| j        || j        dd}|dk    r|                     |          }d|d	<   ||z  }| 	                    | 
                    |          | 
                    | j                  t          j        d
          }||d<   |	|||dS )NrN  ?r   rA  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   rT  r!  rV  rU  requestPathqueryr   r  dateTimepayload	signatures                 r  signzdeepcoin.sign
  sI   U??NN6**E5zz +sU{*is#c)K7)++---))++I||I..H'#-;G!%'/(,!	 G yy((*<'4		$++g"6"6DK8P8PRYR`bjkkI(1G$%fdwOOOr  reasonr   rT  rV  rU  c
                    |                      |di           }
|                     |d          }|                     |d          }|                     |
d          }|                     |
d          }|                     |
d          }|
|dk    r||}|                     |
d          }|Mt          d	t	          |                    D ]/}|                      ||i           }|                     |d          }0| j        d
z   |z   }|||}|                     |
d          }|||}|dk    s|dk    s||dk    r|                     | j        d         ||           |                     | j        d         ||           |                     | j        d         ||           |                     | j        d         ||           t          |          |                     |
dg           }d|
v r|t          |          d S )Nr6  msgr  sCodesMsg	errorCoder@  	errorListr   r  rk  r0   rI  r  r  rs  )r$  r  r(  r)  r*  r*   throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   r#   )r  r  re  r   rT  rV  rU  r:  requestHeadersrequestBodyr6  rg  messageCoderh  ri  rj  rk  r3  r:  feedbackrk  rs  s                         r  handle_errorszdeepcoin.handle_errors  s$   ~~h33x//&&x88  w//f--$$T;77	O#))$2BCNN455	 1c)nn-- A Ay!R88 ,,UK@@		7S=4'M	 5E""433M 3ECKK[C//U5F5TW<<001I;X`aaa001I5RZ[[[001I3PXYYY001I3PXYYY)))>>$33D$T\"8,,,tr  )N)b__name__
__module____qualname__r   r  strr   r   r&  r   r4  r,  dictrp  rr  r	   r   r  rs  r  r   r   r  r   r  r   r  r  r  r   r  r   r  r  r   r
  r  r   r%  r"  r   r6  r;  r@  r
   rE  rU  rT  floatr   r   rf  rl  r   r   r   ru  rq  rx  rw  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  rt  r  r  r  r   r  r  r  intr  r   r$  r   r'  r&  r<  r@  rE  rG  rM  rd  rr  __classcell__)r  s   @r  r'   r'      sH       \# \ \ \ \ \ \|
 OS[]lp m m mV mux m m m m m m; ; ; *,  V    0 8: #0 #0 #0 #0Jv4 vF v v v vp	 	 	 	 	 	 @DB %O %OS %O %OS\ %O %O %O %ON 8<$]ajl VH VH VHC VHWZ VHquvzq{ VH VH VH VHp 6:" 4 47 4 4 4 4 4,: :4 : :6 : : : :x <@d[] = = =S = =bfglbm = = = =2F s    < < <v < < < < <|;S ; ; ; ; *, , , , , , ,&) ) ) ) )@ 04$UYbd &Y &Y &YC &Ys &Yimnyiz &Y &Y &Y &YP 37TX\eg &Y &YC &Ys &YRU &Ylpq|l} &Y &Y &Y &YP,
 ,
T ,
X ,
Q\ ,
 ,
 ,
 ,
\:s :s : : : : >B" 6R 6R7 6RQUVdQe 6R 6R 6R 6Rp =?   >    8
 
 
N 
 
 
 
< .2SW`b <? <?s <?# <?S <?gklwgx <? <? <? <?|# #t #x #; # # # #J8 8 8 ac 3 33 3 3C 3TW 3gt 3 3 3 3j
 
t 
x 
= 
 
 
 
,C C    
 mqy{ 2. 2. 2.I 2.Y 2.X] 2.fi 2. 2. 2. 2.h os{} ` `3 `i `y `Z_ `hk ` ` ` `$ w{  DF _, _,3 _,i _,y _,bg _,ps _, _, _, _,B w{  DF C, C,3 C,i C,y C,bg C,ps C, C, C, C,J	I 	 	 	 	 eg 
P 
P# 
PY 
PV[ 
P 
P 
P 
P XZ 	Q 	Qc 	Q 	Q^c 	Q 	Q 	Q 	Q Y[ 	R 	Rs 	R% 	R_d 	R 	R 	R 	R ?C2 D/ D/3 D/ D/RW D/ D/ D/ D/L =A / / /c /PU / / / /6 DHVZimvx y= y=S y=PS y=cf y=  ~B  CH  ~I y= y= y= y=v 9=4^bkm Y Y# YS YX[ Yrvw|r} Y Y Y Y$ 7;\`ik Y Y Y3 YVY Yptuzp{ Y Y Y Y$ 59tZ^gi qQ qQc qQ qQTW qQnrsxny qQ qQ qQ qQf 9=R . .S .# .E . . . .< 59 #/ #/c #/U #/ #/ #/ #/J fjx|  FH 6& 6&3 6& 6&9 6&I 6&_b 6&ru 6& 6& 6& 6&p AER / /tCy /# /TXY^T_ / / / /*p p pv p p p p pd: : : : : :3S 3S 3 3 3 3:c :c : : : : DF > >s >$x. > > > >, 8<B 03 03W 034PX> 03 03 03 03d3 3t 3V 3x 3 3 3 3j ?C2 2 23 2 2 2 2 2h <@ 08 08 08| 08 08 08 08d <> $6 $6s $6+ $6 $6 $6 $6L
 
6 
[ 
 
 
 
< >BPTcgpr /M /Ms /M# /M]` /M /M /M /Mb
 
v 
 
 
 
( 37TX\eg A= A=C A=s A=RU A= A= A= A=F ?CQUdhqs H H3 H H3 H^a H H H H* CGr  .  .3  .i  .V[  .  .  .  .D &eBSW P P P P4# s  c TX `c        r  r'   )- ccxt.async_support.base.exchanger   ccxt.abstract.deepcoinr   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   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     sc   6 5 5 5 5 5 . . . . . .   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  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r       * * * * * * . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %S, S, S, S, S,x S, S, S, S, S,r  