
    ei
b                       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          Z4dS )    )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dkdedefdZdddi fdeded	e	d
e	de
e         f
dZdi f 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dkd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dkd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"dkd!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d0Z1di fd-ede fd1Z2di fd-ede fd2Z3dddi fd-ede d	e	d
e	fd3Z4de5fd4Z6i fde5fd5Z7i fde8fd6Z9di fded
e	de:fd7Z;i fd8ede<fd9Z=i fd8ede<fd:Z>i fd8ed;edefd<Z?de<fd=Z@i fd8ed)e+d>ed?edeAf
d@ZBdkdAedBeCdeAfdCZDdi fd8ed)e+dDedEe deEf
dFZFdddi fd8e d	e	d
e	fdGZGdddi fd8e d	e	d
e	de
eE         fdHZHdddi fd8e d	e	d
e	de
eE         fdIZIdi fdJefdKZJdldLZKdkdBeCfdMZLdddi fd8e d	e	d
e	de
eE         fdNZMde fdOZNdkdPedBeCdeEfdQZOdi fdRePde fdSZQi fdedeRfdTZSdkdRededeRfdUZTdi fde fdVZUdi fdWeVde fdXZWdi fdede
eX         fdYZYdkdZedefd[ZZi fdede[fd\Z\dkd]edede[fd^Z]i fded)e+de[fd_Z^i fded)e+de[fd`Z_da Z`dbdci ddfddZad8ePdeedfedgedhediefdjZb xZcS )mpoloniexreturnc                    |                      t          t          |                                           i ddddddgddd	d
dddi dd dddd dddddd
dddddddd dddddd
dd
dddd ddi ddd dd!d
d"dd#d
d$dd%dd&dd'd
d(d
d)dd*dd+d,d-dd.d
d/d
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dddddddS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|                     d          |                     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dddddddd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 d0t           d1t          d2t          d3t"          d4t"          d5t$          d6t           d7t          d8t          d9t$          d:t          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 dRt           dSt           dTt           dUt           dVt           dWt          dXt          dYt          dZt          d[t           d\t           d]t           d^t           d_t           d`t           dat           dbt           i dct          ddt           det          dft           dgt           dht           dit          djt"          dkt           dlt          dmt$          dnt$          dot$          dpt          dqt          drt          dst          i dt          S (u  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fetchAllGreeksfetchBalancefetchClosedOrderfetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchLedgerfetchLeveragefetchLiquidationsfetchMarginModefetchMarketsfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrderTradesfetchPositionfetchPositionModefetchPositionsfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransferfetchTransfersfetchVolatilityHistory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TRC20r   r  )r   r   costming-C6?g      ?gQ?)BTCr   r   r   BNBUSDCUSDJTUSDDAIPAXBUSDfutures)r=   r@   )exchanger  )defaultType!createMarketBuyOrderRequiresPricenetworksnetworksById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,  r0  r(  r/  r,    )	r   rJ   rK   rh   ro   rl   fetchOrdersrR   ri   extendsdefault)r  r  r#  stpModer%  gUUUUUU?)r  r,  r-  daysBackCanceledr.  r0  r(  r/  Z   )r,  r.  )r4  rJ   rK   rl   rR   rh   forContracts)linearinverse)r5  r=   r9  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    Y/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/poloniex.pyr  zpoloniex.describe    s   h 5 5 > > @ @ cC
*cC
JcC
 $cC

 cC
 cC
 4cC
  KKK $K 	K
 $K %K TK "4K tK K 'K /K ,UK 0K tK  !K" "4#K K$ %d%K& T'K( !%)K* +K, #E-K. $T/K0 "41K2 &t3K4 (5K6 1%7K8  9K: +D;K< *:=K> +D?K@ &uAKB 'CKD (EK K KF #EGKH *5IKJ $TKKL uMKN tOKP  QKR $TSKT "5UKV WKX  YKZ d[K\ +E]K^ !%_K` "4aKb ucKd #EeKf dgK K Kh !$iKj "5kKl #DmKn  oKp $TqKr !$sKt tuKv wKx TyKz t{K| "5}K~ #DK@ $ZAKB  CKD !%EKF )%GKH #DIK KJ !%##'  UK K KcC
