
    ei^                    x   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZ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l/m0Z0 d dl1m2Z2  G d dee          Z3d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    K/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/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_ohlcvE  s   J %jj A%
 	!!%++  **  **  **  **  **  eR((UA&&UA&&UA&&UA&&UA&&
 	
r  r   symbol	timeframesincer,  c           	      X   |                                   d}|                     |ddd          \  }}|r|                     d|||||d          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          }|                     |||||          S |                     |                     ||                    }|                     |||||          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
        Fri   paginater2  r2   )r  intervalr=   	startTimesTimeendTimeeTimeNr,  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~  s     	88z[`aa& 	w::<QVX]_hjpruvvv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;;DKKQW<X<XYYK$ >>+v66D$$T69eUKKK55dkk'66R6RSS*   69eUKKKr  Fc                     t          t          |                               ||          }|                     | 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  sg    $''44VVDD $>U V V!)f)48MM$/S^4_4_DL01r  c                     |                      |          |                     |          g}|}|                     |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
        r   r   )fetch_spot_marketsfetch_swap_marketsarray_concat)r  r  promisesresultss       r  fetch_marketszpoloniex.fetch_markets  sM     ++F33T5L5LV5T5TU  WQZ888r  c                 V    |                      |          }|                     |          S N)publicGetMarketsparse_markets)r  r  r   s      r  r  zpoloniex.fetch_spot_markets  s+    ''//0 !!'***r  c                     |                      |          }|                     |d          }|                     |          S )Nr  )#swapPublicGetV3MarketAllInstrumentsr  r  )r  r  r  r   s       r  r  zpoloniex.fetch_swap_markets  s?    ;;FCC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_market0  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_marketh  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                 X    |                      |          }|                     |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
        
serverTime)publicGetTimestampr  )r  r  r  s      r  
fetch_timezpoloniex.fetch_time  s-     **622  <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quoteVolumerO  
indexPricer  )safe_integer_2safe_string_2safe_marketr-   
string_mulsafe_tickeriso8601r  )r  r,  r  r   marketIdrelativeChangerJ  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                 .   |                                   d}i }|Z|                     |dddd          }t          |          }|dk    r,|                     |d                   }|dk    r|d         |d<   d}|                     d||          \  }}|d	k    rU|                     |                     ||                    }|                     |d
          }|                     ||          S | 	                    |          }	|                     |	|          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-  s+    	))'4tUKKGLLMq  WQZ00 A%%(.tGH%
!??PVX^__
F;;DKKQW<X<XYYK6 >>+v66D%%dG44411&992 !!(G444r  c                    |                      |                     |ddi                    }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
        includeMultiChainCurrenciesTr   isChildChainchildChainsN
blockchainr2   walletStatewalletDepositStateENABLEDwalletWithdrawalStatewithdrawalFeer  r   deposit)
r  r2   r  networkr   rs  r   feer  r  cryptor3   )r  r   rs  )r  coder2   r  r  r3   r   rs  r   ru  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|  entryrw  allChainEntriesrk  jchildChainIdchildNetworkEntryr  
chainEntrynetworkNamenetworkCodespecialNetworkIds                         r  fetch_currencieszpoloniex.fetch_currencies}  s    ++DKKA^`d@e,f,fgg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                 \   |                                   |                     |          }d|d         i}|d         r3|                     |d         g|          }|                     ||          S |                     |                     ||                    }|                     ||          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>`
        r  r2   r  )r  r  rg  rz  publicGetMarketsSymbolTicker24hr  r]  )r  r  r  r  r  tickersr  s          r  fetch_tickerzpoloniex.fetch_ticker  s     	V$$fTl
 * 	3((&*:);VDDG>>'622277GV8T8TUU.   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)r.  
createTimer/  cTimer  _side	takerSider  pxrL  rM  r  rN  feeCurrencyfeeCcy	feeAmountfeeAmt)r  currencyordTyper  	matchRolerole)r2   r  r   r4  r  orderr  r  takerOrMakerr  r  r  ru  )	safe_string_nrV  safe_integer_nr  rW  safe_string_lower_2r  
safe_traderZ  )r  r  r  r2   r  r   r[  r  r  ru  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                    |                                   |                     |          }d|d         i}|||d<   |d         rW|                     |                     ||                    }|                     |d          }|                     ||||          S |                     |                     ||                    }	|                     |	|||          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>`
        r  r2   Nr,  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77GV8T8TUUH &99J$$ZFFF224;;w3O3OPP   >>>r  c                    |                                   d}|                     |dd          \  }}|r|                     d||||          S d}||                     |          }d}|                     d||          \  }}|                     |ddg          }i }	|rdnd}
