
    i,                         d dl mZ d dlm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 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)
IntMarketNumOrder	OrderSide	OrderTypeStrStringsTickerTickers)List)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)ExchangeNotAvailable)	TICK_SIZEc                       e Zd Z fdZi fdee         fdZdefdZdi fdede	fdZ
i fdedefd	Zd&d
efdZdi fdedefdZddi fdededefdZd&d
efdZdddi fdededefdZd&d
edefdZi fdZd Zdi fdededededef
dZdi fdedefdZdd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fdZ dd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&d
ede"fd!Z$d"d#i ddfd$Z%d% Z& xZ'S )'p2bc                 V   |                      t          t          |                                           dddg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	d'd	d(d	i d)d	d*d	d+d	d,d	d-d	d.d	d/d	d0d	d1d	d2d	d3d	d4dd5d	d6dd7dd8d	d9d	i d:dd;dd<d	d=dd>dd?d	d@d	dAd	dBd	dCd	dDd	dEddFddGddHd	dId	dJd	d	d	d	d	d	d	d	d	d	d	d	d	d	dKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d[d[d[d[d[d[d[d\id]d[d[d[d[d[d[d[d[d[d[d^
idUd_dd|                     d`          |                     da          g|                     db          |                     dc          g|                     dd          |                     de          g|                     df          |                     dg          g|                     dh          |                     di          g|                     dj          |                     dk          g|                     dl          |                     dm          g|                     dn          |                     do          g|                     dp          |                     dq          g|                     dr          |                     ds          g|                     dt          |                     du          gg|                     d`          |                     da          g|                     db          |                     de          g|                     dd          |                     di          g|                     df          |                     dm          g|                     dh          |                     dq          g|                     dj          |                     du          g|                     dl          |                     dv          g|                     dn          |                     dw          g|                     dp          |                     dx          g|                     dr          |                     dy          g|                     dt          |                     dz          ggd{ii t
          i d|t          d}t          d~t          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          t          t          di d          S )Nr   LTd   v2TCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketOrdercreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLedgerEntryfetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrdersfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPermissionsfetchPositionfetchPositionsfetchPositionsForSymbolfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingLimitsfetchTransactionFeefetchTransactionFees)fetchTransactionsfetchTransfersfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsreduceMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw1m1h1d)rm   rn   ro   z.jsonz$https://p2pb2b.com?referral=ee784c53zQhttps://github.com/ccxt/ccxt/assets/43336371/8da13a80-1f0a-49be-bb90-ff8b25164755z$https://api.p2pb2b.com/api/v2/publiczhttps://api.p2pb2b.com/api/v2)publicprivatezhttps://p2pb2b.com/z?https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.mdz https://p2pb2b.com/fee-schedule/)	extensionreferrallogoapiwwwdocfeesget   )marketsmarkettickerstickerbookhistoryzdepth/resultzmarket/klinepost)
zaccount/balanceszaccount/balancez	order/newzorder/cancelorderszaccount/market_order_historyzaccount/market_deal_historyzaccount/orderzaccount/order_historyzaccount/executed_historytrading0z0.21z0.195z0.1810z0.1725z0.1675z0.15100z0.14150z0.13300z0.12450z0.11500z0.1z0.08z0.06z0.04z0.02z0.01)	tierBased
percentagetakermaker1001100210031004100510061007100810091010101110121013101410151016201020202021203020402050205120522060206120622070300130203030304030503060)3070308030903100311040016010)idname	countries	rateLimitversionprohas
timeframesurlsru   rx   commonCurrenciesprecisionMode
exceptionsoptions)
deep_extendsuperr   describeparse_numberr   r   r   r   r   )self	__class__s    \/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/p2b.pyr   zp2b.describe   sU
   c4 0 0 9 9 ; ;RRR %R 	R
 %R %R UR "5R tR R $UR  R 'R $UR tR  !R" &u#R R$ (%R& ''R( ()R* "5+R,  -R. /R0 &u1R2 )%3R4 $T5R6 '7R8 (9R: ;R< &u=R> (?R@ 1%ARB  CRD +EER R RF &uGRH #EIRJ *5KRL $UMRN "5ORP *5QRR +ESRT uURV #EWRX %eYRZ +E[R\ ]R^ !%_R`  aRb dcRd $UeRf +EgR R Rh "4iRj !$kRl "5mRn toRp #DqRr #EsRt  uRv !%wRx *5yRz %e{R| )%}R~ tR@ ARB tCRD %eERF &uGRH 'IR RJ &+"'*/#($) %$"!&#(!!cR R Rh   %BkD>  -X:  #$"##$"# !#$()()	 	 ,-+,%&()"#8978)*1245  : !%"&**3//1B1B51I1IJ**3//1B1B61J1JK**3//1B1B61J1JK**400$2C2CF2K2KL**400$2C2CF2K2KL**400$2C2CF2K2KL**51143D3DV3L3LM**51143D3DV3L3LM**51143D3DV3L3LM**51143D3DV3L3LM**51143D3DU3K3KL **3//1B1B51I1IJ**3//1B1B61J1JK**3//1B1B61J1JK**400$2C2CF2K2KL**400$2C2CF2K2KL**400$2C2CE2J2JK**51143D3DV3L3LM**51143D3DV3L3LM**51143D3DV3L3LM**51143D3DV3L3LM**51143D3DV3L3LM! @!&*+*+* +* +	*
 +* +* +* +* +* +* +* +* +* +* +*  +!*" 
