
    ei,                         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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IntMarketNumOrder	OrderSide	OrderTypeStrStringsTickerTickers)List)AuthenticationError)ArgumentsRequired)
BadRequest)InsufficientFunds)ExchangeNotAvailable)	TICK_SIZEc                       e Zd Zdef fdZi fdee         fdZde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defdZdddi fd	e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de$fd$Z&d%d&i ddfd'Z'd(e(d)ed*ed+ed,ed-efd.Z) xZ*S )0p2breturnc                    |                      t          t          |                                           i ddddddg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d.dd/di d0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@di dAddBddCddDddEddFddGddHddIddJddKddLddMddNddOddPddQdi dRddSddTddUddVddWddXddYddZd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ddddddddddddddtdudvdwdxdydzd{d|d}d~dddddddddddddddddidddddddddddd
iddddd|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg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ddddd ddddddd dddddddddddid	d d dd d dddi dt
          di dt          dt          dt          dt          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ۜdi           S )Nidr   name	countriesLT	rateLimitd   versionv2proThasCORSspotmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketOrdercreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChainfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistory)fetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw
timeframes1m1h1d)r   r   r   urlsz.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feesr   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_historyr   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features)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergi )r   limitdaysBack	untilDayssymbolRequired)r   r   triggerr   r   gUUUUUU?)r   r   r   daysBackCanceledr   r   r   r   r   i  )	sandboxr6   r7   rl   
fetchOrderrq   rv   rF   rm   )linearinverse)r&   r(   r)   commonCurrenciesprecisionMode
exceptions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options)
deep_extendsuperr   describeparse_numberr   r   r   r   r   )self	__class__s    F/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/p2b.pyr  zp2b.describe   s   c4 0 0 9 9 ; ; z>
%z>
Ez>
 $z>
 	z>

 tz>
 4z>
  ttt %t 	t
 %t %t Ut $Ut 't t "5t tt t $Ut  t  '!t" $U#t t$ t%t& 't( &u)t* (+t, '-t. (/t0 "51t2  3t4 !%5t6 7t8 &u9t: "5;t< +E=t> )%?t@ #EAtB ,UCtD $TEt t tF 'GtH (ItJ KtL &uMtN (OtP 1%QtR  StT +EUtV &uWtX 'YtZ ([t\ #E]t^ *5_t` $Uatb uctd "5etf *5gt t th +Eitj )%ktl umtn #Eotp  qtr !%stt %eutv $Uwtx &uytz -e{t| /}t~ "5t@ #EAtB +ECtD EtF !%GtH !%It t tJ "5KtL &uMtN +EOtP  QtR dStT $UUtV +EWtX %eYtZ "4[t\ u]t^ #E_t` !$atb "5ctd uetf #Dgth  itj 'kt t tl $Umtn !%otp *5qtr (stt %eutv )%wtx )%ytz t{t| }t~ tt@ %eAtB &uCtD 'EtF $UGtH !%ItJ (KtL )%Mt tN +0#($) %$)',$"!&#(!!gt t tz>
x  yz>
B $BkD>  -X: Cz>
Z #$"##$"# !#$()()	 	 ,-+,%&()"#8978)*1245  [z>
R !%"&**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! Sz>
R $&+(-,1,0).+06:#'#'"&#(	( ( #($)$)+027/4#()$ $, %)&+!$$*%&*.& & #'&+!$#($)*.( ( $(&+!$$*,2%&#($)*/	* 	*  #g6 6p ## 
 ## y@ @Sz>
T  !Uz>
X YYz>
Z  *+*+* +* +	*
 +* +* +* +* +* +* +* +* +* +* +*  +!*" 
