
    !:h                         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y)    )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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 )/p2breturnc                 4   | j                  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ddddddddddddddddRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddededededededededfidgdededededededededededh
id^didjdd| j	                  dk      | j	                  dl      g| j	                  dm      | j	                  dn      g| j	                  do      | j	                  dp      g| j	                  dq      | j	                  dr      g| j	                  ds      | j	                  dt      g| j	                  du      | j	                  dv      g| j	                  dw      | j	                  dx      g| j	                  dy      | j	                  dz      g| j	                  d{      | j	                  d|      g| j	                  d}      | j	                  d~      g| j	                  d      | j	                  d      gg| j	                  dk      | j	                  dl      g| j	                  dm      | j	                  dp      g| j	                  do      | j	                  dt      g| j	                  dq      | j	                  dx      g| j	                  ds      | j	                  d|      g| j	                  du      | j	                  d      g| j	                  dw      | j	                  d      g| j	                  dy      | j	                  d      g| j	                  d{      | j	                  d      g| j	                  d}      | j	                  d      g| j	                  d      | j	                  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ddeddd ddddddd ddddded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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fetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingLimits)fetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsreduceMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw
timeframes1m1h1d)ry   rz   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  )	sandboxr3   r4   rT   
fetchOrderrX   r[   r>   rU   )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    B/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/p2b.pyr   zp2b.describe   s
   c4 9 ; Z>
%Z>
EZ>
 $Z>
 	Z>

 tZ>
 4Z>
  TTT %T 	T
 %T %T UT "5T tT T $UT  T 'T $UT tT  !T" &u#T$ (%T& ''T( ()T* "5+T,  -T. /T0 &u1T2 )%3T4 $T5T6 '7T8 (9T: ;T< &u=T> (?T@ 1%ATB  CTD +EETF &uGTH #EITJ *5KTL $UMTN "5OTP *5QTR +ESTT uUTV #EWTX %eYTZ +E[T\ ]T^ !%_T`  aTb dcTd $UeTf +EgTh "4iTj !$kTl "5mTn uoTp #DqTr  sTt 'uTv $UwTx !%yTz *5{T| (}T~ %eT@ )%ATB tCTD ETF tGTH %eITJ (-(-%*"'*/#($) %$"!&#(!!gTZ>
x yZ>
B $BkD> -X:CZ>
Z #$"##$"# !#$()()	 ,-+,%&()"#8978)*1245[Z>
R !%"&**3/1B1B51IJ**3/1B1B61JK**3/1B1B61JK**40$2C2CF2KL**40$2C2CF2KL**40$2C2CF2KL**5143D3DV3LM**5143D3DV3LM**5143D3DV3LM**5143D3DV3LM**5143D3DU3KL **3/1B1B51IJ**3/1B1B61JK**3/1B1B61JK**40$2C2CF2KL**40$2C2CF2KL**40$2C2CE2JK**5143D3DV3LM**5143D3DV3LM**5143D3DV3LM**5143D3DV3LM**5143D3DV3LM!SZ>
R $&+(-,1,0).+06:#'#'"&#(	( #($)$)+027/4#()$, %)&+!$$*%&*.& #'&+!$#($)*.( $(&+!$$*,2%&#($)*/	*  #g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	    c                 l    | j                  |      }| j                  |dg       }| j                  |      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_markets2  s9     ((0< //(Hb9!!'**r   r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }| j                  |d      }| j                  |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 | j                  |d      | j                  |d      dd d d| j                  |d      | j	                  | j                  |            d| j                  |d       | j	                  | j                  |	            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!!&'2""673&&v.''02$$V\:	##FK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,,T^^I-FG
  ++FK@,,T^^H-EF
  $ _0
 0	
r   Nsymbolsc                     | j                          | j                  |      }| j                  |di       }| j                  ||      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   r%  r   r   r   s        r   fetch_tickerszp2b.fetch_tickers  sG     	((04 8R8!!&'22r   r  c                 H   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |dd      }| j                  || j                  |      d| j                  ||            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)r'  r   publicGetTickerextendr   safe_integer_productiso8601parse_ticker)r   r  r   r   requestr   r   r.  s           r   fetch_tickerzp2b.fetch_ticker  s     	V$fTl
 ''GV(DE* 8R8--hdK	{{#i1HIff-
 	
r   c                 N   | j                  |dd      }d|v r| j                  |d      }| j                  |d      }| j                  i d| j                  |d      d|d| j	                  |      d| j                  |d      d	| j                  |d	      d
| j                  |d
      dd d| j                  |d      dd dd d| j                  |d      d|d|dd dd d| j                  |d      dd | j                  |dd      | j                  |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  )r2  r   r  safe_tickerr3  safe_string_2)r   r   r   r.  r9  s        r   r4  zp2b.parse_ticker  s   @ --fdDA	v__VX6F/ !
d&&vx8!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D$$VV4!
 T!
 D!
 T!
 d!
  $**68<!!