|rd	nd
}|||	|
<   |||	d<   |r||d         |	d<   |                     ||	|          \  }	}|rW|                     |                     |	|                    }| 	                    |d          }| 
                    ||||          S |                     |                     |	|                    }| 
                    ||||          }|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>`
        Frh   r  Nr?   r@   r  r  r  r  r,  r2   r  r  )r  r  fetch_paginated_call_dynamicr  ra  r  r   swapPrivateGetV3TradeOrderTradesr  r  r  privateGetTrades)r  r  r  r,  r  r  r  rf  r  r  startKeyendKeyrawr  r  r  s                   r  fetch_my_tradeszpoloniex.fetch_my_trades  s    	88R\]]& 	d44_feUZ\bccc[[((F
!??QWY_``
F]]:/ABB

 )977k&5I %GH$GG 	-&, &tGH2267FKK "	A77GV8T8TUUC@ >>#v..D$$T65%@@@((Wf)E)EFF, ""8VUEBBr  r  c                 D    dddddddd}|                      |||          S )NrD  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  rL  szfilledQuantityexecQtyr  r  r  )orderNumberr2   r  r  tokenFeeCurrencyr  ru  buyr  r  tokenFeer  )r  r  r  clientOrderIdclOrdIdmgnMode
reduceOnlyleverposSideBOTHr  r   r4  lastTradeTimestamp
updateTimer  r"  postOnlyLIMIT_MAKERr  r  	stopPricer  execAmtrK  avgPriceavgPxr  )filled	remainingr   ru  r  r  r$  r#  )r  	parse8601r  rW  r  
isinstancer{  r  rV  r  safe_string_lowerparse_order_typer  r}  r  
safe_orderrZ  )r  r  r  r   r[  r  r  r  r  r  r  r  rawTyper  r2   ru  r  feeCostr  r  r  r  r  r$  r#  s                            r  parse_orderzpoloniex.parse_orderg  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   rD  r,  r  r  )r  r  r  r  )ry  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                    |                                   d}i }| |                     |          }|d         |d<   d}|                     d||          \  }}||dk    rdnd} |||          |d<   |                     |d	d
          }	|                     |d	d
g          }d}
|dk    r@|                     |                     ||                    }|                     |d          }
nU|	r*|                     |                     ||                    }
n)| 	                    |                     ||                    }
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  rD  )r  r  ra  safe_value_2omitswapPrivateGetV3TradeOrderOpensr  r  privateGetSmartordersprivateGetOrdersparse_orders)r  r  r  r,  r  r  r  rf  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66t{{7F7S7STTCP ~~c622HH 	K11$++gv2N2NOOHH,,T[[&-I-IJJH0 $V,	  65%KKKr  c                    |                                   d}i }| |                     |          }|d         |d<   d}|                     d||d          \  }}|dk    rt          | j        dz             |t          d|          |d	<   |||d
<   |                     d||          \  }}|                     |                     ||                    }| 	                    |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  ra  r(   r2   r  r  !swapPrivateGetV3TradeOrderHistoryr  r  r  )
r  r  r  r,  r  r  r  rf  r  r  s
             r  fetch_closed_orderszpoloniex.fetch_closed_orders  s#    	[[((F &tGH
!??@SU[]cekll
Ftw)eefff"3GG$GG227GVLL99$++gv:V:VWWR ~~h33  vue<<<r  r  r  r  r  c           	      r   |                                   |                     |          }|d         |                                d}|                     |dd          }	|                     |||||||          \  }}d}
|d         s|d         r@|                     |                     ||                    }|                     |d          }
nU|	*|                     |                     ||                    }
n)| 	                    |                     ||                    }
| 
                    |
|          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>`
        r2   )r  r  r  r  Nr?   r@   r  )r  r  uppersafe_number_2order_requestswapPrivatePostV3TradeOrderr  rz  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_``&> 		LVH- 		L">>t{{7TZ?[?[\\O ~~ov>>HH%224;;w3O3OPPHH--dkk'6.J.JKKH &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  rL  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-   rX  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           	      (   |                                   |                     |          }|d         s#t          | j        dz   |d         z   dz             d|i}	|                     |dd          }