#* *$ 
%*& 
'*( 
)** )+*, 
-*. 
/*0 
1*2 
3*4 
5*6 
7*8 
9*: 
;*< 
=*> 
?*@ 
A*B 
C*D 
E* *F #"""",)S* * *[z>
p	  q	z>
 z z z	    c                     |                      |          }|                     |dg           }|                     |          S )a'  
        retrieves data on all markets for bigone

        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
        result)publicGetMarkets
safe_valueparse_markets)r  paramsresponser   s       r  fetch_marketszp2b.fetch_marketsR  sB     ((00< //(Hb99!!'***r  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contractr   	step_size	tick_size)amountprice)minmax
min_amount	min_price)r   r.  r/  cost)
r   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                     |                                   |                     |          }|                     |di           }|                     ||          S )a   
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        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>`
        r  )load_marketspublicGetTickersr  parse_tickers)r  rE  r  r  r  s        r  fetch_tickerszp2b.fetch_tickers  sV     	((004 8R88!!&'222r  r!  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |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

        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>`
        r   r   r  
cache_time  )	timestampdatetime)rG  r   publicGetTickerextendr  safe_integer_productiso8601parse_ticker)r  r!  r  r   requestr  r  rN  s           r  fetch_tickerzp2b.fetch_ticker  s     	V$$fTl
 ''GV(D(DEE* 8R88--hdKK	{{#i1H1HIIff--
 
 	
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atrM  r   lastr!  rN  rO  highlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechanger   averagevolvolumedeal)
baseVolumequoteVolumer<  )rR  r  r=  safe_tickerrS  safe_string_2)r  r   r   rN  rY  s        r  rT  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  r   c           	      f   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |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

        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
        r   r   Nr   r  current_timerM  r!  bidsasksr   r   )rG  r   publicGetDepthResultrQ  r  rR  parse_order_book)	r  r!  r   r  r   rU  r  r  rN  s	            r  fetch_order_bookzp2b.fetch_order_bookE  s     	V$$fTl
 $GG,,T[[&-I-IJJ4 8R88--hMM	$$VVH-=y&RXZ[]^___r  sincec                    |                                   |                     |d          }|t          | j        dz             |                     |          }|d         |d}|||d<   |                     |                     ||                    }|                     |dg           }	|                     |	|||          S )aG  
        get the list of most recent trades for a particular symbol

        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>`
        lastIdNz; fetchTrades() requires an extra parameter params["lastId"]r   )r   rv  r   r  )	rG  safe_integerr   r   r   publicGetHistoryrQ  	safe_listparse_trades)
r  r!  rt  r   r  rv  r   rU  r  r  s
             r  fetch_tradeszp2b.fetch_tradesx  s     	""6844>#DG.k$klllV$$Tl
 
 $GG((Wf)E)EFF( (B77  >>>r  tradec                 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_timerM  roler   r   2r   r   deal_idr!  dealOrderIddeal_order_idr)  sider/  r.  rh  r$  feedeal_feecurrencyr4  )r<  r   rN  rO  r!  orderr)  r  takerOrMakerr/  r.  r4  r  )safe_integer_product_2r=  
safe_traderl  rS  )r  r|  r   rN  r  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  r   	timeframec                 *   |                                   |                     |          }|d         |d}|||d<   |                     |                     ||                    }|                     |dg           }	|                     |	||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        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
        r   )r   intervalNr   r  )rG  r   publicGetMarketKlinerQ  ry  parse_ohlcvs)
r  r!  r  rt  r   r  r   rU  r  r  s
             r  fetch_ohlcvzp2b.fetch_ohlcv  s     	V$$Tl!
 
 $GG,,T[[&-I-IJJ. (B77  E5IIIr  c           	         |                      |dd          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   rM  r               )rR  r?  )r  ohlcvr   s      r  parse_ohlcvzp2b.parse_ohlcv  s     %%eQ55UA&&UA&&UA&&UA&&UA&&
 	
r  c                     |                                   |                     |          }|                     |di           }|                     |          S )av  
        query for balance and get the amount of funds available for trading or funds locked in orders

        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>`
        r  )rG  privatePostAccountBalancesr  parse_balance)r  r  r  r  s       r  fetch_balancezp2b.fetch_balance/  sT     	226::$ 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  r  i
currencyIdbalancecoder  r  accounts              r  r  zp2b.parse_balanceN  s     H
 HMMOO$$q#d))$$ 
	# 
	#AaJz*G**:66D##GX66D((+>>I! G #F4LL  (((r  r)  r  r.  r/  c                    |                                   |dk    rt          | j        dz             |                     |          }|d         ||                     ||          |                     ||          d}|                     |                     ||                    }	|                     |	d          }
| 	                    |
|          S )a  
        create a trade order

        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 fulfilled, 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   z7 createOrder() can only accept orders with type "limit"r   )r   r  r.  r/  r  )
rG  r   r   r   amount_to_precisionprice_to_precisionprivatePostOrderNewrQ  	safe_dictparse_order)r  r!  r)  r  r.  r/  r  r   rU  r  r  s              r  create_orderzp2b.create_orderl  s     	8TW'``aaaV$$Tl..vv>>,,VU;;	
 
 ++DKK,H,HII. (33///r  r   c                 D   |t          | j        dz             |                                  |                     |          }|d         |d}|                     |                     ||                    }|                     |d          }|                     |          S )a  
        cancels an open order

        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   rG  r   privatePostOrderCancelrQ  r  r  )r  r   r!  r  r   rU  r  r  s           r  cancel_orderzp2b.cancel_order  s     >#DG.Y$YZZZV$$Tl
 
 ..t{{7F/K/KLL. (33'''r  c                 X   |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |dg           }|                     ||||          S )a  
        fetch all unfilled currently open orders

        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   rG  r   privatePostOrdersrQ  ry  parse_orders)	r  r!  rt  r   r  r   rU  r  r  s	            r  fetch_open_orderszp2b.fetch_open_orders  s     >#DG._$_```V$$fTl
 $GG))$++gv*F*FGG4 (B77  >>>r  c                 H   |                                   |                     |          }d|i}|||d<   |                     |                     ||                    }|                     |di           }	|                     |	dg           }
|                     |
|||          S )ao  
        fetch all the trades made from a single order

        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>`
        r  Nr   r  records)rG  safe_marketprivatePostAccountOrderrQ  r  ry  rz  )r  r   r!  rt  r   r  r   rU  r  r  r  s              r  fetch_order_tradeszp2b.fetch_order_trades   s      	!!&))r
 $GG//GV0L0LMM0 8R88..B77  &%???r  c                    |t          | j        dz             |                                  |                     |d          }|                     |d          }|||                                 }n|dz   }||dz
  }||z
  dk    rt          | j        dz             |                     |          }|d         |                     |dz            |                     |dz            d}|||d	<   | 	                    | 
                    ||                    }|                     |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

        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   rM  )r   	startTimeendTimer   r  deals)r   r   rG  rw  omitmillisecondsr   r   parse_to_int#privatePostAccountMarketDealHistoryrQ  r  ry  rz  )r  r!  rt  r   r  r  r   rU  r  r  r  s              r  fetch_my_tradeszp2b.fetch_my_trades3  s     >#DG.[$[\\\!!&'2267++=}))++(=H$EEMX%%TW  (E  E  F  F  FV$$Tl**54<88((66
 

 $GG;;DKKQW<X<XYY6 8R88vw33  u===r  c                 L   |                                   |                     |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
          }	g }
t          |	                                          }t          dt          |                    D ]@}||         }|	|         }|                     ||||          }|                     |
|          }
A|
S )az  
        fetches information on multiple closed orders made by the user, the time between since and params["untnil"] cannot be longer than 24 hours

        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>`
        r  Nr  z_ fetchClosedOrders() the time between since and params["until"] cannot be greater than 24 hoursrM  )r  r  r   r   r   r  r   )rG  rw  r  r   r  r   r   r  privatePostAccountOrderHistoryrQ  r  r  r  r  r  r  array_concat)r  r!  rt  r   r  r  r   rU  r  r  r   r  r  rA  marketOrdersparsedOrderss                   r  fetch_closed_orderszp2b.fetch_closed_ordersx  s     	!!&'2267++[[((F=}))++(=H$EEMX%%TW  (I  I  J  J  J**54<88((66
 
  &tGH$GG66t{{7F7S7STT6 844FKKMM""q#d))$$ 	= 	=AAwH!(+L,,\65%PPL&&v|<<FFr  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 )NrN  ctimerM  r   r<  r   r  clientOrderIdrO  lastTradeTimestampr!  r)  r   postOnlyr  r/  r   r.  r4  re  filled	dealStockleftr$  dealFeer  )	remainingstatusr  trades)r  r=  r  
safe_orderrl  rS  )r  r  r   rN  rA  s        r  r  zp2b.parse_order  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 
 d&&uh77 
 D 
  t! 
" d&&uk::# 
$ ))%88"7O((	::  1 
  
  
2 3  	r  r   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 )Nr   r"  r  ?r   z/api/v2/rU  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  pathr   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  r  reasonr  r  r  r  c
                     |d S |dk    rh|                      |d          }
|                     |
d          }| j        dz   |                     |          z   }|                     | j        ||           d S )Ni  errorr   )r  r=  r   r  throw_exactly_matched_exceptionr   )r  r  r  r  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  dictrD  r   r   rJ  r  r   rV  rT  r   rs  r{  r  r  r  r  r  r  r   r
   floatr   r  r   r  r  r  r  r	   r  r  r  intr  __classcell__)r  s   @r  r   r      s       {# { { { { { {z	 $& (+ (+$v, (+ (+ (+ (+T9
4 9
F 9
 9
 9
 9
v 04B &3 &3W &37 &3 &3 &3 &3P 02 )
 )
3 )
f )
 )
 )
 )
V9 96 9 9 9 9v :>b 1` 1`s 1`3 1` 1` 1` 1`f 6:UW -? -?3 -?s -?# -? -? -? -?^@ @ @v @ @ @ @D 9=4^bkm .J .J# .J# .JS .JX[ .J .J .J .J`
 
 
4 
 
 
 
, $& * * * *>) ) )< gksu 00 003 00i 00y 00RW 00`c 00 00 00 00d 37r +( +(s +(C +( +( +( +(Z /3TXac 3? 3? 3?3 3?c 3? 3? 3? 3?j 9=4^bkm 1@ 1@S 1@# 1@S 1@X[ 1@ 1@ 1@ 1@f -1tRV_a C> C>c C> C>C C> C> C> C>J 154VZce J J# JS JPS Jjnotju J J J JXB B Bv B B B B BH &eBSW P P P P&	# 	s 	 	c 	TX 	`c 	 	 	 	 	 	 	 	r  r   )ccxt.base.exchanger   ccxt.abstract.p2br   r  ccxt.base.typesr   r   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@   ( ' ' ' ' ' ) ) ) ) ) )  m m m m m m m m m m m m m m m m m m m m m m m m m m       0 0 0 0 0 0 . . . . . . ' ' ' ' ' ' . . . . . . 1 1 1 1 1 1 4 4 4 4 4 4Q Q Q Q Q(K Q Q Q Q Qr  