h   """  icC
H }66 
 H 2<3D IcC
d  !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 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 AecC
h $!..x88!..x88	   icC
z  $!y$!$! }$! (	$!
 |$! y$! w$! 5$! $! $! y$! )$! y$! .$! *$!  ~!$!" #$!$ #! ""!G$! $! $!{cC
D	 %59""#!	  ##! !
 #)#)$'#&#'$'$'$*#&#&$'   $ #'# #
 !''! !E& &E	cC
R
 #&*(,,0,1).+06:#'#'"&#(	( ( #($)+/27/3$)#()$ $. r% ',!%$*%+*/& & ',#($)*/	# # ',!%#($)*/( ( $()-#c4 4l y  )&*(-"&#'+0$ $ r%  ( ',!$$(,1%)#($)*/	* 	* "%%'& &3! !@ "> "> 	  "> "> 	 g gS
cC
b YccC
d 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( .)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 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 l 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 l 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 l 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 lZ]p pecC
 c c c	    Nmarketc           	      0   t          |          }|dk    }|r|                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )	N	      r   r   r      r8      )lensafe_integersafe_number)r  ohlcvr  ohlcvLength
isContracts        r  parse_ohlcvzpoloniex.parse_ohlcvF  s   J %jj A%
 	!!%++  **  **  **  **  **  eR((UA&&UA&&UA&&UA&&UA&&
 	
r  r   symbol	timeframesincer,  c           	        K   |                                   d{V  d}|                     |ddd          \  }}|r!|                     d|||||d           d{V S |                     |          }|d         |                     | j        ||          d}|d         rd	nd
}	|d         rdnd}
||||	<   |||d<   |                     |
||          \  }}|d         r|                     |ddg          r)t          | j	        dz   |z   dz   |d         z   dz             | 
                    |                     ||                     d{V }|                     |d          }|                     |||||          S |                     |                     ||                     d{V }|                     |||||          S )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
        NFri   paginater2  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  r  r  r,  paramsr  r  requestkeyStartkeyEndresponseRawr  responses                 r  fetch_ohlcvzpoloniex.fetch_ohlcv  s9       !!!!!!!!!88z[`aa& 	}@@vW\^cenpvx{|||||||||V$$Tl(()YOO
 
 #).=;;g$Vn9' %GH$GG2267FKK* 	L}}Y66 v"47S=9#<s#BVF^#SVt#tuuu $ A A$++gW]B^B^ _ _______K$ >>+v66D$$T69eUKKK;;DKKQW<X<XYYYYYYYY*   69eUKKKr  Fc                    K   t          t          |                               ||           d {V }|                     | j        d          }||r#|                     | j        d          | j        d<   |S )NcurrenciesByNumericId	numericId)r  r/   r  
safe_valuer   index_byr   )r  reloadr  r   r  r  s        r  r  zpoloniex.load_markets  s}      h--::66JJJJJJJJ $>U V V!)f)48MM$/S^4_4_DL01r  c                    K   |                      |          |                     |          g}t          j        |  d{V }|                     |d         |d                   S )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  sj       ++F33T5L5LV5T5TU1111111  WQZ888r  c                 f   K   |                      |           d {V }|                     |          S N)publicGetMarketsparse_markets)r  r  r   s      r  r  zpoloniex.fetch_spot_markets  sA      --f555555550 !!'***r  c                    K   |                      |           d {V }|                     |d          }|                     |          S )Nr  )#swapPublicGetV3MarketAllInstrumentsr  r  )r  r  r  r   s       r  r  zpoloniex.fetch_swap_markets  sU      AA&IIIIIIIIN ..622!!'***r  c                 ^    d|v r|                      |          S |                     |          S )NctType)parse_swap_marketparse_spot_market)r  r  s     r  parse_marketzpoloniex.parse_market+  s5    v))&111))&111r  c                 N   |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                      |d          }|dk    }|                     |d          }	i d|d|dz   |z   d	|d
|dd d|d|dd ddddddddddddd|dddd d d d d d d |                     |                     |                      |	d                              |                     |                     |                      |	d                              d|                     |	d          d dd d d|                     |	d          d dd |                     |d!          |d"
S )#Nr  baseCurrencyNamequoteCurrencyNamestateNORMALsymbolTradeLimitr2   /basequotesettlebaseIdquoteIdsettleIdr  r=   Tr>   Fr?   r@   rA   activer  r:  quantityScale
priceScaleamountpriceminQuantityr  r*  	minAmount)r  r  r  tradableStartTime)
r;  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_market1  s   fh//!!&*<==""6+>??&&v..''00  11("??63EFF,
",
dSj5(,
 D,
 U	,

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

 f2
 f2
 w2
 2
 !1!1HH2
 E2
 e2
 DFN2
 dh&2
 e2
 f2
  !2
" f#2
$ "z ,,VW=="%%ff55%%ff55**67;;))&%88   ++FG<<++FMBB 
  ++FG<<++FG<< 
   
  ++FJ??  $ ((99c2
 2
 2
 2	
r  c                 h   K   |                      |           d{V }|                     |d          S )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  sC       0088888888  <888r  tickerc           
         |                      |dd          }|                     |dd          }|                     |          }|                     |dd          }t          j        |d          }|                     i d|d|d         d	|d
|                     |          d|                     |dd          d|                     |dd          d|                     |dd          d|                     |dd          d|                     |dd          d|                     |dd          dd d|                     |dd          d|                     |dd          dd dd d |d!d |                     |d"d#          |                     |d$d%          |                     |d&d'          |                     |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quoteVolumerQ  
indexPricer  )safe_integer_2safe_string_2safe_marketr-   
string_mulsafe_tickeriso8601r  )r  r.  r  r   marketIdrelativeChangerL  s          r  parse_tickerzpoloniex.parse_ticker  s`   ` ''d;;	%%fh<<!!(++++FM4HH'>>
 !
(!
fX&!
 !
 Y//	!

 D&&vvs;;!
 4%%feS99!
 4%%feU;;!
 ++FM5II!
 4%%feU;;!
 ++FM5II!
 D!
 D&&vvs;;!
 T''==!
 T!
 d!
  *!!
" t#!
$ ,,VZGG--fhFF++FKGG**6599-!
 !
 !
. /  	r  symbolsc                 V  K   |                                   d{V  d}i }|Z|                     |dddd          }t          |          }|dk    r,|                     |d                   }|dk    r|d         |d<   d}|                     d||          \  }}|d	k    r[|                     |                     ||                     d{V }|                     |d
          }|                     ||          S | 	                    |           d{V }	|                     |	|          S )af  
        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  rw   r?   r  )
r  market_symbolsr  r  handle_market_type_and_paramsswapPublicGetV3MarketTickersr  r  parse_tickerspublicGetMarketsTicker24h)
r  r`  r  r  r  symbolsLength
marketTyper  r  r  s
             r  fetch_tickerszpoloniex.fetch_tickers.  se      !!!!!!!!!))'4tUKKGLLMq  WQZ00 A%%(.tGH%
!??PVX^__
F $ A A$++gW]B^B^ _ _______K6 >>+v66D%%dG44477????????2 !!(G444r  c                   K   |                      |                     |ddi                     d{V }i }i }t          dt          |                    D ]Z}|                     ||          }t          |                                          }|                     |d          }||         ||<   [t          |                                          }	t          dt          |	                    D ]}|	|         }||         }
|                     |          }| 	                    |
d          r?g }| 
                    |
dg           }|St          dt          |                    D ]5}||         }|                     ||          }|                    |           6|                    |
           i }t          dt          |                    D ]}||         }|                     |d          }|                     ||          }|                     |||          }|||                     |d          || 	                    |d	          |                     |d
          dk    |                     |d          dk    |                     |d          ddddddddd
||<   |                     |
|||                     |
d          d|                     |
d          ddddddddddddddd|d          ||<   |S )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   isChildChainchildChains
blockchainr2   walletStatewalletDepositStateENABLEDwalletWithdrawalStatewithdrawalFeer	  r   deposit)
r  r2   r  networkr  ru  r   feer  r  cryptor3   )r  r   ru  )r  coder2   r  r  r3   r  ru  r   rw  r  r  r  )publicGetCurrenciesr  ranger  	safe_dictlistkeysr  r  	safe_boolr  appendnetwork_id_to_coder  r  safe_currency_structure)r  r  r  resultcurrenciesDictiitemidsr2   r~  entryry  allChainEntriesrm  jchildChainIdchildNetworkEntryr  
chainEntrynetworkNamenetworkCodespecialNetworkIds                         r  fetch_currencieszpoloniex.fetch_currencies~  s      11$++fGdfjFk2l2lmmmmmmmmt  q#h--(( 	* 	*A>>(A..Dtyy{{##C!!#q))B!%bN2N''))**q#d))$$ E	 E	AaB"2&E**2..D~~e^44  O..rBBK&q#k"2"233 > >A#.q>L(,~|(T(T%#**+<====""5)))H1c/2233  ,Q/
"..z<HH"55k4HH#'#3#3KB#G#G &*!%!2!2:t!D!D*"nnZGG#//
<PQQU^^ $ 0 0=T U UYb b++JHH!% $(#'% %
 $(#'$ $	 	) )%%*  77!..ud;; ((77 !  $# 
  $#! !
  $#     %59 9  F4LL8 r  c                   K   |                                   d{V  |                     |          }d|d         i}|d         r9|                     |d         g|           d{V }|                     ||          S |                     |                     ||                     d{V }|                     ||          S )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  ri  r|  publicGetMarketsSymbolTicker24hr  r_  )r  r  r  r  r  tickersr  s          r  fetch_tickerzpoloniex.fetch_ticker  s       !!!!!!!!!V$$fTl
 * 	3 ..x0@/A6JJJJJJJJG>>'6222==dkk'SY>Z>Z[[[[[[[[.   6222r  tradec                    |                      |g d          }|                     |dd          }|                     |g d          }|                     |d          }|                     ||d          }|d         }|                     |dd          }d }	|                     |d	d
          }
|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd          }||                     |          }||d}	|                     ||||                     |          |||                     |dd          ||                     |dd          |
|||	d|          S )N)r2   tradeIDtrdIdorderIdordId)r0  
createTimer1  cTimer  _side	takerSider  pxrN  rO  r  rP  feeCurrencyfeeCcy	feeAmountfeeAmt)r  currencyordTyper  	matchRolerole)r2   r  r   r6  r  orderr  r  takerOrMakerr  r  r  rw  )	safe_string_nrX  safe_integer_nr  rY  safe_string_lower_2r  
safe_trader\  )r  r  r  r2   r  r   r]  r  r  rw  priceStringamountString
costStringfeeCurrencyIdfeeCostStringfeeCurrencyCodes                   r  parse_tradezpoloniex.parse_trade?  s   B 'A'A'ABB$$UIw??''/R/R/RSS	##E844!!(FC88!''v{CC((>>))%UCC''x??
**5-JJ**5+xHH$"55mDDO%+ C "Y//,,UIvFF 44UKPP " 
  
   	r  c                   K   |                                   d{V  |                     |          }d|d         i}|||d<   |d         r]|                     |                     ||                     d{V }|                     |d          }|                     ||||          S |                     |                     ||                     d{V }	|                     |	|||          S )au  
        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* 	G!==dkk'SY>Z>Z[[[[[[[[H &99J$$ZFFF88Wf9U9UVVVVVVVV   >>>r  c                 (  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S d}||                     |          }d}|                     d||          \  }}|                     |ddg          }i }	|rdnd}
|rd	nd
}|||	|
<   |||	d<   |r||d         |	d<   |                     ||	|          \  }	}|r]|                     |                     |	|                     d{V }| 	                    |d          }| 
                    ||||          S |                     |                     |	|                     d{V }| 
                    ||||          }|S )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>`
        NFrh   r  r?   r@   r  r  r  r  r,  r2   r  r  )r  r  fetch_paginated_call_dynamicr  rc  r  r   swapPrivateGetV3TradeOrderTradesr  r  r  privateGetTrades)r  r  r  r,  r  r  r  rh  r  r  startKeyendKeyrawr  r  r  s                   r  fetch_my_tradeszpoloniex.fetch_my_trades  s      !!!!!!!!!88R\]]& 	j::?FTY[`bhiiiiiiiii[[((F
!??QWY_``
F]]:/ABB

 )977k&5I %GH$GG 	-&, &tGH2267FKK "	A==dkk'SY>Z>Z[[[[[[[[C@ >>#v..D$$T65%@@@..t{{7F/K/KLLLLLLLL, ""8VUEBBr  r  c                 D    dddddddd}|                      |||          S )NrF  closedcanceled)NEWPARTIALLY_FILLEDFILLEDPENDING_CANCELPARTIALLY_CANCELEDCANCELEDFAILEDr  r  r  statusess      r  parse_order_statuszpoloniex.parse_order_status\  s=     &("," 
 
 &&999r  r  c                    |                      |g d          }|)|                     |                     |d                    }|                     |d          }|                     ||d          }|d         }|                     |d          }|@t          |t                    s+|                     ||                     |d|                    }|                     |g d          }|                     |dd	          }|                     |d
d          }	| 	                    |                     |d                    }
| 
                    |d          }|                     |d          }|                     |          }|                     |g d          }d }|                     |dd          }d }d }|                     |d          }||dk    r|d         n|d         }n,|                     |          }|                     |dd          }||||d}|                     |dd          }| 
                    |d          }|                     |d          }|                     |d          }|                     |d          dk    }|                     i d |d|d|d!|d"|                     |          d#|                     |d$          d%|
d|d|d&|                     |d&          d'|d(k    d|d)|d*|                     |d*d+          d,|                     |d-          d.|                     |d/d0          d1||	d ||||||d2|          S )3N)r   r  r  dater  r  resultingTradesr2   )r  rater  rN  szfilledQuantityexecQtyr  r  r  )orderNumberr2   r  r  tokenFeeCurrencyr  rw  buyr  r  tokenFeer  )r  r  r  clientOrderIdclOrdIdmgnMode
reduceOnlyleverposSideBOTHr  r   r6  lastTradeTimestamp
updateTimer  r"  postOnlyLIMIT_MAKERr  r  	stopPricer  execAmtrM  avgPriceavgPxr  )filled	remainingr   rw  r  r  r$  r#  )r  	parse8601r  rY  r  
isinstancer}  r  rX  r  safe_string_lowerparse_order_typer  r  r  
safe_orderr\  )r  r  r  r   r]  r  r  r  r  r  r  r  rawTyper  r2   rw  r  feeCostr  r  r  r  r  r$  r#  s                            r  parse_orderzpoloniex.parse_orderh  s$   F ''/S/S/STT	t'7'7v'F'FGGI##E844!!(FC88!//%1BCC&ot44 m"&///4CSCSTZ\`bjCkCk"l"l""5*A*A*ABB##E:t<<##E+;YGG(()9)9%)I)IJJ%%eV44""5&11$$W--'P'P'PQQ((0BHMM#u--15fVnnVG_OO #55kBBO((
HEEG+ C
 **5/9MM++E9==
^^E<88
$$UG44!!%33v=  
E 
" 
 ] 
 	 

 Y// 
 !$"3"3E<"H"H 
 f 
 f 
 D 
 4++E=AA 
 =0 
 D 
 U 
 D..unkRR 
 D$$UI66 
  t))%WEE! 
" f# 
$ %$$ 3 
  
  
4 5  	r  c                 @    dddddd}|                      |||          S )Nr  r,  )MARKETLIMITr  z
STOP-LIMITzSTOP-MARKETr  r  s      r  r  zpoloniex.parse_order_type  s7    "!#
 
 &&999r  c           	          t          dt          |                    D ]Z}||         }|                     |dd|d         |d         d          }|                    |                     ||                     [|S )Nr   rF  r,  r  r  )r  r  r  r  )r{  r  r  r  r  )r  r   r  r  r  r  extendeds          r  parse_open_orderszpoloniex.parse_open_orders  s    q#f++&& 	> 	>A1IE{{5 fv	+ +  H MM$**8V<<====r  c                   K   |                                   d{V  d}i }| |                     |          }|d         |d<   d}|                     d||          \  }}||dk    rdnd} |||          |d<   |                     |d	d
          }	|                     |d	d
g          }d}
|dk    rF|                     |                     ||                     d{V }|                     |d          }
na|	r0|                     |                     ||                     d{V }
n/| 	                    |                     ||                     d{V }
ddi}| 
                    |
||||          S )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  rl   r=   r1  r   r,  r0  stopr  r  rF  )r  r  rc  safe_value_2omitswapPrivateGetV3TradeOrderOpensr  r  privateGetSmartordersprivateGetOrdersparse_orders)r  r  r  r,  r  r  r  rh  r*  	isTriggerr  r  	extensions                r  fetch_open_orderszpoloniex.fetch_open_orders%  s      !!!!!!!!![[((F &tGH
!??@QSY[abb
F%//$$cC"s5#GG%%fi@@	6Iv#677<<T[[RX=Y=YZZZZZZZZCP ~~c622HH 	Q!77GV8T8TUUUUUUUUHH!224;;w3O3OPPPPPPPPH0 $V,	  65%KKKr  c                 "  K   |                                   d{V  d}i }| |                     |          }|d         |d<   d}|                     d||d          \  }}|dk    rt          | j        dz             |t          d|          |d	<   |||d
<   |                     d||          \  }}|                     |                     ||                     d{V }| 	                    |dg           }	| 
                    |	|||          S )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  rR   r?   r=   z: fetchClosedOrders() is not supported for spot markets yet   r,  r  r  r  )r  r  rc  r(   r2   r  r  !swapPrivateGetV3TradeOrderHistoryr  r  r  )
r  r  r  r,  r  r  r  rh  r  r  s
             r  fetch_closed_orderszpoloniex.fetch_closed_orders  sL      !!!!!!!!![[((F &tGH
!??@SU[]cekll
Ftw)eefff"3GG$GG227GVLL??GU[@\@\]]]]]]]]R ~~h33  vue<<<r  r  r  r  r  c           	        K   |                                   d{V  |                     |          }|d         |                                d}|                     |dd          }	|                     |||||||          \  }}d}
|d         s|d         rF|                     |                     ||                     d{V }|                     |d          }
na|	0|                     |                     ||                     d{V }
n/| 	                    |                     ||                     d{V }
| 
                    |
|          S )	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JJLL
 
 ))&+~NN,,VT4RWY_``&> 		RVH- 		R$($D$DT[[QXZ`EaEa$b$bbbbbbbO ~~ov>>HH%!88Wf9U9UVVVVVVVVHH!33DKK4P4PQQQQQQQQH &111r  c                 2   |                      |dd          }|                     |          }	|	d         rd }
|                     |d          \  }
}|
1|                     d|
dddg           |
                                |d<   d }|                     |d	          \  }}|r4|
t          | j        d
z             d|vrt          | j        dz             |                                }|dk    }|                     ||dk    |          }|                     |g d          }|7|	d         s#t          | j        dz   |	d         z   dz             |dnd}||d<   n|rd}||d<   |r2|dk    rd }d}| 
                    |ddd          \  }}|                     |d          }|                     |d          }||                     ||          }n|rw|	d         ro|t          | j        dz             |                     |          }|                     |          }t          j        ||          }|                     ||          }n|                     ||          }|	d         rdnd}|||<   np|	d         rdnd}|                     ||          ||<   nJ|	d         rdnd}|                     ||          ||<   |	d         rdnd}|                     ||          ||<   |                     |d           }|||d <   |                     |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  rN  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-   rZ  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  s   ))&+~NNV$$* 	IJ!%!9!9&,!O!OJ%,,]JW^`jVklll%/%5%5%7%7	"F!55fhGGNFF I%+DG  7O  -O  P  P  P!V+++DG  7H  -H  I  I  I

 H,&&x-1OQWXX
6#L#L#LMM#&> B"47-b#beklres#s  wA  $A  B  B  B',}FF<M#/GK   	*)M' 	Gu}}"481<@<Y<YZ`bo  rU  W[  =\  =\916''776622#"&"8"8"F"FKK6 	I6&> 	I}*47  6A  ,A  B  B  B'+'<'<V'D'D&*&;&;E&B&B&-&8{&S&S&*&<&<V[&Q&Q"&"8"8"H"HK(.v@HHD	%0	""*0.BJJd	%)%=%=ff%M%M	""&,Vn>

$I!%!9!9&&!I!IGI"(.:wwdH $ 7 7 F FGH((AA$'4GO$YYv77F  r  r2   c           	      P  K   |                                   d{V  |                     |          }|d         s#t          | j        dz   |d         z   dz             d|i}	|                     |dd          }
|                     |||||	||          \  }	}d}|
0|                     |                     |	|                     d{V }n/|                     |                     |	|                     d{V }|                     |||d	          }| 	                    ||          S )
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_orderA  s|     " !!!!!!!!!V$$f~ 	Gtw)IIFSYNZ  ^F   F  G  G  G"
 ))&+~NN,,VT4RWY_``#!99$++gv:V:VWWWWWWWWHH!44T[[&5Q5QRRRRRRRRH ;;x*
 *
   &111r  c                   K   |                                   d {V  |t          | j        dz             |                     |          }i }|d         sh|d         |d<   ||d<   |                     |                     ||                     d {V }|                     |                     |d                    S |                     |d          }||}||d<   | 	                    |dd	          }| 
                    |g d
          }d }	|r0|                     |                     ||                     d {V }	n/|                     |                     ||                     d {V }	|                     |	          S )Nz) cancelOrder() requires a symbol argumentr=   r2   r  r  r  r  r0  r  )r  r0  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_orderm  s      !!!!!!!!!>#DG.Y$YZZZV$$f~ 	A &tGH!GG::4;;wPV;W;WXXXXXXXXC ##DNN3$?$?@@@@@$B%%fi@@	6#G#G#GHH 	V!<<T[[RX=Y=YZZZZZZZZHH!77GV8T8TUUUUUUUUH )))r  c                   K   |                                   d{V  dg i}d}|!|                     |          }|d         g|d<   d}d}|                     d||          \  }}|dk    s|dk    r[|                     |                     ||                     d{V }|                     |d          }|                     ||          S |                     |dd	          }|                     |dd	g          }|r0| 	                    |                     ||                     d{V }n/| 
                    |                     ||                     d{V }|                     ||          S )
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>`
        Nr`  r2   rC   r?   r@   r  r0  r  )r  r  rc  !swapPrivateDeleteV3TradeAllOrdersr  r  r  r  r   privateDeleteSmartordersprivateDeleteOrders)	r  r  r  r  r  r  rh  r  r  s	            r  cancel_all_orderszpoloniex.cancel_all_orders  s      !!!!!!!!! r
 [[((Ft"GI 
!??@QSY[abb
F:#9#9>>t{{7TZ?[?[\\\\\\\\C ~~c622H$$Xv666%%fi@@	6Iv#677 	T!::4;;wPV;W;WXXXXXXXXHH!55dkk'66R6RSSSSSSSSH$   6222r  c                   K   |                                   d{V  t          |          }d|i}d}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    rt	          | j        dz   |z   dz             |                     |dd	          }|                     |dd	g          }d}|rF|                     | 	                    ||                     d{V }| 
                    |d
          }n/|                     | 	                    ||                     d{V }|                     |          }	||	d<   |	S )a2  
        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  ro   r=   z# fetchOrder() is not supported for z markets yetr0  r  r   )r  strr  rc  r(   r2   r  r   privateGetSmartordersIdr  r  privateGetOrdersIdr  )
r  r2   r  r  r  r  rh  r  r  r  s
             r  fetch_orderzpoloniex.fetch_order  s      !!!!!!!!!WW"
 [[((F &tGH
!??fV\]]
Ftw)NNQ[[^llmmm%%fi@@	6Iv#677 	S!99$++gv:V:VWWWWWWWWHx33HH!44T[[&5Q5QRRRRRRRRH,   **dr  c                    K   |                                   d {V  |                     |d d |           d {V }|                     |d          }||v rdndS )Nr2   rF  r  )r  r  r  )r  r2   r  r  r   indexeds         r  fetch_order_statuszpoloniex.fetch_order_status%	  sz      !!!!!!!!!--fdD&IIIIIIII------vvh6r  c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |          S )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+	  s       !!!!!!!!!"
 44T[[&5Q5QRRRRRRRR,   (((r  c                 N   |d d d}t          |t                    s|                     |d          }||d<   |                     |          |d<   |                     |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     |          }| 	                                }	|                     |d          |	d	<   |                     |d
          |	d<   |	||<   | 
                    |          S t          dt          |                    D ]}|                     ||i           }	|                     |	d          }
t          dt          |
                    D ]}|                     |
|          }|                     |d          }|                     |          }| 	                                }|                     |d          |d<   |                     |d          |d<   |||<   | 
                    |          S )N)r  r   r6  uTimer   r6  detailsr   ccyavailtotalimusedbalancesr  	availablefreehold)r  r}  r  r\  r  r{  r  r  r  accountsafe_balancer  )r  r  r  r0  rC  r  balance
currencyIdry  rM  rI  r  
newAccounts                r  parse_balancezpoloniex.parse_balanceT	  s,   
 
 (D)) 	-""8W55B"$F;!%b!1!1F:nnXy"==G1c'll++ ' '!!*!--gu==
..z::,,..#'#3#3GW#E#E "&"2"27D"A"A&t$$V,,,q#h--(( 
	* 
	*Aooh266Gw
;;H1c(mm,, * *//(A66!--gzBB
..z::!\\^^
%)%5%5g{%K%K
6"%)%5%5gv%F%F
6")t*   (((r  c                   K   |                                   d{V  d}|                     dd|          \  }}|dk    rG|                     |           d{V }|                     |di           }|                     |          S ddi}|                     |                     ||                     d{V }|                     |          S )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>`
        NrP   r=   r  accountTypeSPOT)r  rc  swapPrivateGetV3AccountBalancer|  rR  privateGetAccountsBalancesr  )r  r  rh  r  r  r  r  s          r  fetch_balancezpoloniex.fetch_balancew	  s      !!!!!!!!!
!??PTV\]]
F $ C CF K KKKKKKKKL >>+vr::D%%d+++6
 88Wf9U9UVVVVVVVV" !!(+++r  c                 D  K   |                                   d{V  |                     |           d{V }i }t          dt          | j                            D ]C}| j        |         }|||                     |d          |                     |d          ddd||<   D|S )aX  
        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   rL  	tierBased)r  privateGetFeeinfor{  r  r`  r  )r  r  r  r  r  r  s         r  fetch_trading_feeszpoloniex.fetch_trading_fees	  s       !!!!!!!!!//77777777 q#dl++,, 		 		A\!_F  ))(K@@))(K@@"! F6NN r  c                 B  K   |                                   d{V  |                     |          }d|d         i}|(||d<   |d         r|                     g d|          |d<   |d         rs|                     |                     ||                     d{V }|                     |di           }|                     |d          }|                     |||          S |                     |                     ||                     d{V }	|                     |	d	          }
| 	                    |	d
          }| 	                    |	d          }g }g }t          dt          |                    D ]b}|dz  dk     rW|                     ||          }|                     ||                     |d                    }|                    ||g           ct          dt          |                    D ]b}|dz  dk     rW|                     ||          }|                     ||                     |d                    }|                    ||g           c|d         |                     |dd          |                     |d          |
|                     |
          ddS )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://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  r0  timeasksbidsr   r   r   T)r  rc  rb  r   r6  nonce)r  r  find_nearest_ceilingswapPublicGetV3MarketOrderBookr  r|  r  parse_order_bookpublicGetMarketsSymbolOrderBookr  r{  r  r  sumr  sort_byr\  )r  r  r,  r  r  r  r  r  r0  r  r   rb  rc  
asksResult
bidsResultr  r  r  s                     r  fetch_order_bookzpoloniex.fetch_order_book	  s      !!!!!!!!!V$$fTl
 $GGj! [#'#<#<=R=R=RTY#Z#Z * 	; $ C CDKKPWY_D`D` a aaaaaaaK >>+vr::D""4..B((vr:::==dkk'SY>Z>Z[[[[[[[[ %%h77	x00x00

q#d))$$ 	3 	3AA{{((q11))$A??!!5&/222q#d))$$ 	3 	3AA{{((q11))$A??!!5&/222X&LLQ55LLQ//"Y//
 
 	
r  ry  c                    K   |                                   d{V  |                     ||          \  }}}}|}|                     |                     ||                     d{V }|                     |||          S )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>`
        N)r  #prepare_request_for_deposit_addressprivatePostWalletsAddressr  parse_deposit_address_special)r  ry  r  r  extraParamsr  networkEntryr  s           r  create_deposit_addresszpoloniex.create_deposit_address+
  s       !!!!!!!!!7;7_7_`dfl7m7m4h77GV8T8TUUUUUUUU 11(HlSSSr  c                   K   |                                   d{V  |                     ||          \  }}}}|}|                     |                     ||                     d{V }t	          |                                          }t          |          }	|	dk     rt          | j        dz             | 	                    |||          S )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   z fetchDepositAddress() returned an empty response, you might need to try "createDepositAddress" at first and then use "fetchDepositAddress")
r  ro  privateGetWalletsAddressesr  r}  r~  r  r   r2   rq  )
r  ry  r  r  rr  r  rs  r  r~  lengths
             r  fetch_deposit_addresszpoloniex.fetch_deposit_address@
  s       !!!!!!!!!7;7_7_`dfl7m7m4h88Wf9U9UVVVVVVVV HMMOO$$TA::  +x  !x  y  y  y11(HlSSSr  r  c                    || j         vrt          | j        dz   |z   dz             |                     |          }d }|                     |          \  }}|t          | j        dz   |z   dz             d }|                     ||          }|                     |d         |          }|	|d         }n|}d|i}||||gS )Nz* fetchDepositAddress(): can not recognize z currency, you might try using unified currency-code and add provide specific "network" parameter, like: fetchDepositAddress("USDT", {"network": "TRC20"})z6 fetchDepositAddress requires a network parameter for .r  r2   r  )r   r$   r2   r  handle_network_code_and_paramsr"   r  r|  )r  ry  r  r  r  exchangeNetworkIdrs  r  s           r  ro  z,poloniex.prepare_request_for_deposit_addressY
  s   ''DG&RRUYY  ]y  y  z  z  z==&&"AA&IIV#DG.f$fim$mps$sttt --k4@@~~hz&:KHH# ,T 2 +)
 <88r  c                 $   |                      |d          }||                      ||d                   }d }|                     |           |"|                      |d         d          }||}|}||d         |                      |d          ||dS )Naddressr2   r  depositAddressry  rv  )r  r  rv  r~  tag)r  check_address)r  r  r  rs  r~  r  r  s          r  rq  z&poloniex.parse_deposit_address_specialn
  s    ""8Y77?&&xd1CDDG7####!--l6.BDTUUN)( (''i@@
 
 	
r  fromAccount	toAccountc                   K   |                                   d{V  |                     |          }|                     | j        di           }|                     |||          }|                     |||          }	|                     ||          |d         ||	d}
|                     |                     |
|                     d{V }|                     ||          S )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  r  r  )	r  r  r  r   r  currency_to_precisionprivatePostAccountsTransferr  parse_transfer)r  ry  r  r  r  r  r  r  fromIdtoIdr  r  s               r  r   zpoloniex.transfer
  s       !!!!!!!!!==&&7GLL!!.+{KK	;GG00v>> !	
 
 99$++gv:V:VWWWWWWWW ""8X666r  r   r  c           
      j    ||                      |d          d d |                      |d          d d d d d	S )N
transferIdr2   )	r  r2   r   r6  r  r  r  r  r  r  )r  r   r  s      r  r  zpoloniex.parse_transfer
  sN     ""8\::((488

 

 
	
r  r~  r  c                 z  K   |                      ||          \  }}|                     |           |                     ||          \  }}}}	|}|                     ||          |d<   ||d<   |||d<   |                     |                     ||                     d{V }
|
|	d}|                     ||          S )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>`
        r  r~  N	paymentId)r  withdrawNetworkEntry)handle_withdraw_tag_and_paramsr  ro  r  privatePostWalletsWithdrawr  parse_transaction)r  ry  r  r~  r  r  r  rr  r  rs  r  withdrawResponses               r  r   zpoloniex.withdraw
  s       99#vFFV7###7;7_7_`dfl7m7m4h 66tVDD$	?#&GK 88Wf9U9UVVVVVVVV !$0
 
 %%&6AAAr  c                   K   |                                   d {V  d}|                                 }||                     |dz            n|d|z  z
  }||d}|                     |                     ||                     d {V }	|	S )Ni r+  r   )startend)r  secondsparse_to_intprivateGetWalletsActivityr  )
r  ry  r  r,  r  yearnowr  r  r  s
             r  fetch_transactions_helperz"poloniex.fetch_transactions_helper
  s      !!!!!!!!!llnn494E!!%$,///CRTW[R[O
 
 77GV8T8TUUUUUUUUP r  c                   K   |                                   d{V  |                     ||||           d{V }d}||                     |          }|                     |dg           }|                     |dg           }|                     ||||          }	|                     ||||          }
|                     |
|	          }|                     |                     |d          |||          S )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_limitrj  )r  ry  r  r,  r  r  r  r  r  withdrawalTransactionsdepositTransactionstransactionss               r  fetch_deposits_withdrawalsz#poloniex.fetch_deposits_withdrawals)  s      !!!!!!!!!77eUFSSSSSSSS!}}T**HoohrBB??8Z<<!%!8!8hPUW\!]!]"55h%QVWW(()<>TUU224<<k3Z3Z\`bginooor  c                   K   |                      ||||           d{V }d}||                     |          }|                     |dg           }|                     ||||          }|                     ||||          S )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  ry  r  r,  r  r  r  r  r  s	            r  fetch_withdrawalszpoloniex.fetch_withdrawalsA  s       77eUFSSSSSSSS!}}T**HoohrBB..{HeUSS22<ueTTTr  codesc                   K   |                                   d{V  |                     |                     |ddi                     d{V }i }t          dt	          |                    D ]L}||         }t          |                                          }|                     |d          }||         ||<   M|                     ||          S )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>`
        Nrk  Tr   )	r  rz  r  r{  r  r}  r~  r  parse_deposit_withdraw_fees)	r  r  r  r  r  r  r  r   rP  s	            r  fetch_deposit_withdraw_feesz$poloniex.fetch_deposit_withdraw_feesU  s       !!!!!!!!!11$++fGdfjFk2l2lmmmmmmmm0 q#h--(( 	1 	1AQKEejjll++J))*a88J$Z0D//e<<<r  c                 d   i }|                      |          }t          |                                          }t          dt	          |                    D ]X}||         }|                     |          }||         }	||                     ||          r|                     |          }
|                     |	|
          ||<   | 	                    |	d          }t	          |          }|dk    rt          dt	          |                    D ]}||         }|
                    |d          }|                     |          }| 	                    ||          }i }|                     |d          }||dnd dd d dd||<   |                     ||         d         |          ||         d<   Z|S )	Nr   rm   rs  Frw  rL  rt  r  )market_codesr}  r~  r{  r  r  r  r  parse_deposit_withdraw_feer  replacer  r  r  )r  r  r  currencyIdKeydepositWithdrawFeesresponseKeysr  rP  ry  feeInfor  rm  chainsLengthr  	networkIdr  networkInfonetworkObjectwithdrawFees                      r  r  z$poloniex.parse_deposit_withdraw_fees  s   , %'!!%((HMMOO,,q#l++,, 	B 	BA%aJ**:66Dz*G4==u#=#===..,0,K,KGU],^,^#D)"oog}EE";//!##"1c+&6&677 B B$/N	$-$5$5dB$?$?	&*&=&=i&H&H&*ooh	&J&J.0&*&6&6{O&T&T (38C8OeeVZ) )
 (,.2( (	6 	6k2 AEL_`dLefpLq  tA  AB  AB+D1*==""r  c                     |                      i           }||d         |d         <   |                     |d          }|                     |d          }||dnd d}d d d}||d<   ||d<   |                     |          }||d	|d
         |<   |S )Nr  ry  rn  rs  Fr  r   ru  rt  r  )deposit_withdraw_feer  r  r  )	r  rw  r  depositWithdrawFeer  r  withdrawResultdepositResultr  s	            r  r  z#poloniex.parse_deposit_withdraw_fee  s    !66r::7:6"8F#34$$S,77	&&sO<<$/$;%%$ 
  

 
 
 *8:&(59%--i88&$7
 7
:&{3 "!r  c                   K   |                      ||||           d{V }d}||                     |          }|                     |dg           }|                     ||||          }|                     ||||          S )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  ry  r  r,  r  r  r  r  r  s	            r  fetch_depositszpoloniex.fetch_deposits  s       77eUFSSSSSSSS}}T**H??8Z<<..x5%PP22<ueTTTr  c           	      F    ddddddddd}|                      |||          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  s@    !*!* #&&	
 	
 &&999r  transactionc                 4   d|v r|d         }|                      |d          }|                     |d          }|                     |          }|                     |dd          }|                     |          }|                     |d          }d|v rd	nd
}|                     |dd          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d          }|d	k    rt          j        ||          }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S )Nr  r  r   r  r  r  txidwithdrawalRequestsId
withdrawalru  depositNumberr~  	paymentIDr  rw  r  r2   rv  	addressToaddressFromr  tagTotagFromr  updatedr6  )r  r  r  )commentinternalrw  )	safe_timestampr  r  r  rX  r-   
string_subr  r\  )r  r  r  r   rP  ry  r  r  r  r2   r~  r  r  r  s                 r  r  zpoloniex.parse_transaction  sV   J "[00%j1K''[AA	%%k:>>
&&z22!!+xCC..v66V44 6+ E E||I-C_UU"";	::{K88''X>>((e<<<"-lMJJL
K
"
 
 d''55	

 t
 w
 
 4
 3
 T
 t
 f
 D
 t
 D
  !
" Y//#
$  ))-88 )
 
 
 	
r  r$  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d}|                     d|          \  }}|t          | j        dz             d}|                     |dd          \  }}|rd|vrt          | j        dz             ||                                |d	         d
}|                     |                     ||                     d{V }|S )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>  sL      >#DG.Y$YZZZ!!!!!!!!!V$$
!??vVV
F#DG.t$tuuu//%HH 	D'''  3C  )C  D  D  D!''))Tl
 

 ??GU[@\@\]]]]]]]]r  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     d|          \  }}|t          | j        dz             |                                |d<   |                     |                     ||                     d{V }|                     ||          S )ag  
        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   rd   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_leverage_  s       !!!!!!!!!V$$fTl
 
!??QWXX
F#DG.v$vwww'--//	??GU[@\@\]]]]]]]]L ""8V444r  c                    d }d }d }d }|                      |d          }t          dt          |                    D ]x}||         }	|                     |	d          }|                     |	d          }|                     |	d          }
|                     |	d          }|dk    r|
}k|dk    r|
}t|
}|
}y||                     ||          |||d	S )
Nr  r   r  r  r  r  LONGSHORT)r  r  r  longLeverageshortLeverage)r  r{  r  r  r  safe_symbol)r  r$  r  r  r  r]  r  r  r  r  r  r  s               r  r  zpoloniex.parse_leverage  s   ! 
~~h//q#d))$$ 	& 	&AGE''x88H))%;;J%%eW55E&&ui88G&  $G## %$ %&&x88$(*
 
 	
r  c                    K   |                      |           d{V }|                     |di           }|                     |d          }|dk    }||dS )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  sx       ::6BBBBBBBB ~~h33""433G#
 
 	
r  r#  c                 |   K   |rdnd}d|i}|                      |                     ||                     d{V }|S )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  s_       !/wwit
 ;;DKKQW<X<XYYYYYYYY r  c                    K   |                                   d{V  |                     |          }|                     |           d{V }|                     |dg           }|                     ||          S )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  rb  "swapPrivateGetV3TradePositionOpensr  parse_positions)r  r`  r  r  	positionss        r  fetch_positionszpoloniex.fetch_positions  s       !!!!!!!!!%%g..@@HHHHHHHHH NN8VR88	##Iw777r  positionc                 <   |                      |d          }|                     ||          }|                     |d          }|                     |d          }|                      |d          }|                      |d          }t	          j        ||          }|                      |d          }	|                      |d          }
t	          j        |	|
          }|                     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 t          |          |                     |d          |                     |d          |                     |d          d 
          S )!Nr  r  r  r  rG  rO  	openAvgPxr  r2   notionalr  liquidationPriceliqPx
entryPriceunrealizedPnluplrL  	contractsr  rQ  markPx	lastPricer  r  r#  r   r6  mmmgnRatioslTrgPxtpTrgPx)
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager$  marginRatior  r   )
r  rY  r  r  r-   rZ  safe_positionr  r\  int)r  r  r  r]  r   r  r$  r  r  rO  r  r  s               r  parse_positionzpoloniex.parse_position  s   < ##Hh77!!(F33%%h88	++Hi@@
##Hg66((488%h>>x//##Hk::'X66
!! #
H#
$#
 fX&#
 	#

 *#
  0 07 C C#
 $**8[AA#
 T--h>>#
 $#
 ))(E::#
 D#
 ))(H==#
 #
 D**8Y??#
 d#
  !#
" Y//##
$ $(!%!1!1(D!A!A+/$*'+H++HjAA!--h	BB#//)DD7#
 #
 #
   	r  c                   K   |                                   d {V  |                     |          }|                     ||          }|d         t          j        |          |                                d}d|vrd|d<   |                     |                     ||                     d {V }|dk    rt          j        |          }|                     |d          }| 	                    ||          S )Nr2   )r  rP  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_helperf  s     !!!!!!!!!V$$))&&99Tl%f--JJLL
 
 V##!'GIBB4;;wX^C_C_```````` 8'//F~~h//--dF;;;r  r  c                     |                      |d          }|                     ||          }|                      |d          }|dk    rdnd}||d         |d |                     |d          d d dd d d
S )	Nr  r  ADDaddr  rP  r  )
r  r  r  r  r  rF  ry  r  r   r6  )r  rY  r  )r  r  r  r]  r  r  s         r  r  z"poloniex.parse_margin_modification  s    ##D(33!!(F33""400 E))uuX&&&tU33
 
 	
r  c                 D   K   |                      || d|           d{V S )aJ  
        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=margin-structure>`
        r  Nr  r  r  r  r  s       r  reduce_marginzpoloniex.reduce_margin  s6       ..vw&QQQQQQQQQr  c                 B   K   |                      ||d|           d{V S )a0  
        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=margin-structure>`
        r  Nr  r   s       r  
add_marginzpoloniex.add_margin  s4       ..vvufMMMMMMMMMr  c                 *    |                                  S r  )milliseconds)r  s    r  rd  zpoloniex.nonce  s      """r  r   GETc                 T   | j         d         d         }|                     |ddg          r| j         d         d         }|dk    r"d|v r|                     |d                   |d<   |                     ||                     |                    }|                     ||          }	|dk    s|dk    r'|d	|	z   z  }|r|d
|                     |          z   z  }nJ|                                  t          | 	                                          }
|dz   }|d	|	z   z  }|d	|	z   z  }|dk    s|dk    s|dk    r0|dz  }|r | 
                    |          }|d|z   dz   z  }|d|