|                     |||||	||          \  }	}d}|
*|                     |                     |	|                    }n)|                     |                     |	|                    }|                     |||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>`
        r=   z editOrder() does not support r  z& orders, only spot orders are acceptedr2   r  r  N)r  r  )
r  r  r(   r2   r  r  privatePutSmartordersIdr  privatePutOrdersIdr  )r  r2   r  r  r  r  r  r  r  r  r  r  s               r  
edit_orderzpoloniex.edit_order@  sB   " 	V$$f~ 	Gtw)IIFSYNZ  ^F   F  G  G  G"
 ))&+~NN,,VT4RWY_``#33DKK4P4PQQHH..t{{7F/K/KLLH ;;x*
 *
   &111r  c                    |                                   |t          | j        dz             |                     |          }i }|d         sb|d         |d<   ||d<   |                     |                     ||                    }|                     |                     |d                    S |                     |d          }||}||d<   | 	                    |dd	          }| 
                    |g d
          }d }	|r*|                     |                     ||                    }	n)|                     |                     ||                    }	|                     |	          S )Nz) cancelOrder() requires a symbol argumentr=   r2   r  r  r  r  r0  r  )r  r0  r  )r  r"   r2   r  swapPrivateDeleteV3TradeOrderr  r  rz  r  r  r  privateDeleteSmartordersIdprivateDeleteOrdersId)
r  r2   r  r  r  r  r  r  r  r  s
             r  cancel_orderzpoloniex.cancel_orderl  sq    	>#DG.Y$YZZZV$$f~ 	A &tGH!GG44T[[&5Q5QRRC ##DNN3$?$?@@@@@$B%%fi@@	6#G#G#GHH 	P66t{{7F7S7STTHH11$++gv2N2NOOH )))r  c                    |                                   dg i}d}|!|                     |          }|d         g|d<   d}d}|                     d||          \  }}|dk    s|dk    rU|                     |                     ||                    }|                     |d          }|                     ||          S |                     |dd	          }|                     |dd	g          }|r*| 	                    |                     ||                    }n)| 
                    |                     ||                    }|                     ||          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>`
        r^  Nr2   rC   r?   r@   r  r0  r  )r  r  ra  !swapPrivateDeleteV3TradeAllOrdersr  r  r  r  r  privateDeleteSmartordersprivateDeleteOrders)	r  r  r  r  r  r  rf  r  r  s	            r  cancel_all_orderszpoloniex.cancel_all_orders  su    	 r
 [[((Ft"GI 
!??@QSY[abb
F:#9#988Wf9U9UVVC ~~c622H$$Xv666%%fi@@	6Iv#677 	N44T[[&5Q5QRRHH//GV0L0LMMH$   6222r  c                    |                                   t          |          }d|i}d}| |                     |          }|d         |d<   d}|                     d||          \  }}|dk    rt	          | j        dz   |z   dz             |                     |dd	          }|                     |dd	g          }d}|r@|                     | 	                    ||                    }| 
                    |d
          }n)|                     | 	                    ||                    }|                     |          }	||	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>`
        r2   Nr  ro   r=   z# fetchOrder() is not supported for z markets yetr0  r  r   )r  strr  ra  r(   r2   r  r  privateGetSmartordersIdr  r  privateGetOrdersIdr  )
r  r2   r  r  r  r  rf  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 	M33DKK4P4PQQHx33HH..t{{7F/K/KLLH,   **dr  c                     |                                   |                     |d d |          }|                     |d          }||v rdndS )Nr2   rD  r  )r  r  r  )r  r2   r  r  r   indexeds         r  fetch_order_statuszpoloniex.fetch_order_status$	  sR    ''dFCC------vvh6r  c                     |                                   d|i}|                     |                     ||                    }|                     |          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>`
        r2   )r  privateGetOrdersIdTradesr  r  )r  r2   r  r  r,  r  r  r   s           r  fetch_order_tradeszpoloniex.fetch_order_trades*	  s[     	"
 ..t{{7F/K/KLL,   (((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   r4  uTimer   r4  detailsr   ccyavailtotalimusedbalancesr  	availablefreehold)r  r{  r  rZ  r  ry  r  r  r  accountsafe_balancer  )r  r  r  r.  rA  r  balance
currencyIdrw  rK  rG  r  
newAccounts                r  parse_balancezpoloniex.parse_balanceS	  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                 t   |                                   d}|                     dd|          \  }}|dk    rA|                     |          }|                     |di           }|                     |          S ddi}|                     |                     ||                    }|                     |          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  ra  swapPrivateGetV3AccountBalancerz  rP  privateGetAccountsBalancesr  )r  r  rf  r  r  r  r  s          r  fetch_balancezpoloniex.fetch_balancev	  s     	
!??PTV\]]
F==fEEKL >>+vr::D%%d+++6
 224;;w3O3OPP" !!(+++r  c                 (   |                                   |                     |          }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
        r   	makerRate	takerRateT)r  r  r   r   rJ  	tierBased)r  privateGetFeeinfory  r  r^  r  )r  r  r  r  r  r  s         r  fetch_trading_feeszpoloniex.fetch_trading_fees	  s     	))&11 q#dl++,, 		 		A\!_F  ))(K@@))(K@@"! F6NN r  c                    |                                   |                     |          }d|d         i}|(||d<   |d         r|                     g d|          |d<   |d         rm|                     |                     ||                    }|                     |di           }|                     |d          }|                     |||          S |                     |                     ||                    }	|                     |	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
        r  r2   Nr,  r  )r8   r   r   r      r  r.  timeasksbidsr   r   r   T)r  ra  r`  r   r4  nonce)r  r  find_nearest_ceilingswapPublicGetV3MarketOrderBookr  rz  r  parse_order_bookpublicGetMarketsSymbolOrderBookr  ry  r  r  sumr~  sort_byrZ  )r  r  r,  r  r  r  r  r  r.  r  r   r`  ra  