" t#!
$ ,,VUHE++FF;)!
* + 	r   r   c           	      "   | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dd      }| j                  ||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   r   r   current_timer-  r  bidsasksr   r   )r'  r   publicGetDepthResultr1  r   r2  parse_order_book)	r   r  r   r   r   r5  r   r   r.  s	            r   fetch_order_bookzp2b.fetch_order_book%  s     	V$fTl
 $GG,,T[[&-IJ4 8R8--hM	$$VVH-=y&RXZ[]^__r   sincec                 J   | j                          | j                  |d      }|t        | j                  dz         | j	                  |      }|d   |d}|||d<   | j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      S )aI  
        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>`
        lastIdz; fetchTrades() requires an extra parameter params["lastId"]r   )r   rV  r   r   )	r'  safe_integerr   r   r   publicGetHistoryr1  	safe_listparse_trades)
r   r  rT  r   r   rV  r   r5  r   r   s
             r   fetch_tradeszp2b.fetch_tradesX  s     	""684>#DGG.k$kllV$Tl
 $GG((Wf)EF( (B7  >>r   tradec                    | j                  |ddd      }| j                  |d      }|dk(  rd}n|dk(  rd}| j                  || j                  |d	d
      || j	                  |      | j                  |d      | j                  |dd      d | j                  |dd      || j                  |d      | j                  |d      | j                  |d      |d   | j                  |dd      dd|      S )Ntime	deal_timer-  roler   r   2r   r   deal_idr  dealOrderIddeal_order_idr	  sider  r  rH  r  feedeal_feecurrencyr  )r  r   r.  r/  r  orderr	  re  takerOrMakerr  r  r  rf  )safe_integer_product_2r  
safe_traderL  r3  )r   r\  r   r.  rk  s        r   parse_tradezp2b.parse_trade  s   R //v{DQ	''v63"LS "L$$UD)<"Y/&&vx8''}oN&&uff=(%%eW5&&uh7$$UF3"7O**5%D 
" # 	r   ry   c                     | j                          | j                  |      }|d   |d}|||d<   | j                  | j                  ||            }| j	                  |dg       }	| j                  |	||||      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   intervalr   r   )r'  r   publicGetMarketKliner1  rY  parse_ohlcvs)
r   r  	timeframerT  r   r   r   r5  r   r   s
             r   fetch_ohlcvzp2b.fetch_ohlcv  s     	V$Tl!
 $GG,,T[[&-IJ. (B7  E5IIr   c           	          | j                  |dd      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r-  r               )r2  r  )r   ohlcvr   s      r   parse_ohlcvzp2b.parse_ohlcv  sp     %%eQ5UA&UA&UA&UA&UA&
 	
r   c                     | j                          | j                  |      }| j                  |di       }| j                  |      S )ax  
        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   )r'  privatePostAccountBalancesr   parse_balance)r   r   r   r   s       r   fetch_balancezp2b.fetch_balance  sE     	226:$ 8R8!!&))r   c                 $   d|i}t        |j                               }t        dt        |            D ]K  }||   }||   }| j	                  |      }| j                  |d      }| j                  |d      }	|	|d}
|
||<   M | j                  |      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_balance.  s     H
 HMMO$q#d)$ 
	#AaJz*G**:6D##GX6D((+>I!G #F4L
	#   ((r   r	  re  r  r  c                 \   | j                          |dk(  rt        | j                  dz         | j                  |      }|d   || j	                  ||      | j                  ||      d}| j                  | j                  ||            }	| j                  |	d      }
| j                  |
|      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   re  r  r  r   )
r'  r   r   r   amount_to_precisionprice_to_precisionprivatePostOrderNewr1  	safe_dictparse_order)r   r  r	  re  r  r  r   r   r5  r   r   s              r   create_orderzp2b.create_orderL  s     	8TWW'``aaV$Tl..vv>,,VU;	
 ++DKK,HI. (3//r   r   c                    |t        | j                  dz         | j                          | j                  |      }|d   |d}| j	                  | j                  ||            }| j                  |d      }| j                  |      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>`
        z) cancelOrder() requires a symbol argumentr   )r   orderIdr   )r   r   r'  r   privatePostOrderCancelr1  r  r  )r   r   r  r   r   r5  r   r   s           r   cancel_orderzp2b.cancel_order~  s     >#DGG.Y$YZZV$Tl
 ..t{{7F/KL. (3''r   c                 $   |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   | j	                  | j                  ||            }| j                  |dg       }| j                  ||||      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>`
        z/ fetchOpenOrders() requires the symbol argumentr   r   r   r   )r   r   r'  r   privatePostOrdersr1  rY  parse_orders)	r   r  rT  r   r   r   r5  r   r   s	            r   fetch_open_orderszp2b.fetch_open_orders  s     >#DGG._$_``V$fTl
 $GG))$++gv*FG4 (B7  >>r   c                    | j                          | j                  |      }d|i}|||d<   | j                  | j                  ||            }| j	                  |di       }	| j                  |	dg       }
| j                  |
|||      S )aq  
        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  r   r   records)r'  safe_marketprivatePostAccountOrderr1  r   rY  rZ  )r   r   r  rT  r   r   r   r5  r   r   r  s              r   fetch_order_tradeszp2b.fetch_order_trades  s      	!!&)r
 $GG//GV0LM0 8R8..B7  &%??r   c                 `   |t        | j                  dz         | j                          | j                  |d      }| j	                  |d      }||| j                         }n|dz   }||dz
  }||z
  dkD  rt        | j                  dz         | j                  |      }|d   | j                  |dz        | j                  |dz        d}|||d<   | j                  | j                  ||            }| j                  |d	i       }	| j                  |	d
