
    !:h`                    x   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlm Z  d dl!m"Z" d dl!m#Z# d dl!m$Z$ d d	l!m%Z% d d
l!m&Z& d dl!m'Z' d dl!m(Z( d dl!m)Z) d dl!m*Z* d dl!m+Z+ d dl!m,Z, d dl!m-Z- d dl!m.Z. d dl!m/Z/ d dl0m1Z1 d dl2m3Z3  G d dee      Z4y)    )Exchange)ImplicitAPIN)AnyBalancesBool
CurrenciesCurrencyDepositAddressIntLeverageMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)ExchangeNotAvailable)OnMaintenance)RequestTimeout)	TICK_SIZE)Precisec                       e Zd Zdef fdZdfdedefdZdddi fdede	d	e	de
e   fd
Zdi f fd	Zi fde
e   fdZi fde
e   fdZi fde
e   fdZdedefdZdedefdZdedefdZi fde	fdZdfdededefdZdi fdedefdZi fdefdZi fdedefdZdfdededefdZddi fdede	d	e	de
e   fdZdddi fde de	d	e	fdZ!de fdZ"dfd edede#fd!Z$d" Z%d# Z&dddi fde de	d	e	de
e#   fd$Z'dddi fde de	d	e	de
e#   fd%Z(di fded&e)d'e*d(e+d)e,f
d*Z-di fd+Z.ddi fd,eded&e)d'e*d(e,d)e,fd-Z/di fd,ede fd.Z0di fde fd/Z1di fd,ede fd0Z2di fd,ede fd1Z3dddi fd,ede de	d	e	fd2Z4de5fd3Z6i fde5fd4Z7i fde8fd5Z9di fded	e	de:fd6Z;i fd7ede<fd8Z=i fd7ede<fd9Z>i fd7ed(e+d:ed;ede?f
d<Z@dfd=ed>eAde?fd?ZBdi fd7ed(e+d@edeCfdAZDdddi fd7e de	d	e	fdBZEdddi fd7e de	d	e	de
eC   fdCZFdddi fd7e de	d	e	de
eC   fdDZGdi fdEefdFZHdgdGZIdfd>eAfdHZJdddi fd7e de	d	e	de
eC   fdIZKde fdJZLdfdKed>eAdeCfdLZMdi fdMe	de fdNZNi fdedeOfdOZPdfdMededeOfdPZQdi fde fdQZRdi fdReSde fdSZTdi fdede
eU   fdTZVdfdUedefdVZWi fdedeXfdWZYdfdXededeXfdYZZi fded(e+deXfdZZ[i fded(e+deXfd[Z\d\ Z]d]d^i ddfd_Z^d7e_d`edaedbedceddefdeZ` xZaS )hpoloniexreturnc                    | 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
d0d
i d1d
d2d d3d d4dd5d d6d
d7dd8dd9dd:d
d;d
d<dd=dd>dd?d
d@ddAd
i dBddCddDddEddFddGddHd
dIddJd+dKd
dLd
dMddNddOddPddQddRddSdidTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdfdgddhididjdkdldmdndoi dpdqdrdsdtdqdudqdvdqdwdqdxdsdydsdzdsd{dsd|dsd}dsd~dsddsddqddqddqdsdsdsdii ddddddddqddqddddqddsddddqddddqddddqddqddqdddddqdddqddqdqdqddddqdqdqdqddqddd	ddqdqddqdqddqdqdddoi ddddddddddddddddddddddddddddddddddiddqdqdqdqdqdqdqdqd	dddqddqdqdqdddqdqdddddo| j	                  d      | j	                  d      di ddi ddddddddddÓddœddǓddɓdd˓dd͓ddϓddѓddӓddՓddדddٓddۓdddddddddd	dddddddddddddddddddddiidddddddddddd d
d
d
d dddd
dd
d
dd
dd
d
dddqid
dddd
dd
d
d
d
dd
dd
d
d
dd d ddid	dd id dd
ddd
dddiddid
dd dd d
d
d
dddddddiddidddiddidd	d
t
        di dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        d t        d!t        d"t        d#t        d$t        d%t        d&t        d't        d(t        d)t        d*t        d+t        d,t         d-t         i d.t         d/t        d0t        d1t"        d2t"        d3t$        d4t         d5t        d6t        d7t$        d8t        d9t        d:t$        d;t        d<t         d=t         d>t         i d?t         d@t         dAt         dBt         dCt         dDt         dEt         dFt         dGt        dHt         dIt         dJt         dKt         dLt         dMt         dNt         dOt         i dPt         dQt         dRt         dSt         dTt         dUt        dVt        dWt        dXt        dYt         dZt         d[t         d\t         d]t         d^t         d_t         d`t         i dat        dbt         dct        ddt         det         dft         dgt        dht"        dit         djt        dkt$        dlt$        dmt$        dnt        dot        dpt        dqt        i dr      S (s  Nidr/   namePoloniex	countriesUS	rateLimit   	certifiedFproThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreateStopOrdercreateTriggerOrder	editOrderfetchBalancefetchClosedOrderfetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchLedgerfetchLeveragefetchLiquidationsfetchMarginModefetchMarketsfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawalsreduceMarginsandboxsetLeveragesetPositionModetransferwithdraw
timeframesMINUTE_1MINUTE_5	MINUTE_10	MINUTE_15	MINUTE_30HOUR_1HOUR_2HOUR_4HOUR_6HOUR_12DAY_1DAY_3WEEK_1MONTH_1)1m5m10m15m30m1h2h4h6h12h1d3d1w1Murlszchttps://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpgzhttps://api.poloniex.com)r=   r?   z*https://sand-spot-api-gateway.poloniex.comzhttps://www.poloniex.comz#https://api-docs.poloniex.com/spot/zhttps://poloniex.com/feesz&https://poloniex.com/signup?c=UBFZJRPJ)logoapitestwwwdocfeesreferralr   getmarkets   zmarkets/{symbol}   
currencieszcurrencies/{currency}zv2/currencieszv2/currencies/{currency}	timestampzmarkets/pricezmarkets/{symbol}/pricezmarkets/markPricezmarkets/{symbol}/markPricez$markets/{symbol}/markPriceComponentszmarkets/{symbol}/orderBookzmarkets/{symbol}/candleszmarkets/{symbol}/tradeszmarkets/ticker24hzmarkets/{symbol}/ticker24h)zmarkets/collateralInfoz!markets/{currency}/collateralInfozmarkets/borrowRatesInfoaccounts   zaccounts/balanceszaccounts/{id}/balanceszaccounts/activityaccounts/transferzaccounts/transfer/{id}feeinfozaccounts/interest/historysubaccountszsubaccounts/balanceszsubaccounts/{id}/balancessubaccounts/transferzsubaccounts/transfer/{id}zwallets/addresseszwallets/addresses/{currency}zwallets/activityzmargin/accountMargin)zmargin/borrowStatuszmargin/maxSizeordersorders/{id}zorders/killSwitchStatussmartorderssmartorders/{id}zorders/historyzsmartorders/historytradeszorders/{id}/trades)	r   r   zwallets/addresszwallets/withdrawzv2/wallets/withdrawr   zorders/batchzorders/killSwitchr   )r   zorders/cancelByIdsr   r   zsmartorders/cancelByIdsr   )r   r   )r   postdeleteputzv3/market/allInstrumentsgUUUUUU?zv3/market/instrumentszv3/market/orderBookzv3/market/candles
   z v3/market/indexPriceCandlesticksz"v3/market/premiumIndexCandlestickszv3/market/markPriceCandlestickszv3/market/tradeszv3/market/liquidationOrderzv3/market/tickerszv3/market/markPricezv3/market/indexPricezv3/market/indexPriceComponentszv3/market/fundingRatezv3/market/openInterestzv3/market/insurancezv3/market/riskLimit)	zv3/account/balancezv3/account/billszv3/trade/order/openszv3/trade/order/tradeszv3/trade/order/historyzv3/trade/position/openszv3/trade/position/historyzv3/position/leveragesv3/position/mode(   d   )v3/trade/orderzv3/trade/orderszv3/trade/positionzv3/trade/positionAllzv3/position/leverager   zv3/trade/position/margin   )r   zv3/trade/batchOrderszv3/trade/allOrders)r   r   r   )publicprivate