asksResult
bidsResultr  r  r  s                     r  fetch_order_bookzpoloniex.fetch_order_book	  s    	V$$fTl
 $GGj! [#'#<#<=R=R=RTY#Z#Z * 	;==dkk'SY>Z>Z[[K >>+vr::D""4..B((vr:::77GV8T8TUU %%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  rw  c                     |                                   |                     ||          \  }}}}|}|                     |                     ||                    }|                     |||          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>`
        )r  #prepare_request_for_deposit_addressprivatePostWalletsAddressr  parse_deposit_address_special)r  rw  r  r  extraParamsr  networkEntryr  s           r  create_deposit_addresszpoloniex.create_deposit_address*
  sv     	7;7_7_`dfl7m7m4h11$++gv2N2NOO 11(HlSSSr  c                 ~   |                                   |                     ||          \  }}}}|}|                     |                     ||                    }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>`
        r   z fetchDepositAddress() returned an empty response, you might need to try "createDepositAddress" at first and then use "fetchDepositAddress")
r  rm  privateGetWalletsAddressesr  r{  r|  r  r   r2   ro  )
r  rw  r  r  rp  r  rq  r  r|  lengths
             r  fetch_deposit_addresszpoloniex.fetch_deposit_address?
  s     	7;7_7_`dfl7m7m4h224;;w3O3OPP 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  rz  )r  rw  r  r  r  exchangeNetworkIdrq  r  s           r  rm  z,poloniex.prepare_request_for_deposit_addressX
  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  depositAddressrw  rt  )r  r  rt  r|  tag)r  check_address)r  r  r  rq  r|  r~  r}  s          r  ro  z&poloniex.parse_deposit_address_specialm
  s    ""8Y77?&&xd1CDDG7####!--l6.BDTUUN)( (''i@@
 
 	
r  fromAccount	toAccountc                    |                                   |                     |          }|                     | j        di           }|                     |||          }|                     |||          }	|                     ||          |d         ||	d}
|                     |                     |
|                    }|                     ||          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>`
        r  r2   )r  r  r  r  )	r  r  r  r   r  currency_to_precisionprivatePostAccountsTransferr  parse_transfer)r  rw  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>> !	
 
 33DKK4P4PQQ ""8X666r  r   r  c           
      j    ||                      |d          d d |                      |d          d d d d d	S )N
transferIdr2   )	r  r2   r   r4  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                 j   |                      ||          \  }}|                     |           |                     ||          \  }}}}	|}|                     ||          |d<   ||d<   |||d<   |                     |                     ||                    }
|
|	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  rm  r  privatePostWalletsWithdrawr  parse_transaction)r  rw  r  r|  r~  r  r  rp  r  rq  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 224;;w3O3OPP !$0
 
 %%&6AAAr  c                     |                                   d}|                                 }||                     |dz            n|d|z  z
  }||d}|                     |                     ||                    }	|	S )Ni r+  r   )startend)r  secondsparse_to_intprivateGetWalletsActivityr  )