z   z  }ne|                     d|
i|          }|                     |          }|d|                     |          z   z  }|r|d
|                     |          z   z  }|                     |                     |          |                     | j                  t           j        d          }d| j        |
|d}||||dS )Nr   r=   r   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  encode_uri_componentr   extract_paramsimplode_params	urlencodecheck_required_credentialsr7  rd  jsonr  keysorthmacencodesecrethashlibsha256apiKey)r  pathr   r3  r  r5  r4  r2  queryimplodedPathr   authsortedQueryr1  s                 r  signzpoloniex.sign  sg   iv&==|];<< 	+)E"6*CU??F 2 2#889IJJF8		&$"5"5d";";<<**488(??c\113%%C 3sT^^E2222++---DJJLL))ID=D3%%CC,&&D&  foo6X;M;M 899U++DNT1C77D(944"kk?I*FNN"ll;77t~~k:::: 73!6!666C		$++d"3"3T[[5M5Mw~_ghhI 2{!*&	 G fdwOOOr  reasonr2  r3  r5  r4  c
                 F   |d S |                      |d          }
|
|
dk    r~|d         }|                      |d          }| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nry  200messager  r  r  )r  r2   throw_exactly_matched_exceptionr=  throw_broadly_matched_exceptionr   )r  ry  rI  r2  r3  r5  r4  r  requestHeadersrequestBodyresponseCode	codeInnerrL  feedbacks                 r  handle_errorszpoloniex.handle_errors  s    4 ''&99$<5+@+@ (I&&x;;Gw}t+H001I9V^___001I7T\]]])))tr  r  )NN)d__name__
__module____qualname__r   r  r   r}  r  r7  r   r   r  r  r  r  r  dictr  r  r  r-  r   r_  r   r   ri  r   r  r  r   r  r  r   r  r  r   r  r  r  r  r  r   r   floatr   r  r  r+  r0  r5  r:  r=  r@  r   rR  rX  r   r^  r   rm  r
   rt  rx  ro  rq  r   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#  rd  rH  rT  __classcell__)r  s   @r  r/   r/      s>       d# d d d d d dL7
 7
 7