#* *$ 
%*& 
'*( 
)** )+*, 
-*. 
/*0 
1*2 
3*4 
5*6 
7*8 
9*: 
;*< 
=*> 
?*@ 
A*B 
C*D 
E* *F #"""",)S* * *VkW>
 W>
 W W W	    returnc                    K   |                      |           d{V }|                     |dg           }|                     |          S )a+  
        retrieves data on all markets for bigone
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nresult)publicGetMarkets
safe_valueparse_markets)r   paramsresponser{   s       r   fetch_marketszp2b.fetch_markets   sX       ..v66666666< //(Hb99!!'***r   c                 N   |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                     |d          }|                      |d          }|                      |d          }	i d|d|d	z   |z   d
|d|dd d|d|dd dddddddddddddddd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   stockmoneylimits
max_amount	max_pricer   symbol/basequotesettlebaseIdquoteIdsettleIdtyper   Tr   Fr   r    r!   activecontractlinear	step_size	tick_size)amountprice)minmax
min_amount	min_price)leverager   r   cost)
inversecontractSizeexpiryexpiryDatetimestrike
optionType	precisionr   createdinfo)safe_stringsafe_currency_coder   safe_numberr   	omit_zero)
r   r|   marketIdr   r   r   r   r   	maxAmountmaxPrices
             r   parse_marketzp2b.parse_market  s   ##FF33!!&'22""6733&&v..''0022$$V\::	##FK880
(0
dSj5(0
 D0
 U	0

 d0
 f0
 w0
 0
 F0
 D0
 e0
 E0
 e0
 e0
 d0
  !0
" d#0
$  "**6;??))&+>>    
  ++FLAA,,T^^I-F-FGG 
  ++FK@@,,T^^H-E-EFF 
    $ _0
 0
 0
 0	
r   Nsymbolsc                    K   |                                   d{V  |                     |           d{V }|                     |di           }|                     ||          S )a&  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://futures-docs.poloniex.com/#get-real-time-ticker-of-all-symbols
        :param str[]|None 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   )load_marketspublicGetTickersr   parse_tickers)r   r  r   r   r   s        r   fetch_tickerszp2b.fetch_tickersR  s~       !!!!!!!!!..v666666664 8R88!!&'222r   r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |dd          }|                     ||                     |          d|                     ||                    S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#ticker
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr|   r   r   
cache_time  )	timestampdatetime)r	  r|   publicGetTickerextendr   safe_integer_productiso8601parse_ticker)r   r   r   r|   requestr   r   r  s           r   fetch_tickerzp2b.fetch_tickerx  s       !!!!!!!!!V$$fTl
 --dkk'6.J.JKKKKKKKK* 8R88--hdKK	{{#i1H1HIIff--
 
 	
r   r|   c                    |                      |dd          }d|v 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d |                     |dd          |                     |d          |d|          S )Natr  r~   lastr   r  r  highlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechanger   averagevolvolumedeal)
baseVolumequoteVolumer   )r  r   r   safe_tickerr  safe_string_2)r   r~   r|   r  r  s        r   r  zp2b.parse_ticker  s   @ --fdDAA	v__VX66F// !
d&&vx88!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D$$VV44!
 T!
 D!
 T!
 d!
  $**68<<!!
" t#!
$ ,,VUHEE++FF;;)!
 !
 !
* +  	r   limitc           	        K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dd          }|                     ||d         |d	d
dd          S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#depth-result
        :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
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param str [params.interval]: 0(default), 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nr|   r   r/  r   current_timer  r   bidsasksr   rz   )r	  r|   publicGetDepthResultr  r   r  parse_order_book)	r   r   r/  r   r|   r  r   r   r  s	            r   fetch_order_bookzp2b.fetch_order_book  s       !!!!!!!!!V$$fTl
 $GG224;;w3O3OPPPPPPPP4 8R88--hMM	$$VVH-=y&RXZ[]^___r   sincec                   K   |                                   d{V  |                     |d          }|t          | j        dz             |                     |          }|d         |d}|||d<   |                     |                     ||                     d{V }|                     |dg           }	|                     |	|||          S )aM  
        get the list of most recent trades for a particular symbol
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#history
        :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]: 1-100, default=50
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int params['lastId']: order id
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        NlastIdz; fetchTrades() requires an extra parameter params["lastId"]r   )r|   r9  r/  r   )	r	  safe_integerr   r   r|   publicGetHistoryr  	safe_listparse_trades)
r   r   r7  r/  r   r9  r|   r  r   r   s
             r   fetch_tradeszp2b.fetch_trades  s       !!!!!!!!!""6844>#DG.k$klllV$$Tl
 
 $GG..t{{7F/K/KLLLLLLLL( (B77  >>>r   c                 H   |                      |ddd          }|                     |d          }|dk    rd}n|dk    rd}|                     ||                     |d	d
          ||                     |          |                     |d          |                     |dd          d |                     |dd          ||                     |d          |                     |d          |                     |d          |d         |                     |dd          dd|          S )Ntime	deal_timer  roler   r   2r   r   deal_idr   dealOrderIddeal_order_idr   sider   r   r*  r   feedeal_feecurrencyr   )r   r   r  r  r   orderr   rG  takerOrMakerr   r   r   rH  )safe_integer_product_2r   
safe_trader.  r  )r   trader|   r  rM  s        r   parse_tradezp2b.parse_trade:  sF   R //v{DQQ	''v663"LLS  "L$$UD)<<"Y//&&vx88''}oNN&&uff==(%%eW55&&uh77$$UF33"7O**5%DD  
  
" #  	r   rm   c                 F  K   |                                   d{V  |                     |          }|d         |d}|||d<   |                     |                     ||                     d{V }|                     |dg           }	|                     |	||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#kline
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: 1m, 1h, or 1d
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: 1-500, default=50
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.offset]: default=0, with self value the last candles are returned
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr   )r|   intervalr/  r   )r	  r|   publicGetMarketKliner  r<  parse_ohlcvs)
r   r   	timeframer7  r/  r   r|   r  r   r   s
             r   fetch_ohlcvzp2b.fetch_ohlcv|  s       !!!!!!!!!V$$Tl!
 
 $GG224;;w3O3OPPPPPPPP. (B77  E5IIIr   c           	         |                      |dd          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r  rz               )r  r  )r   ohlcvr|   s      r   parse_ohlcvzp2b.parse_ohlcv  s     %%eQ55UA&&UA&&UA&&UA&&UA&&
 	
r   c                    K   |                                   d{V  |                     |           d{V }|                     |di           }|                     |          S )a|  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#all-balances
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr   )r	  privatePostAccountBalancesr   parse_balance)r   r   r   r   s       r   fetch_balancezp2b.fetch_balance  s|       !!!!!!!!!88@@@@@@@@$ 8R88!!&)))r   c                 l   d|i}t          |                                          }t          dt          |                    D ]]}||         }||         }|                     |          }|                     |d          }|                     |d          }	|	|d}
|
||<   ^|                     |          S )Nr   r   freeze	available)freeused)listkeysrangelenr   r   safe_balance)r   r   r   ri  i
currencyIdbalancecoderg  re  accounts              r   ra  zp2b.parse_balance  s     H
 HMMOO$$q#d))$$ 
	# 
	#AaJz*G**:66D##GX66D((+>>I! G #F4LL  (((r   r   rG  r   r   c                   K   |                                   d{V  |dk    rt          | j        dz             |                     |          }|d         ||                     ||          |                     ||          d}|                     |                     ||                     d{V }	|                     |	d          }
| 	                    |
|          S )a  
        create a trade order
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#create-order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: must be '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 fullfilled, 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>`
        Nr|   z7 createOrder() can only accept orders with type "limit"r   )r|   rG  r   r   r   )
r	  r   r   r|   amount_to_precisionprice_to_precisionprivatePostOrderNewr  	safe_dictparse_order)r   r   r   rG  r   r   r   r|   r  r   r   s              r   create_orderzp2b.create_order  s       !!!!!!!!!8TW'``aaaV$$Tl..vv>>,,VU;;	
 
 11$++gv2N2NOOOOOOOO. (33///r   r   c                 `  K   |t          | j        dz             |                                  d{V  |                     |          }|d         |d}|                     |                     ||                     d{V }|                     |d          }|                     |          S )a  
        cancels an open order
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#cancel-order
        :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>`
        Nz) cancelOrder() requires a symbol argumentr   )r|   orderIdr   )r   r   r	  r|   privatePostOrderCancelr  rv  rw  )r   r   r   r   r|   r  r   r   s           r   cancel_orderzp2b.cancel_order+  s       >#DG.Y$YZZZ!!!!!!!!!V$$Tl
 
 44T[[&5Q5QRRRRRRRR. (33'''r   c                 t  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        fetch all unfilled currently open orders
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#open-orders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param int [params.offset]: 0-10000, default=0
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz/ fetchOpenOrders() requires the symbol argumentr|   r   r/  r   )r   r   r	  r|   privatePostOrdersr  r<  parse_orders)	r   r   r7  r/  r   r|   r  r   r   s	            r   fetch_open_orderszp2b.fetch_open_ordersV  s       >#DG._$_```!!!!!!!!!V$$fTl
 $GG//GV0L0LMMMMMMMM4 (B77  >>>r   c                 d  K   |                                   d{V  |                     |          }d|i}|||d<   |                     |                     ||                     d{V }|                     |di           }	|                     |	dg           }
|                     |
|||          S )a  
        fetch all the trades made from a single order
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#deals-by-order-id
        :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]: 1-100, default=50
        :param dict [params]: extra parameters specific to the exchange API endpoint
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param int [params.offset]: 0-10000, default=0
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nrz  r/  r   records)r	  safe_marketprivatePostAccountOrderr  r   r<  r=  )r   r   r   r7  r/  r   r|   r  r   r   r  s              r   fetch_order_tradeszp2b.fetch_order_trades  s       !!!!!!!!!!!&))r
 $GG55dkk'66R6RSSSSSSSS0 8R88..B77  &%???r   c                   K   |t          | j        dz             |                                  d{V  |                     |d          }|                     |d          }|||                                 }n|dz   }||dz
  }||z
  dk    rt          | j        dz             |                     |          }|d         |                     |dz            |                     |dz            d}|||d	<   | 	                    | 
                    ||                     d{V }|                     |d
i           }	|                     |	dg           }
|                     |
|||          S )a  
        fetch all trades made by the user, only the transaction records in the past 3 month can be queried, the time between since and params["until"] cannot be longer than 24 hours
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#deals-history-by-market
        :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, default = params["until"] - 86400000
        :param int [limit]: 1-100, default=50
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for, default = current timestamp or since + 86400000
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param int [params.offset]: 0-10000, default=0
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nz+ fetchMyTrades() requires a symbol argumentuntil \&z[ fetchMyTrades() the time between since and params["until"] cannot be greater than 24 hoursr   r  )r|   	startTimeendTimer/  r   deals)r   r   r	  r:  omitmillisecondsr   r|   parse_to_int#privatePostAccountMarketDealHistoryr  r   r<  r=  )r   r   r7  r/  r   r  r|   r  r   r   r  s              r   fetch_my_tradeszp2b.fetch_my_trades  s      >#DG.[$[\\\!!!!!!!!!!!&'2267++=}))++(=H$EEMX%%TW  (E  E  F  F  FV$$Tl**54<88((66
 

 $GGAA$++gW]B^B^________6 8R88vw33  u===r   c                 h  K   |                                   d{V  |                     |d          }|                     |d          }d}||                     |          }|||                                 }n|dz   }||dz
  }||z
  dk    rt          | j        dz             |                     |dz            |                     |dz            d}||d         |d<   |||d	<   |                     | 	                    ||                     d{V }| 
                    |d
          }	g }
t          |	                                          }t          dt          |                    D ]@}||         }|	|         }|                     ||||          }|                     |
|          }
A|
S )a  
        fetches information on multiple closed orders made by the user, the time between since and params["untnil"] cannot be longer than 24 hours
        :see: https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#orders-history-by-market
        :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, default = params["until"] - 86400000
        :param int [limit]: 1-100, default=50
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch orders for, default = current timestamp or since + 86400000
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param int [params.offset]: 0-10000, default=0
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  z_ fetchClosedOrders() the time between since and params["until"] cannot be greater than 24 hoursr  )r  r  r   r|   r/  r   r   )r	  r:  r  r|   r  r   r   r  privatePostAccountOrderHistoryr  r   rh  ri  rj  rk  r  array_concat)r   r   r7  r/  r   r  r|   r  r   r   r   ri  rm  r  marketOrdersparsedOrderss                   r   fetch_closed_orderszp2b.fetch_closed_orders  s       !!!!!!!!!!!&'2267++[[((F=}))++(=H$EEMX%%TW  (I  I  J  J  J**54<88((66
 
  &tGH$GG<<T[[RX=Y=YZZZZZZZZ6 844FKKMM""q#d))$$ 	= 	=AAwH!(+L,,\65%PPL&&v|<<FFr   c           
         |                      |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 |d         |                     |d          dd d|          S )Nr  ctimer  r|   r   r   rz  clientOrderIdr  lastTradeTimestampr   r   timeInForcepostOnlyrG  r   	stopPricer   r   r'  filled	dealStockleftr   dealFeerJ  )	remainingstatusrH  trades)rN  r   r  
safe_orderr.  r  )r   rL  r|   r  r  s        r   rw  zp2b.parse_orderG  s   L //{GTRR	##E844!!(F33  
E 
$$$UD)<< 
 T 
 	 

 Y// 
 !$ 
 fX& 
 D$$UF33 
 4 
  
 D$$UF33 
 T%%eW55 
  
 d&&uh77 
 D 
  t! 
" d&&uk::# 
$ ))%88"7O((	::  1 
  
  
2 3  	r   rp   GETc           	         | j         d         |         dz   |                     ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }|dk    rd|z   |d<   t          |                                           |d<   |                     |                     |                    }d	| j	        || 
                    |                     |          |                     | j                  t          j                  d
}|                     |          }||||dS )Nru   r   r  ?rq   z/api/v2/r  noncezapplication/json)zContent-TypezX-TXC-APIKEYzX-TXC-PAYLOADzX-TXC-SIGNATURE)urlmethodbodyheaders)r   implode_paramsr  extract_params	urlencodestrr  string_to_base64jsonapiKeyhmacencodesecrethashlibsha512)	r   pathru   r  r   r  r  r  payloads	            r   signzp2b.sign  s9   is#c)D,?,?f,M,MM64#6#6t#<#<==U?? 4sT^^F3333) *T 1F9!$**,,//F7O++DIIf,=,=>>G 2 $!(#'99T[[-A-A4;;t{C[C[]d]k#l#l	 G 99V$$DfdwOOOr   c
                     |d S |dk    rh|                      |d          }
|                     |
d          }| j        dz   |                     |          z   }|                     | j        ||           d S )Ni  errorrp   )r   r   r   r  throw_exactly_matched_exceptionr   )r   rp  reasonr  r  r  r  r   requestHeadersrequestBodyr  	errorCodefeedbacks                r   handle_errorszp2b.handle_errors  sy    43;;OOHg66E((77Iw}tyy':'::H00)XVVVtr   )N)(__name__
__module____qualname__r   r   r   r   r  r   r   r  r  r   r  r  r   r6  r>  rQ  rW  rh  r^  rb  ra  r
   r	   floatr   rx  r   r|  r  r  r  r   r  rw  r  r  __classcell__)r   s   @r   r   r      s/       X X X X Xt *, &+ &+V &+ &+ &+ &+P9
f 9
 9
 9
 9
v 6:" $3 $37 $3 $3 $3 $3 $3L 68 '
 '
 '
F '
 '
 '
 '
R9 96 9 9 9 9v @DB /` /`S /` /` /` /` /`b <@d[] +? +? +?S +? +? +? +? +?Z@ @ @ @ @ @D 8<$]ajl ,J ,J ,JC ,JWZ ,J ,J ,J ,J\
 
 
4 
 
 
 
, *, * * * *:) ) )< mqy{ .0 .0 .0I .0Y .0X] .0fi .0 .0 .0 .0` 9=R )( )(S )(# )( )( )( )(V 59tZ^gi 1? 1?c 1? 1?TW 1? 1? 1? 1?f ?CQUdhqs /@ /@3 /@ /@3 /@^a /@ /@ /@ /@b 37TX\eg A> A>C A>s A>RU A> A> A> A>F 7;\`ik H H H3 HVY Hptuzp{ H H H HTB B B5 B B B BH &eBSW P P P P&	 	 	 	 	 	 	r   r   ) ccxt.async_support.base.exchanger   ccxt.abstract.p2br   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   ccxt.base.decimal_to_precisionr   r    r   r   <module>r     s:   6 5 5 5 5 5 ) ) ) ) ) )  h h h h h h h h h h h h h h h h h h h h h h h h       0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' . . . . . . 1 1 1 1 1 1 4 4 4 4 4 4T T T T T(K T T T T Tr   