r  rw  r  r,  r  yearnowr  r  r  s
             r  fetch_transactions_helperz"poloniex.fetch_transactions_helper
  s    llnn494E!!%$,///CRTW[R[O
 
 11$++gv2N2NOOP r  c                    |                                   |                     ||||          }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_limitrh  )r  rw  r  r,  r  r  r  r  r  withdrawalTransactionsdepositTransactionstransactionss               r  fetch_deposits_withdrawalsz#poloniex.fetch_deposits_withdrawals(  s     	11$ufMM!}}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                     |                      ||||          }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  rw  r  r,  r  r  r  r  r  s	            r  fetch_withdrawalszpoloniex.fetch_withdrawals@  s     11$ufMM!}}T**HoohrBB..{HeUSS22<ueTTTr  codesc                    |                                   |                     |                     |ddi                    }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>`
        ri  Tr   )	r  rx  r  ry  r  r{  r|  r  parse_deposit_withdraw_fees)	r  r  r  r  r  r  r  r   rN  s	            r  fetch_deposit_withdraw_feesz$poloniex.fetch_deposit_withdraw_feesT  s     	++DKKA^`d@e,f,fgg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   rk   rq  Fru  rJ  rr  r  )market_codesr{  r|  ry  r  r  r  r  parse_deposit_withdraw_feer  replacer  r  r  )r  r  r  currencyIdKeydepositWithdrawFeesresponseKeysr  rN  rw  feeInfor  rk  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  rw  rl  rq  Fr  r   rs  rr  r  )deposit_withdraw_feer  r  r  )	r  ru  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                     |                      ||||          }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  rw  r  r,  r  r  r  r  r  s	            r  fetch_depositszpoloniex.fetch_deposits  s     11$ufMM}}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
withdrawalrs  depositNumberr|  	paymentIDr  ru  r  r2   rt  	addressToaddressFromr~  tagTotagFromr  updatedr4  )r  r  r  )commentinternalru  )	safe_timestampr  r  r  rV  r-   
string_subr  rZ  )r  r  r  r   rN  rw  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                    |t          | j        dz             |                                  |                     |          }d}|                     d|          \  }}|t          | j        dz             d}|                     |dd          \  }}|rd|vrt          | j        dz             ||                                |d	         d
}|                     |                     ||                    }|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=  s#    >#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
 

 99$++gv:V:VWWr  c                 |   |                                   |                     |          }d|d         i}d}|                     d|          \  }}|t          | j        dz             |                                |d<   |                     |                     ||                    }|                     ||          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>`
        r  r2   Nrd   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'--//	99$++gv:V:VWW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  ry  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                     |                      |          }|                     |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
        r  posModeHEDGE)r  r#  )swapPrivateGetV3PositionModerz  r  )r  r  r  r  r  r  r#  s          r  fetch_position_modezpoloniex.fetch_position_mode  sb     44V<< ~~h33""433G#
 
 	
