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

 YC
 YC
 4YC
  FFF $F 	F
 $F %F TF "4F tF F 'F /F ,UF 0F tF  !F" "4#F$ %d%F& T'F( )F* #E+F, $T-F. "4/F0 &t1F2 (3F4 1%5F6  7F8 +D9F: *:;F< +D=F> &u?F@ 'AFB (CFD #EEFF *5GFH $TIFJ tKFL  MFN $TOFP "5QFR SFT  UFV dWFX +EYFZ !%[F\ "4]F^ d_F` !$aFb "5cFd #DeFf  gFh $TiFj !$kFl tmFn oFp TqFr tsFt "5uFv #DwFx $ZyFz  {F| !%}F~ #DF@ AFB 4CFD tEFF "4GFH DIFJ DKFYC
^   """ _YC
~ }66
 H 2<3DYC
Z  !2*A %b 0	
 ( 3B $Q ( 1! ,Q 5a ? 5a 3A 22  ,R!" 5b#$ 34=>34)2"A+Q 1! ,R	
 ,R 1! "2 4Q &q / 4Q / 4Q ,R 7  +B!" /#$ 01*+"$'(34'),-*,/1"$./9> ./02+-,./1"#(*-.'(
 ().0"$,-35') (*,.e6p  2E 0 .u	
 ,R ;B =b :2 +E 5e ,U .u / 9% 0  1%!" .u#$ .u%0 /0,.021324355713,.
 +,+--/0302,.46 +,02.0+ MA[YC
^ $!..x8!..x8	 _YC
p  $!y$!$! }$! (	$!
 |$! y$! w$! 5$! $! $! y$! )$! y$! .$! *$!  ~!$!" #$!$ #! ""!G$!qYC
z %59""# #)#)$'#&#'$'$'$*#&#&$' $ #'#
 !''!;!{YC
~	 #&*(,,0,1).+06:#'#'"&#(	( #($)+/27/3$)#()$. r% ',!%$*%+*/& ',#($)*/	# ',!%#($)*/( $()-#c4l y  )&*(-"&#'+0$ r%  ( ',!$$(,1%)#($)*/	* "%%'&3!@ "> "> 	 "> "> 	g	YC
N YOYC
P l/l >l :	l
 =l ,l Zl 0l 0l ]l 0l 0l Zl Zl  ]!l" Z#l$ -%l& ]'l( .)l* m+l, j-l. j/l0 j1l2 j3l4 /5l6 j7l8 m9l< Z=l> Y?l@ ]AlB YClD YElF ]GlH \IlJ \KlL \MlN -OlP YQlR -SlT -UlV ]WlX \YlZ Z[l\ 1]l` ]alb ]cld ]elf ]glh ]ilj \kll \mln \olp \qlr \slt \ulv \wlx \ylz \{l| \}l~ \l@ ZAlB \ClD \ElF \GlH \IlJ \KlL \MlN \OlP \QlR \SlT \UlV \WlX \YlZ \[l\ ]]l^ Z_l` .alb Ycld \elf \glh \ilj \kll \mlp \qlr \slt \ulv ]wlx \ylz ]{l| \}l~ \l@ \AlB ]ClD -ElF \GlH ]IlJ ]KlL ]MlN ]OlP ]QlR ]SlT ZUlV YWlZ]pQYC
 Y Y	    Nmarketc           	         t        |      }|dk(  }|rh| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )	N	      r   r   r      r8      )lensafe_integersafe_number)r  ohlcvr  ohlcvLength
isContracts        r  parse_ohlcvzpoloniex.parse_ohlcv;  s    J %j A%
!!%+  *  *  *  *  *  eR(UA&UA&UA&UA&UA&
 	
r  r   symbolsincer&  c           	         | j                          d}| j                  |ddd      \  }}|r| j                  d|||||d      S | j                  |      }|d   | j	                  | j
                  ||      d}|d   rdnd	}	|d   rd
nd}
||||	<   |||d<   | j                  |
||      \  }}|d   r| j                  |ddg      r't        | j                  dz   |z   dz   |d   z   dz         | j                  | j                  ||            }| j                  |d      }| j                  |||||      S | j                  | j                  ||            }| j                  |||||      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
        Frg   paginater,  r2   )r  intervalr=   	startTimesTimeendTimeeTimer&  contractr   r    typez fetchOHLCV is not supporteddata)load_marketshandle_option_and_params"fetch_paginated_call_deterministicr  safe_stringr   handle_until_optionin_arrayr(   r2   swapPublicGetV3MarketCandlesextend	safe_listparse_ohlcvspublicGetMarketsSymbolCandles)r  r  	timeframer  r&  paramsr  r  requestkeyStartkeyEndresponseRawr  responses                 r  fetch_ohlcvzpoloniex.fetch_ohlcvt  s     	88z[`a&::<QVX]_hjpruvvV$Tl(()YO
 #).;g$Vn' %GH$GG2267FK*}}Y6"477S=9#<s#BVF^#SVt#tuu;;DKKQW<XYK$ >>+v6D$$T69eUKK55dkk'66RS*   69eUKKr  Fc                     t         t        |   ||      }| j                  | j                  d      }||r)| j                  | 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  sX    $4VVD $>U V!)f48MM$//S^4_DLL01r  c                 z    | j                  |      | j                  |      g}|}| j                  |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  sD     ++F3T5L5LV5TU  WQZ88r  c                 F    | j                  |      }| j                  |      S N)publicGetMarketsparse_markets)r  r  r   s      r  r  zpoloniex.fetch_spot_markets  s%    ''/0 !!'**r  c                 j    | j                  |      }| j                  |d      }| j                  |      S )Nr  )#swapPublicGetV3MarketAllInstrumentsr  r  )r  r  r  r   s       r  r  zpoloniex.fetch_swap_markets  s6    ;;FCN ..62!!'**r  c                 N    d|v r| j                  |      S | j                  |      S )NctType)parse_swap_marketparse_spot_market)r  r  s     r  parse_marketzpoloniex.parse_market   s,    v))&11))&11r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }|dk(  }| j                  |d      }	i d|d|dz   |z   d	|d
|dd d|d|dd ddddddddddddd|dddd d d d d d d | j                  | j	                  | j                  |	d                  | j                  | j	                  | j                  |	d                  d| j                  |	d      d dd d d| j                  |	d      d dd | j                  |d!      |d"
S )#Nr  baseCurrencyNamequoteCurrencyNamestateNORMALsymbolTradeLimitr2   /basequotesettlebaseIdquoteIdsettleIdr  r=   Tr>   Fr?   r@   rA   activer  r4  quantityScale
priceScaleamountpriceminQuantityr   r$  	minAmount)r  r  r   tradableStartTime)
r5  contractSizeexpiryexpiryDatetimestrike
optionType	precisionr  createdinfo)r  safe_currency_coder  r  parse_precisionr  r  )
r  r  r2   r  r  r  r  r  r  r  s
             r  r  zpoloniex.parse_spot_market&  s0   fh/!!&*<=""6+>?&&v.''0  1("??63EF,
",
dSj5(,
 D,
 U	,

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

 f2
 f2
 w2
 2
 !1H2
 E2
 e2
 DFN2
 dh&2
 e2
 f2
  !2
" f#2
$ "z ,,VW="%%ff5%%ff5**67;))&%8  ++FG<++FMB
  ++FG<++FG<
  
  ++FJ?$ ((9c2
 2	
r  c                 H    | j                  |      }| j                  |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  <88r  tickerc           
         | j                  |dd      }| j                  |dd      }| j                  |      }| j                  |dd      }t        j                  |d      }| j                  i d|d|d   d	|d
| j                  |      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |dd      dd d| j                  |dd      d| j                  |dd      dd dd d |d!d | j                  |d"d#      | j                  |d$d%      | j                  |d&d'      | j                  |d(      |d)|      S )*NtscTr  sdailyChangedc100r2   r   datetimehighhlowlbidbPx	bidVolumebidQuantitybSzaskaPx	askVolumeaskQuantityaSzvwapopenoclosecpreviousClosechange
percentageaveragequantityqtyr  amt	markPricemPxiPx)
baseVolumequoteVolumerI  
indexPricer  )safe_integer_2safe_string_2safe_marketr-   
string_mulsafe_tickeriso8601r  )r  r&  r  r   marketIdrelativeChangerD  s          r  parse_tickerzpoloniex.parse_ticker  s   ` ''d;	%%fh<!!(+++FM4H''>
 !
(!
fX&!
 !
 Y/	!

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

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

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTFr   r   r2   r  rs   r?   r  )
r  market_symbolsr  r  handle_market_type_and_paramsswapPublicGetV3MarketTickersr  r  parse_tickerspublicGetMarketsTicker24h)
r  rX  r  r  r  symbolsLength
marketTyper  r  r  s
             r  fetch_tickerszpoloniex.fetch_tickers#  s     	))'4tUKGLMq WQZ0 A%(.tGH%
!??PVX^_
F;;DKKQW<XYK6 >>+v6D%%dG4411&92 !!(G44r  c                    | j                  | j                  |ddi            }i }t        dt        |            D ]  }| j	                  ||      }t        |j                               }| j	                  |d      }| j	                  ||      }| j                  |      }	| j                  |d      }
| j                  |d      }d}|| j                  ||	      }| j	                  |d      }| j                  |d      d	k(  }| j                  |d
      d	k(  }| j                  |d      d	k(  }| xr
 |xr |xr |}| j                  |d      }| j                  |d      }| j	                  |d      }|du }| j	                  ||	      -||	d|
|||| j                  |      ddddddddddddd||	<   | j                  ||	   d      }|||nt        j                  ||      }| j	                  ||	   d      }|r|n|}| j	                  ||	   d      }|r|n|}| j	                  ||	   di       }|-||||||||| j                  |      dddddddddddd||<   |||	   d<   | j	                  ||	   dg       }i }|||<   |j                  |       |||	   d<   |r|||	   d<   |
||	   d<   |xr |||	   d<   |||	   d<   |||	   d<   | j                  |      ||	   d<    |S )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   r3   
blockchainNdelistedwalletStateENABLEDwalletDepositStatewalletWithdrawalStater2   withdrawalFeeparentChaincryptor  )r  depositr   )r2   coder  r3   r  rm  r   feer	  r  r  ro  rm  r   r  )r  r   rm  )r  r2   network
currencyIdr  rm  r   r  ro  r	  r  r  r  )publicGetCurrenciesr  ranger  r  listkeysr  r  network_id_to_coder  r  r-   
string_minappend)r  r  r  resultiitemidsr2   currencyrn  r3   	networkIdnetworkCodere  walletEnableddepositEnabledwithdrawEnabledr  r  	feeStringrk  noParentChainminFeeStringdepositAvailablewithdrawAvailabler  r  rawInfos                               r  fetch_currencieszpoloniex.fetch_currenciess  s    ++DKKA^`d@e,fg4 q#h-( ^	BA??8Q/Dtyy{#Ca(BtR0H**2.D##Hf5D((<@IK$"55iFx<H ,,X}ERM!--h8LMQZZN"..x9PQU^^O!\ZmZZ?F))(D9I((?CI//(MBK'4/Mvt,4   $- /,,Y7!%$ $(#'#
 $(#'$
 $(#'% t4  ++F4L%@L$-9-AyHZHZ[dfrHs#vd|YG2@~GW $tj I4CJ[vd|ZDH&$#*"$!*- /$,,Y7!% $(#'#
 $(#'%
 $(#'$)%4 (0F4L$??6$<<DG"GBKKK #'F4L %'tT"'+tV$%5%K:KF4L"&6F4L#'8F4L$"&"3"3L"AF4L}^	B~ r  c                    | j                          | j                  |      }d|d   i}|d   r(| j                  |d   g|      }| j                  ||      S | j	                  | j                  ||            }| j                  ||      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  ra  	safe_dictpublicGetMarketsSymbolTicker24hr  rW  )r  r  r  r  r  tickersr  s          r  fetch_tickerzpoloniex.fetch_ticker  s     	V$fTl
 *((&*:);VDG>>'62277GV8TU.   622r  tradec                    | j                  |g d      }| j                  |dd      }| j                  |g d      }| j                  |d      }| j	                  ||d      }|d   }| j                  |dd      }d }	| j                  |d	d
      }
| j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |dd      }|| j                  |      }||d}	| j                  |||| j                  |      ||| j                  |dd      || j                  |dd      |
|||	d|      S )N)r2   tradeIDtrdIdorderIdordId)r(  
createTimer)  cTimer  _side	takerSider  pxrF  rG  r  rH  feeCurrencyfeeCcy	feeAmountfeeAmt)r   r}  ordTyper  	matchRolerole)r2   r  r   r.  r  orderr  r  takerOrMakerr  r  r   ro  )	safe_string_nrP  safe_integer_nr  rQ  safe_string_lower_2r  
safe_traderT  )r  r  r  r2   r  r   rU  r  r  ro  priceStringamountString
costStringfeeCurrencyIdfeeCostStringfeeCurrencyCodes                   r  parse_tradezpoloniex.parse_trade$  sz   B 'AB$$UIw?''/RS	##E84!!(FC8!''v{C((>))%UC''x?
**5-J**5+xH$"55mDO%+C "Y/,,UIvF 44UKP " 
  	r  c                 b   | j                          | j                  |      }d|d   i}|||d<   |d   rG| j                  | j                  ||            }| j	                  |d      }| j                  ||||      S | j                  | j                  ||            }	| j                  |	|||      S )aw  
        get the list of most recent trades for a particular symbol

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

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r2   r&  r  r  )r  r  swapPublicGetV3MarketTradesr  r  parse_tradespublicGetMarketsSymbolTrades)
r  r  r  r&  r  r  r  r  
tradesListr   s
             r  fetch_tradeszpoloniex.fetch_trades  s     	V$fTl
 $GG*77GV8TUH &9J$$ZFF224;;w3OP   >>r  c                 ~   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S d}|| j                  |      }d}| j	                  d||      \  }}| j                  |ddg      }i }	|rdnd}
|rd	nd
}|||	|
<   |||	d<   |r
||d   |	d<   | j                  ||	|      \  }	}|rG| j                  | j                  |	|            }| j                  |d      }| j                  ||||      S | j                  | j                  |	|            }| j                  ||||      }|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>`
        Frf   r  Nr?   r@   r  r  r  r  r&  r2   r  r  )r  r  fetch_paginated_call_dynamicr  r[  r  r   swapPrivateGetV3TradeOrderTradesr  r  r  privateGetTrades)r  r  r  r&  r  r  r  r`  r  r  startKeyendKeyrawr  r  ry  s                   r  fetch_my_tradeszpoloniex.fetch_my_trades  s    	88R\]&44_feUZ\bcc[[(F
!??QWY_`
F]]:/AB

 )7k&I %GH$GG&, &tGH2267FK77GV8TUC@ >>#v.D$$T65%@@((Wf)EF, ""8VUEBr  r  c                 <    dddddddd}| j                  |||      S )Nr>  closedcanceled)NEWPARTIALLY_FILLEDFILLEDPENDING_CANCELPARTIALLY_CANCELEDCANCELEDFAILEDr  r  r  statusess      r  parse_order_statuszpoloniex.parse_order_statusA  s5     &("," 
 &&99r  r  c                    | j                  |g d      }|!| j                  | j                  |d            }| j                  |d      }| j                  ||d      }|d   }| j	                  |d      }|3t        |t              s#| j	                  || j                  |d|            }| j                  |g d      }| j                  |dd	      }| j                  |d
d      }	| j                  | j                  |d            }
| j                  |d      }| j                  |d      }| j                  |      }| j                  |g d      }d }| j                  |dd      }d }d }| j                  |d      }||dk(  r|d   n|d   }n$| j                  |      }| j                  |dd      }||||d}| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      dk7  }| j                  i d |d|d|d!|d"| j!                  |      d#| j                  |d$      d%|
d|d|d&| j                  |d&      d'|d(k(  d|d)|d*| j                  |d*d+      d,| j                  |d-      d.| j                  |d/d0      d1||	d ||||||d2|      S )3N)r   r  r  dater  r  resultingTradesr2   )r  rater  rF  szfilledQuantityexecQtyr  r  r  )orderNumberr2   r  r  tokenFeeCurrencyr  ro  buyr  r  tokenFeer  )r  r   r}  clientOrderIdclOrdIdmgnMode
reduceOnlyleverposSideBOTHr  r   r.  lastTradeTimestamp
updateTimer  r  postOnlyLIMIT_MAKERr  r  	stopPricer   execAmtrE  avgPriceavgPxr  )filled	remainingr   ro  r  r  r  r  )r  	parse8601r  rQ  r  
isinstancert  r  rP  r  safe_string_lowerparse_order_typer  	safe_boolr  
safe_orderrT  )r  r  r  r   rU  r  r  r  r  r  r  r  rawTyper  r2   ro  r  feeCostr  r  r  r  r  r  r  s                            r  parse_orderzpoloniex.parse_orderM  s   F ''/ST	t'7'7v'FGI##E84!!(FC8!//%1BC&ot4"&///4CSCSTZ\`bjCk"l""5*AB##E:t<##E+;YG(()9)9%)IJ%%eV4""5&1$$W-'PQ((0BHM#u-15fVnVG_O #55kBO((
HEG+C
 **5/9M++E9=
^^E<8
$$UG4!!%3v=  
E 
" 
 ] 
 	 

 Y/ 
 !$"3"3E<"H 
 f 
 f 
 D 
 4++E=A 
 =0 
 D 
 U 
 D..unkR 
 D$$UI6 
  t))%WE! 
" f# 
$ %$$ 3 
4 5 	r  c                 8    dddddd}| j                  |||      S )Nr  r&  )MARKETLIMITr  z
STOP-LIMITzSTOP-MARKETr  r  s      r  r  zpoloniex.parse_order_type  s/    "!#
 &&99r  c           	          t        dt        |            D ]E  }||   }| j                  |dd|d   |d   d      }|j                  | j	                  ||             G |S )Nr   r>  r&  r  r  )r  r  r  r  )rs  r  r  rx  r  )r  r   r  ry  rz  r  extendeds          r  parse_open_orderszpoloniex.parse_open_orders  sp    q#f+& 	>A1IE{{5 fv	+ H MM$**8V<=	> r  c                 >   | j                          d}i }|| j                  |      }|d   |d<   d}| j                  d||      \  }}||dk(  rdnd} |||      |d<   | j                  |d	d
      }	| j	                  |d	d
g      }d}
|dk7  r4| j                  | j                  ||            }| j                  |d      }
nE|	r"| j                  | j                  ||            }
n!| j                  | j                  ||            }
ddi}| j                  |
||||      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  rj   r=   r+  r   r&  r*  stopr  r  r>  )r  r  r[  safe_value_2omitswapPrivateGetV3TradeOrderOpensr  r  privateGetSmartordersprivateGetOrdersparse_orders)r  r  r  r&  r  r  r  r`  r$  	isTriggerr  r  	extensions                r  fetch_open_orderszpoloniex.fetch_open_orders
  sC    	[[(F &tGH
!??@QSY[ab
F%/$cC"5#GG%%fi@	6Iv#6766t{{7F7STCP ~~c62H11$++gv2NOH,,T[[&-IJH0 $V,	  65%KKr  c                    | j                          d}i }|| j                  |      }|d   |d<   d}| j                  d||d      \  }}|dk(  rt        | j                  dz         |t        d|      |d	<   |||d
<   | j                  d||      \  }}| j                  | j                  ||            }| j                  |dg       }	| j                  |	|||      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  rQ   r?   r=   z: fetchClosedOrders() is not supported for spot markets yet   r&  r  r  r  )r  r  r[  r(   r2   r   r  !swapPrivateGetV3TradeOrderHistoryr  r  r  )
r  r  r  r&  r  r  r  r`  r  r  s
             r  fetch_closed_orderszpoloniex.fetch_closed_orderso  s    	[[(F &tGH
!??@SU[]cekl
Ftww)eeff"3GG$GG227GVL99$++gv:VWR ~~h3  vue<<r  r  r  r  r  c           	         | j                          | j                  |      }|d   |j                         d}| j                  |dd      }	| j	                  |||||||      \  }}d}
|d   s|d   r4| j                  | j                  ||            }| j                  |d      }
nE|	"| j                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
|      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  r  privatePostSmartordersprivatePostOrdersr  )r  r  r  r  r  r  r  r  r  r  r  responseInitials               r  create_orderzpoloniex.create_order  s    " 	V$TlJJL
 ))&+~N,,VT4RWY_`&>VH-">>t{{7TZ?[\O ~~ov>H%224;;w3OPH--dkk'6.JKH &11r  c                 T   | j                  |dd      }| j                  |      }	|	d   rd }
| j                  |d      \  }
}|
)| j                  d|
dddg       |
j	                         |d<   d }| j                  |d	      \  }}|r6|
t        | j                  d
z         d|vrt        | j                  dz         |j	                         }|dk(  }| j                  ||dk(  |      }| j                  |g d      }|2|	d   s!t        | j                  dz   |	d   z   dz         |dnd}||d<   n|rd}||d<   |r|dk(  rd }d}| j                  |ddd      \  }}| j                  |d      }| j                  |d      }|| j                  ||      }n~|rj|	d   re|t        | j                  dz         | j                  |      }| j                  |      }t        j                  ||      }| j                  ||      }n| j                  ||      }|	d   rdnd}|||<   n[|	d   rdnd}| j!                  ||      ||<   n<|	d   rdnd}| j!                  ||      ||<   |	d   rdnd}| j#                  ||      ||<   | j%                  |d       }|||d <   | j                  |d       }||gS )!Nr  r  r  r  rJ   crossisolatedr  r  zV createOrder() requires a marginMode parameter "cross" or "isolated" for hedged ordersr  zO createOrder() requires a posSide parameter "LONG" or "SHORT" for hedged ordersr  r  )r  r  r  r=   z3 createOrder() does not support trigger orders for r  z marketsSTOP
STOP_LIMITr  Tr  r   a	   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentr  r  rF  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-   rR  amount_to_precisionprice_to_precisionr  )r  r  r  r  r  r  r  r  r  r  r  r  upperCaseTypeisMarket
isPostOnlyquoteAmountr  r   r  r  costRequest	amountKeypriceKeyr  s                           r  r  zpoloniex.order_request  sP   ))&+~NV$*J!%!9!9&,!OJ%,,]JW^`jVkl%/%5%5%7	"F!55fhGNFF%+DGG  7O  -O  P  P!V++DGG  7H  -H  I  I

 H,&&x-1OQWX
6#LM#&>"477-b#beklres#s  wA  $A  B  B',}F<M#/GK )M'u}"481<@<Y<YZ`bo  rU  W[  =\916''7662#"&"8"8"FK66&>}*477  6A  ,A  B  B'+'<'<V'D&*&;&;E&B&-&8&8{&S&*&<&<V[&Q"&"8"8"HK(.vHD	%0	"*0.Jd	%)%=%=ff%M	"&,Vn
$I!%!9!9&&!IGI"(.wdH $ 7 7 FGH((A$'4GO$YYv7F  r  r2   c           	         | j                          | j                  |      }|d   s!t        | j                  dz   |d   z   dz         d|i}	| j	                  |dd      }
| j                  |||||	||      \  }	}d}|
"| j                  | j                  |	|            }n!| j                  | j                  |	|            }| j                  |||d	      }| j                  ||      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&  s   " 	V$f~tww)IIFSYNZ  ^F   F  G  G"
 ))&+~N,,VT4RWY_`#33DKK4PQH..t{{7F/KLH ;;x*
  &11r  c                 X   | j                          |t        | j                  dz         | j                  |      }i }|d   sO|d   |d<   ||d<   | j	                  | j                  ||            }| j                  | j                  |d            S | j                  |d      }||}||d<   | j                  |dd	      }| j                  |g d
      }d }	|r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	      S )Nz) cancelOrder() requires a symbol argumentr=   r2   r  r  r  r  r*  r  )r  r*  r  )r  r"   r2   r  swapPrivateDeleteV3TradeOrderr  r  r  r  r  r  privateDeleteSmartordersIdprivateDeleteOrdersId)
r  r2   r  r  r  r  r  r  r  r  s
             r  cancel_orderzpoloniex.cancel_orderR  s/    	>#DGG.Y$YZZV$f~ &tGH!GG44T[[&5QRC ##DNN3$?@@@$B%%fi@	6#GH66t{{7F7STH11$++gv2NOH ))r  c                 4   | j                          dg i}d}|| j                  |      }|d   g|d<   d}d}| j                  d||      \  }}|dk(  s|dk(  rE| j                  | j	                  ||            }| j                  |d      }| j                  ||      S | j                  |dd	      }| j                  |dd	g      }|r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  ||      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>`
        rX  Nr2   rC   r?   r@   r  r*  r  )r  r  r[  !swapPrivateDeleteV3TradeAllOrdersr  r  r  r  r  privateDeleteSmartordersprivateDeleteOrders)	r  r  r  r  r  r  r`  r  r  s	            r  cancel_all_orderszpoloniex.cancel_all_orders  s:    	 r
 [[(Ft"GI 
!??@QSY[ab
F:#988Wf9UVC ~~c62H$$Xv66%%fi@	6Iv#6744T[[&5QRH//GV0LMH$   622r  c                     | j                          t        |      }d|i}d}|| j                  |      }|d   |d<   d}| j                  d||      \  }}|dk7  rt	        | j
                  dz   |z   dz         | j                  |dd	      }| j                  |dd	g      }d}|r4| j                  | j                  ||            }| j                  |d
      }n!| j                  | j                  ||            }| j                  |      }	||	d<   |	S )a4  
        fetch an order by it's id

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

        :param str id: order id
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching a trigger order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r2   Nr  rk   r=   z# fetchOrder() is not supported for z markets yetr*  r  r   )r  strr  r[  r(   r2   r  r  privateGetSmartordersIdr  r  privateGetOrdersIdr  )
r  r2   r  r  r  r  r`  r  r  r  s
             r  fetch_orderzpoloniex.fetch_order  s-    	W"
 [[(F &tGH
!??fV\]
Ftww)NNQ[[^llmm%%fi@	6Iv#6733DKK4PQHx3H..t{{7F/KLH,   *dr  c                 ~    | j                          | j                  |d d |      }| j                  |d      }||v rdS dS )Nr2   r>  r  )r  r   r  )r  r2   r  r  r   indexeds         r  fetch_order_statuszpoloniex.fetch_order_status
	  sE    ''dFC----v6h6r  c                     | j                          d|i}| j                  | j                  ||            }| j                  |      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	  sL     	"
 ..t{{7F/KL,   ((r  c                    |d d d}t        |t              s| j                  |d      }||d<   | j                  |      |d<   | j	                  |dg       }t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }	| j                  |d      |	d	<   | j                  |d
      |	d<   |	||<   k | j                  |      S t        dt        |            D ]  }| j                  ||i       }	| j                  |	d      }
t        dt        |
            D ]v  }| j                  |
|      }| j                  |d      }| j                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   x  | j                  |      S )N)r  r   r.  uTimer   r.  detailsr   ccyavailtotalimusedbalancesr}  	availablefreehold)r  rt  r  rT  r  rs  r  r  r  accountsafe_balancer  )r  r  ry  r(  r<  rz  balancerq  rn  rF  rB  j
newAccounts                r  parse_balancezpoloniex.parse_balance9	  s   
 (D)""8W5B"$F;!%b!1F:nnXy"=G1c'l+ '!!*!--gu=
..z:,,.#'#3#3GW#E "&"2"27D"A&t' $$V,,q#h-( 
	*Aooh26Gw
;H1c(m, *//(A6!--gzB
..z:!\\^
%)%5%5g{%K
6"%)%5%5gv%F
6")t*
	*   ((r  c                 2   | j                          d}| j                  dd|      \  }}|dk7  r5| j                  |      }| j                  |di       }| j	                  |      S ddi}| j                  | j                  ||            }| j	                  |      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>`
        NrO   r=   r  accountTypeSPOT)r  r[  swapPrivateGetV3AccountBalancer  rK  privateGetAccountsBalancesr  )r  r  r`  r  r  r  r  s          r  fetch_balancezpoloniex.fetch_balance\	  s     	
!??PTV\]
F==fEKL >>+vr:D%%d++6
 224;;w3OP" !!(++r  c                 
   | j                          | j                  |      }i }t        dt        | j                              D ]=  }| j                  |   }||| j                  |d      | j                  |d      ddd||<   ? |S )aZ  
        fetch the trading fees for multiple markets

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        r   	makerRate	takerRateT)r  r  r   r   rD  	tierBased)r  privateGetFeeinfors  r  rX  r  )r  r  r  ry  rz  r  s         r  fetch_trading_feeszpoloniex.fetch_trading_fees	  s     	))&1 q#dll+, 		A\\!_F  ))(K@))(K@"!F6N		 r  c                 *   | j                          | j                  |      }d|d   i}|!||d<   |d   r| j                  g d|      |d<   |d   rY| j                  | j	                  ||            }| j                  |di       }| j                  |d      }| j                  |||      S | j                  | j	                  ||            }	| j                  |	d	      }
| j                  |	d
      }| j                  |	d      }g }g }t        dt        |            D ]R  }|dz  dk  s| j                  ||      }| j                  || j                  |d            }|j                  ||g       T t        dt        |            D ]R  }|dz  dk  s| j                  ||      }| j                  || j                  |d            }|j                  ||g       T |d   | j                  |dd      | j                  |d      |
| j!                  |
      ddS )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  r\  r[  r   r.  nonce)r  r  find_nearest_ceilingswapPublicGetV3MarketOrderBookr  r  r  parse_order_bookpublicGetMarketsSymbolOrderBookr  rs  r  r  sumrx  sort_byrT  )r  r  r&  r  r  r  r  r  r(  r  r   r[  r\  
asksResult
bidsResultrz  r  r  s                     r  fetch_order_bookzpoloniex.fetch_order_book	  s)    	V$fTl
 $GGj!#'#<#<=RTY#Z *==dkk'SY>Z[K >>+vr:D""4.B((vr::77GV8TU %%h7	x0x0

q#d)$ 	3AA{((q1))$A?!!5&/2		3
 q#d)$ 	3AA{((q1))$A?!!5&/2		3 X&LLQ5LLQ/"Y/
 	
r  rn  c                 8   | j                          | j                  |      }d|d   i}| j                  | j                  di       }| j	                  |d      }| j                  |||      }||d   |z   |d<   | j                  |d      }n&|d   dk(  rt        | j                  dz   |z   dz         | j                  | j                  ||            }| j                  |d	      }d}	| j                  |       || j                  |d
   d      }
|
|}	|
}|||	||d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}  r2   r  rp  Nr   z7 createDepositAddress requires a network parameter for .addressr  depositAddress)r}  ri  tagrp  r  )r  r}  r  r   safe_string_upperr  r  r"   r2   privatePostWalletsAddressr  check_addressr  rn  r  r}  r  r  rp  r  ri  rk  rj  s              r  create_deposit_addresszpoloniex.create_deposit_address
  sL    	==&
 ??4<<R@((;""8Wg>")*"5"?GJYYvy1F~''2k(knr(rux(xyy11$++gv2NO ""8Y77#!--hv.>@PQN)(
 	
r  c                 >   | j                          | j                  |      }d|d   i}| j                  | j                  di       }| j	                  |d      }| j                  |||      }||d   |z   |d<   | j                  |d      }n&|d   dk(  rt        | j                  dz   |z   dz         | j                  | j                  ||            }| j                  ||d         }d}	| j                  |       || j                  |d	   d
      }
|
|}	|
}|||||	d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}  r2   r  rp  Nr   z6 fetchDepositAddress requires a network parameter for rh  r  rj  )r  r}  rp  ri  rk  )r  r}  r  r   rl  r  r  r"   r2   privateGetWalletsAddressesr  rn  ro  s              r  fetch_deposit_addresszpoloniex.fetch_deposit_address>
  sQ    	==&
 ??4<<R@((;""8Wg>")*"5"?GJYYvy1F~''2j(jmq(qtw(wxx224;;w3OP ""8WZ-@A7#!--hv.>@PQN)(
 	
r  fromAccount	toAccountc                 d   | j                          | j                  |      }| j                  | j                  di       }| j	                  |||      }| j	                  |||      }	| j                  ||      |d   ||	d}
| j                  | j                  |
|            }| j                  ||      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}  rt  ru  )	r  r}  r  r   r  currency_to_precisionprivatePostAccountsTransferr  parse_transfer)r  rn  r  rt  ru  r  r}  r  fromIdtoIdr  r  s               r  r   zpoloniex.transferl
  s     	==&7GL!!.+{K	;G00v> !	
 33DKK4PQ ""8X66r  r   r}  c           
      Z    || j                  |d      d d | j                  |d      d d d d d	S )N
transferIdr2   )	r  r2   r   r.  r}  r  rt  ru  r  r  )r  r   r}  s      r  ry  zpoloniex.parse_transfer
  sC     ""8\:((48

 
	
r  ri  c                    | j                  ||      \  }}| j                  |       | j                          | j                  |      }|d   ||d}|||d<   | j	                  | j
                  di       }| j                  |d      }	| j                  ||	|	      }	|	|d   |	z   |d<   | j                  |d      }| j                  | j                  ||            }
| j                  |
|      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>`
        r2   )r}  r  ri  	paymentIdr  rp  r}  )handle_withdraw_tag_and_paramsrn  r  r}  r  r   rl  r  r  privatePostWalletsWithdrawr  parse_transaction)r  rn  r  ri  rk  r  r}  r  r  rp  r  s              r  r   zpoloniex.withdraw
  s     99#vFV7#==& 

 ?#&GK ??4<<R@((;""8Wg>")*"5"?GJYYvy1F224;;w3OP %%h99r  c                     | j                          d}| j                         }|| j                  |dz        n|d|z  z
  }||d}| j                  | j	                  ||            }	|	S )Ni r%  r   )startend)r  secondsparse_to_intprivateGetWalletsActivityr  )
r  rn  r  r&  r  yearnowr  r  r  s
             r  fetch_transactions_helperz"poloniex.fetch_transactions_helper
  sv    lln494E!!%$,/CRTW[R[O
 11$++gv2NOP r  c                 |   | j                          | j                  ||||      }d}|| j                  |      }| j                  |dg       }| j                  |dg       }| j	                  ||||      }	| j	                  ||||      }
| j                  |
|	      }| j                  | j                  |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_limitrc  )r  rn  r  r&  r  r  r}  r  r  withdrawalTransactionsdepositTransactionstransactionss               r  fetch_deposits_withdrawalsz#poloniex.fetch_deposits_withdrawals  s     	11$ufM!}}T*HoohrB??8Z<!%!8!8hPUW\!]"55h%QVW(()<>TU224<<k3Z\`bginoor  c                     | j                  ||||      }d}|| j                  |      }| j                  |dg       }| j                  ||||      }| j	                  ||||      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  rn  r  r&  r  r  r}  r  r  s	            r  fetch_withdrawalszpoloniex.fetch_withdrawals1  sr     11$ufM!}}T*HoohrB..{HeUS22<ueTTr  codesc                 4   | j                          | j                  | j                  |ddi            }i }t        dt	        |            D ]:  }||   }t        |j                               }| j                  |d      }||   ||<   < | j                  ||      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>`
        rc  Tr   )	r  rr  r  rs  r  rt  ru  r  parse_deposit_withdraw_fees)	r  r  r  r  r  rz  entryr   rq  s	            r  fetch_deposit_withdraw_feesz$poloniex.fetch_deposit_withdraw_feesE  s     	++DKKA^`d@e,fg0 q#h-( 	1AQKEejjl+J))*a8J$Z0D		1
 //e<<r  c                    i }| j                  |      }t        |j                               }t        dt	        |            D ]  }||   }| j                  |      }||   }	|| j                  ||      s4| j                  |      }
| j                  |	|
      ||<   | j                  |	d      }t	        |      }|dkD  s}t        dt	        |            D ]  }||   }|j                  |d      }| j                  |      }| j                  ||      }i }| j                  |d      }||dnd dd d dd||<   | j                  ||   d   |      ||   d<     |S )	Nr   childChains rj  Fro  rD  r   rm  r  )market_codesrt  ru  rs  r  r  r  r}  parse_deposit_withdraw_feer  replacerv  r  r  )r  r  r  currencyIdKeydepositWithdrawFeesresponseKeysrz  rq  rn  feeInfor}  r  chainsLengthrI  r~  r  networkInfonetworkObjectwithdrawFees                      r  r  z$poloniex.parse_deposit_withdraw_feesp  s   , %'!!%(HMMO,q#l+, 	BA%aJ**:6Dz*G4==u#===.,0,K,KGU],^#D)"oog}E";/!#"1c+&67 B$/N	$-$5$5dB$?	&*&=&=i&H&*ooh	&J.0&*&6&6{O&T (38C8OeVZ)
 (,.2(	6k2 AEL_`dLefpLq  tA  AB+D1*=#B	B8 #"r  c                     | j                  i       }||d   |d   <   | j                  |d      }| j                  |d      }||dnd d}d d d}||d<   ||d<   | j                  |      }||d	|d
   |<   |S )Nr  rn  rd  rj  Fr  r   rm  r  r  )deposit_withdraw_feer  r  rv  )	r  ro  r}  depositWithdrawFeer~  r  withdrawResultdepositResultr  s	            r  r  z#poloniex.parse_deposit_withdraw_fee  s    !66r:7:6"8F#34$$S,7	&&sO<$/$;%$ 

 
 *8:&(59%--i8&$7
:&{3 "!r  c                     | j                  ||||      }d}|| j                  |      }| j                  |dg       }| j                  ||||      }| j	                  ||||      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  rn  r  r&  r  r  r}  r  r  s	            r  fetch_depositszpoloniex.fetch_deposits  sr     11$ufM}}T*H??8Z<..x5%P22<ueTTr  c           	      >    ddddddddd}| j                  |||      S )Nokpendingfailed)COMPLETE	COMPLETEDzAWAITING APPROVALAWAITING_APPROVALPENDING
PROCESSINGzCOMPLETE ERRORCOMPLETE_ERRORr  r  s      r  parse_transaction_statusz!poloniex.parse_transaction_status  s8    !*!* #&&	
 &&99r  transactionc                    | j                  |d      }| j                  |d      }| j                  |      }| j                  |dd      }| j                  |      }| j                  |d      }d|v rdnd}| j	                  |dd	      }	| j                  |d
      }
| j                  |d      }| j                  |d      }| j                  |d      }|dk(  rt        j                  ||      }i d|d|	d|d| j                  |      dd d
|
dd dd d|dd dd d|d|dd d|d|d| j                  |      d d || j                  |      d ddS )Nr   r}  r  r  txidwithdrawalRequestsId
withdrawalrm  depositNumberri  	paymentIDr  ro  r  r2   rp  	addressToaddressFromrk  tagTotagFromr  updatedr.  )r}  r   r  )commentinternalro  )	safe_timestampr  r  r  rP  r-   
string_subr  rT  )r  r  r}  r   rq  rn  r  r  r  r2   ri  rk  r  r  s                 r  r  zpoloniex.parse_transaction  s    H ''[A	%%k:>
&&z2!!+xC..v6V4 6+ E|I-C_U"";	:{K8''X>((e<<"--lMJL
K
"
 
 d''5	

 t
 w
 
 4
 3
 T
 t
 f
 D
 t
 D
  !
" Y/#
$  ))-8)
 	
r  r  c                    |t        | j                  dz         | j                          | j                  |      }d}| j	                  d|      \  }}|t        | j                  dz         d}| j                  |dd      \  }}|rd|vrt        | j                  dz         ||j                         |d	   d
}| j                  | j                  ||            }|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     >#DGG.Y$YZZV$
!??vV
F#DGG.t$tuu//%H''  3C  )C  D  D!'')Tl

 99$++gv:VWr  c                 @   | j                          | j                  |      }d|d   i}d}| j                  d|      \  }}|t        | j                  dz         |j                         |d<   | j                  | j                  ||            }| j                  ||      S )ai  
        fetch the set leverage for a market

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        r  r2   Nrb   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_leverageL  s     	V$fTl
 
!??QWX
F#DGG.v$vww'--/	99$++gv:VWL ""8V44r  c                 \   d }d }d }d }| j                  |d      }t        dt        |            D ]c  }||   }	| j                  |	d      }| j                  |	d      }| j	                  |	d      }
| j                  |	d      }|dk(  r|
}X|dk(  r|
}`|
}|
}e || j                  ||      |||d	S )
Nr  r   r  r  r  r  LONGSHORT)r  r  r  longLeverageshortLeverage)r  rs  r  r  r  safe_symbol)r  r  r  r  r  rU  r  r  rz  r  r  r  s               r  r  zpoloniex.parse_leverage  s    ! 
~~h/q#d)$ 	&AGE''x8H))%;J%%eW5E&&ui8G& $G# %$ %	& &&x8$(*
 	
r  c                     | j                  |      }| j                  |di       }| j                  |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  )swapPrivateGetV3PositionModer  r  )r  r  r  r  r  r  r  s          r  fetch_position_modezpoloniex.fetch_position_mode  sT     44V< ~~h3""43G#
 	
r  r  c                 \    |rdnd}d|i}| j                  | j                  ||            }|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  s=     !wit
 55dkk'66RS r  c                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  ||      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  rZ  "swapPrivateGetV3TradePositionOpensr  parse_positions)r  rX  r  r  	positionss        r  fetch_positionszpoloniex.fetch_positions  sX     	%%g.::6BH NN8VR8	##Iw77r  positionc                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t	        j
                  ||      }| j                  |d      }	| j                  |d      }
t	        j
                  |	|
      }| j                  i d|d	d d|d   d
|d|d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |d      dd d| j                  |d      dd d| j                  |d      dd d|d| j                  |      d | j                  |d      d ||d t        |      | j                  |d      | j                  |d      | j                  |d      d 
      S )!Nr  r  r  r  r@  rG  	openAvgPxr  r2   notionalr  liquidationPriceliqPx
entryPriceunrealizedPnluplrD  	contractsr  rI  markPx	lastPricer  r  r  r   r.  mmmgnRatioslTrgPxtpTrgPx)
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior  r  )
r  rQ  r  r  r-   rR  safe_positionr  rT  int)r  r  r  rU  r   r  r  r  r  rG  r  r   s               r  parse_positionzpoloniex.parse_position  sQ   < ##Hh7!!(F3%%h8	++Hi@
##Hg6((48%%h>x/##Hk:''X6
!! #
H#
$#
 fX&#
 	#

 *#
  0 07 C#
 $**8[A#
 T--h>#
 $#
 ))(E:#
 D#
 ))(H=#
 #
 D**8Y?#
 d#
  !#
" Y/##
$ $(!%!1!1(D!A+/$*'+H++HjA!--h	B#//)D7#
  	r  c                    | j                          | j                  |      }| j                  ||      }|d   t        j                  |      |j                         d}d|vrd|d<   | j                  | j                  ||            }|dk(  rt        j                  |      }| j                  |d      }| j                  ||      S )Nr2   )r  rH  r  r  r  reducer  )
r  r  r  r-   
string_absr  $swapPrivatePostV3TradePositionMarginr  r  parse_margin_modification)	r  r  r  r  r  r  r  r  r  s	            r  modify_margin_helperzpoloniex.modify_margin_helperS  s    V$))&&9Tl%%f-JJL
 V#!'GI<<T[[RX=YZ 8''/F~~h/--dF;;r  r  c                     | j                  |d      }| j                  ||      }| j                  |d      }|dk(  rdnd}||d   |d | j                  |d      d d dd d d
S )	Nr  r  ADDaddr  rH  r  )
r  r  r  r  r  r?  rn  r  r   r.  )r  rQ  r  )r  r  r  rU  r  r  s         r  r  z"poloniex.parse_margin_modificationr  s    ##D(3!!(F3""40 E)uX&&&tU3
 	
r  c                 ,    | j                  || d|      S )aS  
        remove margin from a position
        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r  r  r  r  r  r  s       r  reduce_marginzpoloniex.reduce_margin  s     ((&(FKKr  c                 *    | j                  ||d|      S )a6  
        add margin
        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r  r  r  s       r  
add_marginzpoloniex.add_margin  s     ((GGr  c                 "    | j                         S r  )milliseconds)r  s    r  r]  zpoloniex.nonce  s      ""r  r   GETc                    | j                   d   d   }| j                  |ddg      r| j                   d   d   }| j                  || j                  |            }| j	                  ||      }	|dk(  s|dk(  r$|d|	z   z  }|rB|d| j                  |      z   z  }n)| j                          t        | j                               }
|d	z   }|d|	z   z  }|d|	z   z  }|d
k(  s
|dk(  s|dk(  r,|d	z  }|r| j                  |      }|d|z   dz   z  }|d|
z   z  }nU| j                  d|
i|      }| j                  |      }|d	| j                  |      z   z  }|r|d| j                  |      z   z  }| j                  | j                  |      | j                  | j                        t        j                   d      }d| j"                  |
|d}||||dS )Nr   r=   r   r   r?   r   r  ?
POSTPUTDELETEzrequestBody=&zsignTimestamp=signTimestampbase64zapplication/json)zContent-Typekeyr   	signature)urlmethodbodyheaders)r   r  r  extract_paramsimplode_params	urlencodecheck_required_credentialsr0  r]  jsonr  keysorthmacencodesecrethashlibsha256apiKey)r  pathr   r%  r  r'  r&  r$  queryimplodedPathr   authsortedQueryr#  s                 r  signzpoloniex.sign  s   iiv&==|];<))E"6*C		&$"5"5d";<**48(?c\13%%CsT^^E222++-DJJL)ID=D3%%CC,&&D& fo6X;M99U+DNT1C77D(944"kk?I*FN"ll;7t~~k:::3!666C		$++d"3T[[5Mw~~_ghI 2{{!*&	G fdwOOr  reasonr$  r%  r'  r&  c
                 $   |y | j                  |d      }
|
y|
dk7  rt|d   }| j                  |d      }| j                  dz   |z   }| j                  | j                  d   ||       | j	                  | j                  d   ||       t        |      y )Nrn  200messager  r  r  )r  r2   throw_exactly_matched_exceptionr7  throw_broadly_matched_exceptionr   )r  rn  r:  r$  r%  r'  r&  r  requestHeadersrequestBodyresponseCode	codeInnerr=  feedbacks                 r  handle_errorszpoloniex.handle_errors  s     ''&9$<5+@ (I&&x;Gww}t+H001I9V^_001I7T\]))r  r  )NN)b__name__
__module____qualname__r   r  r   rt  r  r0  r   r   r  r  r  r  r  dictr  r  r  r%  r   rW  r   r   ra  r   r  r  r   r  r  r   r  r  r   r  r  r  r   r  r   r   floatr   r  r  r$  r)  r.  r3  r6  r9  r   rK  rQ  r   rW  r   rf  r
   rp  rs  r   r   r	   ry  r   r   r  r  r  r  r  r  r  r  r  r  r   r  r  r  boolr  r   r  r  r   r  r  r  r  r]  r9  r  rE  __classcell__)r  s   @r  r/   r/      sk   Z# Zx7
 7
4 7
r 26DW[df NL# NLc NLQT NLkoptku NL` #(  $& 9$v, 9 )+ +tF| +6 )+ *+tF| *+X24 2F 26
 6
 6
pi
 i
 i
V !# 
9s 
9L4 L L6 L\ 04B N5W N57 N5` ') CZ CJ 02 *33 *3f *3XB Bv B BH 6:UW 4?3 4?s 4?# 4?\`af\g 4?l -1tRV_a ac a aC aF
: 
:e ev e eN:
 /3TXac cL cL3 cLc cLhlmrhs cLJ 154VZce F=# F=S F=PS F=jnotju F=P gksu -23 -2i -2y -2RW -2`c -2^ HLTV >!@ `drv  @B *2S *2# *2Y *2i *2Y\ *2lo *2X 37r 5*s 5*C 5*n /32 D3 D3L 26b 9c 93 9v 9=R 7S 7# 7 9=4^bkm ')S ')# ')S ')X[ ')R!) !)F $& J,( J,X )+ { @ :>b F
s F
3 F
Y F
P 8: ,
3 ,
n ,
\ 79 ,
# ,
^ ,
\ [] 7S 7% 7c 7c 7an 7@
t 
x 
= 
$ DHPR &:S &:% &:# &:Wb &:P 59tZ^gi Qc Q QTW Qf 6:[_hj ps p# pUX post  pA p0 -1tRV_a Uc U UC Ufjkvfw U( <@ )= )=V5#n" ", *.Dt\^ U3 Uc U Ucghsct U(:s :K
T K
X K
Q\ K
Z 9=R S # B 24 :5S :5 :5x
t 
V 
x 
6 15R 
# 
8 =A  c 2 26b 28w 28T(^ 28hEt EV EN FH <3 <L^ <>
d 
F 
N` 
$ @B LC L LFX L =? H He HCU H# &eBSW #PJ# s  c TX `c r  r/   )4ccxt.base.exchanger   ccxt.abstract.poloniexr   r1  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>rU     s}    ( .  G  G  G  G  G  G  G  * 0 - - . ' & . ) * ) 1 * + 4 %t6x t6r  