
    ei߻                         d dl Zd dlmZmZmZmZ d dl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  G d d	ej        j                  ZdS )
    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)
AnyIntMarketOrder	OrderBookPositionStrStringsTickerTrade)Client)List)ExchangeError)
BadRequestc                       e Zd Zdef fdZdefdZdefdZd ZdFd	e	d
e
dededef
dZi dfd	e	dededededefdZi i dfd	e	dedededededefdZi fdededefdZi fdZi fdedefdZi fdedefdZdefdZdGded	e	defdZddi fdedededee         fdZi fdefd Zdefd!ZdGd"ed	e	defd#Zd$edefd%Z d&edefd'Z!d(ddi fded)edededee"         f
d*Z#d(i fded)edefd+Z$defd,Z%dGd	e	de"fd-Z&di fdedede'fd.Z(i fdedefd/Z)defd0Z*defd1Z+defd2Z,d3 Z-dddi fdedededee         fd4Z.defd5Z/dddi fdedededee0         fd6Z1defd7Z2dGd	e	de0fd8Z3d9edefd:Z4dddi fd;e5dededee6         fd<Z7defd=Z8dGd	e	de6fd>Z9d$edefd?Z:d@edefdAZ;defdBZ<defdCZ=dedefdDZ>defdEZ? xZ@S )Hdeepcoinreturnc                 V   |                      t          t          |                                           i ddddddddddddd	dd
dddddddddddddddddddddddddddddddddddddddddiid d d ddidddd d!d"d#d$d%d&d'd(d)d*| j        id+          S ),NwsTwatchTickerwatchMarkPriceFwatchMarkPriceswatchTickerswatchBidsAskswatchOrderBookwatchTradeswatchTradesForSymbolswatchOrderBookForSymbolswatchBalancewatchLiquidationswatchLiquidationsForSymbolswatchMyLiquidationswatchMyLiquidationsForSymbols
watchOHLCVwatchOHLCVForSymbols)watchOrderswatchMyTradeswatchPositionswatchFundingRatewatchFundingRatescreateOrderWseditOrderWscancelOrderWscancelOrdersWscancelAllOrdersWsunWatchTickerunWatchTradesunWatchOHLCVunWatchOrderBookapizBwss://stream.deepcoin.com/streamlet/trade/public/spot?platform=apizBwss://stream.deepcoin.com/streamlet/trade/public/swap?platform=api)spotswapz$wss://stream.deepcoin.com/v1/private)publicprivatemethod!privateGetDeepcoinListenkeyExtend1m5m15m30m1h4h12h1d1w1o1y)r?   r@   rA   rB   rC   rD   rE   rF   rG   1MrI   )lastRequestId	listenKeylistenKeyExpiryTimestampauthenticate
timeframesping)hasurlsoptions	streaming)deep_extendsuperr   describerP   )self	__class__s    O/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/deepcoin.pyrW   zdeepcoin.describe   s   h 5 5 > > @ @ d t  !%  "5	 
      !$  t  (  +E    $U  .u  &u  0   d! " '# $  $!%"&$)%*!&$!&"'%*!%!% $$(?     D $h$h# # $J 
 "&!,0A!      , 	EEC
 EC
 E E E	    clientc                 x    |j         }|                    d          dk    r|                                 |_        dS )Nr<   r   rP   )urlfindmillisecondslastPong)rX   r\   r^   s      rZ   rP   zdeepcoin.pingY   s8    j88I!##"//11FOvr[   c                 8    |                                  |_        |S N)r`   ra   )rX   r\   messages      rZ   handle_pongzdeepcoin.handle_pong`   s    ++--r[   c                     |                                   |                     | j        dd          }|                     |d          }|| j        d<   |                                  |S )NrK   r      )lock_idsafe_integerrS   sum	unlock_id)rX   previousValuenewValues      rZ   