r  r#  c                 l    |rdnd}d|i}|                      |                     ||                    }|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  )swapPrivatePostV3PositionModer  )r  r#  r  r  moder  r  s          r  set_position_modezpoloniex.set_position_mode  sH     !/wwit
 55dkk'66R6RSS r  c                     |                                   |                     |          }|                     |          }|                     |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>`
        r  )r  r`  "swapPrivateGetV3TradePositionOpensr  parse_positions)r  r^  r  r  	positionss        r  fetch_positionszpoloniex.fetch_positions  sj     	%%g..::6BB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  rE  rM  	openAvgPxr  r2   notionalr  liquidationPriceliqPx
entryPriceunrealizedPnluplrJ  	contractsr
  rO  markPx	lastPricer  r  r#  r   r4  mmmgnRatioslTrgPxtpTrgPx)
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager$  marginRatior  r   )
r  rW  r  r  r-   rX  safe_positionr  rZ  int)r  r  r  r[  r   r  r$  r  r  rM  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                    |                                   |                     |          }|                     ||          }|d         t          j        |          |                                d}d|vrd|d<   |                     |                     ||                    }|dk    rt          j        |          }|                     |d          }| 	                    ||          S )Nr2   )r  rN  r  r  r  reducer  )
r  r  r  r-   
string_absr  $swapPrivatePostV3TradePositionMarginr  rz  parse_margin_modification)	r  r  r  r  r  r  r  r  r  s	            r  modify_margin_helperzpoloniex.modify_margin_helpere  s    V$$))&&99Tl%f--JJLL
 
 V##!'GI<<T[[RX=Y=YZZ 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  rN  r  )
r  r  r  r  r  rD  rw  r  r   r4  )r  rW  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                 4    |                      || d|          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  r  r  r  r  r  s       r  reduce_marginzpoloniex.reduce_margin  s      ((&(FKKKr  c                 2    |                      ||d|          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  r  r  s       r  
add_marginzpoloniex.add_margin  s     ((GGGr  c                 *    |                                  S r  )milliseconds)r  s    r  rb  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_credentialsr5  rb  jsonr  keysorthmacencodesecrethashlibsha256apiKey)r  pathr   r1  r  r3  r2  r0  queryimplodedPathr   authsortedQueryr/  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  reasonr0  r1  r3  r2  c
                 F   |d S |                      |d          }
|
|
dk    r~|d         }|                      |d          }| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nrw  200messager  r  r  )r  r2   throw_exactly_matched_exceptionr=  throw_broadly_matched_exceptionr   )r  rw  rG  r0  r1  r3  r2  r  requestHeadersrequestBodyresponseCode	codeInnerrJ  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  r5  r   r   r  r  r  r  r  dictr  r  r  r+  r   r]  r   r   rg  r   r  r  r   r  r  r   r  r  r   r  r  r  r  r	  r   r   floatr   r  r  r)  r.  r3  r8  r;  r>  r   rP  rV  r   r\  r   rk  r
   rr  rv  rm  ro  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!  rb  rF  rR  __classcell__)r  s   @r  r/   r/      s       d# d d d d d dL7
 7
 7
4 7
 7
 7
 7
r 9=4^bkm NL NL# NL# NLS NLX[ NLrvw{r| NL NL NL NL` #(       $& 9 9$v, 9 9 9 9 )+ + +tF| + + + +6 )+ *+ *+tF| *+ *+ *+ *+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\ 04B N5 N5W N57 N5 N5 N5 N5` ') S SZ S S S Sj 02 *3 *33 *3f *3 *3 *3 *3XB B Bv B B B B BH 6:UW 4? 4?3 4?s 4?# 4?\`af\g 4? 4? 4? 4?l -1tRV_a a ac a aC a a a aF
: 
: 
: 
: 
:e e ev e e e e eN: : :
 
 
 /3TXac cL cL cL3 cLc cLhlmrhs cL cL cL cLJ 154VZce F= F=# F=S F=PS F=jnotju F= F= F= F=P gksu -2 -23 -2i -2y -2RW -2`c -2 -2 -2 -2^ HLTV >! >! >! >!@ `drv  @B *2 *2S *2# *2Y *2i *2Y\ *2lo *2 *2 *2 *2X 37r 5* 5*s 5*C 5* 5* 5* 5*n /32 D3 D3 D3 D3 D3 D3L 26b 9 9c 93 9 9 9 9v 9=R 7 7S 7# 7 7 7 7 9=4^bkm ') ')S ')# ')S ')X[ ') ') ') ')R!) !) !) !) !)F $& J, J,( J, J, J, J,X )+  {    @ :>b F
 F
s F
3 F
Y F
 F
 F
 F
P 8: T T3 Tn T T T T* 79 T T# T^ T T T T2 MO 9 9 9T 9SV 9 9 9 9*
Q_ 
 
 
 
& [] 7 7S 7% 7c 7c 7an 7 7 7 7@
 
t 
x 
= 
 
 
 
$ KOWY !B !BS !B% !B# !BC !B^i !B !B !B !BF 59tZ^gi Q Qc Q QTW Q Q Q Qf 6:[_hj p ps p# pUX post  pA p p p p0 -1tRV_a U Uc U UC Ufjkvfw U U U U( <@ )= )= )= )= )= )=V5# 5# 5# 5#n" " " " " ", *.Dt\^ U U3 Uc U Ucghsct U U U U(:s : : : :N
 N
T N
X N
Q\ N
 N
 N
 N
` 9=R  S #    B 24 :5 :5S :5 :5 :5 :5 :5x
 
t 
V 
x 
 
 
 
6 15R 
 
# 
 
 
 
8 =A   c    2 26b 28 28w 28T(^ 28 28 28 28hE Et EV E E E EN FH < <3 <L^ < < < <>
 
d 
F 
N` 
 
 
 
$ @B L LC L LFX L L L L =? H H He HCU H H H H# # # &eBSW %P %P %P %PN# s  c TX `c        r  r/   )4ccxt.base.exchanger   ccxt.abstract.poloniexr   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>rb     s   ( ' ' ' ' ' . . . . . .  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  