
    E#iB^                    p   S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SK J!r!  S SK J"r"  S SK J#r#  S S	K J$r$  S S
K J%r%  S SK J&r&  S SK J'r'  S SK J(r(  S SK J)r)  S SK J*r*  S SK J+r+  S SK J,r,  S SK J-r-  S SK J.r.  S SK/J0r0  S SK1J2r2   " S S\\5      r3g)    )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                     ^  \ rS rSrS\4U 4S jjrSmS\S\4S jjrSSS0 4S\	S	\	S
\
S\
S\\   4
S jjrS0 4U 4S jjr0 4S\\   4S jjr0 4S\\   4S jjr0 4S\\   4S jjrS\S\4S jrS\S\4S jrS\S\4S jr0 4S\
4S jjrSmS\S\S\4S jjrS0 4S\S\4S jjr0 4S\4S jjr0 4S\	S\4S jjrSmS\S\S\4S jjrSS0 4S\	S
\
S\
S\\   4S jjr SSS0 4S\!S
\
S\
4S jjr"S \!4S! jr#SmS"\S\S\$4S# jjr%S$ r&S% r'SSS0 4S\!S
\
S\
S\\$   4S& jjr(SSS0 4S\!S
\
S\
S\\$   4S' jjr)S0 4S\	S(\*S)\+S*\,S+\-4
S, jjr.S0 4S- jr/SS0 4S.\	S\	S(\*S)\+S*\-S+\-4S/ jjr0S0 4S.\	S\!4S0 jjr1S0 4S\!4S1 jjr2S0 4S.\	S\!4S2 jjr3S0 4S.\	S\!4S3 jjr4SSS0 4S.\	S\!S
\
S\
4S4 jjr5S\64S5 jr70 4S\64S6 jjr80 4S\94S7 jjr:S0 4S\	S\
S\;4S8 jjr<0 4S9\	S\=4S: jjr>0 4S9\	S\=4S; jjr?0 4S9\	S<\S\4S= jjr@S\=4S> jrA0 4S9\	S*\,S?\	S@\	S\B4
SA jjrCSmSB\SC\DS\B4SD jjrES0 4S9\	S*\,SE\	SF\!S\F4
SG jjrGSSS0 4S9\!S
\
S\
4SH jjrHSSS0 4S9\!S
\
S\
S\\F   4SI jjrISSS0 4S9\!S
\
S\
S\\F   4SJ jjrJS0 4SK\4SL jjrKSnSM jrLSmSC\D4SN jjrMSSS0 4S9\!S
\
S\
S\\F   4SO jjrNS \!4SP jrOSmSQ\SC\DS\F4SR jjrPS0 4SS\QS\!4ST jjrR0 4S\	S\S4SU jjrTSmSS\S\S\S4SV jjrUS0 4S\!4SW jjrVS0 4SX\WS\!4SY jjrXS0 4S\S\\Y   4SZ jjrZSmS[\S\4S\ jjr[0 4S\	S\\4S] jjr]SmS^\S\S\\4S_ jjr^0 4S\	S*\,S\\4S` jjr_0 4S\	S*\,S\\4Sa jjr`Sb raScSd0 SS4Se jrbS9\QSf\	Sg\	Sh\	Si\Sj\	4Sk jrcSlrdU =re$ )opoloniex   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_S0 SS _SS_SS _SS_SS_SS
_SS_SS_SS_SS _SS_SS_SS
_SS
_SS_SS _SS_0 SS_S S_S!S_S"S
_S#S_S$S_S%S_S&S
_S'S
_S(S_S)S_S*S+_S,S_S-S
_S.S
_S/S
_S0S
_E0 S1S
_S2S _S3S _S4S_S5S _S6S
_S7S_S8S_S9S_S:S
_S;S
_S<S_S=S_S>S_S?S
_S@S_SAS
_E0 SBS_SCS_SDS_SES_SFS_SGS_SHS
_SIS_SJS+_SKS
_SLS
_SMS_SNS_SOS_SPS_SQS_SRS_ESSS0E_STSUSVSWSXSYSZS[S\S]S^S_S`SaSbSc._SdSeSfSfSg.SSh0SiSjSkSlSm._SnSo0 SpSq_SrSs_StSq_SuSq_SvSq_SwSq_SxSs_SySs_SzSs_S{Ss_S|Ss_S}Ss_S~Ss_SSs_SSq_SSq_SSq_SsSsSsS.E00 SS_SS_SS_SSq_SSq_SS_SSq_SSs_SS_SSq_SS_SSq_SS_SSq_SSq_SSq_SS_SSSqSSSqSSqSqSqSS.ESSqSqSqSqSSqSSS.	SSqSqSSqSqS.SqSqS.S.So0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0SSqSqSqSqSqSqSqSqS.	SSSqSSqSqSqS.SSqSqS.S.S._SSoU R	                  S5      U R	                  S5      S.0 S._S0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSSS.	E_SSSSSSSS.SSS.SSSSSSSSSSSSSS.00SSS.SSS.S._SSSSS S
S
S
S SSSS
S.S
S
SS
SS
S
S.SSq0S
SSSS
S.S
S
S
S
S.S
SS
S
S
S.S S SS0GS .	GSGS0GSSS
SSS
GS.SS0SS0S
SS GSS S
S
S
GS.SGSGS.GS.GSGS	0GSGS	0GS
.GSGS	0GSGS	0GS
.GS._GS[
        _GS0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _0 GS[        _GS [        _GS![        _GS"[        _GS#[        _GS$[        _GS%[        _GS&[        _GS'[        _GS([        _GS)[        _GS*[        _GS+[        _GS,[        _GS-[        _GS.[         _GS/[         _E0 GS0[         _GS1[        _GS2[        _GS3["        _GS4["        _GS5[$        _GS6[         _GS7[        _GS8[        _GS9[$        _GS:[        _GS;[        _GS<[$        _GS=[        _GS>[         _GS?[         _GS@[         _E0 GSA[         _GSB[         _GSC[         _GSD[         _GSE[         _GSF[         _GSG[         _GSH[         _GSI[        _GSJ[         _GSK[         _GSL[         _GSM[         _GSN[         _GSO[         _GSP[         _GSQ[         _E0 GSR[         _GSS[         _GST[         _GSU[         _GSV[         _GSW[        _GSX[        _GSY[        _GSZ[        _GS[[         _GS\[         _GS][         _GS^[         _GS_[         _GS`[         _GSa[         _GSb[         _E0 GSc[        _GSd[         _GSe[        _GSf[         _GSg[         _GSh[         _GSi[        _GSj["        _GSk[         _GSl[        _GSm[$        _GSn[$        _GSo[$        _GSp[        _GSq[        _GSr[        _GSs[        _E0 GSt._5      $ (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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TRC20r   r   )r   r   costming-C6?g      ?gQ?)BTCr   r   r   BNBUSDCUSDJTUSDDAIPAXBUSDfutures)r>   rA   )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(  r,  r$  r+  r(    )	r~   rK   rL   rg   rl   rk   fetchOrdersrR   rh   extendsdefault)r  r  r  stpModer!  gUUUUUU?)r  r(  r)  daysBackCanceledr*  r,  r$  r+  Z   )r(  r*  )r0  rK   rL   rk   rR   rg   forContracts)linearinverse)r1  r>   r5  r@   rA   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/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/poloniex.pyr  poloniex.describe   sk   h > @ ^C
*^C
J^C
 $^C

 ^C
 ^C
 4^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^C
^   """ _^C
~ }66
 H 2<3D^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[^C
^ $!..x8!..x8	 _^C
p  $!y$!$! }$! (	$!
 |$! y$! w$! 5$! $! $! y$! )$! y$! .$! *$!  ~!$!" #$!$ #! ""!G$!q^C
z %59""#!	 ##!
 #)#)$'#&#'$'$'$*#&#&$' $ #'#
 !''!E&{^C
H
 #&*(,,0,1).+06:#'#'"&#(	( #($)+/27/3$)#()$. r% ',!%$*%+*/& ',#($)*/	# ',!%#($)*/( $()-#c4l y  )&*(-"&#'+0$ r%  ( ',!$$(,1%)#($)*/	* "%%'&3!@ "> "> 	 "> "> 	gI
^C
X YY^C
Z 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[^C
 ^ ^	    Nmarketc           	         [        U5      nUS:H  nU(       ah  U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )	N	      r   r   r      r9      )lensafe_integersafe_number)r  ohlcvr  ohlcvLength
isContracts        r  parse_ohlcvpoloniex.parse_ohlcv@  s    J %j A%
!!%+  *  *  *  *  *  eR(UA&UA&UA&UA&UA&
 	
r  r   symbol	timeframesincer(  c           	         U R                  5         SnU R                  USSS5      u  peU(       a  U R                  SXXBUS5      $ U R                  U5      nUS   U R	                  U R
                  X"5      S.nUS   (       a  SOS	n	US   (       a  S
OSn
Ub  X8U	'   Ub  XHS'   U R                  XU5      u  pUS   (       a  U R                  USS/5      (       a'  [        U R                  S-   U-   S-   US   -   S-   5      eU R                  U R                  X5      5      nU R                  US5      nU R                  XX#U5      $ U R                  U R                  X5      5      nU R                  XX#U5      $ )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
Frh   paginater.  r3   )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(   r3   swapPublicGetV3MarketCandlesextend	safe_listparse_ohlcvspublicGetMarketsSymbolCandles)r  r  r  r  r(  paramsr  r  requestkeyStartkeyEndresponseRawr  responses                 r  fetch_ohlcvpoloniex.fetch_ohlcvy  s     	88z[`a::<X]jpruvvV$Tl(()O
 #).;g$Vn' %H$G226FK*}}Y66"477S=9#<s#BVF^#SVt#tuu;;DKK<XYK$ >>+v6D$$T9UKK55dkk'6RS*   9UKKr  Fc                    > [         [        U ]  X5      nU R                  U R                  S5      nUb  U(       a)  U R                  U R                  S5      U R                  S'   U$ )NcurrenciesByNumericId	numericId)r  r/   r  
safe_valuer   index_byr   )r  reloadr  r   r  r  s        r  r  poloniex.load_markets  sV    $4VD $>U V!)f48MM$//S^4_DLL01r  c                 z    U R                  U5      U R                  U5      /nUnU R                  US   US   5      $ )aR  
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_marketspoloniex.fetch_markets  sD     ++F3T5L5LV5TU  WQZ88r  c                 F    U R                  U5      nU R                  U5      $ N)publicGetMarketsparse_markets)r  r  r   s      r  r  poloniex.fetch_spot_markets  s%    ''/0 !!'**r  c                 j    U R                  U5      nU R                  US5      nU R                  U5      $ )Nr  )#swapPublicGetV3MarketAllInstrumentsr  r  )r  r  r  r   s       r  r  poloniex.fetch_swap_markets  s6    ;;FCN ..62!!'**r  c                 R    SU;   a  U R                  U5      $ U R                  U5      $ )NctType)parse_swap_marketparse_spot_market)r  r  s     r  parse_marketpoloniex.parse_market%  s,    v))&11))&11r  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      nUS:H  nU R                  US5      n	0 SU_SUS-   U-   _S	U_S
U_SS _SU_SU_SS _SS_SS_SS_SS_SS_SS_SU_SS_SS _S S S S S S U R                  U R	                  U R                  U	S5      5      5      U R                  U R	                  U R                  U	S5      5      5      S.U R                  U	S5      S S.S S S.U R                  U	S5      S S.S .U R                  US!5      US".
E$ )#Nr  baseCurrencyNamequoteCurrencyNamestateNORMALsymbolTradeLimitr3   /basequotesettlebaseIdquoteIdsettleIdr  r>   Tr?   Fr@   rA   rB   activer  r6  quantityScale
priceScaleamountpriceminQuantityr   r&  	minAmount)r  r	  r   tradableStartTime)
r7  contractSizeexpiryexpiryDatetimestrike
optionType	precisionr  createdinfo)r  safe_currency_coder  r  parse_precisionr  r  )
r  r  r3   r  r  r  r  r  r  r  s
             r  r  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                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  U5      nU R                  US5      n	U	S:H  n
US   S:H  nUS	-   U-   nU(       a	  US
U-   -  nOUS
U-   -  nU R                  US5      nSnUb  Sn0 SU_SU_SU_SU_SU_SU_SU_SU_SUS:X  a  SOS_SS_SS_SUS:H  _SUS:H  _SS_SU
_SS_SU_U(       + U R                  US5      S S S S U R                  US5      U R                  US 5      U R                  US!5      U R                  US"5      S#.U R                  US$5      U R                  US%5      S&.U R                  US'5      U R                  US(5      S&.S S S&.U R                  US)5      S S*.S+.U R                  US,5      US-.E$ ).Nr  bCcyqCcysCcystatusOPENr  LINEARr  :aliasr@   rA   r3   r  r  r   r  r  r  r  r>   Fr?   rB   r  r  Tr6  ctValtFeemFeelotSztSzr  minSzlimitMaxQtyr  minPxmaxPxmaxLever)r&  r   )r  r	  r   r   oDate)r7  r  r  r  r  r  r   r   r  r  r  r  )r  r  r  r  )r  r  r3   r  r  r  r  r  r   r  r  r6  r  r!  r  s                  r  r  poloniex.parse_swap_marketc  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    U R                  U5      nU R                  US5      $ )aB  
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_timepoloniex.fetch_time  s'     **62  <88r  tickerc           
         U R                  USS5      nU R                  USS5      nU R                  U5      nU R                  USS5      n[        R                  " US5      nU R                  0 SU_SUS   _S	U_S
U R                  U5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SS _SU R                  USS5      _SU R                  USS5      _SS _SS _S U_S!S _U R                  US"S#5      U R                  US$S%5      U R                  US&S'5      U R                  US(5      US).EU5      $ )*NtscTr  sdailyChangedc100r3   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quoteVolumerV  
indexPricer  )safe_integer_2safe_string_2safe_marketr-   
string_mulsafe_tickeriso8601r  )r  r3  r  r   marketIdrelativeChangerQ  s          r  parse_ticker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                    U R                  5         Sn0 nUbH  U R                  USSSS5      n[        U5      nUS:  a"  U R                  US   5      nUS:X  a  US   US'   SnU R	                  SX25      u  pbUS	:X  aC  U R                  U R                  XB5      5      nU R                  US
5      nU R                  X5      $ U R                  U5      n	U R                  X5      $ )a0  
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   r3   r  rt   r@   r  )
r  market_symbolsr  r  handle_market_type_and_paramsswapPublicGetV3MarketTickersr  r  parse_tickerspublicGetMarketsTicker24h)
r  rf  r  r  r  symbolsLength
marketTyper  r  r  s
             r  fetch_tickerspoloniex.fetch_tickers(  s     	))'4tUKGLMq WQZ0 A%(.tGH%
!??PV_
;;DKK<XYK6 >>+v6D%%d4411&92 !!(44r  c                    U R                  U R                  USS05      5      n0 n0 n[        S[        U5      5       HE  nU R	                  X%5      n[        UR                  5       5      nU R                  US5      nXh   XH'   MG     [        UR                  5       5      n	[        S[        U	5      5       GH  nX   nXH   n
U R                  U5      nU R                  U
S5      (       a  M6  / nU R                  U
S/ 5      nUbB  [        S[        U5      5       H)  nX   nU R	                  XO5      nUR                  U5        M+     UR                  U
5        0 n[        S[        U5      5       H  nX   nU R                  US5      nU R                  UU5      nU R                  XU5      nUUU R                  US5      UU R                  US	5      U R                  US
5      S:H  U R                  US5      S:H  U R                  US5      SSSS.SSS.S.S.
UU'   M     U R                  U
UUU R                  U
S5      SU R                  U
S5      SSSSSSSS.SSS.SSS.S.US.5      X;'   GM     U$ )a	  
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
blockchainr3   walletStatewalletDepositStateENABLEDwalletWithdrawalStatewithdrawalFeer  r   deposit)
r  r3   r  networkr  r|  r   feer  r  cryptor4   )r  r   r|  )r  coder3   r  r  r4   r  r|  r   r~  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idsr3   r  entryr  allChainEntriesrt  jchildChainIdchildNetworkEntryr  
chainEntrynetworkNamenetworkCodespecialNetworkIds                         r  fetch_currenciespoloniex.fetch_currenciesx  s    ++DKKA^`d@e,fgt  q#h-(A>>(.Dtyy{#C!!#q)B!%N	 )
 N'')*q#d)$AB"&E**2.D~~e^44 O..rBK&q#k"23A#.>L(,~(T%#**+<= 4 ""5)H1c/23,/
"..z<H"55k4H#'#3#3KB#G &*!%!2!2:t!D*"nnZG#//
<PQU^^ $ 0 0=T UYb b++JH!% $(#'%
 $(#'$	)% 44  77!..ud; ((7 !  $#
  $#!
  $#  %59 FLU %L r  c                    U R                  5         U R                  U5      nSUS   0nUS   (       a'  U R                  US   /U5      nU R                  XQ5      $ U R	                  U R                  XB5      5      nU R                  Xc5      $ )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  r3   r  )r  r  ro  r  publicGetMarketsSymbolTicker24hr  rd  )r  r  r  r  r  tickersr  s          r  fetch_tickerpoloniex.fetch_ticker  s     	V$fTl
 *((&*:);VDG>>'2277G8TU.   22r  tradec                    U R                  U/ SQ5      nU R                  USS5      nU R                  U/ SQ5      nU R                  US5      nU R	                  XbS5      nUS   nU R                  USS5      nS n	U R                  US	S
5      n
U R                  USS5      nU R                  USS5      nU R                  USS5      nU R                  USS5      nUb  U R                  U5      nUUS.n	U R                  UUUU R                  U5      UUU R                  USS5      UU R                  USS5      U
UUU	S.U5      $ )N)r3   tradeIDtrdIdorderIdordId)r5  
createTimer6  cTimer  _side	takerSider	  pxrS  rT  r  rU  feeCurrencyfeeCcy	feeAmountfeeAmt)r   currencyordTyper  	matchRolerole)r3   r  r   r;  r  orderr  r  takerOrMakerr	  r  r   r~  )	safe_string_nr]  safe_integer_nr  r^  safe_string_lower_2r  
safe_tradera  )r  r  r  r3   r  r   rb  r  r  r~  priceStringamountString
costStringfeeCurrencyIdfeeCostStringfeeCurrencyCodes                   r  parse_tradepoloniex.parse_trade9  sx   B 'AB$$UIw?''/RS	##E84!!(C8!''v{C((>))%UC''x?
**5-J**5+xH$"55mDO%+C "Y/,,UIvF 44UKP " 
  	r  c                 `   U R                  5         U R                  U5      nSUS   0nUb  X6S'   US   (       aD  U R                  U R                  Xd5      5      nU R	                  US5      nU R                  XX#5      $ U R                  U R                  Xd5      5      n	U R                  XX#5      $ )a/  
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  r3   r(  r  r  )r  r  swapPublicGetV3MarketTradesr  r  parse_tradespublicGetMarketsSymbolTrades)
r  r  r  r(  r  r  r  r  
tradesListr   s
             r  fetch_tradespoloniex.fetch_trades  s     	V$fTl
 $G*77G8TUH &9J$$ZFF224;;w3OP   >>r  c                    U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ SnUb  U R                  U5      nSnU R	                  SXd5      u  ptU R                  USS/5      n0 n	U(       a  SOSn
U(       a  S	OS
nUb  X)U
'   Ub  X9S'   U(       a  Ub  US   U	S'   U R                  XU5      u  pU(       aD  U R                  U R                  X5      5      nU R                  US5      nU R                  XX#5      $ U R                  U R                  X5      5      nU R                  XX#5      nU$ )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>`
Frg   r  Nr@   rA   r  r  r  r  r(  r3   r  r  )r  r  fetch_paginated_call_dynamicr  ri  r  r   swapPrivateGetV3TradeOrderTradesr  r  r  privateGetTrades)r  r  r  r(  r  r  r  rn  r  r  startKeyendKeyrawr  r  r  s                   r  fetch_my_tradespoloniex.fetch_my_trades  sd    	88R\]44_fUZcc[[(F
!??QW`
]]:/AB

 )7k&I %H$G&, &tGH226FK77G8TUC@ >>#v.D$$T5@@((W)EF, ""8UBr  r  c                 :    SSSSSSSS.nU R                  X!U5      $ )NrK  closedcanceled)NEWPARTIALLY_FILLEDFILLEDPENDING_CANCELPARTIALLY_CANCELEDCANCELEDFAILEDr  r  r  statusess      r  parse_order_statuspoloniex.parse_order_statusV  s3     &("," 
 &99r  r  c                    U R                  U/ SQ5      nUc!  U R                  U R                  US5      5      nU R                  US5      nU R                  XBS5      nUS   nU R	                  US5      nUb7  [        U[        5      (       d"  U R	                  X`R                  USU5      5      nU R                  U/ SQ5      nU R                  USS	5      nU R                  US
S5      n	U R                  U R                  US5      5      n
U R                  US5      nU R                  US5      nU R                  U5      nU R                  U/ SQ5      nS nU R                  USS5      nS nS nU R                  US5      nUc  US:X  a  US   OUS   nO$U R                  U5      nU R                  USS5      nUb  UUUS.nU R                  USS5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      S:g  nU R                  0 S U_SU_SU_S!U_S"U R!                  U5      _S#U R                  US$5      _S%U
_SU_SU_S&U R                  US&5      _S'US(:H  _SU_S)U_S*U R                  US*S+5      _S,U R                  US-5      _S.U R                  US/S05      _S1U_U	S UUUUUUS2.EU5      $ )3N)r   r  r  dater  r  resultingTradesr3   )r	  rater  rS  szfilledQuantityexecQtyr  r  r  )orderNumberr3   r  r  tokenFeeCurrencyr  r~  buyr  r  tokenFeer  )r  r   r  clientOrderIdclOrdIdmgnMode
reduceOnlyleverposSideBOTHr  r   r;  lastTradeTimestamp
updateTimer  r  postOnlyLIMIT_MAKERr	  r  	stopPricer   execAmtrR  avgPriceavgPxr  )filled	remainingr   r~  r  r  r   r  )r  	parse8601r  r^  r  
isinstancer  r  r]  r  safe_string_lowerparse_order_typer  r  r  
safe_orderra  )r  r  r  r   rb  r  r  r	  r  r  r  r  rawTyper  r3   r~  r  feeCostr  r  r  r  r  r   r  s                            r  parse_orderpoloniex.parse_orderb  s   F ''/ST	t'7'7v'FGI##E84!!(C8!//%1BC&ot44"&///CSCSTZ\`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                 6    SSSSSS.nU R                  X!U5      $ )Nr  r(  )MARKETLIMITr  z
STOP-LIMITzSTOP-MARKETr  r  s      r  r  poloniex.parse_order_type	  s-    "!#
 &99r  c           	          [        S[        U5      5       HD  nX   nU R                  USSUS   US   S.5      nUR                  U R	                  Xb5      5        MF     U$ )Nr   rK  r(  r  r  )r  r  r  r	  )r  r  r  r  r  )r  r   r  r  r  r  extendeds          r  parse_open_orderspoloniex.parse_open_orders  sg    q#f+&AIE{{5 fv	+ H MM$**8<= ' r  c                 @   U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnU R                  SXT5      u  ptUb  US:X  a  SOSnU" X85      US'   U R                  US	S
5      n	U R	                  US	S
/5      nSn
US:w  a3  U R                  U R                  Xd5      5      nU R                  US5      n
OHU	(       a!  U R                  U R                  Xd5      5      n
O U R                  U R                  Xd5      5      n
SS0nU R                  XX#U5      $ )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>`
Nr3   r  rk   r>   r-  r   r(  r,  stopr  r  rK  )r  r  ri  safe_value_2omitswapPrivateGetV3TradeOrderOpensr  r  privateGetSmartordersprivateGetOrdersparse_orders)r  r  r  r(  r  r  r  rn  r&  	isTriggerr  r  	extensions                r  fetch_open_orderspoloniex.fetch_open_orders  s2    	[[(F &tGH
!??@QSYb
%/$cC"5GG%%fi@	6Iv#6766t{{77STCP ~~c62H11$++g2NOH,,T[[-IJH0 $V,	  5KKr  c                    U R                  5         Sn0 nUb  U R                  U5      nUS   US'   SnU R                  SXTS5      u  ptUS:X  a  [        U R                  S-   5      eUb  [        SU5      US	'   Ub  X&S
'   U R                  SXd5      u  pdU R                  U R                  Xd5      5      nU R                  US/ 5      n	U R                  XX#5      $ )aB  

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>`
Nr3   r  rR   r@   r>   z: fetchClosedOrders() is not supported for spot markets yet   r(  r  r  r  )r  r  ri  r(   r3   r   r  !swapPrivateGetV3TradeOrderHistoryr  r  r  )
r  r  r  r(  r  r  r  rn  r  r  s
             r  fetch_closed_orderspoloniex.fetch_closed_orders  s     	[[(F &tGH
!??@SU[ekl
tww)eeff"3GG$G227GL99$++g:VWR ~~h3  u<<r  r  r  r  r	  c           	         U R                  5         U R                  U5      nUS   UR                  5       S.nU R                  USS5      n	U R	                  XX4XU5      u  pSn
US   (       d
  US   (       a3  U R                  U R                  X5      5      nU R                  US5      n
ODU	b!  U R                  U R                  X5      5      n
O U R                  U R                  X5      5      n
U R                  X5      $ )	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>`
r3   )r  r  r  r  Nr@   rA   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_orderpoloniex.create_order  s    " 	V$TlJJL
 ))&+~N,,V4Y_`&>VH-">>t{{7?[\O ~~ov>H%224;;w3OPH--dkk'.JKH 11r  c                    U R                  USS5      nU R                  U5      n	U	S   (       a  S n
U R                  US5      u  pU
b)  U R                  SU
SSS/5        U
R	                  5       US'   S nU R                  US	5      u  pU(       a9  U
c  [        U R                  S
-   5      eSU;  a  [        U R                  S-   5      eUR	                  5       nUS:H  nU R                  XS:H  U5      nU R                  U/ SQ5      nUb7  U	S   (       d!  [        U R                  S-   U	S   -   S-   5      eUc  SOSnXS'   O	U(       a  SnXS'   U(       Ga  US:X  a  S nSnU R                  USSS5      u  nnU R                  US5      nU R                  US5      nUb  U R                  UU5      nOU(       aq  U	S   (       ag  Uc  [        U R                  S-   5      eU R                  U5      nU R                  U5      n[        R                  " UU5      nU R                  UU5      nOU R                  X5      nU	S   (       a  SOSnXU'   OgU	S   (       a  SOSnU R!                  X5      UU'   ODU	S   (       a  SOSnU R!                  X5      UU'   U	S   (       a  SOSnU R#                  X5      UU'   U R%                  US 5      nUb  UUS '   U R                  US 5      nXW/$ )!Nr  r  r  r  rK   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  rS  r	  r  r  )r   r  handle_param_stringcheck_required_argumentr  r"   r3   is_post_onlyr  r&   r  r  cost_to_precisionnumber_to_stringr-   r_  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!  poloniex.order_request  s:   ))&+~NV$*J!%!9!9&,!OJ%,,]JW^`jVkl%/%5%5%7	"F!55fhGNF%+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#/K )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	%)%=%=f%M	"&,Vn
$I!%!9!9&!IGI"(.wdH $ 7 7 FGH((A$'4GO$YYv7F  r  r3   c           	         U R                  5         U R                  U5      nUS   (       d!  [        U R                  S-   US   -   S-   5      eSU0n	U R	                  USS5      n
U R                  X#XEXU5      u  pSnU
b!  U R                  U R                  X5      5      nO U R                  U R                  X5      5      nU R                  UUUS	.5      nU R                  X5      $ )
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 acceptedr3   r  r  N)r  r  )
r  r  r(   r3   r   r!  privatePutSmartordersIdr  privatePutOrdersIdr  )r  r3   r  r  r  r  r	  r  r  r  r  r  s               r  
edit_orderpoloniex.edit_order;  s    " 	V$f~tww)IIFSYNZ  ^F   F  G  G"
 ))&+~N,,V4Y_`#33DKK4PQH..t{{7/KLH ;;x*
  11r  c                 f   U R                  5         Uc  [        U R                  S-   5      eU R                  U5      n0 nUS   (       dM  US   US'   XS'   U R	                  U R                  XS5      5      nU R                  U R                  US5      5      $ U R                  US5      nUb  UnXS'   U R                  USS	5      nU R                  U/ S
Q5      nS n	U(       a!  U R                  U R                  XS5      5      n	O U R                  U R                  XS5      5      n	U R                  U	5      $ )Nz) cancelOrder() requires a symbol argumentr>   r3   r  r  r  r  r,  r  )r  r,  r  )r  r"   r3   r  swapPrivateDeleteV3TradeOrderr  r  r  r  r  r  privateDeleteSmartordersIdprivateDeleteOrdersId)
r  r3   r  r  r  r  r  r  r  r  s
             r  cancel_orderpoloniex.cancel_orderg  s%    	>#DGG.Y$YZZV$f~ &tGH!G44T[[5QRC ##DNN3$?@@@$B%%fi@	6#GH66t{{77STH11$++g2NOH ))r  c                 6   U R                  5         S/ 0nSnUb  U R                  U5      nUS   /US'   SnSnU R                  SXB5      u  pbUS:X  d  US:X  aC  U R                  U R	                  X25      5      nU R                  US5      nU R                  XT5      $ U R                  USS	5      nU R                  USS	/5      nU(       a!  U R                  U R	                  X25      5      nO U R                  U R	                  X25      5      nU R                  XT5      $ )
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>`
rf  Nr3   rD   r@   rA   r  r,  r  )r  r  ri  !swapPrivateDeleteV3TradeAllOrdersr  r  r  r  r  privateDeleteSmartordersprivateDeleteOrders)	r  r  r  r  r  r  rn  r  r  s	            r  cancel_all_orderspoloniex.cancel_all_orders  s+    	 r
 [[(Ft"GI 
!??@QSYb
:#988W9UVC ~~c62H$$X66%%fi@	6Iv#6744T[[5QRH//G0LMH$   22r  c                 $   U R                  5         [        U5      nSU0nSnUb  U R                  U5      nUS   US'   SnU R                  SXS5      u  pcUS:w  a  [	        U R
                  S-   U-   S-   5      eU R                  USS	5      nU R                  USS	/5      nSnU(       a3  U R                  U R                  XC5      5      nU R                  US
5      nO U R                  U R                  XC5      5      nU R                  U5      n	XS'   U	$ )a  
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>`
r3   Nr  rl   r>   z# fetchOrder() is not supported for z markets yetr,  r  r   )r  strr  ri  r(   r3   r  r  privateGetSmartordersIdr  r  privateGetOrdersIdr  )
r  r3   r  r  r  r  rn  r  r  r  s
             r  fetch_orderpoloniex.fetch_order  s"    	W"
 [[(F &tGH
!??f]
tww)NNQ[[^llmm%%fi@	6Iv#6733DKK4PQHx3H..t{{7/KLH,   *dr  c                     U R                  5         U R                  US S U5      nU R                  US5      nX;   a  S$ S$ )Nr3   rK  r  )r  r  r  )r  r3   r  r  r   indexeds         r  fetch_order_statuspoloniex.fetch_order_status	  sC    ''dFC----v6h6r  c                     U R                  5         SU0nU R                  U R                  Xe5      5      nU R                  U5      $ )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>`
r3   )r  privateGetOrdersIdTradesr  r  )r  r3   r  r  r(  r  r  r   s           r  fetch_order_tradespoloniex.fetch_order_trades%	  sJ     	"
 ..t{{7/KL,   ((r  c                    US S S.n[        U[        5      (       d  U R                  US5      nX2S'   U R                  U5      US'   U R	                  US/ 5      n[        S[        U5      5       Hh  nXE   nU R                  US5      nU R                  U5      nU R                  5       n	U R                  US5      U	S	'   U R                  US
5      U	S'   XU'   Mj     U R                  U5      $ [        S[        U5      5       H  nU R                  X0 5      n	U R                  U	S5      n
[        S[        U
5      5       Hu  nU R                  X5      nU R                  US5      nU R                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   XU'   Mw     M     U R                  U5      $ )N)r  r   r;  uTimer   r;  detailsr   ccyavailtotalimusedbalancesr  	availablefreehold)r  r  r  ra  r  r  r  r  r  accountsafe_balancer  )r  r  r  r5  r]  r  balance
currencyIdr  rg  rc  r  
newAccounts                r  parse_balancepoloniex.parse_balanceN	  s   
 (D))""8W5B"$;!%b!1F:nnXy"=G1c'l+!*!--gu=
..z:,,.#'#3#3GW#E "&"2"27D"A&t , $$V,,q#h-(Aooh26Gw
;H1c(m,//(6!--gzB
..z:!\\^
%)%5%5g{%K
6"%)%5%5gv%F
6")t - )   ((r  c                 0   U R                  5         SnU R                  SSU5      u  p!US:w  a5  U R                  U5      nU R                  US0 5      nU R	                  U5      $ SS0nU R                  U R                  XQ5      5      nU R	                  U5      $ )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  ri  swapPrivateGetV3AccountBalancer  rl  privateGetAccountsBalancesr  )r  r  rn  r  r  r  r  s          r  fetch_balancepoloniex.fetch_balanceq	  s     	
!??PTV\]
==fEKL >>+vr:D%%d++6
 224;;w3OP" !!(++r  c                    U R                  5         U R                  U5      n0 n[        S[        U R                  5      5       H=  nU R                  U   nUUU R                  US5      U R                  US5      SSS.X5'   M?     U$ )a2  
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   rQ  	tierBased)r  privateGetFeeinfor  r  rf  r  )r  r  r  r  r  r  s         r  fetch_trading_feespoloniex.fetch_trading_fees	  s     	))&1 q#dll+,A\\!_F  ))(K@))(K@"!FN - r  c                 @   U R                  5         U R                  U5      nSUS   0nUb%  X%S'   US   (       a  U R                  / SQU5      US'   US   (       aW  U R                  U R	                  XS5      5      nU R                  US0 5      nU R                  US5      nU R                  XqU5      $ U R                  U R	                  XS5      5      n	U R                  U	S	5      n
U R                  U	S
5      nU R                  U	S5      n/ n/ n[        S[        U5      5       HS  nUS-  S:  d  M  U R                  X5      nU R                  XR                  US5      5      nUR                  UU/5        MU     [        S[        U5      5       HS  nUS-  S:  d  M  U R                  X5      nU R                  XR                  US5      5      nUR                  UU/5        MU     US   U R                  USS5      U R                  US5      U
U R!                  U
5      SS.$ )aM  
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  r3   Nr(  r  )r9   r   r   r      r  r5  timeasksbidsr   r   r   T)r  r  r  r   r;  nonce)r  r  find_nearest_ceilingswapPublicGetV3MarketOrderBookr  r  r  parse_order_bookpublicGetMarketsSymbolOrderBookr  r  r  r  sumr  sort_byra  )r  r  r(  r  r  r  r  r  r5  r  r   r  r  
asksResult
bidsResultr  r	  r  s                     r  fetch_order_bookpoloniex.fetch_order_book	  s    	V$fTl
 $Gj!#'#<#<=RTY#Z *==dkk'>Z[K >>+vr:D""4.B((r::77G8TU %%h7	x0x0

q#d)$AA{((1))$A?!!5&/2	 %
 q#d)$AA{((1))$A?!!5&/2	 % X&LLQ5LLQ/"Y/
 	
r  r  c                     U R                  5         U R                  X5      u  p4pVUnU R                  U R                  X25      5      nU R	                  XuU5      $ )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  r  r  r  extraParamsr  networkEntryr  s           r  create_deposit_addresspoloniex.create_deposit_address%
  sY     	7;7_7_`d7m4h11$++g2NO 11(lSSr  c                 6   U R                  5         U R                  X5      u  p4pVUnU R                  U R                  X25      5      n[	        UR                  5       5      n[        U5      n	U	S:  a  [        U R                  S-   5      eU R                  XuU5      $ )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  r  privateGetWalletsAddressesr  r  r  r  r   r3   r  )
r  r  r  r  r  r  r  r  r  lengths
             r  fetch_deposit_addresspoloniex.fetch_deposit_address:
  s     	7;7_7_`d7m4h224;;w3OP HMMO$TA:  +x  !x  y  y11(lSSr  r  c                 `   XR                   ;  a  [        U R                  S-   U-   S-   5      eU R                  U5      nS nU R	                  U5      u  pBUc  [        U R                  S-   U-   S-   5      eS nU R                  XA5      nU R                  US   U5      nUb  US   nOUnSU0nXrX6/$ )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  r3   r  )r   r$   r3   r  handle_network_code_and_paramsr"   r  r  )r  r  r  r  r  exchangeNetworkIdr  r  s           r  r  ,poloniex.prepare_request_for_deposit_addressS
  s    'DGG&RRUYY  ]y  y  z  z==&"AA&I#DGG.f$fim$mps$stt --k@~~hz&:KH# ,T 2 +)
 88r  c                     U R                  US5      nUc  U R                  XS   5      nS nU R                  U5        Ub  U R                  US   S5      nUb  UnUnUUS   U R                  US5      UUS.$ )Naddressr3   r  depositAddressr  r}  )r  r  r}  r  tag)r  check_address)r  r  r  r  r  r  r  s          r  r  &poloniex.parse_deposit_address_specialh
  s    ""8Y7?&&xd1CDG7##!--l6.BDTUN)( (''i@
 	
r  fromAccount	toAccountc                 Z   U R                  5         U R                  U5      nU R                  U R                  S0 5      nU R	                  XsU5      nU R	                  XtU5      n	U R                  X5      US   UU	S.n
U R                  U R                  X5      5      nU R                  X5      $ )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  r3   )r  r  r  r  )	r  r  r  r   r  currency_to_precisionprivatePostAccountsTransferr  parse_transfer)r  r  r  r  r  r  r  r  fromIdtoIdr  r  s               r  r   poloniex.transfer{
  s     	==&7GL!!.{K;G00> !	
 33DKK4PQ ""866r  r   r  c           
      Z    UU R                  US5      S S U R                  US5      S S S S S.	$ )N
transferIdr3   )	r  r3   r   r;  r  r  r  r  r  r  )r  r   r  s      r  r  poloniex.parse_transfer
  sC     ""8\:((48

 
	
r  r  r  c                     U R                  XE5      u  pEU R                  U5        U R                  X5      u  pgpUnU R                  X5      US'   X6S'   Ub  XFS'   U R	                  U R                  Xe5      5      n
U
U	S.nU R                  X5      $ )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  	paymentId)r  withdrawNetworkEntry)handle_withdraw_tag_and_paramsr  r  r  privatePostWalletsWithdrawr  parse_transaction)r  r  r  r  r  r  r  r  r  r  r  withdrawResponses               r  r   poloniex.withdraw
  s     99#F7#7;7_7_`d7m4h 66tD$	?#&K 224;;w3OP !$0
 %%&6AAr  c                     U R                  5         SnU R                  5       nUb  U R                  US-  5      OUSU-  -
  nUUS.nU R                  U R	                  X5      5      n	U	$ )Ni r'  r   )startend)r  secondsparse_to_intprivateGetWalletsActivityr  )
r  r  r  r(  r  yearnowr  r  r  s
             r  fetch_transactions_helper"poloniex.fetch_transactions_helper
  st    lln494E!!%$,/CRTW[R[O
 11$++g2NOP r  c                 n   U R                  5         U R                  XX45      nSnUb  U R                  U5      nU R                  US/ 5      nU R                  US/ 5      nU R	                  XvX#5      n	U R	                  XX#5      n
U R                  X5      nU R                  U R                  US5      XU5      $ )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_limitr  )r  r  r  r(  r  r  r  r  r  withdrawalTransactionsdepositTransactionstransactionss               r  fetch_deposits_withdrawals#poloniex.fetch_deposits_withdrawals#  s     	11$uM!}}T*HoohrB??8Z<!%!8!8PU!]"55h%W(()<U224<<k3Z\`inoor  c                     U R                  XX45      nSnUb  U R                  U5      nU R                  US/ 5      nU R                  XvX#5      nU R	                  XX#5      $ )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  r  r  r(  r  r  r  r  r  s	            r  fetch_withdrawalspoloniex.fetch_withdrawals;  sf     11$uM!}}T*HoohrB..{eS22<uTTr  codesc                 0   U R                  5         U R                  U R                  USS05      5      n0 n[        S[	        U5      5       H8  nX5   n[        UR                  5       5      nU R                  US5      nXh   XH'   M:     U R                  XA5      $ )aS  
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>`
rr  Tr   )	r  r  r  r  r  r  r  r  parse_deposit_withdraw_fees)	r  r  r  r  r  r  r  r   rj  s	            r  fetch_deposit_withdraw_fees$poloniex.fetch_deposit_withdraw_feesO  s     	++DKKA^`d@e,fg0 q#h-(AKEejjl+J))*a8J$0D	 )
 //<<r  c                    0 nU R                  U5      n[        UR                  5       5      n[        S[	        U5      5       GH  nXV   nU R                  U5      nX   n	Ub  U R                  X5      (       d  M8  U R                  U5      n
U R                  X5      XH'   U R                  U	S5      n[	        U5      nUS:  d  M  [        S[	        U5      5       H~  nX   nUR                  US5      nU R                  U5      nU R                  X5      n0 nU R                  US5      nUUb  SOS S.S S S.S.UU'   U R                  XH   S   U5      XH   S'   M     GM     U$ )	Nr   rt   rz  Fr~  rQ  r{  r  )market_codesr  r  r  r  r  r  r  parse_deposit_withdraw_feer  replacer  r  r  )r  r  r  currencyIdKeydepositWithdrawFeesresponseKeysr  rj  r  feeInfor  rt  chainsLengthr  	networkIdr  networkInfonetworkObjectwithdrawFees                      r  r  $poloniex.parse_deposit_withdraw_feesz  s   , %'!!%(HMMO,q#l+,A%J**:6D*G4==#=#===.,0,K,KG,^#)"oog}E";/!#"1c+&67$/N	$-$5$5dB$?	&*&=&=i&H&*ooh&J.0&*&6&6{O&T (38C8OeVZ)
 (,.2(	6k2 AEL_LefpLq  tA  AB+1*=# 8 -8 #"r  c                     U R                  0 5      nXS   US   '   U R                  US5      nU R                  US5      nUUb  SOS S.nS S S.nXcS'   XsS'   U R                  U5      nUUS	.US
   U'   U$ )Nr  r  ru  rz  Fr  r   r|  r{  r  )deposit_withdraw_feer  r  r  )	r  r~  r  depositWithdrawFeer  r  withdrawResultdepositResultr  s	            r  r  #poloniex.parse_deposit_withdraw_fee  s    !66r:7:6"8F#34$$S,7	&&sO<$/$;%$ 

 
 *8:&(59%--i8&$7
:&{3 "!r  c                     U R                  XX45      nSnUb  U R                  U5      nU R                  US/ 5      nU R                  XvX#5      nU R	                  XX#5      $ )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  r  r  r(  r  r  r  r  r  s	            r  fetch_depositspoloniex.fetch_deposits  sf     11$uM}}T*H??8Z<..x5P22<uTTr  c           	      <    SSSSSSSSS.nU R                  X!U5      $ )Nokpendingfailed)COMPLETE	COMPLETEDzAWAITING APPROVALAWAITING_APPROVALPENDING
PROCESSINGzCOMPLETE ERRORCOMPLETE_ERRORr  r  s      r  parse_transaction_status!poloniex.parse_transaction_status  s6    !*!* #&&	
 &99r  transactionc                    SU;   a  US   nU R                  US5      nU R                  US5      nU R                  U5      nU R                  USS5      nU R                  U5      nU R                  US5      nSU;   a  S	OS
nU R	                  USS5      n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  US5      nUS	:X  a  [
        R                  " X5      n0 SU_SU	_SU_SU R                  U5      _SS _SU
_SS _SS _SU_SS _SS _SU_SU_SS _SU_SU_SU R                  U5      _S S UU R                  U5      S S.S.E$ )Nr  r  r   r  r  r  txidwithdrawalRequestsId
withdrawalr|  depositNumberr  	paymentIDr  r~  r  r3   r}  	addressToaddressFromr  tagTotagFromr  updatedr;  )r  r   r  )commentinternalr~  )	safe_timestampr  r  r  r]  r-   
string_subr  ra  )r  r  r  r   rj  r  r  r  r  r3   r  r  r  r  s                 r  r  poloniex.parse_transaction  s   J "[0%j1K''[A	%%k:>
&&z2!!+xC..v6V4 6+ E|I-C_U"";	:{K8''X>((e<<"--lJL
K
"
 
 d''5	

 t
 w
 
 4
 3
 T
 t
 f
 D
 t
 D
  !
" Y/#
$  ))-8)
 	
r  r   c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSnU R	                  SU5      u  pSUc  [        U R                  S-   5      eSnU R                  USS5      u  pcU(       a  SU;  a  [        U R                  S-   5      eUUR                  5       US	   S
.nU R                  U R                  Xs5      5      nU$ )an  
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"r3   )r  r  r  )	r"   r3   r  r  handle_margin_mode_and_paramshandle_param_boolr  !swapPrivatePostV3PositionLeverager  )	r  r   r  r  r  r  r  r  r  s	            r  set_leveragepoloniex.set_leverage8  s     >#DGG.Y$YZZV$
!??vV
#DGG.t$tuu//%H''  3C  )C  D  D!'')Tl

 99$++g:VWr  c                 <   U R                  5         U R                  U5      nSUS   0nSnU R                  SU5      u  pRUc  [        U R                  S-   5      eUR                  5       US'   U R                  U R                  XB5      5      nU R                  Xc5      $ )a9  
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  r3   Nrc   zF fetchLeverage() requires a marginMode parameter "cross" or "isolated"r  )	r  r  r  r"   r3   r  !swapPrivateGetV3PositionLeveragesr  parse_leverage)r  r  r  r  r  r  r  s          r  fetch_leveragepoloniex.fetch_leverageY  s     	V$fTl
 
!??QWX
#DGG.v$vww'--/	99$++g:VWL ""844r  c                 d   S nS nS nS nU R                  US5      n[        S[        U5      5       Hg  nXx   n	U R                  U	S5      nU R                  U	S5      nU R	                  U	S5      n
U R                  U	S5      nUS:X  a  U
nMY  US:X  a  U
nMc  U
nU
nMi     UU R                  XR5      UUUS	.$ )
Nr  r   r  r  r  r  LONGSHORT)r  r  r  longLeverageshortLeverage)r  r  r  r  r  safe_symbol)r  r   r  r  r  rb  r  r  r  r  r  r  s               r  r  poloniex.parse_leverage  s    ! 
~~h/q#d)$AGE''x8H))%;J%%eW5E&&ui8G& $G# %$ % % &&x8$(*
 	
r  c                     U R                  U5      nU R                  US0 5      nU R                  US5      nUS:H  nUU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_modepoloniex.fetch_position_mode  sT     44V< ~~h3""43G#
 	
r  r  c                 d    U(       a  SOSnSU0nU R                  U R                  XS5      5      nU$ )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_modepoloniex.set_position_mode  s;     !wit
 55dkk'6RS r  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  XA5      $ )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  rh  "swapPrivateGetV3TradePositionOpensr  parse_positions)r  rf  r  r  	positionss        r  fetch_positionspoloniex.fetch_positions  sV     	%%g.::6BH NN8VR8	##I77r  positionc                    U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R
                  " Xg5      nU R                  US5      n	U R                  US5      n
[        R
                  " X5      nU R                  0 SU_S	S _SUS   _S
U_SU_SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SS _SU R                  US5      _SS _SU R                  US5      _SS _SU_SU R                  U5      _S U R                  US5      S UUS [        U5      U R                  US5      U R                  US5      U R                  US5      S .
E5      $ )!Nr  r  r  r  ra  rT  	openAvgPxr  r3   notionalr  liquidationPriceliqPx
entryPriceunrealizedPnluplrQ  	contractsr  rV  markPx	lastPricer  r  r  r   r;  mmmgnRatioslTrgPxtpTrgPx)
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager   marginRatior  r  )
r  r^  r  r  r-   r_  safe_positionr  ra  int)r  r/  r  rb  r   r  r   rC  r2  rT  r  rB  s               r  parse_positionpoloniex.parse_position  sK   < ##Hh7!!(3%%h8	++Hi@
##Hg6((48%%h>x/##Hk:''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                    U R                  5         U R                  U5      nU R                  X5      nUS   [        R                  " U5      UR                  5       S.nSU;  a  SUS'   U R                  U R                  Xd5      5      nUS:X  a  [        R                  " U5      nU R                  US5      nU R                  X5      $ )Nr3   )r  rU  r  r  r  reducer  )
r  r  r2  r-   
string_absr  $swapPrivatePostV3TradePositionMarginr  r  parse_margin_modification)	r  r  r  r  r  r  r  r  r  s	            r  modify_margin_helperpoloniex.modify_margin_helper`  s    V$))&9Tl%%f-JJL
 V#!'GI<<T[[=YZ 8''/F~~h/--d;;r  r  c                     U R                  US5      nU R                  X25      nU R                  US5      nUS:X  a  SOSnUUS   US U R                  US5      S S SS S S.
$ )	Nr  r  ADDaddrK  rU  r  )
r  r  r  r  r  r`  r  r  r   r;  )r  r^  r  )r  r  r  rb  r  r  s         r  rN  "poloniex.parse_margin_modification  s~    ##D(3!!(3""40 E)uX&&&tU3
 	
r  c                 *    U R                  X* SU5      $ )a#  
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>`
rK  rO  r  r  r  r  s       r  reduce_marginpoloniex.reduce_margin  s     (((FKKr  c                 (    U R                  XSU5      $ )a  
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>`
rS  rV  rW  s       r  
add_marginpoloniex.add_margin  s     ((GGr  c                 "    U R                  5       $ r  )milliseconds)r  s    r  r  poloniex.nonce  s      ""r  r   GETc                    U R                   S   S   nU R                  USS/5      (       a  U R                   S   S   nSU;   a  U R                  US   5      US'   U R                  X@R	                  U5      5      nU R                  X5      n	US:X  d  US:X  a(  USU	-   -  nU(       a  US	U R                  U5      -   -  nGO6U R                  5         [        U R                  5       5      n
US
-   nUSU	-   -  nUSU	-   -  nUS:X  d  US:X  d  US:X  a1  US
-  nU(       a  U R                  U5      nUSU-   S-   -  nUSU
-   -  nOZU R                  SU
0U5      nU R                  U5      nUS
U R                  U5      -   -  nU(       a  US	U R                  U5      -   -  nU R                  U R                  U5      U R                  U R                  5      [         R"                  S5      nSU R$                  U
US.nXsXeS.$ )Nr   r>   r   r   r@   r  r   r  ?
POSTPUTDELETEzrequestBody=&zsignTimestamp=signTimestampbase64zapplication/json)zContent-Typekeyrh  	signature)urlmethodbodyheaders)r   r  encode_uri_componentr  extract_paramsimplode_params	urlencodecheck_required_credentialsrN  r  jsonr  keysorthmacencodesecrethashlibsha256apiKey)r  pathr   rm  r  ro  rn  rl  queryimplodedPathr   authsortedQueryrk  s                 r  signpoloniex.sign  s   iiv&==|];<<))E"6*Cv#889IJF8		&"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 dOOr  reasonrl  rm  ro  rn  c
                 &   Uc  g U R                  US5      n
U
bx  U
S:w  ar  US   nU R                  US5      nU R                  S-   U-   nU R                  U R                  S   X5        U R	                  U R                  S   X5        [        U5      eg )Nr  200messager  r  r  )r  r3   throw_exactly_matched_exceptionr9  throw_broadly_matched_exceptionr   )r  r  r  rl  rm  ro  rn  r  requestHeadersrequestBodyresponseCode	codeInnerr  feedbacks                 r  handle_errorspoloniex.handle_errors  s     ''&9$<5+@ (I&&x;Gww}t+H001I9_001I7]))r   r  )NN)f__name__
__module____qualname____firstlineno__r   r  r   r  r  rN  r   r   r  r  r  r  r  dictr  r  r  r1  r   rd  r   r   ro  r   r  r  r   r  r  r   r  r  r   r  r  r  r  r  r   r   floatr   r&  r!  r?  rE  rK  rQ  rU  rY  r   rl  rs  r   rz  r   r  r
   r  r  r  r  r   r   r	   r  r   r   r  r  r  r  r  r  r  r  r  rG  r  r   r  r  r!  boolr'  r   r-  rH  r   rO  rN  rX  r[  r  r  r  __static_attributes____classcell__)r  s   @r  r/   r/      s   _# _B7
 7
4 7
r 9=4^bkm NL# NL# NLS NLX[ NLrvw{r| 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` ') SZ S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: T3 Tn T* 79 T# T^ T2 MO 9 9T 9SV 9*
Q_ 
& [] 7S 7% 7c 7c 7an 7@
t 
x 
= 
$ KOWY !BS !B% !B# !BC !B^i !BF 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 :N
T N
X N
Q\ N
` 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N# s  c TX `c  r  r/   )4ccxt.base.exchanger   ccxt.abstract.poloniexr   rz  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  r  <module>r     s}    ( .  G  G  G  G  G  G  G  * 0 - - . ' & . ) * ) 1 * + 4 %C7x C7r  