4 7
 7
 7
 7
r ?CQUdhqs NL NL NL NL3 NL^a NLx|  ~B  yC NL NL NL NL` ).b       *, 9 9V 9 9 9 9 /1 + +T&\ + + + +6 /1 *+ *+T&\ *+ *+ *+ *+X24 2F 2 2 2 26
 6
 6
 6
 6
 6
pi
 i
 i
 i
 i
 i
V ') 
9 
9S 
9 
9 
9 
9L L4 L L6 L L L L\ 6:" N5 N57 N5 N5 N5 N5 N5` -/ S S: S S S Sj 68 *3 *3 *3F *3 *3 *3 *3XB B Bv B B B B BH <@d[] 4? 4? 4?S 4? 4?bfglbm 4? 4? 4? 4?l 37TX\eg a aC as aRU a a a aF
: 
: 
: 
: 
:e e ev e e e e eN: : :
 
 
 59tZ^gi cL cLc cL cLTW cLnrsxny cL cL cL cLJ 7;\`ik F= F= F=3 F=VY F=ptuzp{ F= F= F= F=P mqy{ -2 -2 -2I -2Y -2X] -2fi -2 -2 -2 -2^ HLTV >! >! >! >!@ fjx|  FH *2 *23 *2 *29 *2I *2_b *2ru *2 *2 *2 *2X 9=R 5* 5*S 5*# 5* 5* 5* 5*n 59 D3 D3c D3 D3 D3 D3L 8<B 9 9C 9 9 9 9 9v ?C2 7 73 7 7 7 7 7 ?CQUdhqs ') ')3 ') ')3 ')^a ') ') ') ')R!) !) !) !) !)F *, J, J, J, J, J, J,X /1  [    @ @DB F
 F
S F
 F
S\ F
 F
 F
 F
P >@ T T TN T T T T* =? T T T> T T T T2 MO 9 9 9T 9SV 9 9 9 9*
Q_ 
 
 
 
& ac 7 73 7 7C 7TW 7gt 7 7 7 7@
 
t 
x 
= 
 
 
 
$ QU]_ !B !B3 !B !B !B# !Bdo !B !B !B !BF ;?T`dmo Q QC Qs QZ] Q Q Q Qf <@daenp p pS p p[^ puy  {F  vG p p p p0 37TX\eg U UC Us URU Ulpq|l} U U U U( BFb )= )=w )= )= )= )=V5# 5# 5# 5#n" " " " " ", 04$UYbd U U UC Us Uimnyiz U U U U(:s : : : :N
 N
T N
X N
Q\ N
 N
 N
 N
` ?C2  3     B 8: :5 :53 :5h :5 :5 :5 :5x
 
t 
V 
x 
 
 
 
6 7;2 
 
 
 
 
 
8 CGr  d C    2 8<B 28 28W 284PX> 28 28 28 28hE Et EV E E E EN LN < < <Rd < < < <>
 
d 
F 
N` 
 
 
 
$ FH R R# Ru RL^ R R R R CE N Ns NE NI[ N N N N# # # &eBSW %P %P %P %PN# s  c TX `c        r  r/   )5 ccxt.async_support.base.exchanger   ccxt.abstract.poloniexr   r  r@  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>rd     s   6 5 5 5 5 5 . . . . . .   G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G  G       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) 1 1 1 1 1 1 * * * * * * + + + + + + 4 4 4 4 4 4 % % % % % %H7 H7 H7 H7 H7x H7 H7 H7 H7 H7r  