g       }
| j                  |
|||      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>`
        z+ 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'  rW  omitmillisecondsr   r   parse_to_int#privatePostAccountMarketDealHistoryr1  r   rY  rZ  )r   r  rT  r   r   r  r   r5  r   r   r  s              r   fetch_my_tradeszp2b.fetch_my_trades  sU     >#DGG.[$[\\!!&'267+=}))+(=H$EEMX%TWW  (E  E  F  FV$Tl**54<8((6

 $GG;;DKKQW<XY6 8R8vw3  u==r   c                    | j                          | j                  |d      }| j                  |d      }d}|| j                  |      }||| j	                         }n|dz   }||dz
  }||z
  dkD  rt        | j                  dz         | j                  |dz        | j                  |dz        d}||d   |d<   |||d	<   | j                  | j                  ||            }| j                  |d
      }	g }
t        |	j                               }t        dt        |            D ]2  }||   }|	|   }| j                  ||||      }| j!                  |
|      }
4 |
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

        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 hoursr-  )r  r  r   r   r   r   r   )r'  rW  r  r   r  r   r   r  privatePostAccountOrderHistoryr1  r   r  r  r  r  r  array_concat)r   r  rT  r   r   r  r   r5  r   r   r   r  r  r!  marketOrdersparsedOrderss                   r   fetch_closed_orderszp2b.fetch_closed_ordersX  s     	!!&'267+[[(F=}))+(=H$EEMX%TWW  (I  I  J  J**54<8((6
  &tGH$GG66t{{7F7ST6 84FKKM"q#d)$ 	=AAwH!(+L,,\65%PL&&v|<F		=
 r   rj  c           
      <   | j                  |ddd      }| j                  |d      }| j                  ||      }| j                  i d|d| j	                  |dd      dd d|d	| j                  |      d
d d|d   d| j                  |d      dd dd d| j                  |d      d| j                  |d      dd d| j                  |d      dd dd d| j                  |d      | j                  |d      d |d   | j                  |d      dd d|      S )Nr.  ctimer-  r   r  r   r  clientOrderIdr/  lastTradeTimestampr  r	  r   postOnlyre  r  r   r  r  rE  filled	dealStockleftr  dealFeerh  )	remainingstatusrf  trades)rl  r  r  
safe_orderrL  r3  )r   rj  r   r.  r!  s        r   r  zp2b.parse_order  s   L //{GTR	##E84!!(F3  
E 
$$$UD)< 
 T 
 	 

 Y/ 
 !$ 
 fX& 
 D$$UF3 
 4 
  
 D$$UF3 
 T%%eW5 
 D 
 d&&uh7 
 D 
  t! 
" d&&uk:# 
$ ))%8"7O((	: 1 
2 3 	r   r}   GETc           	      B   | j                   d   |   dz   | j                  ||      z   }| j                  || j                  |            }|dk(  r|r|d| j	                  |      z   z  }|dk(  rd|z   |d<   t        | j                               |d<   | j                  | j                  |            }d	| j                  || j                  | j                  |      | j                  | j                        t        j                        d
}| j                  |      }||||dS )Nr   r  r  ?r~   z/api/v2/r5  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  s   iis#c)D,?,?f,MM64#6#6t#<=U?sT^^F333) *T 1F9!$**,/F7O++DIIf,=>G 2 $!(#'99T[[-A4;;t{{C[]d]k]k#l	G 99V$DfdwOOr   r  reasonr  r  r  r  c
                     |y |dk(  rb| j                  |d      }
| j                  |
d      }| j                  dz   | j                  |      z   }| j	                  | j
                  ||       y )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  sh    3;OOHg6E((7Iww}tyy'::H00)XVr   )N)+__name__
__module____qualname__r   r   r   r   r   dictr$  r   r   r*  r  r   r6  r4  r   rS  r[  rn  rt  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
v 04B &3W &37 &3P 02 )
3 )
f )
V96 9v :>b 1`s 1`3 1`f 6:UW -?3 -?s -?# -?^@ @v @D 26DW[df .J# .Jc .JQT .J`
 
4 
, $& *>)< gksu 003 00i 00y 00RW 00`c 00d 37r +(s +(C +(Z /3TXac 3? 3?3 3?c 3?j 9=4^bkm 1@S 1@# 1@S 1@X[ 1@f -1tRV_a C>c C> C>C C>J 154VZce J# JS JPS Jjnotju JXB Bv B BH &eBSW 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     sA    ( )  m m m m  0 . ' . 1 4q(K qr   