request_idzdeepcoin.request_idd   s\    ))$,KK88M1--(0_%r[    Fmarket	requestIdtopicIDsuffixunWatchc                 |    |d         }|d         dk    r|d         |d         z   }d}|rd}d|d	|z   |z   |d
|di}|S )Nsymboltyper:   baseIdquoteId10sendTopicAction	DeepCoin_)ActionFilterValueLocalNoResumeNoTopicID )	rX   rp   rq   rr   rs   rt   marketIdactionrequests	            rZ   create_public_requestzdeepcoin.create_public_requestl   su    (#&>V##h'&*;;H 	F *X5>$"   
 r[   messageHashparamsc                   K   | j         d         d         d         |d                  }|                                 }|                     ||||          }||d}	|                     |||                     ||          ||	           d {V S )Nr8   r   r;   rw   )subHashid)rR   rn   r   watchrU   )
rX   rp   r   rr   r   rs   r^   rq   r   subscriptions
             rZ   watch_publiczdeepcoin.watch_public~   s      it$X.vf~>OO%%	,,VYPP"
 
 ZZ[$2B2B7F2S2SU`bnooooooooor[   r   c                 "  K   | j         d         d         d         |d                  }|                                 }|                     |          }	|                     |	j        |          }
|
t          | j        dz   |z             |                     |
d          }|                     ||||d          }d|z   }| 	                    ||||d	         g|d
          }| 
                    |||                     ||          ||           d {V S )Nr8   r   r;   rw   z no subscription for r   Tunsubscribe::rv   )r   	unsubHashsymbolsr   )rR   rn   r\   	safe_dictsubscriptionsr   r   ri   r   extendr   rU   )rX   rp   r   rr   r   r   rs   r^   rq   r\   existingSubscriptionsubIdr   r   s                 rZ   un_watch_publiczdeepcoin.un_watch_public   s+     it$X.vf~>OO%%	S!!#~~f.BKPP'TW'>>LMMM!!"6==,,VUGVTRR#k1	{{<""x()	2
 2
   ZZY0@0@&0Q0QS\^jkkkkkkkkkr[   c                    K   |                                   d {V }| j        d         d         d         dz   |z   }|                     ||d d|           d {V S )Nr8   r   r<   ?listenKey=)rN   rR   r   )rX   r   r   rL   r^   s        rZ   watch_privatezdeepcoin.watch_private   su      ++--------	it$Y/-?)KZZ[$	6JJJJJJJJJr[   c                   K   |                                   |                                 }|                     | j        d|          }||z
  dk    }|                     | j        d          }d }||                     |           d {V }nu|rs|                     | j        dd          }|dk    }|r|                     |           d {V }n3d|i}	|                     |                     |	|                     d {V }|W|                     |di           }
|                     |
d          }| 	                    |
d	          }|| j        d<   || j        d<   |S )
NrM   i`  rL   r=   r>   "privateGetDeepcoinListenkeyAcquire	listenkeydataexpire_time)
check_required_credentialsr`   ri   rS   safe_stringr   r>   r   r   safe_timestamp)rX   r   timerM   expiredrL   responser=   	getNewKeyr   r   s              rZ   rN   zdeepcoin.authenticate   s     '')))  ""#'#4#4T\C]_c#d#d 22e;$$T\;??	!DDVLLLLLLLLHH 		f%%dlH>abbF#GGI f!%!H!H!P!PPPPPPP  ! "&!G!GT[]cHdHd!e!eeeeeee>>(FB77D(({;;I'+':':4'O'O$(1DL%7ODL34r[   rv   c                    K   |                                   d{V  |                     |          }d|d         z   }|                     ||d|           d{V S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.deepcoin.com/docs/publicWS/latestMarketData

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nticker::rv   7)load_marketsrp   r   )rX   rv   r   rp   r   s        rZ   watch_tickerzdeepcoin.watch_ticker   sx       !!!!!!!!!V$$%x(88&&v{CHHHHHHHHHr[   c                    K   |                                   d{V  |                     |          }d|d         z   }ddi}|                     ||d||           d{V S )a  
        unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.deepcoin.com/docs/publicWS/latestMarketData

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr   rv   topictickerr   r   rp   r   rX   rv   r   rp   r   r   s         rZ   un_watch_tickerzdeepcoin.un_watch_ticker          !!!!!!!!!V$$%x(88X
 ))&+sFLYYYYYYYYYr[   c                    |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }|                     ||          }	d|z   }
|	| j        |<   |                    |	|
           d S )Nrr   dI/r   )	safe_listr   r   safe_marketsafe_symbolparse_ws_tickertickersresolve)rX   r\   rd   r   firstr   r   rp   rv   parsedTickerr   s              rZ   handle_tickerzdeepcoin.handle_ticker   s    > >>'333xB//~~eS"--##D#..!!(D#66!!(F33++D&99%.+V|[11111r[   Nr   c                 z   |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d	          }|d
         r|
}|}
|}|                     i d|d         d|d|                     |          d|d|d|dd d|	dd dd d|d|d|dd dd dd dd |
||d|          S )NUHLONBP1AP1VTinverserv   	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaverage)
baseVolumequoteVolumeinfo)ri   safe_numbersafe_tickeriso8601)rX   r   rp   r   r   r   r   r   r   r   r   r   temps                rZ   r   zdeepcoin.parse_ws_ticker  s   . %%fc22	,,vs++,,,,vu--vu--%%fc22
&&vs33) 	D$JK !
fX&!
!
 Y//!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r[   sincelimitc                 "  K   |                                   d{V  |                     |          }d|d         z   }|                     ||d|           d{V }| j        r|                    ||          }|                     |||dd          S )a,  
        watches information on multiple trades made in a market

        https://www.deepcoin.com/docs/publicWS/lastTransactions

        :param str symbol: unified market symbol of the market trades were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of trade structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Ntrades::rv   2r   T)r   rp   r   
newUpdatesgetLimitfilter_by_since_limit)rX   rv   r   r   r   rp   r   tradess           rZ   watch_tradeszdeepcoin.watch_trades@  s       !!!!!!!!!V$$%x(88((c6JJJJJJJJ? 	3OOFE22E))&%TRRRr[   c                    K   |                                   d{V  |                     |          }d|d         z   }ddi}|                     ||d||           d{V S )a  
        unWatches the list of most recent trades for a particular symbol

        https://www.deepcoin.com/docs/publicWS/lastTransactions

        :param str symbol: unified symbol of the market to fetch trades for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr   rv   r   r   r   r   r   s         rZ   un_watch_tradeszdeepcoin.un_watch_tradesT  r   r[   c                 8   |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }|| j        vr3|                     | j        dd          }	t          |	          | j        |<   | j        |         }
|+| 	                    ||          }|

                    |           d|z   }|                    |
|           d S )	Nr   r   r   r   r   tradesLimit  r   )r   r   r   r   r   r   ri   rS   r   parse_ws_tradeappendr   )rX   r\   rd   r   r   r   r   rp   rv   r   stroredtrader   s                rZ   handle_tradeszdeepcoin.handle_tradesf  s   * >>'333xB//~~eS"--##D#..!!(D#66!!(F33$+%%%%dlM4HHE",U"3"3DK+f%''f55ENN5!!!%.w,,,,,r[   r   c                    |                      |d          }|                     |dd          }|                      |d          }d }|                      |d          }|,||                     |                      |d                    d}|                     |||                     |          |d         |                     |d	d
          |                      |d          d |                     |          |                     |          |                      |d          |                      |d          |                      |d          |d|          S )NDTTr   mFf)costcurrencyrv   TradeIDTIOSPr   )r   r   r   rv   r   orderrw   takerOrMakersidepriceamountr   fee)r   safe_timestamp_2safe_currency_code
safe_trader   safe_string_2handle_taker_or_makerparse_trade_side)rX   r   rp   	directionr   	matchRoler  feeCosts           rZ   r   zdeepcoin.parse_ws_trade  sc   D $$UC00	))%s;;	$$UC00	""5#.. 33D4D4DUC4P4PQQ C "Y//X&$$UIt<<%%eT22 66yAA)))44%%eS11&&uc22$$UC00 
  
   	r[   r  c                 :    ddd}|                      |||          S )Nbuysellr{   rz   r   )rX   r  sidess      rZ   r  zdeepcoin.parse_trade_side  s.    
 
 y)<<<r[   r  c                 :    ddd}|                      |||          S )Nmakertakerr  r  )rX   r  roless      rZ   r  zdeepcoin.handle_taker_or_maker  s.    
 
 y)<<<r[   r?   	timeframec                   K   |                                   d{V  |                     |          }|d         }|                     | j        di           }|                     |||          }d|z   dz   |z   }	d|z   }
|                     ||	d||
           d{V }| j        r|                    ||          }|                     |||dd	          S )
a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://www.deepcoin.com/docs/publicWS/KLines

        :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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nrv   rO   ohlcv::::_11r   T)	r   rp   r   rS   r   r   r   r   r   )rX   rv   r  r   r   r   rp   rO   intervalr   rs   ohlcvs               rZ   watch_ohlcvzdeepcoin.watch_ohlcv  s       !!!!!!!!!V$$!^^DL,CC
##J	9EE$v-4y@x''T66RRRRRRRR? 	2NN6511E))%q$GGGr[   c                 J  K   |                                   d{V  |                     |          }|d         }|                     | j        di           }|                     |||          }d|z   dz   |z   }d|z   }d||ggd}	|                     ||d	||	|           d{V S )
a  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.backpack.exchange/#tag/Streams/Public/K-Line

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str [timeframe]: the length of time each candle represents
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nrv   rO   r!  r"  r#  r&  )r   symbolsAndTimeframesr$  )r   rp   r   rS   r   r   )
rX   rv   r  r   rp   rO   r%  r   rs   r   s
             rZ   un_watch_ohlcvzdeepcoin.un_watch_ohlcv  s       !!!!!!!!!V$$!^^DL,CC
##J	9EE$v-4y@x&,i%8$9
 
 ))&+tV\[abbbbbbbbbr[   c                    |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }|                     |d          }	|                     |	          }
|| j        vr
i | j        |<   |
| j        |         vr9|                     | j        dd          }t          |          | j        |         |
<   | j        |         |
         }|+| 
                    ||          }|                    |           d	|z   d
z   |
z   }|                    ||           d S )Nr   r   r   r   r   r  
OHLCVLimitr   r!  r"  )r   r   r   r   r   find_timeframeohlcvsri   rS   r   parse_ws_ohlcvr   r   )rX   r\   rd   r   r   r   r   rp   rv   r%  r  r   storedr&  r   s                  rZ   handle_ohlcvzdeepcoin.handle_ohlcv  su   0 >>'333xB//~~eS"--##D#..!!(D#66!!(F33##D#..''11	$+%%"$DKT[000%%dlL$GGE-B5-I-IDK	*V$Y/''f55EMM%   $v-4y@v{+++++r[   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )NBr   r   r   Cr   )r   r   )rX   r&  rp   s      rZ   r/  zdeepcoin.parse_ws_ohlcv2  s     s++UC((UC((UC((UC((UC((
 	
r[   c                    K   |                                   d{V  |                     |          }d|d         z   }d}|                     ||d||           d{V }|                                S )a@  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://www.deepcoin.com/docs/publicWS/25LevelIncrementalMarketData

        :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
        Norderbook::rv   _0.125)r   rp   r   r   )rX   rv   r   r   rp   r   rs   	orderbooks           rZ   watch_order_bookzdeepcoin.watch_order_bookI  s       !!!!!!!!!V$$(6(+;;++FKvvVVVVVVVV	   r[   c                    K   |                                   d{V  |                     |          }d|d         z   }d}ddi}|                     ||d|||           d{V S )a  
        unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://www.deepcoin.com/docs/publicWS/25LevelIncrementalMarketData

        :param str symbol: unified array of symbols
        :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
        Nr6  rv   r7  r   r9  r8  r   )rX   rv   r   rp   r   rs   r   s          rZ   un_watch_order_bookzdeepcoin.un_watch_order_book[  s       !!!!!!!!!V$$(6(+;;[
 ))&+tV\[abbbbbbbbbr[   c                    |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }|| j        vr|                                 | j        |<   | j        |         }	|                     |d          }
|	d         :|
dk    r|                     ||           d S |	j        	                    |           d S | 
                    |||	           d	|z   }|                    |	|           d S )
Nr   r   r   r   r   tr   r   r6  )r   r   r   r   r   
orderbooks
order_bookhandle_order_book_snapshotcacher   handle_order_book_messager   )rX   r\   rd   r   r   r   r   rp   rv   r9  rw   r   s               rZ   handle_order_bookzdeepcoin.handle_order_bookn  sR   " >>'333xB//~~eS"--##D#..!!(D#66!!(F33$/))&*oo&7&7DOF#OF+	--[!)s{{//@@@@@ &&w/////**67IFFF,v5KNN9k22222r[   c                    |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }| j        |         }	g g d}
t          dt          |                    D ]}||         }|                     |di           }|                     |d          }|                     |d          }|                     |d	          }|d
k    r|
d         	                    ||g           |dk    r|
d         	                    ||g           | 
                    |d          }|                     |
||          }|	                    |           |	j        }t          dt          |                    D ]!}||         }|                     |||	           "g |	_        d|z   }|                    |	|           d S )Nr   r   r   r   r   )bidsasksr   r  r   r{   rF  rz   rG  mtr6  )r   r   r   r   r   r?  rangelenr   r   ri   parse_order_bookresetrB  rC  r   )rX   r\   rd   entriesr   r   r   rp   rv   r9  orderedEntriesientry	entryDatar  r	  volumer   snapshotcachedMessagesjcachedMessager   s                          rZ   rA  z#deepcoin.handle_order_book_snapshot  s&   ..#r22w2..~~eS"--##D#..!!(D#66!!(F33OF+	 
  
 q#g,,'' 	? 	?AAJEuc266I##Is33D$$Y44E%%i55Fs{{v&--ufo>>>>v&--ufo>>>%%gt44	((KK!!!"q#n--.. 	M 	MA*1-M**6=)LLLL	(61y+.....r[   c                     |                      |d          }||d         k    rL|                     |dg           }|                     ||           ||d<   |                     |          |d<   d S d S )NrH  r   r   r   )ri   r   handle_deltasr   )rX   r\   rd   r9  r   r   s         rZ   rC  z"deepcoin.handle_order_book_message  s      %%gt44	y---~~gsB77Hy(333%.Ik"$(LL$;$;Ij!!!	 .-r[   c                 P   |                      |di           }|d         }|d         }|                     |d          }|                     |d          }|                     |d          }|dk    r|                    ||           d S |dk    r|                    ||           d S d S )	Nr   rF  rG  r   r  r   r{   rz   )r   r   r   store)	rX   r9  rP  r   rF  rG  r  r	  rR  s	            rZ   handle_deltazdeepcoin.handle_delta  s    ~~eS"--  c**  s++!!$,,3;;JJuf%%%%%S[[JJuf%%%%% [r[   c                    K   d}|                                   d{V  ||                     |          }|d|z   z  }|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )a"  
        watches information on multiple trades made by the user

        https://www.deepcoin.com/docs/privateWS/Trade

        :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
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        myTradesNr"  Tr   rv   r   r   r   filter_by_symbol_since_limit)rX   rv   r   r   r   r   r   s          rZ   watch_my_tradeszdeepcoin.watch_my_trades  s       !!!!!!!!!![[((F4&=(K))+v>>>>>>>>? 	3OOFE22E00tTTTr[   c                 |   |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }d}	|	dz   |z   }
|	|j        v s	|
|j        v r| j        0|                     | j        dd	          }t          |          | _        | j        }| 
                    ||          }|                    |           |                    ||	           |                    ||
           d S d S )
Nresultr   r   r   r   r]  r"  r   r   )r   r   r   r   r   futuresr]  ri   rS   r   r   r   r   )rX   r\   rd   rb  r   r   r   rp   rv   r   symbolMessageHashr   r0  parseds                 rZ   handle_my_tradezdeepcoin.handle_my_trade  sI   > 266vq"--~~eVR00##D#..!!(D#66!!(F33 '$.76>))/@FN/R/R}$))$,tLL 6u = =]F((v66FMM&!!!NN6;///NN6#455555 0S/Rr[   c                    K   d}|                                   d{V  ||                     |          }|d|z   z  }|                     ||           d{V }| j        r|                    ||          }|                     ||||d          S )a"  
        watches information on multiple orders made by the user

        https://www.deepcoin.com/docs/privateWS/order

        :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
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        ordersNr"  Tr^  )rX   rv   r   r   r   r   rh  s          rZ   watch_orderszdeepcoin.watch_orders$  s       !!!!!!!!![[((F4&=(K))+v>>>>>>>>? 	3OOFE22E00tTTTr[   c                    |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }d}	|	dz   |z   }
|	|j        v s	|
|j        v r| j        0|                     | j        dd	          }t          |          | _        | 
                    ||          }| j                            |           |                    | j        |	           |                    | j        |
           d S d S )
Nrb  r   r   r   r   rh  r"  ordersLimitr   )r   r   r   r   r   rc  rh  ri   rS   r   parse_ws_orderr   r   )rX   r\   rd   rb  r   r   r   rp   rv   r   rd  r   re  s                rZ   handle_orderzdeepcoin.handle_order:  sJ   > 266vq"--~~eVR00##D#..!!(D#66!!(F33'$.76>))/@FN/R/R{"))$,tLL4U;;((v66FKv&&&NN4;444NN4;(9::::: 0S/Rr[   c                    |                      |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 d d d |d|          S )NOrITr   r   r  clientOrderIdr   r   lastTradeTimestamplastUpdateTimestampr   statusrv   rw   timeInForcer  r	  r  r   r>  r
  r   filledVT	remainingtriggerPriceTPTSLTr   )takeProfitPricestopLossPricer   r   r  
reduceOnlypostOnlyr   )r   r   
safe_orderr   parse_ws_order_statusr  )rX   r  rp   stater   r  s         rZ   rl  zdeepcoin.parse_ws_orderj  s   .   --''t44	$$UC00	  
$""5$// 
T 
 Y// 
 	 

 !$ 
 "4#6#6uc#B#B 
 d0077 
 fX& 
 D 
 4 
 D)))44 
 T%%eS11 
 t''s33 
 d&&uc22 
 d&&ud33 
  ! 
" D# 
$  $//u==!--eU;;$$UC003 
  
  
4 5  	r[   rt  c                 <    dddd}|                      |||          S )Nclosedr   canceled)rz   46r  )rX   rt  statusess      rZ   r  zdeepcoin.parse_ws_order_status  s1    
 

 &&999r[   r   c                 $  K   |                                   d{V  |                                  d{V }|                     |          }d}g }|Ft          dt	          |                    D ]'}||         }	|dz   |	z   }
|                    |
           (n|                    |           | j        d         d         d         dz   |z   }|                     |||dg           d{V }| j        r|S | 	                    | j
        |||d	          S )
a  
        watch all open positions

        https://www.deepcoin.com/docs/privateWS/Position

        :param str[] [symbols]: list of unified market symbols to watch positions for
        :param int [since]: the earliest time in ms to fetch positions for
        :param int [limit]: the maximum number of positions to retrieve
        :param dict params: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
        N	positionsr   r"  r8   r   r<   r   T)r   rN   market_symbolsrI  rJ  r   rR   watch_multipler   filter_by_symbols_since_limitr  )rX   r   r   r   r   rL   r   messageHashesrO  rv   rd  r^   r  s                rZ   watch_positionszdeepcoin.watch_positions  sZ      !!!!!!!!!++--------	%%g..!1c'll++ 8 8 $/$$6$?!$$%677778
   ---it$Y/-?)K--c=&9+VVVVVVVV	? 	11$.'5RWY]^^^r[   c                 R   |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |d d          }|                     ||          }d}	|	dz   |z   }
|	|j        v s	|
|j        v r| j        t                      | _        |                     ||          }| j        	                    |           |
                    | j        |	           |
                    | j        |
           d S d S )Nrb  r   r   r   r   r  r"  )r   r   r   r   r   rc  r  r   parse_ws_positionr   r   )rX   r\   rd   rb  r   r   r   rp   rv   r   rd  re  s               rZ   handle_positionzdeepcoin.handle_position  s/   0 266vq"--~~eVR00##D#..!!(D#66!!(F33!'$.76>))/@FN/R/R~%!9!;!;++D&99FN!!&)))NN4>;777NN4>+<===== 0S/Rr[   c                 v   |                      |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 d d d d d d |d          S )Nr   prO  rv   r   r   r   	contractsPocontractSizer  notionalleveragelunrealizedPnlrealizedPnl
collateral
entryPriceOP	markPriceliquidationPrice
marginModehedgedTu)maintenanceMarginmaintenanceMarginPercentageinitialMargininitialMarginPercentagemarginRatiors  	lastPricer}  r|  r   r   )ri   r   safe_positionr   parse_position_side	omit_zeroparse_ws_margin_mode)rX   positionrp   r   r  r  s         rZ   r  zdeepcoin.parse_ws_position  s     %%h44	$$Xs33	%%h44
!! #
fX&#
$#
 #
 Y//	#

 ))(D99#
 D#
 D,,Y77#
 #
 t'7'7#'F'FGG#
 T#
 4#
 $#
 $**8T::#
 #
 #
  $33J??!#
" d##
$ "&!1!1(C!@!@+/!'+#'!#9#
 #
 #
   	r[   c                 B    ||S ddd}|                      |||          S )Nlongshortr  r  )rX   r  
directionss      rZ   r  zdeepcoin.parse_position_side   s:    
 

 
IyAAAr[   r  c                 B    ||S ddd}|                      |||          S )Nisolatedcrossr  r  )rX   r  modess      rZ   r  zdeepcoin.parse_ws_margin_mode)  s:    
 
 z:>>>r[   c                    |dk    r|                      ||           d S |                     |d          }||dk    r|                     ||           |                     |dd          }|dk    r|                     ||           d S |dk    r|                     ||           d S |dk    r|                     ||           d S |d	k    r|                     ||           d S |d
k    r|                     ||           d S |dk    r| 	                    ||           d S |dk    r| 
                    ||           d S |dk    r|                     ||           d S d S )Npongr   Successar   RecvTopicActionPOPMTPKPMO	PushTrade	PushOrderPushPosition)re   r   handle_error_messager  handle_subscription_statusr   r   r1  rD  rf  rm  r  )rX   r\   rd   r   r   s        rZ   handle_messagezdeepcoin.handle_message2  s   fVW-----  #..AANN))&':::''h??F***//@@@@@4""67333335""67333334!!&'222225&&vw77777;&&$$VW55555;&&!!&'22222>))$$VW55555 *)r[   c                    |                      |dg           }|                     |di           }|                     |di           }|                     |d          }|dk    r|                     |j        d          }|                     |d          }|                     ||i           }	|                     |	d          }
d	|
z   }|                     |j        |i           }|                     ||           d S d S )
Nr   r   r   Ar{   r   r   r   r   )r   r   r   index_byr   ri   handle_un_subscription)rX   r\   rd   r   r   r   r   subscriptionsByIdr   r   r   r   unsubsciptions                rZ   r  z#deepcoin.handle_subscription_statusK  s    $ >>'333xB//~~eS"--!!$,,S== $f.BD I I%%dC00E>>*;UBGGL&&|Y??G''1I NN6+?BOOM''>>>>> =r[   c                     |                      |d          }|                      |d          }|                     |||           |                     |           d S )Nr   r   )r   clean_unsubscriptionclean_cache)rX   r\   r   r   r   s        rZ   r  zdeepcoin.handle_un_subscriptionj  s^    ""<;;$$\;??	!!&'9===&&&&&r[   c                    |                      |dd          }|                     |dg           }|                     |di           }|                     |di           }|                     |d          }|                     |j        d          }|                     ||i           }	|                      |	d          }
| j        d	z   |                     |          z   }	 |                     | j	        d
         ||           | 
                    | j	        d         ||           t          |          # t          $ r!}|                    ||
           Y d }~d S d }~ww xY w)Nr   ro   r   r   r   r   r   r    exactbroad)r   r   r   ri   r  r   r   jsonthrow_exactly_matched_exception
exceptionsthrow_broadly_matched_exceptionr   	Exceptionreject)rX   r\   rd   messageTextr   r   r   rq   r  r   r   feedbackes                rZ   r  zdeepcoin.handle_error_messagep  se   $ &&wR88>>'333xB//~~eS"--%%dC00	 MM&*>EE~~&7BGG&&|Y??7S=499W#5#55	*001I;X`aaa001I;X`aaa))) 	* 	* 	*MM![)))))))))	*s   AD/ /
E9EE)ro   Frc   )A__name__
__module____qualname__r   rW   r   rP   re   rn   r	   floatstrboolr   dictr   r   r   rN   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  listr'  r*  r1  r/  r   r:  r<  rD  rA  rC  r[  r`  rf  r
   ri  rm  rl  r  r   r   r  r  r  r  r  r  r  r  r  __classcell__)rY   s   @rZ   r   r      s       F# F F F F F FP6    &       F u s \_ os    $ acrt p p pc pC pY] plo py| p p p p df|~  OQ l lF l ls l\` luy l  IL l  VY l l l l$ DF K Ks KD K# K K K K
 )+    6 68 I I IF I I I I 9; Z ZC Zs Z Z Z Z$(2F (2 (2 (2 (2T9 9d 9F 9f 9 9 9 9v <@d[] S S SS S Sbfglbm S S S S( 9; Z ZC Z Z Z Z$#-F #- #- #- #-J: :D :& :E : : : :x=# =# = = = ==s =s = = = = ?CQUdhqs H H H H3 H^a Hx|  ~B  yC H H H H2 BFb c c3 c3 cUX c c c c0*,6 *, *, *, *,X
 
F 
d 
 
 
 
. @DB ! !S ! !S\ ! ! ! !$ =? c c c3 c c c c&%3 %3 %3 %3 %3N!/ !/ !/ !/ !/F< < < < <.& & & 37TX\eg U UC Us URU Ulpqvlw U U U U,/6f /6 /6 /6 /6b 04$UYbd U U UC Us Uimnsit U U U U,.;6 .; .; .; .;`4 4F 4e 4 4 4 4l:C :C : : : : 8<$]ajl _ _W _C _WZ _quv~q _ _ _ _<&>f &> &> &> &>P0 0& 0H 0 0 0 0dBS BS B B B B?s ?s ? ? ? ?6V 6 6 6 62? ? ? ? ?>'V '4 ' ' ' ' *6  *  *  *  *  *  *  *  *r[   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr   r   r[   rZ   <module>r     s/       A  A  A  A  A  A  A  A  A  A  A  A e e e e e e e e e e e e e e e e e e e e e e e e 4 4 4 4 4 4       * * * * * * ' ' ' ' ' 'A* A* A* A* A*t!* A* A* A* A* A*r[   