swapPublicswapPrivater   z0.0009)feeSidemakertaker)tradingfundingcommonCurrenciesAIRAirCoinAPHAphroditeCoinBCCBTCtalkcoinBCHABCBDG
BadgercoinBTMBitmarkCONCoinoETHTRONETHGOLD
GoldEaglesGPUCGPUHOTHotcoinITCzInformation CoinKEYKEYCoinMASKzNFTX Hashmasks IndexMEMEzDegenerator MemePLXParallaxCoinREPV2REPXLMSOCCUnitradeTRXzAPI CoinUSDTUSTC)	STRSOCTRADETRXETHXAPUSDTBSCUSDTTRONUSDTETHUSToptionsBSCTRON)BEP20ERC20TRC20costming-C6?g      ?gQ?)BTCr   r   r   BNBUSDCUSDJTUSDDAIPAXBUSDfutures)r=   r@   )exchanger  )defaultType!createMarketBuyOrderRequiresPricenetworkslimitsaccountsByTypeaccountsByIdfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventiontrailingicebergmax  i )r  limitdaysBack	untilDayssymbolRequired)r  triggerr"  r)    )r  r&  r*  r"  r)  r&    )	r}   rJ   rK   rf   rk   rj   fetchOrdersrQ   rg   extendsdefault)r  r  r  stpModer  gUUUUUU?)r  r&  r'  daysBackCanceledr(  r*  r"  r)  Z   )r&  r(  )r.  rJ   rK   rj   rQ   rf   forContracts)linearinverse)r/  r=   r3  r?   r@   precisionMode
exceptions5006036014156022160421600216052110221100217042170021705217072170821601217112170925000025000125000225000325000425000525000825001221110100401006010020100412134021341213422134321351213522135321354213592136024106242012130121302213042130521307213092131021311213122131421315213172131921320213212132221324213272132821330213352133621337213442134521346213482134721349213502135521356217212410124102241032410424105250202500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019)exactbroad)deep_extendsuperr/   describeparse_numberr,   r)   r+   r#   r   r"   r   r!   r%   r$   r*   r&   r    r'   )self	__class__s    U/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/poloniex.pyr  zpoloniex.describe    sZ   h > @ YC
*YC
JYC
 $YC

 YC
 YC
 4YC
  FFF $F 	F
 $F %F TF "4F tF F 'F /F ,UF 0F tF  !F" "4#F$ %d%F& T'F( )F* #E+F, $T-F. "4/F0 &t1F2 (3F4 1%5F6  7F8 +D9F: *:;F< +D=F> &u?F@ 'AFB (CFD #EEFF *5GFH $TIFJ tKFL  MFN $TOFP "5QFR SFT  UFV dWFX +EYFZ !%[F\ "4]F^ d_F` !$aFb "5cFd #DeFf  gFh $TiFj !$kFl tmFn oFp TqFr tsFt "5uFv #DwFx $ZyFz  {F| !%}F~ #DF@ AFB 4CFD tEFF "4GFH DIFJ DKFYC
^   """ _YC
~ }66
 H 2<3DYC
Z  !2*A %b 0	
 ( 3B $Q ( 1! ,Q 5a ? 5a 3A 22  ,R!" 5b#$ 34=>34)2"A+Q 1! ,R	
 ,R 1! "2 4Q &q / 4Q / 4Q ,R 7  +B!" /#$ 01*+"$'(34'),-*,/1"$./9> ./02+-,./1"#(*-.'(
 ().0"$,-35') (*,.e6p  2E 0 .u	
 ,R ;B =b :2 +E 5e ,U .u / 9% 0  1%!" .u#$ .u%0 /0,.021324355713,.
 +,+--/0302,.46 +,02.0+ MA[YC
^ $!..x8!..x8	 _YC
p  $!y$!$! }$! (	$!
 |$! y$! w$! 5$! $! $! y$! )$! y$! .$! *$!  ~!$!" #$!$ #! ""!G$!qYC
z %59""# #)#)$'#&#'$'$'$*#&#&$' $ #'#
 !''!;!{YC
~	 #&*(,,0,1).+06:#'#'"&#(	( #($)+/27/3$)#()$. r% ',!%$*%+*/& ',#($)*/	# ',!%#($)*/( $()-#c4l y  )&*(-"&#'+0$ r%  ( ',!$$(,1%)#($)*/	* "%%'&3!@ "> "> 	 "> "> 	g	YC
N YOYC
P l/l >l :	l
 =l ,l Zl 0l 0l ]l 0l 0l Zl Zl  ]!l" Z#l$ -%l& ]'l( .)l* m+l, j-l. j/l0 j1l2 j3l4 /5l6 j7l8 m9l< Z=l> Y?l@ ]AlB YClD YElF ]GlH \IlJ \KlL \MlN -OlP YQlR -SlT -UlV ]WlX \YlZ Z[l\ 1]l` ]alb ]cld ]elf ]glh ]ilj \kll \mln \olp \qlr \slt \ulv \wlx \ylz \{l| \}l~ \l@ ZAlB \ClD \ElF \GlH \IlJ \KlL \MlN \OlP \QlR \SlT \UlV \WlX \YlZ \[l\ ]]l^ Z_l` .alb Ycld \elf \glh \ilj \kll \mlp \qlr \slt \ulv ]wlx \ylz ]{l| \}l~ \l@ \AlB ]ClD -ElF \GlH ]IlJ ]KlL ]MlN ]OlP ]QlR ]SlT ZUlV YWlZ]pQYC
 Y Y	    Nmarketc           	         t        |      }|dk(  }|rh| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )	N	      r   r   r      r8      )lensafe_integersafe_number)r  ohlcvr  ohlcvLength
isContracts        r  parse_ohlcvzpoloniex.parse_ohlcv<  s    J %j A%
!!%+  *  *  *  *  *  eR(UA&UA&UA&UA&UA&
 	
r  r   symbolsincer&  c           	      2  K   | j                          d{    d}| j                  |ddd      \  }}|r| j                  d|||||d       d{   S | j                  |      }|d   | j	                  | j
                  ||      d}|d   rd	nd
}	|d   rdnd}
||||	<   |||d<   | j                  |
||      \  }}|d   r| j                  |ddg      r't        | j                  dz   |z   dz   |d   z   dz         | j                  | j                  ||             d{   }| j                  |d      }| j                  |||||      S | j                  | j                  ||             d{   }| j                  |||||      S 7 w7 @7 o7 !w)a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://api-docs.poloniex.com/spot/api/public/market-data#candles
        https://api-docs.poloniex.com/v3/futures/api/market/get-kline-data

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        NFrg   paginater,  r2   )r  intervalr=   	startTimesTimeendTimeeTimer&  contractr   r    typez fetchOHLCV is not supporteddata)load_marketshandle_option_and_params"fetch_paginated_call_deterministicr  safe_stringr   handle_until_optionin_arrayr(   r2   swapPublicGetV3MarketCandlesextend	safe_listparse_ohlcvspublicGetMarketsSymbolCandles)r  r  	timeframer  r&  paramsr  r  requestkeyStartkeyEndresponseRawr  responses                 r  fetch_ohlcvzpoloniex.fetch_ohlcvu  s      !!!88z[`a&@@vW\^cenpvx{|||V$Tl(()YO
 #).;g$Vn' %GH$GG2267FK*}}Y6"477S=9#<s#BVF^#SVt#tuu $ A A$++gW]B^ __K$ >>+v6D$$T69eUKK;;DKKQW<XYY*   69eUKK} 	" }" `( ZsG   FF9FFCF#F$AF3F4FFFFFc                    K   t         t        |   ||       d {   }| j                  | j                  d      }||r)| j                  | j                  d      | j                  d<   |S 7 Ow)NcurrenciesByNumericId	numericId)r  r/   r  
safe_valuer   index_byr   )r  reloadr  r   r  r  s        r  r  zpoloniex.load_markets  se     h:66JJ $>U V!)f48MM$//S^4_DLL01	 Ks   A-A+AA-c                    K   | j                  |      | j                  |      g}t        j                  |  d{   }| j	                  |d   |d         S 7 w)a  
        retrieves data on all markets for poloniex

        https://api-docs.poloniex.com/spot/api/public/reference-data#symbol-information
        https://api-docs.poloniex.com/v3/futures/api/market/get-all-product-info

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r   )fetch_spot_marketsfetch_swap_marketsasynciogatherarray_concat)r  r  promisesresultss       r  fetch_marketszpoloniex.fetch_markets  sY      ++F3T5L5LV5TU11  WQZ88 2s   8AAAc                 b   K   | j                  |       d {   }| j                  |      S 7 wN)publicGetMarketsparse_markets)r  r  r   s      r  r  zpoloniex.fetch_spot_markets  s1     --f550 !!'**1 6s   /-/c                    K   | j                  |       d {   }| j                  |d      }| j                  |      S 7 'w)Nr  )#swapPublicGetV3MarketAllInstrumentsr  r  )r  r  r  r   s       r  r  zpoloniex.fetch_swap_markets  sD     AA&IIN ..62!!'**Q Js   A?(Ac                 N    d|v r| j                  |      S | j                  |      S )NctType)parse_swap_marketparse_spot_market)r  r  s     r  parse_marketzpoloniex.parse_market!  s,    v))&11))&11r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }|dk(  }| 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 | j                  | j	                  | j                  |	d                  | j                  | j	                  | j                  |	d                  d| j                  |	d      d dd d d| j                  |	d      d dd | j                  |d!      |d"
S )#Nr  baseCurrencyNamequoteCurrencyNamestateNORMALsymbolTradeLimitr2   /basequotesettlebaseIdquoteIdsettleIdr  r=   Tr>   Fr?   r@   rA   activer  r4  quantityScale
priceScaleamountpriceminQuantityr   r$  	minAmount)r   r  r   tradableStartTime)
r5  contractSizeexpiryexpiryDatetimestrike
optionType	precisionr  createdinfo)r  safe_currency_coder  r  parse_precisionr  r  )
r  r  r2   r  r  r  r  r  r  r  s
             r  r  zpoloniex.parse_spot_market'  s0   fh/!!&*<=""6+>?&&v.''0  1("??63EF,
",
dSj5(,
 D,
 U	,

 d,
 f,
 w,
 ,
 F,
 D,
 e,
 E,
 e,
 e,
 f,
  !,
" d#,
$  "++D,@,@AQAQRbdsAt,uv**4+?+?@P@PQaco@p+qr  ++,<mL
  
  ++,<kJ ((1DEW,
 ,	
r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |      }| j                  |d      }	|	dk(  }
|d   dk(  }|d	z   |z   }|r	|d
|z   z  }n|d
|z   z  }| j                  |d      }d}|d}i d|d|d|d|d|d|d|d|d|dk(  rdndddddd|dk(  d|dk(  ddd|
ddd|| | j                  |d      d d d d | j                  |d      | j                  |d       | j                  |d!      | j                  |d"      d#| j                  |d$      | j                  |d%      d&| j                  |d'      | j                  |d(      d&d d d&| j                  |d)      d d*d+| j                  |d,      |d-S ).Nr  bCcyqCcysCcystatusOPENr  LINEARr  :aliasr?   r@   r2   r  r  r  r  r  r  r  r=   Fr>   rA   r  r  Tr4  ctValtFeemFeelotSztSzr  minSzlimitMaxQtyr  minPxmaxPxmaxLever)r$  r   )r   r  r   r  oDate)r5  r  r  r  r	  r
  r   r   r  r  r  r  )r  r  r  r  )r  r  r2   r  r  r  r  r  r  r  r  r4  r  r  r  s                  r  r  zpoloniex.parse_swap_market_  s   F fh/!!&&1""662##FF3&&v.''0((2!!&(36!!X-e#cFl"F cDj F  1D2
"2
f2
 D2
 U	2

 f2
 f2
 w2
 2
 !1H2
 E2
 e2
 DFN2
 dh&2
 e2
 f2
  !2
" f#2
$ "z ,,VW="%%ff5%%ff5**67;))&%8  ++FG<++FMB
  ++FG<++FG<
  
  ++FJ?$ ((9c2
 2	
r  c                 d   K   | j                  |       d{   }| j                  |d      S 7 w)aj  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://api-docs.poloniex.com/spot/api/public/reference-data#system-timestamp

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        N
serverTime)publicGetTimestampr  )r  r  r  s      r  
fetch_timezpoloniex.fetch_time  s3      0088  <88 9s   0.0tickerc           
         | j                  |dd      }| j                  |dd      }| j                  |      }| j                  |dd      }t        j                  |d      }| j                  i d|d|d   d	|d
| j                  |      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |dd      dd d| j                  |dd      d| j                  |dd      dd dd d |d!d | j                  |d"d#      | j                  |d$d%      | j                  |d&d'      | j                  |d(      |d)|      S )*NtscTr  sdailyChangedc100r2   r   datetimehighhlowlbidbPx	bidVolumebidQuantitybSzaskaPx	askVolumeaskQuantityaSzvwapopenoclosecpreviousClosechange
percentageaveragequantityqtyr   amt	markPricemPxiPx)
baseVolumequoteVolumerK  
indexPricer  )safe_integer_2safe_string_2safe_marketr-   
string_mulsafe_tickeriso8601r  )r  r(  r  r   marketIdrelativeChangerF  s          r  parse_tickerzpoloniex.parse_ticker  s   ` ''d;	%%fh<!!(+++FM4H''>
 !
(!
fX&!
 !
 Y/	!

 D&&vvs;!
 4%%feS9!
 4%%feU;!
 ++FM5I!
 4%%feU;!
 ++FM5I!
 D!
 D&&vvs;!
 T''=!
 T!
 d!
  *!!
" t#!
$ ,,VZG--fhF++FKG**659-!
. / 	r  symbolsc                   K   | j                          d{    d}i }|F| j                  |dddd      }t        |      }|dkD  r!| j                  |d         }|dk(  r|d   |d<   d}| j	                  d||      \  }}|d	k(  rM| j                  | j                  ||             d{   }| j                  |d
      }| j                  ||      S | j                  |       d{   }	| j                  |	|      S 7 7 U7 w)ah  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://api-docs.poloniex.com/spot/api/public/market-data#ticker
        https://api-docs.poloniex.com/v3/futures/api/market/get-market-info

        :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>`
        NTFr   r   r2   r  rs   r?   r  )
r  market_symbolsr  r  handle_market_type_and_paramsswapPublicGetV3MarketTickersr  r  parse_tickerspublicGetMarketsTicker24h)
r  rZ  r  r  r  symbolsLength
marketTyper  r  r  s
             r  fetch_tickerszpoloniex.fetch_tickers$  s#     !!!))'4tUKGLMq WQZ0 A%(.tGH%
!??PVX^_
F $ A A$++gW]B^ __K6 >>+v6D%%dG4477??2 !!(G44G 	" `: @s4   DC<BD(C>)<D%D &D>D Dc                   K   | j                  | j                  |ddi             d{   }i }t        dt        |            D ]  }| j	                  ||      }t        |j                               }| j	                  |d      }| j	                  ||      }| j                  |      }	| j                  |d      }
| j                  |d      }d}|| j                  ||	      }| j	                  |d      }| j                  |d      d	k(  }| j                  |d
      d	k(  }| j                  |d      d	k(  }| xr
 |xr |xr |}| j                  |d      }| j                  |d      }| j	                  |d      }|du }| j	                  ||	      -||	d|
|||| j                  |      ddddddddddddd||	<   | j                  ||	   d      }|||nt        j                  ||      }| j	                  ||	   d      }|r|n|}| j	                  ||	   d      }|r|n|}| j	                  ||	   di       }|-||||||||| j                  |      dddddddddddd||<   |||	   d<   | j	                  ||	   dg       }i }|||<   |j                  |       |||	   d<   |r|||	   d<   |
||	   d<   |xr |||	   d<   |||	   d<   |||	   d<   | j                  |      ||	   d<    |S 7 ǭw)a1  
        fetches all available currencies on an exchange

        https://api-docs.poloniex.com/spot/api/public/reference-data#currency-information

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        includeMultiChainCurrenciesTNr   r3   
blockchaindelistedwalletStateENABLEDwalletDepositStatewalletWithdrawalStater2   withdrawalFeeparentChaincryptor  )r   depositr   )r2   coder  r3   r  ro  r   feer  r  r  rq  ro  r   r  )r   r   ro  )r  r2   network
currencyIdr  ro  r   r  rq  r  r  r  r  )publicGetCurrenciesr  ranger  r  listkeysr  r  network_id_to_coder  r  r-   
string_minappend)r  r  r  resultiitemidsr2   currencyrp  r3   	networkIdnetworkCoderg  walletEnableddepositEnabledwithdrawEnabledr  r  	feeStringrm  noParentChainminFeeStringdepositAvailablewithdrawAvailabler  r  rawInfos                               r  fetch_currencieszpoloniex.fetch_currenciest  s     11$++fGdfjFk2lmm4 q#h-( ^	BA??8Q/Dtyy{#Ca(BtR0H**2.D##Hf5D((<@IK$"55iFx<H ,,X}ERM!--h8LMQZZN"..x9PQU^^O!\ZmZZ?F))(D9I((?CI//(MBK'4/Mvt,4   $- /,,Y7!%$ $(#'#
 $(#'$
 $(#'% t4  ++F4L%@L$-9-AyHZHZ[dfrHs#vd|YG2@~GW $tj I4CJ[vd|ZDH&$#*"$!*- /$,,Y7!% $(#'#
 $(#'%
 $(#'$)%4 (0F4L$??6$<<DG"GBKKK #'F4L %'tT"'+tV$%5%K:KF4L"&6F4L#'8F4L$"&"3"3L"AF4L}^	B~ u ns   'K3K0KK3c                 V  K   | j                          d{    | j                  |      }d|d   i}|d   r0| j                  |d   g|       d{   }| j                  ||      S | j	                  | j                  ||             d{   }| j                  ||      S 7 7 S7 w)a'  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://api-docs.poloniex.com/spot/api/public/market-data#ticker
        https://api-docs.poloniex.com/v3/futures/api/market/get-market-info

        :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  r2   r  )r  r  rc  	safe_dictpublicGetMarketsSymbolTicker24hr  rY  )r  r  r  r  r  tickersr  s          r  fetch_tickerzpoloniex.fetch_ticker  s      !!!V$fTl
 * ..x0@/A6JJG>>'622==dkk'SY>Z[[.   622? 	" K[s3   B)B#:B)B%:B)B'B)%B)'B)tradec                    | j                  |g d      }| j                  |dd      }| j                  |g d      }| j                  |d      }| j	                  ||d      }|d   }| j                  |dd      }d }	| j                  |d	d
      }
| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |dd      }|| j                  |      }||d}	| j                  |||| j                  |      ||| j                  |dd      || j                  |dd      |
|||	d|      S )N)r2   tradeIDtrdIdorderIdordId)r*  
createTimer+  cTimer  _side	takerSider  pxrH  rI  r   rJ  feeCurrencyfeeCcy	feeAmountfeeAmt)r   r  ordTyper  	matchRolerole)r2   r  r   r0  r  orderr  r  takerOrMakerr  r   r   rq  )	safe_string_nrR  safe_integer_nr  rS  safe_string_lower_2r  
safe_traderV  )r  r  r  r2   r  r   rW  r  r  rq  priceStringamountString
costStringfeeCurrencyIdfeeCostStringfeeCurrencyCodes                   r  parse_tradezpoloniex.parse_trade%  sz   B 'AB$$UIw?''/RS	##E84!!(FC8!''v{C((>))%UC''x?
**5-J**5+xH$"55mDO%+C "Y/,,UIvF 44UKP " 
  	r  c                   K   | j                          d{    | j                  |      }d|d   i}|||d<   |d   rO| j                  | j                  ||             d{   }| j	                  |d      }| j                  ||||      S | j                  | j                  ||             d{   }	| j                  |	|||      S 7 7 i7 w)aw  
        get the list of most recent trades for a particular symbol

        https://api-docs.poloniex.com/spot/api/public/market-data#trades
        https://api-docs.poloniex.com/v3/futures/api/market/get-execution-info

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr  r2   r&  r  r  )r  r  swapPublicGetV3MarketTradesr  r  parse_tradespublicGetMarketsSymbolTrades)
r  r  r  r&  r  r  r  r  
tradesListr   s
             r  fetch_tradeszpoloniex.fetch_trades  s      !!!V$fTl
 $GG*!==dkk'SY>Z[[H &9J$$ZFF88Wf9UVV   >>O 	" \" Ws5   CCAC#C$AC2C3CCCc                   K   | j                          d{    d}| j                  |dd      \  }}|r| j                  d||||       d{   S d}|| j                  |      }d}| j	                  d||      \  }}| j                  |ddg      }i }	|rdnd}
|rd	nd
}|||	|
<   |||	d<   |r
||d   |	d<   | j                  ||	|      \  }	}|rO| j                  | j                  |	|             d{   }| j                  |d      }| j                  ||||      S | j                  | j                  |	|             d{   }| j                  ||||      }|S 7 K7 7 o7 "w)a  
        fetch all trades made by the user

        https://api-docs.poloniex.com/spot/api/private/trade#trade-history
        https://api-docs.poloniex.com/v3/futures/api/trade/get-execution-details

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        NFrf   r  r?   r@   r  r  r  r  r&  r2   r  r  )r  r  fetch_paginated_call_dynamicr  r]  r  r   swapPrivateGetV3TradeOrderTradesr  r  r  privateGetTrades)r  r  r  r&  r  r  r  rb  r  r  startKeyendKeyrawr  r  r{  s                   r  fetch_my_tradeszpoloniex.fetch_my_trades  s     !!!88R\]&::?FTY[`bhiii[[(F
!??QWY_`
F]]:/AB

 )7k&I %GH$GG&, &tGH2267FK==dkk'SY>Z[[C@ >>#v.D$$T65%@@..t{{7F/KLL, ""8VUEBe 	" j* \D MsG   E+E!6E+E$B)E+7E'8AE+E)E+$E+'E+)E+r  c                 <    dddddddd}| j                  |||      S )Nr@  closedcanceled)NEWPARTIALLY_FILLEDFILLEDPENDING_CANCELPARTIALLY_CANCELEDCANCELEDFAILEDr  r  r  statusess      r  parse_order_statuszpoloniex.parse_order_statusB  s5     &("," 
 &&99r  r  c                    | j                  |g d      }|!| j                  | j                  |d            }| j                  |d      }| j                  ||d      }|d   }| j	                  |d      }|3t        |t              s#| j	                  || j                  |d|            }| j                  |g d      }| j                  |dd	      }| j                  |d
d      }	| j                  | j                  |d            }
| j                  |d      }| j                  |d      }| j                  |      }| j                  |g d      }d }| j                  |dd      }d }d }| j                  |d      }||dk(  r|d   n|d   }n$| j                  |      }| j                  |dd      }||||d}| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      dk7  }| j                  i d |d|d|d!|d"| j!                  |      d#| j                  |d$      d%|
d|d|d&| j                  |d&      d'|d(k(  d|d)|d*| j                  |d*d+      d,| j                  |d-      d.| j                  |d/d0      d1||	d ||||||d2|      S )3N)r   r  r  dater  r  resultingTradesr2   )r  rater  rH  szfilledQuantityexecQtyr  r  r  )orderNumberr2   r  r  tokenFeeCurrencyr  rq  buyr  r  tokenFeer  )r  r   r  clientOrderIdclOrdIdmgnMode
reduceOnlyleverposSideBOTHr  r   r0  lastTradeTimestamp
updateTimer  r  postOnlyLIMIT_MAKERr  r  	stopPricer   execAmtrG  avgPriceavgPxr   )filled	remainingr   rq  r  r  r  r  )r  	parse8601r  rS  r  
isinstancerv  r  rR  r  safe_string_lowerparse_order_typer  	safe_boolr  
safe_orderrV  )r  r  r  r   rW  r  r  r  r   r  r  r  rawTyper  r2   rq  r  feeCostr  r  r  r  r  r  r  s                            r  parse_orderzpoloniex.parse_orderN  s   F ''/ST	t'7'7v'FGI##E84!!(FC8!//%1BC&ot4"&///4CSCSTZ\`bjCk"l""5*AB##E:t<##E+;YG(()9)9%)IJ%%eV4""5&1$$W-'PQ((0BHM#u-15fVnVG_O #55kBO((
HEG+C
 **5/9M++E9=
^^E<8
$$UG4!!%3v=  
E 
" 
 ] 
 	 

 Y/ 
 !$"3"3E<"H 
 f 
 f 
 D 
 4++E=A 
 =0 
 D 
 U 
 D..unkR 
 D$$UI6 
  t))%WE! 
" f# 
$ %$$ 3 
4 5 	r  c                 8    dddddd}| j                  |||      S )Nr  r&  )MARKETLIMITr  z
STOP-LIMITzSTOP-MARKETr  r  s      r  r  zpoloniex.parse_order_type  s/    "!#
 &&99r  c           	          t        dt        |            D ]E  }||   }| j                  |dd|d   |d   d      }|j                  | j	                  ||             G |S )Nr   r@  r&  r  r  )r  r  r  r  )ru  r  r  rz  r  )r  r   r  r{  r|  r  extendeds          r  parse_open_orderszpoloniex.parse_open_orders  sp    q#f+& 	>A1IE{{5 fv	+ H MM$**8V<=	> r  c                   K   | j                          d{    d}i }|| j                  |      }|d   |d<   d}| j                  d||      \  }}||dk(  rdnd} |||      |d<   | j                  |d	d
      }	| j	                  |d	d
g      }d}
|dk7  r<| j                  | j                  ||             d{   }| j                  |d      }
nU|	r*| j                  | j                  ||             d{   }
n)| j                  | j                  ||             d{   }
ddi}| j                  |
||||      S 7 +7 7 L7 $w)a&  
        fetch all unfilled currently open orders

        https://api-docs.poloniex.com/spot/api/private/order#open-orders
        https://api-docs.poloniex.com/spot/api/private/smart-order#open-orders  # trigger orders
        https://api-docs.poloniex.com/v3/futures/api/trade/get-current-orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: set True to fetch trigger orders instead of regular orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr2   r  rj   r=   r+  r   r&  r*  stopr  r  r@  )r  r  r]  safe_value_2omitswapPrivateGetV3TradeOrderOpensr  r  privateGetSmartordersprivateGetOrdersparse_orders)r  r  r  r&  r  r  r  rb  r$  	isTriggerr  r  	extensions                r  fetch_open_orderszpoloniex.fetch_open_orders  sp     !!![[(F &tGH
!??@QSY[ab
F%/$cC"5#GG%%fi@	6Iv#67<<T[[RX=YZZCP ~~c62H!77GV8TUUH!224;;w3OPPH0 $V,	  65%KKi 	" [T VPsF   E
EB$E
;E<=E
9E:)E
#E$E
E
E
E
c                   K   | j                          d{    d}i }|| j                  |      }|d   |d<   d}| j                  d||d      \  }}|dk(  rt        | j                  dz         |t        d|      |d	<   |||d
<   | j                  d||      \  }}| j                  | j                  ||             d{   }| j                  |dg       }	| j                  |	|||      S 7 7 -w)a  

        https://api-docs.poloniex.com/v3/futures/api/trade/get-order-history

        fetches information on multiple closed orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest entry
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr2   r  rQ   r?   r=   z: fetchClosedOrders() is not supported for spot markets yet   r&  r  r  r  )r  r  r]  r(   r2   r   r  !swapPrivateGetV3TradeOrderHistoryr  r  r  )
r  r  r  r&  r  r  r  rb  r  r  s
             r  fetch_closed_orderszpoloniex.fetch_closed_ordersp  s     !!![[(F &tGH
!??@SU[]cekl
Ftww)eeff"3GG$GG227GVL??GU[@\]]R ~~h3  vue<<s 	" ^s"   C2C.B+C2C0,C20C2r  r  r   r  c           	      R  K   | j                          d{    | j                  |      }|d   |j                         d}| j                  |dd      }	| j	                  |||||||      \  }}d}
|d   s|d   r<| j                  | j                  ||             d{   }| j                  |d      }
nU|	*| j                  | j                  ||             d{   }
n)| j                  | j                  ||             d{   }
| j                  |
|      S 7 7 7 E7 w)	a  
        create a trade order

        https://api-docs.poloniex.com/spot/api/private/order#create-order
        https://api-docs.poloniex.com/spot/api/private/smart-order#create-order  # trigger orders

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at
        :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr2   )r  r  r  r  r?   r@   r  )r  r  uppersafe_number_2order_requestswapPrivatePostV3TradeOrderr  r  privatePostSmartordersprivatePostOrdersr  )r  r  r  r  r   r  r  r  r  r  r  responseInitials               r  create_orderzpoloniex.create_order  s*    " !!!V$TlJJL
 ))&+~N,,VT4RWY_`&>VH-$($D$DT[[QXZ`Ea$bbO ~~ov>H%!88Wf9UVVH!33DKK4PQQH &119 	" c WQsF   D'DBD'D! =D'D#)D'D%D'!D'#D'%D'c                 T   | j                  |dd      }| j                  |      }	|	d   rd }
| j                  |d      \  }
}|
)| j                  d|
dddg       |
j	                         |d<   d }| j                  |d	      \  }}|r6|
t        | j                  d
z         d|vrt        | j                  dz         |j	                         }|dk(  }| j                  ||dk(  |      }| j                  |g d      }|2|	d   s!t        | j                  dz   |	d   z   dz         |dnd}||d<   n|rd}||d<   |r|dk(  rd }d}| j                  |ddd      \  }}| j                  |d      }| j                  |d      }|| j                  ||      }n~|rj|	d   re|t        | j                  dz         | j                  |      }| j                  |      }t        j                  ||      }| j                  ||      }n| j                  ||      }|	d   rdnd}|||<   n[|	d   rdnd}| j!                  ||      ||<   n<|	d   rdnd}| j!                  ||      ||<   |	d   rdnd}| j#                  ||      ||<   | j%                  |d       }|||d <   | j                  |d       }||gS )!Nr  r  r  r  rJ   crossisolatedr  r  zV createOrder() requires a marginMode parameter "cross" or "isolated" for hedged ordersr  zO createOrder() requires a posSide parameter "LONG" or "SHORT" for hedged ordersr  r  )r  r  r  r=   z3 createOrder() does not support trigger orders for r  z marketsSTOP
STOP_LIMITr  Tr  r   a	   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentr   r  rH  r  r  r  )r	  r  handle_param_stringcheck_required_argumentr  r"   r2   is_post_onlyr  r&   r  r  cost_to_precisionnumber_to_stringr-   rT  amount_to_precisionprice_to_precisionr  )r  r  r  r  r   r  r  r  r  r  r  r  upperCaseTypeisMarket
isPostOnlyquoteAmountr  r   r  r  costRequest	amountKeypriceKeyr  s                           r  r
  zpoloniex.order_request  sP   ))&+~NV$*J!%!9!9&,!OJ%,,]JW^`jVkl%/%5%5%7	"F!55fhGNFF%+DGG  7O  -O  P  P!V++DGG  7H  -H  I  I

 H,&&x-1OQWX
6#LM#&>"477-b#beklres#s  wA  $A  B  B',}F<M#/GK )M'u}"481<@<Y<YZ`bo  rU  W[  =\916''7662#"&"8"8"FK66&>}*477  6A  ,A  B  B'+'<'<V'D&*&;&;E&B&-&8&8{&S&*&<&<V[&Q"&"8"8"HK(.vHD	%0	"*0.Jd	%)%=%=ff%M	"&,Vn
$I!%!9!9&&!IGI"(.wdH $ 7 7 FGH((A$'4GO$YYv7F  r  r2   c           	        K   | j                          d{    | j                  |      }|d   s!t        | j                  dz   |d   z   dz         d|i}	| j	                  |dd      }
| j                  |||||	||      \  }	}d}|
*| j                  | j                  |	|             d{   }n)| j                  | j                  |	|             d{   }| j                  |||d	      }| j                  ||      S 7 7 W7 /w)
a  
        edit a trade order

        https://api-docs.poloniex.com/spot/api/private/order#cancel-replace-order
        https://api-docs.poloniex.com/spot/api/private/smart-order#cancel-replace-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float [amount]: how much of the currency you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr=   z editOrder() does not support r  z& orders, only spot orders are acceptedr2   r  r  )r  r  )
r  r  r(   r2   r	  r
  privatePutSmartordersIdr  privatePutOrdersIdr  )r  r2   r  r  r  r   r  r  r  r  r  r  s               r  
edit_orderzpoloniex.edit_order'  s.    " !!!V$f~tww)IIFSYNZ  ^F   F  G  G"
 ))&+~N,,VT4RWY_`#!99$++gv:VWWH!44T[[&5QRRH ;;x*
  &113 	" XRs4   DDBD+D,)DD,DDDc                   K   | j                          d {    |t        | j                  dz         | j                  |      }i }|d   sW|d   |d<   ||d<   | j	                  | j                  ||             d {   }| j                  | j                  |d            S | j                  |d      }||}||d<   | j                  |dd	      }| j                  |g d
      }d }	|r*| j                  | j                  ||             d {   }	n)| j                  | j                  ||             d {   }	| j                  |	      S 7 87 7 D7 w)Nz) cancelOrder() requires a symbol argumentr=   r2   r  r  r  r  r*  r  )r  r*  r  )r  r"   r2   r  swapPrivateDeleteV3TradeOrderr  r  r  r  r  r  privateDeleteSmartordersIdprivateDeleteOrdersId)
r  r2   r  r  r  r  r  r  r   r  s
             r  cancel_orderzpoloniex.cancel_orderS  s\     !!!>#DGG.Y$YZZV$f~ &tGH!GG::4;;wPV;WXXC ##DNN3$?@@@$B%%fi@	6#GH!<<T[[RX=YZZH!77GV8TUUH ))Q 	" Y( [UsG   EEA'E>E?BEE)E8E9EEEEc                   K   | j                          d{    dg i}d}|| j                  |      }|d   g|d<   d}d}| j                  d||      \  }}|dk(  s|dk(  rM| j                  | j	                  ||             d{   }| j                  |d      }| j                  ||      S | j                  |dd	      }| j                  |dd	g      }|r*| j                  | j	                  ||             d{   }n)| j                  | j	                  ||             d{   }| j                  ||      S 7 &7 7 E7 w)
a  
        cancel all open orders

        https://api-docs.poloniex.com/spot/api/private/order#cancel-all-orders
        https://api-docs.poloniex.com/spot/api/private/smart-order#cancel-all-orders  # trigger orders
        https://api-docs.poloniex.com/v3/futures/api/trade/cancel-all-orders - contract markets

        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if canceling trigger orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        NrZ  r2   rC   r?   r@   r  r*  r  )r  r  r]  !swapPrivateDeleteV3TradeAllOrdersr  r  r  r  r  privateDeleteSmartordersprivateDeleteOrders)	r  r  r  r  r  r  rb  r  r   s	            r  cancel_all_orderszpoloniex.cancel_all_orders  sg     !!! r
 [[(Ft"GI 
!??@QSY[ab
F:#9>>t{{7TZ?[\\C ~~c62H$$Xv66%%fi@	6Iv#67!::4;;wPV;WXXH!55dkk'66RSSH$   622o 	" ]( YSsG   ED<A.ED?A5E;E<)E%E&E?EEEc                 f  K   | j                          d{    t        |      }d|i}d}|| j                  |      }|d   |d<   d}| j                  d||      \  }}|dk7  rt	        | j
                  dz   |z   dz         | j                  |dd	      }| j                  |dd	g      }d}|r<| j                  | j                  ||             d{   }| j                  |d
      }n)| j                  | j                  ||             d{   }| j                  |      }	||	d<   |	S 7 7 [7 !w)a4  
        fetch an order by it's id

        https://api-docs.poloniex.com/spot/api/private/order#order-details
        https://api-docs.poloniex.com/spot/api/private/smart-order#open-orders  # trigger orders

        :param str id: order id
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching a trigger order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr2   r  rk   r=   z# fetchOrder() is not supported for z markets yetr*  r  r   )r  strr  r]  r(   r2   r  r  privateGetSmartordersIdr  r  privateGetOrdersIdr  )
r  r2   r  r  r  r  rb  r   r  r  s
             r  fetch_orderzpoloniex.fetch_order  sQ     !!!W"
 [[(F &tGH
!??fV\]
Ftww)NNQ[[^llmm%%fi@	6Iv#67!99$++gv:VWWHx3H!44T[[&5QRRH,   *dY 	"" X Ss4   D1D*B:D1D-;D1D/D1-D1/D1c                    K   | j                          d {    | j                  |d d |       d {   }| j                  |d      }||v rdS dS 7 :7  w)Nr2   r@  r  )r  r  r  )r  r2   r  r  r   indexeds         r  fetch_order_statuszpoloniex.fetch_order_status	  s[     !!!--fdD&II----v6h6 	"Is   AAAAAAc                    K   | j                          d{    d|i}| j                  | j                  ||             d{   }| j                  |      S 7 B7 w)a(  
        fetch all the trades made from a single order

        https://api-docs.poloniex.com/spot/api/private/trade#trades-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]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr2   )r  privateGetOrdersIdTradesr  r  )r  r2   r  r  r&  r  r  r   s           r  fetch_order_tradeszpoloniex.fetch_order_trades	  se      !!!"
 44T[[&5QRR,   ((5 	" Ss!   AA,AAAAc                    |d d d}t        |t              s| j                  |d      }||d<   | j                  |      |d<   | j	                  |dg       }t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d	<   | j                  |d
      |	d<   |	||<   k | j                  |      S t        dt        |            D ]  }| j                  ||i       }	| j                  |	d      }
t        dt        |
            D ]v  }| j                  |
|      }| j                  |d      }| j                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   x  | j                  |      S )N)r  r   r0  uTimer   r0  detailsr   ccyavailtotalimusedbalancesr  	availablefreehold)r  rv  r  rV  r  ru  r  r  r  accountsafe_balancer  )r  r  r{  r*  r>  r|  balancers  rp  rH  rD  j
newAccounts                r  parse_balancezpoloniex.parse_balance:	  s   
 (D)""8W5B"$F;!%b!1F:nnXy"=G1c'l+ '!!*!--gu=
..z:,,.#'#3#3GW#E "&"2"27D"A&t' $$V,,q#h-( 
	*Aooh26Gw
;H1c(m, *//(A6!--gzB
..z:!\\^
%)%5%5g{%K
6"%)%5%5gv%F
6")t*
	*   ((r  c                 v  K   | j                          d{    d}| j                  dd|      \  }}|dk7  r=| j                  |       d{   }| j                  |di       }| j	                  |      S ddi}| j                  | j                  ||             d{   }| j	                  |      S 7 7 h7 w)a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://api-docs.poloniex.com/spot/api/private/account#all-account-balances
        https://api-docs.poloniex.com/v3/futures/api/account/balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrO   r=   r  accountTypeSPOT)r  r]  swapPrivateGetV3AccountBalancer  rM  privateGetAccountsBalancesr  )r  r  rb  r  r  r  r  s          r  fetch_balancezpoloniex.fetch_balance]	  s      !!!
!??PTV\]
F $ C CF KKKL >>+vr:D%%d++6
 88Wf9UVV" !!(++A 	" LV Ws4   B9B35B9B5AB9B7B95B97B9c                 :  K   | j                          d{    | j                  |       d{   }i }t        dt        | j                              D ]=  }| j                  |   }||| j                  |d      | j                  |d      ddd||<   ? |S 7 7 iw)aZ  
        fetch the trading fees for multiple markets

        https://api-docs.poloniex.com/spot/api/private/account#fee-info

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   	makerRate	takerRateT)r  r  r   r   rF  	tierBased)r  privateGetFeeinforu  r  rZ  r  )r  r  r  r{  r|  r  s         r  fetch_trading_feeszpoloniex.fetch_trading_fees	  s      !!!//77 q#dll+, 		A\\!_F  ))(K@))(K@"!F6N		 + 	"7s    BBBBA(BBc                 t  K   | j                          d{    | j                  |      }d|d   i}|!||d<   |d   r| j                  g d|      |d<   |d   ra| j                  | j	                  ||             d{   }| j                  |di       }| j                  |d      }| j                  |||      S | j                  | j	                  ||             d{   }	| j                  |	d	      }
| j                  |	d
      }| j                  |	d      }g }g }t        dt        |            D ]R  }|dz  dk  s| j                  ||      }| j                  || j                  |d            }|j                  ||g       T t        dt        |            D ]R  }|dz  dk  s| j                  ||      }| j                  || j                  |d            }|j                  ||g       T |d   | j                  |dd      | j                  |d      |
| j!                  |
      ddS 7 7 7 Uw)a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://api-docs.poloniex.com/spot/api/public/market-data#order-book
        https://api-docs.poloniex.com/v3/futures/api/market/get-order-book

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nr  r2   r&  r  )r8   r   r   r      r  r*  timeasksbidsr   r   r   T)r  r^  r]  r   r0  nonce)r  r  find_nearest_ceilingswapPublicGetV3MarketOrderBookr  r  r  parse_order_bookpublicGetMarketsSymbolOrderBookr  ru  r  r  sumrz  sort_byrV  )r  r  r&  r  r  r  r  r  r*  r  r   r]  r^  
asksResult
bidsResultr|  r  r   s                     r  fetch_order_bookzpoloniex.fetch_order_book	  sO     !!!V$fTl
 $GGj!#'#<#<=RTY#Z * $ C CDKKPWY_D` aaK >>+vr:D""4.B((vr::==dkk'SY>Z[[ %%h7	x0x0

q#d)$ 	3AA{((q1))$A?!!5&/2		3
 q#d)$ 	3AA{((q1))$A?!!5&/2		3 X&LLQ5LLQ/"Y/
 	
g 	" b  \sD   H8H/A(H8?H2 A H8 H5!AH8 A)H8*BH82H85H8rp  c                 j  K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  di       }| j	                  |d      }| j                  |||      }||d   |z   |d<   | j                  |d      }n&|d   dk(  rt        | j                  dz   |z   dz         | j                  | j                  ||             d{   }| j                  |d	      }d}	| j                  |       || j                  |d
   d      }
|
|}	|
}|||	||dS 7 7 Qw)a  
        create a currency deposit address

        https://api-docs.poloniex.com/spot/api/private/wallet#deposit-addresses

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr  r2   r  rr  r   z7 createDepositAddress requires a network parameter for .addressr  depositAddress)r  rk  tagrr  r  )r  r  r  r   safe_string_upperr  r  r"   r2   privatePostWalletsAddressr  check_addressr  rp  r  r  r  r  rr  r  rk  rm  rl  s              r  create_deposit_addresszpoloniex.create_deposit_address
  se     !!!==&
 ??4<<R@((;""8Wg>")*"5"?GJYYvy1F~''2k(knr(rux(xyy77GV8TUU ""8Y77#!--hv.>@PQN)(
 	
9 	" Vs#   D3D.CD3D1 AD31D3c                 p  K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  di       }| j	                  |d      }| j                  |||      }||d   |z   |d<   | j                  |d      }n&|d   dk(  rt        | j                  dz   |z   dz         | j                  | j                  ||             d{   }| j                  ||d         }d}	| j                  |       || j                  |d	   d
      }
|
|}	|
}|||||	dS 7 7 Tw)a  
        fetch the deposit address for a currency associated with self account

        https://api-docs.poloniex.com/spot/api/private/wallet#deposit-addresses

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr  r2   r  rr  r   z6 fetchDepositAddress requires a network parameter for rj  r  rl  )r  r  rr  rk  rm  )r  r  r  r   rn  r  r  r"   r2   privateGetWalletsAddressesr  rp  rq  s              r  fetch_deposit_addresszpoloniex.fetch_deposit_address?
  sj     !!!==&
 ??4<<R@((;""8Wg>")*"5"?GJYYvy1F~''2j(jmq(qtw(wxx88Wf9UVV ""8WZ-@A7#!--hv.>@PQN)(
 	
9 	" Ws#   D6D1CD6D4 AD64D6fromAccount	toAccountc                   K   | j                          d{    | j                  |      }| j                  | j                  di       }| j	                  |||      }| j	                  |||      }	| j                  ||      |d   ||	d}
| j                  | j                  |
|             d{   }| j                  ||      S 7 7 w)a&  
        transfer currency internally between wallets on the same account

        https://api-docs.poloniex.com/spot/api/private/account#accounts-transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr  r2   )r   r  rv  rw  )	r  r  r  r   r  currency_to_precisionprivatePostAccountsTransferr  parse_transfer)r  rp  r   rv  rw  r  r  r  fromIdtoIdr  r  s               r  r   zpoloniex.transferm
  s      !!!==&7GL!!.+{K	;G00v> !	
 99$++gv:VWW ""8X66# 	" Xs"   CCBC-C.CCr   r  c           
      Z    || j                  |d      d d | j                  |d      d d d d d	S )N
transferIdr2   )	r  r2   r   r0  r  r   rv  rw  r  r  )r  r   r  s      r  r{  zpoloniex.parse_transfer
  sC     ""8\:((48

 
	
r  rk  c                   K   | j                  ||      \  }}| j                  |       | j                          d{    | j                  |      }|d   ||d}|||d<   | j	                  | j
                  di       }| j                  |d      }	| j                  ||	|	      }	|	|d   |	z   |d<   | j                  |d      }| j                  | j                  ||             d{   }
| j                  |
|      S 7 7 w)a  
        make a withdrawal

        https://api-docs.poloniex.com/spot/api/private/wallet#withdraw-currency

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr2   )r  r   rk  	paymentIdr  rr  r  )handle_withdraw_tag_and_paramsrp  r  r  r  r   rn  r  r  privatePostWalletsWithdrawr  parse_transaction)r  rp  r   rk  rm  r  r  r  r  rr  r  s              r  r   zpoloniex.withdraw
  s     99#vFV7#!!!==& 

 ?#&GK ??4<<R@((;""8Wg>")*"5"?GJYYvy1F88Wf9UVV %%h99/ 	" Ws"   :DC>B*D'D (D Dc                   K   | j                          d {    d}| j                         }|| j                  |dz        n|d|z  z
  }||d}| j                  | j	                  ||             d {   }	|	S 7 d7 w)Ni r%  r   )startend)r  secondsparse_to_intprivateGetWalletsActivityr  )
r  rp  r  r&  r  yearnowr  r  r  s
             r  fetch_transactions_helperz"poloniex.fetch_transactions_helper
  s     !!!lln494E!!%$,/CRTW[R[O
 77GV8TUUP a 	" Vs"   A?A;AA?4A=5A?=A?c                   K   | j                          d{    | j                  ||||       d{   }d}|| j                  |      }| j                  |dg       }| j                  |dg       }| j	                  ||||      }	| j	                  ||||      }
| j                  |
|	      }| j                  | j                  |d      |||      S 7 7 w)a}  
        fetch history of deposits and withdrawals

        https://api-docs.poloniex.com/spot/api/private/wallet#wallets-activity-records

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nwithdrawalsdepositsr   )r  r  r  r  parse_transactionsr  filter_by_currency_since_limitre  )r  rp  r  r&  r  r  r  r  r  withdrawalTransactionsdepositTransactionstransactionss               r  fetch_deposits_withdrawalsz#poloniex.fetch_deposits_withdrawals  s      !!!77eUFSS!}}T*HoohrB??8Z<!%!8!8hPUW\!]"55h%QVW(()<>TU224<<k3Z\`bginoo 	"Ss    CCCCBCCc                    K   | j                  ||||       d{   }d}|| j                  |      }| j                  |dg       }| j                  ||||      }| j	                  ||||      S 7 Tw)a+  
        fetch all withdrawals made from an account

        https://api-docs.poloniex.com/spot/api/private/wallet#wallets-activity-records

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr  r  r  r  r  r  )	r  rp  r  r&  r  r  r  r  r  s	            r  fetch_withdrawalszpoloniex.fetch_withdrawals2  s      77eUFSS!}}T*HoohrB..{HeUS22<ueTT T   A1A/AA1codesc                 d  K   | j                          d{    | j                  | j                  |ddi             d{   }i }t        dt	        |            D ]:  }||   }t        |j                               }| j                  |d      }||   ||<   < | j                  ||      S 7 7 lw)a  
        fetch deposit and withdraw fees

        https://api-docs.poloniex.com/spot/api/public/reference-data#currency-information

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fees structures <https://docs.ccxt.com/#/?id=fee-structure>`
        Nre  Tr   )	r  rt  r  ru  r  rv  rw  r  parse_deposit_withdraw_fees)	r  r  r  r  r  r|  entryr   rs  s	            r  fetch_deposit_withdraw_feesz$poloniex.fetch_deposit_withdraw_feesF  s      !!!11$++fGdfjFk2lmm0 q#h-( 	1AQKEejjl+J))*a8J$Z0D		1
 //e<<? 	"ms"   B0B,*B0B.A+B0.B0c                    i }| j                  |      }t        |j                               }t        dt	        |            D ]  }||   }| j                  |      }||   }	|| j                  ||      s4| j                  |      }
| j                  |	|
      ||<   | j                  |	d      }t	        |      }|dkD  s}t        dt	        |            D ]  }||   }|j                  |d      }| j                  |      }| j                  ||      }i }| j                  |d      }||dnd dd d dd||<   | j                  ||   d   |      ||   d<     |S )	Nr   childChains rl  Frq  rF  r   ro  r  )market_codesrv  rw  ru  r  r  r  r  parse_deposit_withdraw_feer  replacerx  r  r  )r  r  r  currencyIdKeydepositWithdrawFeesresponseKeysr|  rs  rp  feeInfor  r  chainsLengthrK  r  r  networkInfonetworkObjectwithdrawFees                      r  r  z$poloniex.parse_deposit_withdraw_feesq  s   , %'!!%(HMMO,q#l+, 	BA%aJ**:6Dz*G4==u#===.,0,K,KGU],^#D)"oog}E";/!#"1c+&67 B$/N	$-$5$5dB$?	&*&=&=i&H&*ooh	&J.0&*&6&6{O&T (38C8OeVZ)
 (,.2(	6k2 AEL_`dLefpLq  tA  AB+D1*=#B	B8 #"r  c                     | j                  i       }||d   |d   <   | j                  |d      }| j                  |d      }||dnd d}d d d}||d<   ||d<   | j                  |      }||d	|d
   |<   |S )Nr  rp  rf  rl  Fr  r   ro  r  r  )deposit_withdraw_feer  r  rx  )	r  rq  r  depositWithdrawFeer  r  withdrawResultdepositResultr  s	            r  r  z#poloniex.parse_deposit_withdraw_fee  s    !66r:7:6"8F#34$$S,7	&&sO<$/$;%$ 

 
 *8:&(59%--i8&$7
:&{3 "!r  c                    K   | j                  ||||       d{   }d}|| j                  |      }| j                  |dg       }| j                  ||||      }| j	                  ||||      S 7 Tw)a   
        fetch all deposits made to an account

        https://api-docs.poloniex.com/spot/api/private/wallet#wallets-activity-records

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr  r  )	r  rp  r  r&  r  r  r  r  r  s	            r  fetch_depositszpoloniex.fetch_deposits  s      77eUFSS}}T*H??8Z<..x5%P22<ueTT Tr  c           	      >    ddddddddd}| j                  |||      S )Nokpendingfailed)COMPLETE	COMPLETEDzAWAITING APPROVALAWAITING_APPROVALPENDING
PROCESSINGzCOMPLETE ERRORCOMPLETE_ERRORr  r  s      r  parse_transaction_statusz!poloniex.parse_transaction_status  s8    !*!* #&&	
 &&99r  transactionc                    | j                  |d      }| j                  |d      }| j                  |      }| j                  |dd      }| j                  |      }| j                  |d      }d|v rdnd}| j	                  |dd	      }	| j                  |d
      }
| j                  |d      }| j                  |d      }| j                  |d      }|dk(  rt        j                  ||      }i d|d|	d|d| j                  |      dd d
|
dd dd d|dd dd d|d|dd d|d|d| j                  |      d d || j                  |      d ddS )Nr   r  r  r  txidwithdrawalRequestsId
withdrawalro  depositNumberrk  	paymentIDr   rq  r  r2   rr  	addressToaddressFromrm  tagTotagFromr  updatedr0  )r  r   r  )commentinternalrq  )	safe_timestampr  r  r  rR  r-   
string_subr  rV  )r  r  r  r   rs  rp  r  r  r  r2   rk  rm  r  r  s                 r  r  zpoloniex.parse_transaction  s    H ''[A	%%k:>
&&z2!!+xC..v6V4 6+ E|I-C_U"";	:{K8''X>((e<<"--lMJL
K
"
 
 d''5	

 t
 w
 
 4
 3
 T
 t
 f
 D
 t
 D
  !
" Y/#
$  ))-8)
 	
r  r  c                   K   |t        | j                  dz         | j                          d{    | j                  |      }d}| j	                  d|      \  }}|t        | j                  dz         d}| j                  |dd      \  }}|rd|vrt        | j                  dz         ||j                         |d	   d
}| j                  | j                  ||             d{   }|S 7 7 w)a  
        set the level of leverage for a market

        https://api-docs.poloniex.com/v3/futures/api/positions/set-leverage

        :param int leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated'
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr~   zD setLeverage() requires a marginMode parameter "cross" or "isolated"r  Fr  zN setLeverage() requires a posSide parameter for hedged mode: "LONG" or "SHORT"r2   )r  r  r  )	r"   r2   r  r  handle_margin_mode_and_paramshandle_param_boolr  !swapPrivatePostV3PositionLeverager  )	r  r  r  r  r  r  r  r  r  s	            r  set_leveragezpoloniex.set_leverage,  s     >#DGG.Y$YZZ!!!V$
!??vV
F#DGG.t$tuu//%H''  3C  )C  D  D!'')Tl

 ??GU[@\]]# 	"  ^s"   .C3C/B7C3(C1)C31C3c                 p  K   | j                          d{    | j                  |      }d|d   i}d}| j                  d|      \  }}|t        | j                  dz         |j                         |d<   | j                  | j                  ||             d{   }| j                  ||      S 7 7 w)ai  
        fetch the set leverage for a market

        https://api-docs.poloniex.com/v3/futures/api/positions/get-leverages

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        Nr  r2   rb   zF fetchLeverage() requires a marginMode parameter "cross" or "isolated"r  )	r  r  r  r"   r2   r  !swapPrivateGetV3PositionLeveragesr  parse_leverage)r  r  r  r  r  r  r  s          r  fetch_leveragezpoloniex.fetch_leverageM  s      !!!V$fTl
 
!??QWX
F#DGG.v$vww'--/	??GU[@\]]L ""8V44a 	" ^s"   B6B2BB6B4B64B6c                 \   d }d }d }d }| j                  |d      }t        dt        |            D ]c  }||   }	| j                  |	d      }| j                  |	d      }| j	                  |	d      }
| j                  |	d      }|dk(  r|
}X|dk(  r|
}`|
}|
}e || j                  ||      |||d	S )
Nr  r   r  r  r  r  LONGSHORT)r  r  r  longLeverageshortLeverage)r  ru  r  r  r  safe_symbol)r  r  r  r  r  rW  r  r  r|  r  r  r  s               r  r  zpoloniex.parse_leverage  s    ! 
~~h/q#d)$ 	&AGE''x8H))%;J%%eW5E&&ui8G& $G# %$ %	& &&x8$(*
 	
r  c                    K   | j                  |       d{   }| j                  |di       }| j                  |d      }|dk(  }||dS 7 3w)a  
        fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets

        https://api-docs.poloniex.com/v3/futures/api/positions/position-mode-switch

        :param str symbol: unified symbol of the market to fetch the order book for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        Nr  posModeHEDGE)r  r  )swapPrivateGetV3PositionModer  r  )r  r  r  r  r  r  r  s          r  fetch_position_modezpoloniex.fetch_position_mode  sa      ::6BB ~~h3""43G#
 	
 Cs   AA4Ar  c                 x   K   |rdnd}d|i}| j                  | j                  ||             d{   }|S 7 w)a  
        set hedged to True or False for a market

        https://api-docs.poloniex.com/v3/futures/api/positions/position-mode-switch

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: not used by binance setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        r  ONE_WAYr  N)swapPrivatePostV3PositionModer  )r  r  r  r  moder  r  s          r  set_position_modezpoloniex.set_position_mode  sK      !wit
 ;;DKKQW<XYY  Zs   /:8:c                    K   | j                          d{    | j                  |      }| j                  |       d{   }| j                  |dg       }| j	                  ||      S 7 S7 +w)a  
        fetch all open positions

        https://api-docs.poloniex.com/v3/futures/api/positions/get-current-position

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.standard]: whether to fetch standard contract positions
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        Nr  )r  r\  "swapPrivateGetV3TradePositionOpensr  parse_positions)r  rZ  r  r  	positionss        r  fetch_positionszpoloniex.fetch_positions  so      !!!%%g.@@HHH NN8VR8	##Iw77O 	"Hs!   A.A*)A. A,*A.,A.positionc                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t	        j
                  ||      }| j                  |d      }	| j                  |d      }
t	        j
                  |	|
      }| j                  i d|d	d d|d   d
|d|d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |d      dd d| j                  |d      dd d| j                  |d      dd d|d| j                  |      d | j                  |d      d ||d t        |      | j                  |d      | j                  |d      | j                  |d      d 
      S )!Nr  r  r  r  rB  rI  	openAvgPxr  r2   notionalr  liquidationPriceliqPx
entryPriceunrealizedPnluplrF  	contractsr  rK  markPx	lastPricer  r  r  r   r0  mmmgnRatioslTrgPxtpTrgPx)
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior  r  )
r  rS  r  r  r-   rT  safe_positionr  rV  int)r  r  r  rW  r   r  r  r  r  rI  r  r  s               r  parse_positionzpoloniex.parse_position  sQ   < ##Hh7!!(F3%%h8	++Hi@
##Hg6((48%%h>x/##Hk:''X6
!! #
H#
$#
 fX&#
 	#

 *#
  0 07 C#
 $**8[A#
 T--h>#
 $#
 ))(E:#
 D#
 ))(H=#
 #
 D**8Y?#
 d#
  !#
" Y/##
$ $(!%!1!1(D!A+/$*'+H++HjA!--h	B#//)D7#
  	r  c                   K   | j                          d {    | j                  |      }| j                  ||      }|d   t        j                  |      |j                         d}d|vrd|d<   | j                  | j                  ||             d {   }|dk(  rt        j                  |      }| j                  |d      }| j                  ||      S 7 7 Dw)Nr2   )r  rJ  r  r  r  reducer  )
r  r  r  r-   
string_absr  $swapPrivatePostV3TradePositionMarginr  r  parse_margin_modification)	r  r  r   r  r  r  r  r  r  s	            r  modify_margin_helperzpoloniex.modify_margin_helperT  s     !!!V$))&&9Tl%%f-JJL
 V#!'GIBB4;;wX^C_`` 8''/F~~h/--dF;;9 	" as#   CCA>CCACCr  c                     | j                  |d      }| j                  ||      }| j                  |d      }|dk(  rdnd}||d   |d | j                  |d      d d dd d d
S )	Nr  r  ADDaddr  rJ  r  )
r  r  r  r  r   rA  rp  r  r   r0  )r  rS  r  )r  r  r  rW  r  r  s         r  r  z"poloniex.parse_margin_modifications  s    ##D(3!!(F3""40 E)uX&&&tU3
 	
r  c                 H   K   | j                  || d|       d{   S 7 w)aS  
        remove margin from a position
        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r  Nr  r  r  r   r  s       r  reduce_marginzpoloniex.reduce_margin  s'      ..vw&QQQQs   " "c                 F   K   | j                  ||d|       d{   S 7 w)a6  
        add margin
        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r  Nr  r  s       r  
add_marginzpoloniex.add_margin  s%      ..vvufMMMMs   !!c                 "    | j                         S r  )milliseconds)r  s    r  r_  zpoloniex.nonce  s      ""r  r   GETc                    | j                   d   d   }| j                  |ddg      r| j                   d   d   }| j                  || j                  |            }| j	                  ||      }	|dk(  s|dk(  r$|d|	z   z  }|rB|d| j                  |      z   z  }n)| j                          t        | j                               }
|d	z   }|d|	z   z  }|d|	z   z  }|d
k(  s
|dk(  s|dk(  r,|d	z  }|r| j                  |      }|d|z   dz   z  }|d|
z   z  }nU| j                  d|
i|      }| j                  |      }|d	| j                  |      z   z  }|r|d| j                  |      z   z  }| j                  | j                  |      | j                  | j                        t        j                   d      }d| j"                  |
|d}||||dS )Nr   r=   r   r   r?   r   r  ?
POSTPUTDELETEzrequestBody=&zsignTimestamp=signTimestampbase64zapplication/json)zContent-Typekeyr#  	signature)urlmethodbodyheaders)r   r  r  extract_paramsimplode_params	urlencodecheck_required_credentialsr2  r_  jsonr  keysorthmacencodesecrethashlibsha256apiKey)r  pathr   r(  r  r*  r)  r'  queryimplodedPathr   authsortedQueryr&  s                 r  signzpoloniex.sign  s   iiv&==|];<))E"6*C		&$"5"5d";<**48(?c\13%%CsT^^E222++-DJJL)ID=D3%%CC,&&D& fo6X;M99U+DNT1C77D(944"kk?I*FN"ll;7t~~k:::3!666C		$++d"3T[[5Mw~~_ghI 2{{!*&	G fdwOOr  reasonr'  r(  r*  r)  c
                 $   |y | j                  |d      }
|
y|
dk7  rt|d   }| j                  |d      }| j                  dz   |z   }| j                  | j                  d   ||       | j	                  | j                  d   ||       t        |      y )Nrp  200messager  r  r  )r  r2   throw_exactly_matched_exceptionr7  throw_broadly_matched_exceptionr   )r  rp  r=  r'  r(  r*  r)  r  requestHeadersrequestBodyresponseCode	codeInnerr@  feedbacks                 r  handle_errorszpoloniex.handle_errors  s     ''&9$<5+@ (I&&x;Gww}t+H001I9V^_001I7T\]))r  r  )NN)b__name__
__module____qualname__r   r  r   rv  r  r2  r   r   r  r  r  r  r  dictr  r  r  r'  r   rY  r   r   rc  r   r  r  r   r  r  r   r  r  r   r  r  r  r  r  r   r   floatr   r  r
  r&  r+  r0  r5  r8  r;  r   rM  rS  r   rY  r   rh  r
   rr  ru  r   r   r	   r{  r   r   r  r  r  r  r  r  r  r  r  r  r   r  r  r  boolr  r   r  r	  r   r  r  r  r  r_  r<  r  rH  __classcell__)r  s   @r  r/   r/      s   Z# Zx7
 7
4 7
r 8<$]ajl NL NLC NLWZ NLquvzq{ NL` ).b  *, 9V 9 /1 +T&\ +6 /1 *+T&\ *+X24 2F 26
 6
 6
pi
 i
 i
V ') 
9S 
9L4 L L6 L\ 6:" N57 N5 N5` -/ C: CJ 68 *3 *3F *3XB Bv B BH <@d[] 4? 4?S 4? 4?bfglbm 4?l 37TX\eg aC as aRU aF
: 
:e ev e eN:
 59tZ^gi cLc cL cLTW cLnrsxny cLJ 7;\`ik F= F=3 F=VY F=ptuzp{ F=P mqy{ -2 -2I -2Y -2X] -2fi -2^ HLTV >!@ fjx|  FH *23 *2 *29 *2I *2_b *2ru *2X 9=R 5*S 5*# 5*n 59 D3c D3L 8<B 9C 9 9v ?C2 73 7 7 ?CQUdhqs ')3 ') ')3 ')^a ')R!) !)F *, J, J,X /1 [ @ @DB F
S F
 F
S\ F
P >@ ,
 ,
N ,
\ =? ,
 ,
> ,
\ ac 73 7 7C 7TW 7gt 7@
t 
x 
= 
$ JNVX &:3 &: &: &:]h &:P ;?T`dmo QC Qs QZ] Qf <@daenp pS p p[^ puy  {F  vG p0 37TX\eg UC Us URU Ulpq|l} U( BFb )=w )=V5#n" ", 04$UYbd U UC Us Uimnyiz U(:s :K
T K
X K
Q\ K
Z ?C2 3  B 8: :53 :5h :5x
t 
V 
x 
6 7;2 
 
8 CGr d C 2 8<B 28W 284PX> 28hEt EV EN LN < <Rd <>
d 
F 
N` 
$ FH R# Ru RL^ R CE Ns NE NI[ N# &eBSW #PJ# s  c TX `c r  r/   )5 ccxt.async_support.base.exchanger   ccxt.abstract.poloniexr   r  r4  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   ccxt.base.decimal_to_precisionr,   ccxt.base.preciser-   r/    r  r  <module>rX     s    6 .   G  G  G  G  G  G  G  * 0 - - . ' & . ) * ) 1 * + 4 %t6x t6r  