
    eih                       d dl mZ d dlmZ d dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ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$m0Z0 d dl$m1Z1 d dl$m2Z2 d dl3m4Z4 d dl5m6Z6  G d dee          Z7dS )    )Exchange)ImplicitAPIN)AnyADLBalances
Conversion
CurrenciesCurrencyDepositAddressIntLeverageTierLeverageTiersMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)DuplicateOrderId)DDoSProtection)RateLimitExceeded)CancelPending)	TICK_SIZE)Precisec                       e Zd Zdef fdZddZdefdZdefdZi fde	e
         fdZi fdefd	Zdde
fdZdde
fdZdi fdededefdZd ZddefdZdde
fdZd Zdde
fdZdde
fdZdde
fdZdde
defdZdddi fdedededede	e         f
dZddede
defd Zi fdedefd!Z di fd"e!de"fd#Z#ddi fdededede	e$         fd$Z%dd%ede
de$fd&Z&d' Z'd( Z(i fde)fd)Z*d*e+fd+Z,d,e+fd-Z-d.e+fd/Z.dd0ede
fd1Z/d2 Z0dde
fd3Z1dd0ede
de2fd4Z3di fded,e4d5e5d6e6d7e7f
d8Z8ddi fd9eded,e4d5e5d6e7d7e7fd:Z9di fd9ede+fd;Z:di fde+fd<Z;di fd9ede+fd=Z<dddi fde+dedede	e2         fd>Z=dddi fde+dedede	e2         fd?Z>dddi fde+dedede	e2         fd@Z?dddi fde+dedefdAZ@i fdBedeAfdCZBdddi fdBe+dedede	eC         fdDZDdddi fdBe+dedede	eC         fdEZEd*e+fdFZFddGedHeGdeCfdIZHdi fd"e!de	eI         fdJZJddKede
fdLZKdddi fde+dedefdMZLdde
dNe+fdOZMi fdedeNfdPZOdde
deNfdQZPi fded6e6deQfdRZRdS ZSddTede
deQfdUZTdi fdVede+fdWZUdi fdXeVde+fdYZWdi fd"e!deXfdZZYdde
de	eZ         fd[Z[d\d]i ddfd^Z\di fd_e]de+fd`Z^i fdBed6e6daedbede_f
dcZ`dddi fdBe+dedede	e_         fddZaddeedHeGde_fdfZbd*e+de+fdgZcdddi fde+dedefdhZddi fdBed6e6diedje+deCf
dkZei fdefdlZfdde
fdmZgdi fdnedoed6e7dehfdpZidi fd9ednedoed6e7dehf
dqZjdddi fdBe+dedede	eh         fdrZkddsedteGdueGdehfdvZldi fd"e!de	em         fdwZnddxede
demfdyZodze]d{ed|ed}ed~edefdZp xZqS )phemexreturnc                    |                      t          t          |                                           i ddddddg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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d0dd1dd2dd3di d4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDdEi dFddGddHddIddJddKddLddMddNddOddPddQddRddSddTddUddVdi dWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfddgddhdidjdkdldkdmdndodpdodmdqdrdsdtdudvdwdxi dydzd{d|d}d~dddddddddddddddddddddddddddddddddddddddddiddddddddddd	idddddddddii ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddii dddddddddddddddddddddddddddddddddddddddddddd	ddddddddddddt          dddd|                     d          |                     d          didd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dddddddddddd dddddd d d dddddddddddddddid	ddiddddddddddddiddd idd idd d dddddd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          d*t          d+t          d,t          d-t           d.t           d/t          d0t          d1t          d2t          d3t          d4t          d5t          d6t          d7t          d8t          i d9t          d:t          d;t          d<t          d=t          d>t          d?t          d@t          dAt          dBt          dCt          dDt          dEt          dFt          dGt          dHt          dIt          i dJt          dKt          dLt          dMt          dNt          dOt          dPt          dQt          dRt          dSt          dTt          dUt          dVt          dWt          dXt          dYt          dZt          i d[t          d\t          d]t          d^t          d_t          d`t          dat          dbt          dct          ddt          det          dft          dgt          dht          dit          djt          dkt          i dlt          dmt          dnt          dot          dpt          dqt          drt          dst          dtt          dut          dvt          dwt          dxt          dyt          dzt          d{t          d|t          i d}t          d~t          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          t          t          t          t"          t          t$          t"          t          dt"          t"          t          t          t          t          dddddddddddddddddg dddiddddddd
i          S (  Nidr1   namePhemex	countriesCN	rateLimitg      ^@versionv1	certifiedFproThostnamezapi.phemex.comhasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrderclosePositioncreateConvertTradecreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoriesfetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersemulatedfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionADLRankfetchPositionsfetchPositionsADLRankfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransfersfetchVolatilityHistoryfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModetransferwithdrawurlszchttps://user-images.githubusercontent.com/1294454/85225056-221eb600-b3d7-11ea-930d-564d2690e3f6.jpgz!https://testnet-api.phemex.com/v1zhttps://testnet-api.phemex.comz.https://testnet-api.phemex.com/exchange/public)r;   v2publicprivatezhttps://{hostname}/v1zhttps://{hostname}z"https://{hostname}/exchange/publiczhttps://phemex.comz'https://phemex-docs.github.io/#overviewz"https://phemex.com/fees-conditionsz.https://phemex.com/register?referralCode=EDNVJg?)urldiscount)logotestapiwwwdocfeesreferral
timeframes1m603m1805m30015m90030m18001h36002h72003h108004h144006h2160012h432001d864001w6048001M25920003M77760001Y31104000r   get   )zcfg/v2/productszcfg/fundingRatesproductsznomics/tradeszmd/klinezmd/v2/kline/listzmd/v2/klinezmd/v2/kline/lastmd/orderbookmd/trademd/spot/ticker/24hrz"exchange/public/cfg/chain-settings)	zmd/fullbookr   r   zmd/ticker/24hrzmd/ticker/24hr/allr   zmd/spot/ticker/24hr/allzexchange/public/products)api-data/public/data/funding-rate-history)zpublic/productszpublic/products-pluszmd/v2/orderbookzmd/v2/tradezmd/v2/ticker/24hrzmd/v2/ticker/24hr/allr   zspot/orders/active   spot/orderszspot/walletszexchange/spot/orderzexchange/spot/order/tradeszexchange/order/v2/orderListzexchange/order/v2/tradingListzaccounts/accountPositionszg-accounts/accountPositionszg-accounts/positions   zg-accounts/risk-unitzapi-data/futures/funding-feeszapi-data/g-futures/funding-feeszapi-data/futures/orderszapi-data/g-futures/ordersz#api-data/futures/orders/by-order-idz%api-data/g-futures/orders/by-order-idzapi-data/futures/tradeszapi-data/g-futures/tradeszapi-data/futures/trading-feeszapi-data/g-futures/trading-feesz&api-data/futures/v2/tradeAccountDetailzg-orders/activeListzorders/activeListzexchange/order/listzexchange/orderzexchange/order/tradezphemex-user/users/childrenz%phemex-user/wallets/v2/depositAddressz&phemex-user/wallets/tradeAccountDetailz)phemex-deposit/wallets/api/depositAddressz&phemex-deposit/wallets/api/depositHistz#phemex-deposit/wallets/api/chainCfgz(phemex-withdraw/wallets/api/withdrawHistz&phemex-withdraw/wallets/api/asset/infoz$phemex-user/order/closedPositionListzexchange/margins/transferz!exchange/wallets/confirm/withdrawzexchange/wallets/withdrawListzexchange/wallets/depositListz"exchange/wallets/v2/depositAddresszapi-data/spots/fundszapi-data/spots/ordersz!api-data/spots/orders/by-order-idzapi-data/spots/pnlszapi-data/spots/tradesz!api-data/spots/trades/by-order-idzassets/convertzassets/transferz"assets/spots/sub-accounts/transferz$assets/futures/sub-accounts/transferzassets/quoteordersg-orderszpositions/assignzexchange/wallets/transferOutzexchange/wallets/transferInzexchange/marginszexchange/wallets/createWithdrawzexchange/wallets/cancelWithdrawz&exchange/wallets/createWithdrawAddresszassets/universal-transferz*phemex-withdraw/wallets/api/createWithdrawz*phemex-withdraw/wallets/api/cancelWithdraw)	zspot/orders/creater   zorders/replacezg-orders/replacezg-orders/createzpositions/leveragezg-positions/leveragez g-positions/switch-pos-mode-synczpositions/riskLimit      )r   zspot/orders/allzorders/cancelr   z
orders/allzg-orders/cancelr   zg-orders/all)r   postputdelete)r   r;   r   r   precisionModer   tradingz0.001)	tierBased
percentagetakermakerfeatures)marklastindex)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventiontrailingiceberg   i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r     )	r   rN   createOrdersrv   r|   ry   r~   r\   rw   extendsdefault)r   price)r   r   r     )r   rN   rw   forDerivatives)linearinverse)r   rA   r   rC   rD   requiredCredentials)apiKeysecret
exceptions401412600119999100011000210003100041000511001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611128)11129111301113111132111331113430000300183400335104399953999639997)z401 Insufficient privilegez401 Request IP mismatchzFailed to find api-keyzMissing required parameterz!API Signature verification failedzApi key not found)exactbroadoptions
CCXT123456<   TRXETHBNB)TRC20ERC20BEP20)USDTMKRr   )rA   rC   )BUSDFEITUSDUSDUSDCUSDDUSDPr  fillResponseFromRequestByLastPriceByMarkPriceByIndexPrice
ByAskPrice
ByBidPrice)r   r   r   askbid)
brokerIdx-phemex-request-expirycreateOrderByQuoteRequiresPricenetworksdefaultNetworksdefaultSubTypeaccountsByTypestableCoinsr   triggerPriceTypesMap)deep_extendsuperr1   describer.   parse_numberr!   r%   r*   r)   r-   r'   r(   r    r#   r&   r+   r"   r,   )self	__class__s    W/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/phemex.pyr  zphemex.describe!   s   fd 3 3 < < > > e	A
(e	A
He	A
 $e	A
 	e	A

 te	A
 e	A
 4e	A
 (e	A
  VVV %V 	V
 %V %V UV $UV 'V V "4V tV  V %dV tV  (!V" '#V V$ (%V& "4'V( T)V* !%+V, -V. &u/V0 "51V2 +E3V4 )%5V6 #E7V8 ,U9V: $T;V< $T=V> $U?V@ +DAVB 'CVD (EV V VF "4GVH &tIVJ (KVL 1%MVN  OVP &tQVR #DSVT ,UUVV *4WVX $UYVZ u[V\ "5]V^ *5_V` +EaVb  cVd %deVf +JgV V Vh iVj !%kVl  mVn doVp $TqVr "4sVt uuVv #EwVx dyVz !${V| t}V~ 'V@ !$AVB (CVD %eEVF )%GVH tIV V VJ KVL tMVN "5OVP #EQVR !$SVT )%UVV #DWVX YVZ #E[V\ &u]V^ 4_V` taVb TcVd  eVf "4gVh DiVj DkV Ve	A
@ }=:N?	  2.B3	  ,@<K # # Ae	A
l  de e u	
 v f f g g g w g h i i  j!me	A
P +,,-$%)*$%,-'(,-()$%/0>? " '(()$%*+.//03445EF
 
 +,01+,'(-.12EF 
;,a; &q	;
 '; .q; 5a; 6q; 8; 4Q; 6q; /; /; 8;  :1!;" 21#;$ 4Q%;& >q';( @); ;* 21+;, 4Q-;. 8/;0 :11;2 A!3;4 .q5;6 ,Q7;8 .q9;: )!;;> /?;@ 5aA;B @C;D A!E;F DQG;H A!I;J >qK;L CAM; ; ;N A!O;P ?Q;R 4QS;T <QU;V 8W;X 7Y;Z =a[;\ /];^ 0_;` <Qa;b .qc;d 0e;f <Qg;h )!i;l *1m;n =ao;p ?q; ;r 's; ;x%q !!	
 #A +A 7 6q +A :1 :1 A! *1 =a  ?!" 4Q#$ )!%( Ea)* Ea+2 /0'(*+,-+,./01<=/0  ()+, *+"#&'+,$%() Cn nSX XQe	A
B	 YC	e	A
D	 !&"&!..w77!..w77	 E	e	A
T	 #&+(, %)$(%)- -
 -2).+06:#'#'"&#(	( ( #($)+/27/4$)#(3$ $6 %)&+!$$*%&*/& & ',#($)*.	# # ',!%#($)*.( ( ',!%$(%)#($)*.$ $ ',!$$*,2%&#($)*/	* 	*  #KH HT y  ),0 )-(,)-1 1
 &*7 7 #'$ $  ## #( "#3 "#3 	  ## Ok kU	e	A
l "$ $me	A
t Y.Y :Y J	Y ZY -Y ]Y ]Y ]Y ]Y .Y \Y .Y \Y  .!Y" ]#Y$ ]%Y& ]'Y Y( ])Y* .+Y, \-Y. \/Y0 \1Y2 \3Y4 \5Y6 Z7Y8 ]9Y: ];Y< ]=Y> ]?Y@ ]AYB -CYD ]EYF ]GYH ZIY Y YJ ]KYL YMYN YOYP ]QYR ]SYT ^UYV ^WYX -YYZ \[Y\ \]Y^ \_Y` \aYb \cYd \eYf \gYh \iYj \kY Y Yl \mYn \oYp \qYr \sYt \uYv \wYx \yYz \{Y| \}Y~ \Y@ \AYB \CYD \EYF \GYH \IYJ \KYL \MY Y YN \OYP ]QYR \SYT \UYV \WYX \YYZ \[Y\ \]Y^ \_Y` ]aYb YcYd \eYf \gYh \iYj \kYl \mYn \oY Y Yp \qYr \sYt \uYv \wYx \yYz .{Y| \}Y~ \Y@ -AYB \CYD \EYF \GYH \IYJ \KYL \MYN \OYP \QY Y YR \SYT \UYV \WYX ZYYZ Z[Y\ ]]Y^ ._Y` .aYb ZcYd ZeYf ZgYh .iYj .kYl ]mYn \oYp \qYr \sY Y Yt \uYv \wYx ZyYz \{Y| \}Y~ \Y@ \AYB \CYD \EYF \GYH \IYJ \KYL \MYN \OYP \QYR \SYT \UY YV *)))))''-..-&qY Y Yv 3C/?.A2<9L)< wc cue	A
| (+-37"""  " $ $ #+"$# #	  	  	  .t *)+'') )?& &}e	A
 e	A
 e	 e	 e		    Nc                     ||S |                     d          }d                    |          }|                     d          }|                     |d          S )N,  r   )splitjoinsafe_number)r  valuepartss      r  parse_safe_numberzphemex.parse_safe_number  sS    =LC  C  q)))r  marketc                 Z   |                      |d          }|                      |d          }|                      |d|          }|                      |d          }|                      |d          }|                     |          }|                    dd          }|                     |          }|                     |          }	d}
||k    rd	}
d|vr||k    r|	}|                     |d
          }|                     |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |dd          }d }|	dk    r|                     d          }n[|                    d          r1|                    d          }|                     |d                   }n|                     |          }|                     i d|d|dz   |z   dz   |	z   d|d|d|	d|d|d|dd d!dd"dd d	d#dd$dd%|d&k    d'd	d(|
 |
|                     |                     ||                    |                     |                     ||                    |d d d d |||| 	                    |d)d*          | 
                    |d+          d,|                     d          | 
                    |d-          d.d d d.|                     |                     ||                    |                     |                     ||                    d.d |                     |                      |d/                    d.d0d |d1          S )2NsymbolcontractUnderlyingAssetsbaseCurrencyquoteCurrencysettleCurrencyr  r  FT
priceScale
ratioScale
valueScale
minPriceEp
maxPriceEpmakerFeeRateErtakerFeeRateErstatuscontractSizer  1r   r4   /:basequotesettlebaseIdquoteIdsettleIdtyperC   rA   rB   rD   rE   activeListedcontractr   lotSizeqtyStepSizetickSizeamountr   maxLeverageminmaxmaxOrderQtyr   r  r   costr  r   r   r  expiryexpiryDatetimestrike
optionTyper  r  r  	precisionlimitscreatedinfo)safe_stringsafe_currency_codereplacesafe_integerr  findr  safe_market_structurefrom_ensafe_number_2r  )r  r  r4   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  contractSizeStringr  r  s                         r  parse_swap_marketzphemex.parse_swap_market  s   d fh//#'#3#3F<V#W#W !!&.:RSS""6?;;##F,<==&&v..||C$$''00((22wG"f,,$%--&&v|<<
&&v|<<
&&v|<<
%%fl;;
%%fl;;
))&2BCC))&2BCC!!&(33!--fncJJ V,,S11LL$$S)) 	A ',,S11E,,U1X66LL  ,,-?@@L)) 5+
"5+
dSj5(3.75+
 D5+
 U	5+

 f5+
 f5+
 w5+
 5+
 F5+
 E5+
 e5+
 D5+
 e5+
 e5+
 f(5+
  !5+
" 'k#5+
$ &&t||NJ'O'OPP&&t||NJ'O'OPP("$$$,,VYNN))&*==   ,,S11++FMBB 
   
  ,,T\\*j-Q-QRR,,T\\*j-Q-QRR 
  ,,T-=-=fm-T-TUU  $ i5+
 5+
 5+
 5 5 5	r  c                    |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |          }|                     |          }|                     |d          }|                     |                     |d                    }	|                     |                     |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k    dddd d |                     |d          |                     |d          d d d d d |                     |d          |                     |d          |                     |d          |	|
d d d d!|	|                     |                     |d"                    d!|
d d!|                     |                     |d#                    |                     |                     |d$                    d!d%|                     |d&          |d'          S )(Nr  r  r  r  r  baseTickSizequoteTickSizer4   r  r  r  r  r  r  r  rA   TrB   FrC   rD   rE   r  r  r  r   defaultTakerFeedefaultMakerFeer  r  r  r  r  maxBaseOrderSizeminOrderValuemaxOrderValuer  listTimer  )safe_string_lowerr  r  r  r	  r  r  )r  r  r  r4   r  r  r  r  r  precisionAmountprecisionPrices              r  parse_spot_marketzphemex.parse_spot_market  s'   J %%ff55fh//""6?;;!!&.99&&v..''00!!&(33001A1A&.1Y1YZZ//0@0@0Y0YZZ)) 5+
"5+
dSj5(5+
 D5+
 U	5+

 d5+
 f5+
 w5+
 5+
 D5+
 D5+
 e5+
 E5+
 e5+
 e5+
 f(5+
  !5+
" d#5+
$ %%f.?@@%%f.?@@ "++FLAA++FLAA++FLAA)'    
 +11$2B2B6K]2^2^__ 
 * 
  11$2B2B6?2[2[\\11$2B2B6?2[2[\\  $ ((<<i5+
 5+
 5+
 5 5 5	r  c                 n  K   |                      |          }|                     |          }t          j        ||g  d{V \  }}|                     |dg           }|                     |di           }|                     |dg           }|                     |dg           }	|                     ||	          }|                     |dg           }
|                     |dg           }|                     |
|          }
|                     |dg           }|                     |
d          }|                     |d          }|                     |d	          }g }t          d
t          |                    D ]?}||         }|                     |d          }|dk    s|dk    s|dk    r|                     |d          }|                     ||i           }|                     ||          }|                     ||i           }|                     ||          }|                     |          }nq|                     |d          }|                     ||i           }|                     |dd          }|                     |d|i          }|                     |          }|                    |           A|S )a  
        retrieves data on all markets for phemex

        https://phemex-docs.github.io/#query-product-information-3

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Ndatar   perpProductsV2
riskLimitsriskLimitsV2
currenciesr  currencyr   r  	perpetualperpetualv2perpetualpilotr  r  8)v2GetPublicProductsv1GetExchangePublicProductsasynciogather
safe_value	safe_dict	safe_listarray_concatindex_byrangelenr  r  extendr  r  append)r  paramsv2ProductsPromisev1ProductsPromise
v2Products
v1Productsv1ProductsDatav2ProductsDatar   perpetualProductsV2r  r  r   riskLimitsByIdv1ProductsByIdcurrenciesByCoderesultir  r  r4   riskLimitValuesv1ProductsValuesr  currencyValuesr  s                             r  fetch_marketszphemex.fetch_markets  s      !44V<<l !<<VDD'.~8IK\7]'^!^!^!^!^!^!^
JVR@@H 
FB??>>.*bAA"nn^=MrRR$$X/BCC^^NL"EE
~~nnbII&&z<@@
^^NL"EE
z8<<~x@@==Z@@q#h--(( 	" 	"Aa[F))&&99D##)>)>DL\D\D\%%fh77"&..R"H"HV_==#'>>."b#I#I V-=>>//77#//GG!%0@,PR!S!S!--nlCPP
VlJ-GHH//77MM&!!!!r  c                   K   |                      |           d{V }|                     |di           }|                     |dg           }i }t          dt          |                    D ]d}||         }|                     |d          }|                     |          }	|                     |d          }
t          |
          }|                     |d          }|                     |d          }d}d}d}|z|                     |
          }|                     |          }|                     t          j
        ||                    }|                     t          j
        ||                    }|                     |||	|                     |d	          |                     |d
          dk    ddd|||ddddd|ddd          ||	<   f|S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Nr  r   r   r!  r  
minValueEv
maxValueEvr5   r  r  r  )r  r   crypto)r4   r  coder5   r  depositr   feer   r  r  r  r  )r&  r*  r/  r0  r  r  intparse_precisionr  r/   
string_mulsafe_currency_structure)r  r3  responser  r   r>  r?  r!  r4   rH  valueScaleStringr  rE  rF  	minAmount	maxAmountr   precisionStrings                     r  fetch_currencieszphemex.fetch_currenciesf  s      11&99999999 x44__T<<<
q#j//** '	 '	A!!}H!!(J77B**2..D#//,GG-..J))(LAAJ))(LAAJ!I!I!I%"&"6"67G"H"H --o>>	 --g.@_.].]^^	 --g.@_.].]^^	77 ((6::**8X>>(J &  )( 
  $#! !	 	 )  -9 9  F4LL0 r  r   r   c                 @   |t          | j        dz             |                     ||          }|d         r|                     ||          }|                     |                     |                     ||          |                    |                     |          gS )Nz/ customParseBidAsk() requires a market argumentrA   )r$   r4   r  from_evr  from_ep)r  bidaskpriceKey	amountKeyr  r  s         r  custom_parse_bid_askzphemex.custom_parse_bid_ask  s    >#DG._$_```!!&)44&> 	2\\&&11Fdll4+;+;FH+M+MvVVWWf%%
 	
r  bidsasksc	           
         |||                      |          d d}	||g}
t          dt          |
                    D ]x}|
|         }g }|                     ||          }t          dt          |                    D ]3}|                    |                     ||         |||                     4||	|<   y|                     |	|         dd          |	|<   |                     |	|         d          |	|<   |	S )N)r  	timestampdatetimenoncer   T)iso8601r/  r0  r*  r2  r[  sort_by)r  	orderbookr  r_  bidsKeyasksKeyrY  rZ  r  r>  sidesr?  sider   bidasksks                   r  custom_parse_order_bookzphemex.custom_parse_order_book  s	   "Y//	
 
 '"q#e**%% 	" 	"A8DFooi66G1c'll++ b bd77
HiY_``aaaa!F4LL,,vg4@@w,,vg::wr  r  r   c           
        K   |                                   d{V  |                     |          }d|d         i}d}|d         dk    p|d         dk    }|d         r2|r0|                     |                     ||                     d{V }ng|6|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d	i           }|                     |d
di           }	|                     |dd          }
| 	                    |	||
dddd|          }| 
                    |d          |d<   |S )a_  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryorderbook

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nr  r4   r  r  r  r      r>  bookorderbook_pr_  ư>r\  r]  r   r   sequencera  )load_marketsr  v2GetMdV2Orderbookr1  v1GetMdOrderbookv1GetMdFullbookr*  safe_value_2safe_integer_productrk  r  )r  r  r   r3  r  requestrO  isStableSettledr>  rn  r_  rd  s               r  fetch_order_bookzphemex.fetch_order_book  s      !!!!!!!!!V$$fTl
 !(+v5V6(;Kv;U( 	T 	T!44T[[&5Q5QRRRRRRRRHH!!%!6!6t{{7F7S7S!T!TTTTTTT!%!5!5dkk'66R6R!S!SSSSSSS4 8R88  CC--fk8LL	00vy&RXZ[]^`fgg	!..vzBB	'r  c                     |                      |          }t          |          }|j        |z
  |_        |                                 t	          |          }|                     |          S N)number_to_stringr/   decimalsreducestrparse_to_numeric)r  nscalestringNprecisepreciseStrings         r  to_enzphemex.to_en   sa    ''**'"""+e3G$$]333r  c                 F    |||S |                      ||d                   S Nr  r  )r  r  r  s      r  to_evzphemex.to_ev  s)    NMzz&&"6777r  c                 F    |||S |                      ||d                   S Nr  r  )r  r   r  s      r  to_epzphemex.to_ep  s)    Mv~Lzz%!5666r  c                     ||d S t          |          }|                     |j        |          |_        |                                 t	          |          S r|  )r/   sumr~  r  r  )r  enr  r  s       r  r
  zphemex.from_en  sP    :4"++88G$4e<<7||r  c                 b    |||S |                      ||                     |d                    S r  r
  r  )r  epr  s      r  rW  zphemex.from_ep  4    JFNI||B 1 1&, G GHHHr  c                 b    |||S |                      ||                     |d                    S r  r  )r  evr  s      r  rV  zphemex.from_ev  r  r  c                 b    |||S |                      ||                     |d                    S )Nr  r  )r  err  s      r  from_erzphemex.from_er$  r  r  c                    |F|d         r>|                      |                     |                     |d          |                    }n|                     |d          }|                     |d          |                      |                     |                     |d          |                    |                      |                     |                     |d          |                    |                      |                     |                     |d          |                    |                      |                     |                     |d          |                    |gS )NrA      r   r      r      )r  rV  r  r  safe_timestamprW  )r  ohlcvr  
baseVolumes       r  parse_ohlcvzphemex.parse_ohlcv)  s9    F6N**4<<8H8HPQ8R8RTZ+[+[\\JJ))%33Jq))dll4+;+;E1+E+EvNNOOdll4+;+;E1+E+EvNNOOdll4+;+;E1+E+EvNNOOdll4+;+;E1+E+EvNNOO
 	
r  r   	timeframesincec                 $  K   |                                   d{V  |                     |          }|}|d         |                     | j        ||          d}|                     |dd          }	|                     |dg          }|d         dk    p|d         dk    }
|d	         s|
o|dup|	du}d
}|rd}||}t          ||          |d<   d}|d	         s|
r|	||                     |          }|%t          t          |d
z                      }||d<   n|	dz  ||z  z
  }|	#t          t          |	d
z                      |d<   n)|||z  z   }| 
                                }||k    r|}||d<   |                     |                     ||                     d{V }n|                     |                     ||                     d{V }nx|G|                     |          d
z  }|                                 |z
  }|                     ||z            }|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#querykline
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-kline

        :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]: *only used for USDT settled contracts, otherwise is emulated and not supported by the exchange* 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]: *USDT settled/ linear swaps only* end time in ms
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr4   )r  
resolutionuntiltor  r  r  r   r   r   r   fromd   r  rows)rr  r  r  r   safe_integer_2omitr  parse_timeframerK  roundsecondspublicGetMdV2KlineListr1  publicGetMdV2KlineLastmillisecondsparse_to_intpublicGetMdV2Kliner*  r,  parse_ohlcvs)r  r  r  r  r   r3  r  	userLimitrx  r  ry  usesSpecialFromToEndpointmaxLimitrO  candleDurationr  nowduration	timeDeltar  r  s                        r  fetch_ohlcvzphemex.fetch_ohlcvE  s      !!!!!!!!!V$$	Tl**4?IyQQ
 
 ##FGT::6G9--!(+v5V6(;Kv;U&,X&6&I/$|RW_cRcQ{invziz!$ 	H=Euh//( 	S 	S!u'8!%!5!5i!@!@$edl 3 344E&+GFOO #S[X-FGE$$'edl(;(;$<$<GDMM (^";<B,,..CCxx $&GDM!%!<!<T[[RX=Y=Y!Z!ZZZZZZZ!%!<!<T[[RX=Y=Y!Z!ZZZZZZZ   //	::TA --//%7	)))h*>??!44T[[&5Q5QRRRRRRRRH x44~~dFB//  vy%KKKr  tickerc                 &   |                      |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!|          S )"Nr  r_  rp  lastEpcloseRp
turnoverEv
turnoverRvvolumevolumeEvvolumeRqopenEpr`  highhighEphighRplowlowEplowRpr  bidEp	bidVolumer  askEp	askVolumevwapopencloser   previousClosechanger   average)r  quoteVolumer  )	r  safe_marketrw  rW  safe_string_2r  rV  safe_tickerrb  )
r  r  r  marketIdr  r_  r   r  r  r  s
             r  parse_tickerzphemex.parse_ticker  s   l ##FH55!!(F33!--fk8LL	||D..vxKKVTTll4#5#5flL#Y#Y[abb%%fh77
d&8&8Z&X&XZ`aaJ||D,,VX>>GG !
f!
!
 Y//!
 DLL!3!3FHh!O!OQWXX	!

 4<< 2 267G L LfUU!
 4<< 0 0 A A6JJ!
 !
 4<< 0 0 A A6JJ!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r  c                 ,  K   |                                   d{V  |                     |          }d|d         i}d}|d         rt|d         s|d         dk    r0|                     |                     ||                     d{V }n_|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }|                     ||          S )	a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query24hrsticker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr  r4   rC   r  r  r  r>  )rr  r  v1GetMdTicker24hrr1  v2GetMdV2Ticker24hrv1GetMdSpotTicker24hrr+  r  r  r  r3  r  rx  rO  r>  s          r  fetch_tickerzphemex.fetch_ticker  sI      !!!!!!!!!V$$fTl
 &> 	Vi  XF8$4$=$=!%!7!7GV8T8T!U!UUUUUUU!%!9!9$++gv:V:V!W!WWWWWWW!77GV8T8TUUUUUUUUHZ (B77  000r  symbolsc                   K   |                                   d{V  d}|+|                     |d          }|                     |          }d}|                     d||          \  }}d}|                     d||          \  }}|                     |d          }d}|dk    r|                     |           d{V }nW|dk    s|                     |d          dk    r|                     |           d{V }n| 	                    |           d{V }| 
                    |d	g           }	|                     |	|          S )
a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://phemex-docs.github.io/#query-24-hours-ticker-for-all-symbols-2     # spot
        https://phemex-docs.github.io/#query-24-ticker-for-all-symbols             # linear
        https://phemex-docs.github.io/#query-24-hours-ticker-for-all-symbols       # inverse

        :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>`
        Nr   r   r  rA   r  r  r  r>  )rr  r*  r  handle_market_type_and_paramshandle_sub_type_and_paramsr  v1GetMdSpotTicker24hrAllr  v1GetMdTicker24hrAllv2GetMdV2Ticker24hrAllr,  parse_tickers)
r  r  r3  r  firstr  subTypequeryrO  r>  s
             r  fetch_tickerszphemex.fetch_tickers3  s      !!!!!!!!!OOGQ//E[[''F99.&RXYYf99.&RXYY		&&))6>>!::5AAAAAAAAHH	!!T%5%5fh%G%G5%P%P!66u========HH!88????????H(B77!!&'222r  c                   K   |                                   d{V  |                     |          }d|d         i}d}|d         dk    p|d         dk    }|d         r2|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }	|                     |	d	d
g           }
|                     |
|||          S )aF  
        get the list of most recent trades for a particular symbol

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#querytrades

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr  r4   r  r  r  r   r>  tradestrades_p)rr  r  v2GetMdV2Trader1  v1GetMdTrader*  rv  parse_trades)r  r  r  r   r3  r  rx  rO  ry  r>  r  s              r  fetch_tradeszphemex.fetch_tradesS  s:      !!!!!!!!!V$$fTl
 !(+v5V6(;Kv;U( 	M 	M!00Wf1M1MNNNNNNNNHH!..t{{7F/K/KLLLLLLLLH" 8R88""68ZDD  >>>r  tradec                 ,
   d }d }d }d }d }d }d }	d }
|                      |d          }|                     ||          }|d         }d }d }t          |t                    rt	          |          }|                     |dd          }|dk    r|                      ||dz
            }|                     ||dz
            }|                      ||dz
            }|                      ||dz
            }t          ||dz
           t          j                  r,| 	                    ||          }| 
                    ||          }n|                     |dd          }||                     |d	          }|                     |d
d          }|                      |d          }|d         dk    s|d         dk    r9|                     |d          }|dk    s|dk    r|}n|
|dk    rdnd}|                      |d          }|dk    rd}n|dk    rd}|                      |d          }|                      |d          }|                      |d          }|                     |                      |d                    }|                      |d          }	|-|                      |d          }|                     |          }
n|                     |                      |d                    }||}d}
n|                     |d          }|                     |                      |d                    }|                      |d           }|d!k    rd"}| 	                    |                      |d#          |          }| 
                    |                      |d$          |          }|                      |d%|          }|                     |                     |d&d'          |          }|                     |                     |                      |d(                    |          }||                     |                      |d)          |          }	|d*         r*|                     |                      |d+                    }
n^|                     |d,          }|+|                      |d-          }|                     |          }
n|                      |d          }|d}
||	|
d.}|                     |||||                     |          ||||||||d/|          S )0Nr  r   rp  r  r   r   r   transactTimeNs	createdAtexecIdexecIDorderIDr  r  r  rh  buysellr  ordTyper  2r   execPriceRp	execQtyRqexecValueRv	execFeeRv	feeRateRrr!  ptFeeRvPT
execStatus	MakerFillr   execPriceEpexecBaseQtyEvexecQtyexecQuoteQtyEvexecValueEv	execFeeEv	feeRateErrA   feeCurrencyr  settlementCurrency)r  rater!  )r  r4   r  r_  r`  orderr  rh  takerOrMakerr   r  r  rJ  )r  r  
isinstancelistr0  rw  r  numbersRealrW  rV  r  r  	omit_zeror  parse_order_typer  r*  
safe_traderb  )r  r  r  r4   rh  
costStringr  rJ  feeCostStringfeeRateStringfeeCurrencyCoder  r  orderIdr  tradeLengthr_  priceStringamountStringsideIdr  
currencyIdr  r
  r  settlementCurrencyIds                             r  parse_tradezphemex.parse_trade  sg   r 
!!###E844!!(F33! eT"" E	e**K11%HEEIQ%%e[1_==))%qAAD**5+/BBK++E;?CCL%a0',?? B"ll;??#||L&AA11%9I8TTI  --e[AA	##E8X>>B&&ui88Gh6))VH-=-G-G//v>>eOO6)9)9!DD'%+s]]55D**5)<<c>>#DD^^"D"..umDD#//{CC!--e]CC
 $t/?/?{/S/S T T $ 0 0 D D ,!%!1!1%!D!DJ&*&=&=j&I&IOO"nnT-=-=eY-O-OPPG*(/*.--eV<<,,T-=-=eY-O-OPP!--e\BB
,,#*L"ll4+;+;E=+Q+QSYZZ#||D,<,<UO,T,TV\]]#//y,OO!\\$*<*<UDTVc*d*dflmm
 $T^^D<L<LUT_<`<`-a-aci j j ,$(LL1A1A%1U1UW]$^$^Mf~ \*.*A*A$BRBRSXZgBhBh*i*i#vv>>+373C3CDJ^3_3_0.2.E.EFZ.[.[O$($4$4UI$F$FM$0*.%%+ C
 "Y//( " 
  
   	r  c                 ~   d }d|i}|                      |dg           }t          dt          |                    D ]P}||         }|                     |d          }|                     |          }|                      | j        |i           }	|                     |	dd          }
|                                 }|                     |d          }|                     |d          }|                     |d	          }|                     ||
          }|                     ||
          }|                     ||
          }t          j
        ||          }|                     |d
d          }||nt          ||          }||d<   ||d<   |||<   R||d<   |                     |          |d<   |                     |          S )Nr  r  r   r!  r     	balanceEvlockedTradingBalanceEvlockedWithdrawEvlastUpdateTimeNsrp  totalusedr_  r`  )r*  r/  r0  r  r  r   r  accountr
  r/   
string_addrw  r  rb  safe_balance)r  rO  r_  r>  r  r?  balancer(  rH  r!  r  r3  r-  r.  r/  r1  lockedTradingBalancelockedWithdrawr2  r0  s                       r  parse_spot_balancezphemex.parse_spot_balance  s   2 	)x44q#d))$$ 	# 	#A1gG))':>>J**:66DtbAAH%%ha@@EllnnG((+>>I%)%5%5g?W%X%X"#//9KLLLLE22E#'<<0F#N#N !\\*:EBBN%&:NKKD#88BTV^__-6->((STdEeEeI$GG"GFO"F4LL'{!\\)44z  (((r  c                 L   d|i}|                      |di           }|                      |di           }|                     |d          }|                     |          }|                     |          }|                     |dd          }|                                 }	|                     |dd          }
|                     |d	d
          }|dk    }|r|                     |
|          n|
|	d<   |r|                     ||          n||	d<   |	||<   |                     |          S )Nr  r  r3  r!  r  r,  accountBalanceEvaccountBalanceRvtotalUsedBalanceEvtotalUsedBalanceRvr  r1  r2  )	r*  r  r  r!  r  r3  r  r
  r5  )r  rO  r>  r  r6  r(  rH  r!  r  r3  r;  r=  needsConversions                r  parse_swap_balancezphemex.parse_swap_balance  s6   > )x44//$	266%%gz::
&&z22==&&&&xqAA
,,..--g7IK]^^!//9MOcdd6>IXn4<<(8*EEE^nJYq$,,'9:FFF_qt  (((r  c                 (  K   |                                   d{V  d}|                     dd|          \  }}|                     |d          }|                     |dg          }d}i }|dk    r#|dk    rt	          | j        dz   |z   dz             |dk    rd}|                     |ddd	          \  }}||d}||}n|}|                     |          }|d
         |d<   |d
         d	k    r0|                     | 	                    ||                     d{V }n| 
                    | 	                    ||                     d{V }n|                     |d          }|t          | j        dz   |z   dz             |                     | 	                    ||                     d{V }n/|                     | 	                    ||                     d{V }|dk    r|                     |          S |                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://phemex-docs.github.io/#query-wallets
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
        https://phemex-docs.github.io/#query-trading-account-and-positions

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: spot or swap
        :param str [params.code]: *swap only* currency code of the balance to query(USD, USDT, etc), default is USDT
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        NrU   rH  rA   rC   z does not support z markets, only spot and swapr  r  r4   r!  zP fetchBalance() requires a code parameter or a currency or settle parameter for z type)rr  r  r  r  r%   r4   handle_option_and_paramsr!  #privateGetGAccountsAccountPositionsr1  "privateGetAccountsAccountPositionsr$   privateGetSpotWalletsr@  r9  )	r  r3  r  rH  rO  rx  r  coinr!  s	            r  fetch_balancezphemex.fetch_balance  s      !!!!!!!!!99.$PVWWf//6F8,,FNNTW';;dBEccddd6>>F!::6>S[]cddNFF6#5#DD!D==..&.tn
#D>V++%)%M%MdkkZaciNjNj%k%kkkkkkkHH%)%L%LT[[Y`bhMiMi%j%jjjjjjjHH++FJ??#+DG  7I  -I  LP  -P  SZ  -Z  [  [  [!%!;!;DKKQW<X<X!Y!YYYYYYY!77GV8T8TUUUUUUUUHl 6>>**8444&&x000r  r  c                     i ddddddddddd	dd
dddddddddddddddddddddddi}|                      |||          S )NCreatedr  UntriggeredDeactivatedclosed	TriggeredRejectedrejectedNewPartiallyFilledFilledCanceledcanceled	Suspendedr  r  34567r%  r  r  r  statusess      r  parse_order_statuszphemex.parse_order_status  s    
v
6
 8
 	

 

 6
 v
 h
 

 
 
 
 
 
 
  !
" #
$ %
 
( &&999r  r  c                 N    ddddddddddddd}|                      |||          S )Nr  r   stop	stopLimit)r  r  rV  rW  rX  rY  rZ  r%  910Limitr   r[  )r  r  typess      r  r  zphemex.parse_order_type  sL    
 
 tT222r  r   c                 >    ddddd}|                      |||          S )NGTCr   r   r   )GoodTillCancelPostOnlyImmediateOrCancel
FillOrKillr[  )r  r   timeInForcess      r  parse_time_in_forcezphemex.parse_time_in_force  s4    #!&	
 
 k;GGGr  r  c           
         |                      |d          }|                      |d          }|t          |          dk     rd }|                      |d          }|                     ||          }|d         }|                     |                      |d          |          }|                     |                      |d          |          }|                     |                     |                      |d          |                    }	|                     |                     |dd	          |          }
|                     |                     |d
d          |          }|                     |                      |d          |          }|                     |                      |d                    }| 	                    |d          }| 
                    |                      |d                    }|                     |ddd          }d }|                     |                      |d          |          }|,||                     |                      |d                    d}|                     |                      |d                    }|                     |                     |                     |                      |d                                        }|dk    }|                     i d|d|d|d|d|                     |          dd d|d|d|d |d|d!|d"|d#|d$|d%|d&|
|	||d d'|          S )(Nr  clOrdIDr   r  priceEp	baseQtyEvleavesBaseQtyEvcumBaseQtyEvcumBaseValueEvcumQuoteValueEv
quoteQtyEv
avgPriceEp	ordStatusrh  r  actionTimeNscreateTimeNsrp  cumFeeEvr  r  r!  r   stopPxEpr   r  r4   clientOrderIdr_  r`  lastTradeTimestampr  postOnlyr   r   r  r  r  filled)	remainingr  rJ  r  )r  r0  r  rW  rV  r  r  r  r^  r  r  safe_integer_product_2r  rm  r  
safe_orderrb  )r  r  r  r4   r~  r  r  r   r  r  r  r  r  r  rh  r  r_  rJ  feeCostr   r   r  s                         r  parse_spot_orderzphemex.parse_spot_order  s   r eY//((	::%C,>,>,B,B M##E844!!(F33!T--eY??HHd..ukBBFKKNN4<<0@0@HY0Z0Z\b#c#cdd	d00HXYY[abb||D..u6GVVX^__,,t//|DDfMM(()9)9%)M)MNN%%eV44$$T%5%5eY%G%GHH//~~W_``	,,t//zBBFKK 33D4D4DUM4Z4Z[[ C ..t/?/?}/U/UVV((TEUEUV[]gEhEh8i8i)j)jkk4'  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 f 
 D 
 ; 
  
 D 
 U 
 L 
 f 
 D 
  w! 
" f# 
$ #+ 
  
  
, -  	r  c                 :    ddd}|                      |||          S )Nr  r   )r  r  r[  )r  rh  rg  s      r  parse_order_sidezphemex.parse_order_side?	  s.    
 
 tT222r  c                    |                      |dd          }|                      |dd          }|t          |          dk     rd }|                     |d          }|                     ||          }|                     ||          }|                     |                     |d                    }|                     |                     |d                    }|                     |                     |d	                    }	|                     |d
          }
|
*| 	                    |                     |d          |          }
| 
                    |dd          }| 
                    |dd          }| 
                    |dd          }|                     |dd          }||                     |d          }| 
                    |dd          }|                     |dd          }|dk    rd }|                     |                     |d                    }|                     |                      |dd                    }|dk    }|                     |d          }|                     |d          }|dk    rd }|                     |d!          }|                     |d"          }|                     |                     |d#                    }|                     |                     |d$                    }d }|||d%         d&}n||d'd&}|                     i d(|d)|d*|d+|                     |          d,|d-|d|d.|	d|d/|d|d|d0|
d1|d2|d3|d4||||d ||d d5          S )6Nr  r#  ro  clOrdIdr   r  rx  rh  	orderTypepriceRprp  orderQty
orderQtyRqcumQtycumQtyRq	leavesQtyleavesQtyRqry  rp  r  cumValue
cumValueRvr  r   r   stopPxstopPxRpr   
reduceOnlyexecInst
ReduceOnlyTtakeProfitRp
stopLossRpr  r  r  r|  r	  r  r4   r~  r`  r_  r  r  r  r   r   r   r   r  )r  r  r  r  r  rJ  r  )r  r0  r  safe_symbolr  r^  r  r  r  rW  r  rw  r  rm  r  r*  r  rb  )r  r  r  r4   r~  r  r  r  rh  r  r   r  r  r  r_  r  r  r   r   r  r  r  
takeProfitstopLossfeeValuer  rJ  s                              r  parse_swap_orderzphemex.parse_swap_orderF	  s7   L y)<<**5)YGG%C,>,>,B,B M##E844!!(F33!!(F33(()9)9%)M)MNN$$T%;%;E6%J%JKK$$T%5%5e[%I%IJJ  	22=LL!1!1%!C!CVLLE##E:|DD##E8Z@@&&uk=II	--e^XNN	))%==I!!%\BB!66u>NPXYY""!%..t/?/?}/U/UVV~~d&8&8*&U&UVV4'__UL99
##E:66|##J%%e^<<
##E<88>>$"2"25+"F"FGG..!1!1%!C!CDD "7O CC    C   
E 
" 
 ] 
 Y//	 

  
 !"4 
 f 
 D 
 ; 
  
 * 
 D 
 U 
 L 
 z 
  X! 
" f# 
$ "1 
  
  
   	r  c                     |                      |dd          }d|v pd|v pd|v }|s|r|                     ||          S |                     ||          S )NrC   F	closedPnlclosedPnlRv
totalPnlRv)	safe_boolr  r  )r  r  r  isSwaphasPnls        r  parse_orderzphemex.parse_order	  sq    66&^MU,B^X]H] 	8V 	8((777$$UF333r  rh  r  r   c                 B  K   |                                   d{V  |                     |          }|                     |          }|                     |          }|d         ||d}	|                     |dd          }
|                     |d          }|                     |d          }|du}|du}|d         d	k    p|d         d
k    }|
9|                     | j        dd          }|||                                 z   |	d<   n|
|	d<   |                     |ddg          }| 	                    |g d          }|5|r| 
                    ||          |	d<   n|                     ||          |	d<   |                     |g d          }|d         rk|                     |dd          }|dk    s|dk    s|dk    r|d}||dk    rd|	d<   n|dk    rd|	d<   d|	d<   ||	d<   |dk    r|                     |d          }|                     |d          }| j        d         rv|U|                     |          }|                     |          }t          j        ||          }|                     |          }n|t#          | j        dz   |z   d z             ||n|}|                     |          }|                     ||          |	d!<   ni|                     |          }|                     ||          |	d"<   n9|d#         r0|                     |d$d%          }|                     |d$          }|                     |d&          }|G|rC|                     |d'          }|r |d(k    rd)nd(}|                     |d'          }|d(k    rd*nd+}nd,}|                     |          }||	d&<   |r||	d-<   n|                     |          |	d.<   ||                     |d/d0          }||	d/<   d}|                     |d1          \  }}|t#          | j        d2z             |d3k    s|d4k    r(|d)k    r|dk    rdnd5|	d<   nG|d(k    r|dk    rdnd|	d<   n3|d6k    s|d7k    r'|d)k    r|dk    rdnd|	d<   n|d(k    r|dk    rdnd5|	d<   |s|r|r|                     |d8d9          }|t3          | j        d:z             |r| 
                    ||          |	d;<   n|                     ||          |	d<<   |                     |d=d>          }|%|                     | j        d?         ||          |	d><   |                     |d@          }|| 
                    ||          |	dA<   |r|                     |d8d9          } | t3          | j        dBz             |r| 
                    ||           |	dC<   n|                     | |          |	dD<   |                     |d=dE          }!|!%|                     | j        d?         |!|!          |	dE<   |                     |d@          }"|"| 
                    ||"          |	dF<   |dk    s|dk    s|d5k    rJ|r| 
                    ||          |	dG<   n.|                     |          }|                     ||          |	dH<   |                     |dI          }#|#K|r| 
                    ||#          |	dC<   n|                     |#|          |	dD<   |                     |dI          }|                     |dJ          }$|$K|r| 
                    ||$          |	d;<   n|                     |$|          |	d<<   |                     |dJ          }d}%|r0|                     |                     |	|                     d{V }%ng|dK         r0|                     |                     |	|                     d{V }%n/|                     |                     |	|                     d{V }%|                     |%dLi           }&|                     |&|          S )Ma  
        create a trade order

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#place-order
        https://phemex-docs.github.io/#place-order-http-put-prefered-3

        :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.trigger]: trigger price for conditional orders
        :param dict [params.takeProfit]: *swap only* *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: take profit trigger price
        :param dict [params.stopLoss]: *swap only* *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: stop loss trigger price
        :param str [params.posSide]: *swap only* "Merged" for one way mode, "Long" for buy side of hedged mode, "Short" for sell side of hedged mode
        :param bool [params.hedged]: *swap only* True for hedged mode, False for one way mode, default is False
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr4   )r  rh  r  ro  r~  r  r  r  r  r  r  r  )r  	stopPricer   r  r}  )r  r  r  r  r   rA   qtyTypeByBaser   StopMarketIfTouchedByQuoterd  	StopLimitr  r  r   r  r  z createOrder() z. requires a price argument or a cost parameterrv  rq  rC   r   FposSider  r  r   LongShortMergedr  r  triggerTyper  r   zi createOrder() also requires a 'triggerDirection' parameter with either 'ascending' or 'descending' value	ascendingupLimitIfTouched
descendingdownr   r  zc createOrder() requires a trigger price in params["stopLoss"]["triggerPrice"] for a stop loss orderr  
stopLossEpr   	slTriggerr  r   slPxRpzg createOrder() requires a trigger price in params["takeProfit"]["triggerPrice"] for a take profit orderr  takeProfitEp	tpTriggertpPxRpr  rp  r   r   r  r  ) rr  r  
capitalizer  r*  r  r  uuid16r  safe_string_nprice_to_precisionr  r  r}  r/   rM  r  r$   r4   r  r  r  r  handle_param_stringrv  r(   privatePostGOrdersr1  privatePostOrdersprivatePostSpotOrdersr+  r  )'r  r  r  rh  r  r   r3  r  requestSiderx  r~  r  r  hasStopLosshasTakeProfitry  r  r   r  r  r&  r%  quoteAmountr  r   r  r  r  r   stopLossTriggerPricestopLossTriggerPriceTypeslLimitPricetakeProfitTriggerPricetakeProfitTriggerPriceTypetpLimitPricer   r   rO  r  s'                                          r  create_orderzphemex.create_order	  s 
     , !!!!!!!!!V$$ood++t$$ Tl	
 
8 **69oNN??6:66__V\::
t+#4/!(+v5V6(;Kv;U ''j,OOH#%-%=	"!.GIYYv	?'CDDF))&2Y2Y2YZZ# G&*&=&=fl&S&S
##&*jjv&F&F
#6#d#d#dee&> _	ZoofiBBG  dfnn$BS:S:S$'G'7??)4GI&&X%%)/GI&%2	"!(GI)##''776622< AB J('+'<'<V'D'D&*&;&;E&B&B&-&8{&S&S#00==/:K0Kg0U  YI  1I  J  J  J"&,vvT!22488
(,

:v(F(F%%#44V<<'+zz,'G'G$$F^ B	Z^^FHe<<FYYvx00F,,VY??G '!%!E!EJ! A*.%--vve!%6<!@!@)-ffWGG&Goog..G!(GI @(.%%&*&7&7&?&?
#'"..v}mTT)4&#' +/+C+CFL^+_+_( &#++DG  7b  -b  c  c  c#{226F$6N6Nv~~CG8CSCS->->Zj	**8<8H8HVV{	*%559IV9S9Sv~~8<8H8HVV{	**CG8CSCS->->Zj	* Zm Z Z+/+<+<X~Wb+c+c(+3*47  6[  ,[  \  \  \& Y040G0GPd0e0e--04

;OQW0X0X-/3/A/A(L^`k/l/l,/;/3/?/?Mc@df~  AY  0Z  0Z,#'#3#3Hg#F#FL#/,0,C,CFL,Y,Y)  Z-1->->z>[f-g-g*-5*47  6_  ,_  `  `  `& ]262I2I&Rh2i2i//26**=SU[2\2\/151C1CJPbdo1p1p.1=/3/?/?Mc@d  gA  C]  0^  0^,#'#3#3J#H#HL#/,0,C,CFL,Y,Y)GOO!4!4$BR:R:R E%)%<%<VU%K%K	"""33E::%)ZZV%D%D	"**63DEE& N*.*A*A&/*Z*Z''*.**_f*M*M'YYv'899F((AA$ J(,(?(?(V(V%%(,

=&(I(I%YYv77F 	V!44T[[&5Q5QRRRRRRRRHHJ 	V!33DKK4P4PQQQQQQQQHH!77GV8T8TUUUUUUUUHZ ~~h33f---r  r4   c                   K   |                                   d{V  |                     |          }d|d         i}	|                     |dd          }
|                     |ddg          }|d         dk    p|d         dk    }|
|
|	d<   n||	d	<   |;|r |                     |d         |          |	d
<   n|                     ||          |	d<   |                     |d          }|                     |dg          }|||	d<   n=|;|r |                     |d         |          |	d<   n|                     ||          |	d<   | 	                    |g d          }|5|r|                     ||          |	d<   n|                     ||          |	d<   |                     |g d          }d}|rM|                     |d          }|d|	d<   | 
                    |                     |	|                     d{V }ng|d         r0|                     |                     |	|                     d{V }n/|                     |                     |	|                     d{V }|                     |di           }|                     ||          S )aB  
        edit a trade order

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#amend-order-by-orderid

        :param str id: cancel 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 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 str [params.posSide]: either 'Merged' or 'Long' or 'Short'
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r4   r~  ro  r  r  r  r  r  rp  rq  	baseQtyEVr  )r   r  r  r  r}  r  r  rC   r  )rr  r  r  r  r  r  r  amount_to_precisionr  r  privatePutGOrdersReplacer1  privatePutOrdersReplaceprivatePutSpotOrdersr+  r  )r  r4   r  r  rh  r  r   r3  r  rx  r~  ry  finalQtyr   rO  r  r  s                    r  
edit_orderzphemex.edit_order  s
       !!!!!!!!!V$$fTl
 **6?INN6OY#?@@!(+v5V6(;Kv;U$!.GI!#GI ?%)%<%<VH=Mu%U%U	""%)ZZv%>%>	"##FK886K=11#+GK   B(,(@(@AQSY(Z(Z%%'+zz&&'A'A$))&2Y2Y2YZZ# G&*&=&=fl&S&S
##&*jjv&F&F
#6#J#J#JKK 	U&&vy99G%-	"!::4;;wPV;W;WXXXXXXXXHHF^ 	U!99$++gv:V:VWWWWWWWWHH!66t{{7F7S7STTTTTTTTH~~h33f---r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }|||d<   n||d<   d}|d         d	k    s|d         d
k    rM|                     |d          }|d|d<   |                     |                     ||                     d{V }ng|d         r0| 	                    |                     ||                     d{V }n/| 
                    |                     ||                     d{V }|                     |di           }	|                     |	|          S )a
  
        cancels an open order

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#cancel-single-order-by-orderid

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.posSide]: either 'Merged' or 'Long' or 'Short'
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentr  r4   r~  ro  r  r  r  r  r  r  rC   r  )r$   r4   rr  r  r  r  r  privateDeleteGOrdersCancelr1  privateDeleteOrdersCancelprivateDeleteSpotOrdersr+  r  )
r  r4   r  r3  r  rx  r~  rO  r  r  s
             r  cancel_orderzphemex.cancel_orderN  s      >#DG.Y$YZZZ!!!!!!!!!V$$fTl
 **6?INN6OY#?@@$!.GI!#GI(v%%)9V)C)C&&vy99G%-	"!<<T[[RX=Y=YZZZZZZZZHHF^ 	X!;;DKKQW<X<XYYYYYYYYHH!99$++gv:V:VWWWWWWWWH~~h33f---r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }|                     |ddd          }|                     |ddg          }d|d         i}|r||d<   d}|d	         d
k    s|d	         dk    r0|                     |                     ||                     d{V }ng|d         r0|                     |                     ||                     d{V }n/| 	                    |                     ||                     d{V }| 
                    d|i          gS )a  
        cancel all open orders in a market

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#cancelall

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentr`  r   Fr  r4   untriggerredr  r  r  rC   r  )r$   r4   rr  r  rv  r  privateDeleteGOrdersAllr1  privateDeleteOrdersAllprivateDeleteSpotOrdersAllr  )r  r  r3  r  r   rx  rO  s          r  cancel_all_orderszphemex.cancel_all_orderst  s      >#DG.]$]^^^!!!!!!!!!V$$##FFIuEE6FI#677fTl

  	.&-GN#(v%%)9V)C)C!99$++gv:V:VWWWWWWWWHH F^ 
	[!88Wf9U9UVVVVVVVVHH "<<T[[RX=Y=YZZZZZZZZH OO  
 	
r  c                 b  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }|||d<   n||d<   d}|d         d	k    s|d         d
k    r0|                     |                     ||                     d{V }ng|d         r0|                     |                     ||                     d{V }n/| 	                    |                     ||                     d{V }| 
                    |di           }|}	t          |t                    rut          |          }
|
dk     rH|#t          | j        dz   |z   dz   |z   dz             t          | j        dz   |z   dz   |z   dz             |                     |di           }	n6|d         r.|                     |dg           }|                     |di           }	|                     |	|          S )a  

        https://phemex-docs.github.io/#query-orders-by-ids

        fetches information on an order made by the user
        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr  r4   r~  ro  r  r  r  r  rA   r  r   z fetchOrder() z order with clientOrderId z
 not foundz order with id r   r  )r$   r4   rr  r  r  r  (privateGetApiDataGFuturesOrdersByOrderIdr1  %privateGetApiDataSpotsOrdersByOrderIdprivateGetExchangeOrderr*  r  r  r0  r)   r+  r,  r  )r  r4   r  r3  r  rx  r~  rO  r  r  	numOrdersr  s               r  fetch_orderzphemex.fetch_order  s      >#DG.X$XYYY!!!!!!!!!V$$fTl
 **6?INN6OY#?@@$!.GI!#GI(v%%)9V)C)C!JJ4;;W^`fKgKghhhhhhhhHHF^ 	X!GGT[]cHdHdeeeeeeeeHH!99$++gv:V:VWWWWWWWWHx44dD!! 
	0D		I1}} ,'2B(BV(KNj(jmz(z  ~J  )J  K  K  K'2B(BV(KN_(_bd(dgs(stttNN4B//EEF^ 	0>>$33DNN4B//Ev...r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |||d<   d}|d         dk    s|d         d	k    r;|d         |d
<   |                     |                     ||                     d{V }ng|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }| 	                    |d|          }	| 
                    |	|||          S )aU  
        fetches information on multiple orders made by the user

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryorder

        :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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz) fetchOrders() requires a symbol argumentr  r4   startr   r  r  r  r!  rC   r  r  )r$   r4   rr  r  "privateGetExchangeOrderV2OrderListr1  privateGetExchangeOrderListprivateGetApiDataSpotsOrdersr*  r,  parse_orders
r  r  r  r   r3  r  rx  rO  r  r  s
             r  fetch_orderszphemex.fetch_orders  s      >#DG.Y$YZZZ!!!!!!!!!V$$fTl
 $GG$GG(v%%)9V)C)C"("2GJ!DDT[[QXZ`EaEabbbbbbbbHHF^ 	]!==dkk'SY>Z>Z[[[[[[[[HH!>>t{{7TZ?[?[\\\\\\\\Hx44~~dFD11  vue<<<r  c                   K   |                                   d{V  |t          | j        dz             |                                   d{V  |                     |          }d|d         i}d}	 |d         dk    s|d         dk    r0|                     |                     ||                     d{V }ng|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }n0# t          $ r#}t          |t                    rg cY d}~S |d}~ww xY w|                     |d	i           }	t          |	t                    r|                     |	|||          S |                     |	d
g           }
|                     |
|||          S )a  
        fetch all unfilled currently open orders

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryopenorder
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#spotListAllOpenOrder

        :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 order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz- fetchOpenOrders() requires a symbol argumentr  r4   r  r  r  rC   r  r  )rr  r$   r4   r  privateGetGOrdersActiveListr1  privateGetOrdersActiveListprivateGetSpotOrders	Exceptionr  r)   r*  r  r  r,  )r  r  r  r   r3  r  rx  rO  er  r  s              r  fetch_open_orderszphemex.fetch_open_orders   s      !!!!!!!!!>#DG.]$]^^^!!!!!!!!!V$$fTl
 
	h6))VH-=-G-G!%!A!A$++gW]B^B^!_!_______ Y!%!@!@WV\A]A]!^!^^^^^^^!%!:!:4;;wPV;W;W!X!XXXXXXX 	 	 	!]++ 						G	 x44dD!! 	A$$T65%@@@>>$33D$$T65%@@@s%   2B/D" "
E,E
EE

Ec                 *  K   |                                   d{V  d}||                     |          }i }||d         |d<   |||d<   |||d<   d}||                     |d          dk    rJ|                     |dd          |d<   |                     |                     ||                     d{V }ng|d	         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d
i           }t          |t                    r| 
                    ||||          S |                     |dg           }	| 
                    |	|||          S )a  
        fetches information on multiple closed orders made by the user

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#queryorder
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#queryorder
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedgedd-Perpetual-API.md#query-closed-orders-by-symbol
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#spotDataOrdersByIds

        :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 str [params.settle]: the settlement currency to fetch orders for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nr4   r  r  r   r  r  r!  rC   r  r  )rr  r  r  r  r1  r  privateGetExchangeSpotOrderr*  r  r  r  r,  r  s
             r  fetch_closed_orderszphemex.fetch_closed_orders)  s       !!!!!!!!![[((F
 &tGH$GG$GGN 0 0 B Bf L L"&"2"268V"L"LGJ!DDT[[QXZ`EaEabbbbbbbbHHF^ 	\!==dkk'SY>Z>Z[[[[[[[[HH!==dkk'SY>Z>Z[[[[[[[[HJ x44dD!! 	A$$T65%@@@>>$33D$$T65%@@@r  c                 n  K   |                                   d{V  d}||                     |          }d}|                     d||          \  }}i }|t          d|          }||d<   |dk    o|du p|                     |d          dk    }|rd|d<   d	|d
<   |d|d<   n||d         |d<   |||d<   d}	|r0|                     |                     ||                     d{V }	nj|dk    r5d|d<   |                     |                     ||                     d{V }	n/|                     |                     ||                     d{V }	d}
|r| 	                    |	dg           }
n.| 	                    |	di           }
| 	                    |
dg           }
| 
                    |
|||          S )a  
        fetch all trades made by the user

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-user-trade
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-user-trade
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#spotDataTradesHist

        :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
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nrv   r   r   rA   r  r  r!  r   offsetr4   r  r  rC   r   	tradeTyper  r  )rr  r  r  r  r  $privateGetExchangeOrderV2TradingListr1  privateGetExchangeOrderTrade!privateGetExchangeSpotOrderTradesr*  r  )r  r  r  r   r3  r  r  rx  isUSDTSettledrO  r  s              r  fetch_my_tradeszphemex.fetch_my_tradesx  s8      !!!!!!!!![[((F99/6SYZZfUOOE$GGqv~.p4CSCSTZ\dCeCeioCo 	-"(GJ !GH}#&  &tGH$GG 	b!FFt{{SZ\bGcGcddddddddHHV^^#*GK !>>t{{7TZ?[?[\\\\\\\\HH!CCDKKPWY_D`D`aaaaaaaaHR  	5??8VR88DD??8VR88D??444D  vue<<<r  rH  c                   K   |                                   d{V  |                     |          }d|d         i}|                     | j        d          }|                     ||          }|                     | j        di           }|                     |dd|          }|                     |||          }|t          | j        dz             ||d<   | 	                    |d          }| 
                    |                     ||                     d{V }	|                     |	d	i           }
|                     |
d
          }|                     |
d          }|                     |           |	|d||dS )a  
        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the chain name to fetch the deposit address e.g. ETH, TRX, EOS, SOL, etc.
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nr!  r4   r  r  network	chainNamez3 fetchDepositAddress() requires a network parameterr  addresstag)r  r!  r  r
  r  )rr  r!  r+  r  safe_string_uppersafe_string_upper_2r  r$   r4   r  )privateGetExchangeWalletsV2DepositAddressr1  r*  check_address)r  rH  r3  r!  rx  r  defaultNetworkr  r  rO  r  r
  r  s                r  fetch_deposit_addresszphemex.fetch_deposit_address  s      !!!!!!!!!==&&
 ..7HII//FF>>$,
B??**69k>ZZ""8Wg>>?#DG.c$cddd#*GK YYvy11FGGT[]cHdHdeeeeeeee  x44""433tU++7###
 
 	
r  c                    K   |                                   d{V  d}||                     |          }|                     |           d{V }|                     |dg           }|                     ||||          S )a  
        fetch all deposits made to an account
        :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  )rr  r!  $privateGetExchangeWalletsDepositListr,  parse_transactionsr  rH  r  r   r3  r!  rO  r  s           r  fetch_depositszphemex.fetch_depositsE  s       !!!!!!!!!}}T**HBB6JJJJJJJJ* ~~h33&&tXueDDDr  c                    K   |                                   d{V  d}||                     |          }|                     |           d{V }|                     |dg           }|                     ||||          S )a  
        fetch all withdrawals made from an account
        :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  )rr  r!  %privateGetExchangeWalletsWithdrawListr,  r  r  s           r  fetch_withdrawalszphemex.fetch_withdrawalsj  s       !!!!!!!!!}}T**HCCFKKKKKKKK* ~~h33&&tXueDDDr  c                 T    dddddddddddddddd}|                      |||          S )NokfailedpendingrT  )SuccessSucceedrN  zSecurity check failedSecurityCheckFailedExpiredzAddress RiskzSecurity CheckingSecurityCheckingzPending ReviewzPending TransferAmlCsApporverP  	Confirmed	Cancelledr[  r\  s      r  parse_transaction_statuszphemex.parse_transaction_status  sU     %-#+$!* )' )%"#
 
" &&999r  transactionr!  c                    |                      |d          }|                      |d          }d }|                      |d          }|                      |d          }|                     ||          }|d         }|                      |d          }	|                     |g 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S )Nr4   r
  txHashr!  rH  r	  )r  
submitedAtsubmittedAtr  feeEvr  feeRv
withdrawalr|  r  amountEvamountRvr  txidr_  r`  r  	addressToaddressFromr  tagTotagFromr  updated)commentinternalrJ  )
r  safe_currencysafe_integer_nr  r  r
  r  r&  rb  network_id_to_code)r  r'  r!  r4   r
  r  r1  r(  rH  	networkIdr_  r  r  rJ  r  r  s                   r  parse_transactionzphemex.parse_transaction  s   H k400"";	::X66%%k:>>
%%j(;;$$[+>>	''5_5_5_``	%%k6::##DLL1A1A+w1W1WYabnYo$p$pqq?&&{G<<GD  C ..t/?/?X/V/VWW""4<<0@0@j0Y0Y[cdp[q#r#rss>%%k:>>F
K
"
 D
 	

 Y//
 t..y99
 w
 
 4
 3
 S
 t
 D
 f
 
  f!
" t#
$ )
 
 
 	
r  c                   K   |                                   d{V  |                     |          }d}|                     |ddd          }|                     |ddg          }d}d}|                     |d          }|&|                     |          }|d         }|d         }n|                     |dd|          \  }}|                     d||          \  }}|dk    }|rd}n|dk    rd}n|
|d	k    rd
nd}|                     |          }	d|	d         i}
d}|rd}|                     |ddd          \  }}|dk    r0| 	                    | 
                    |
|                     d{V }n_|                     | 
                    |
|                     d{V }n/|                     | 
                    |
|                     d{V }|                     |di           }|                     |dg           }g }t          dt          |                    D ]2}||         }|                    |                     |                     3|                     |d|d          S )a  
        fetch all open positions

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-trading-account-and-positions
        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
        https://phemex-docs.github.io/#query-account-positions-with-unrealized-pnl

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.code]: the currency code to fetch positions for, USD, BTC or USDT, USDT is the default
        :param str [params.method]: *USDT contracts only* 'privateGetGAccountsAccountPositions' or 'privateGetGAccountsAccountPositions' default is 'privateGetGAccountsAccountPositions'
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr!  rH  r  r   r  r   BTCr   r  r4   methodrC  r  	positionsr  F)rr  market_symbolsr  r  r  r  rB  r  r!  rC  r1  privateGetGAccountsPositionsrD  r*  r/  r0  r2  parse_positionfilter_by_array_positions)r  r  r3  r  rH  r  r  firstSymbolr  r!  rx  rO  r@  r  rA  r>  r?  positions                     r  fetch_positionszphemex.fetch_positions  s      !!!!!!!!!%%g..!!&*ffEE6J#788&&w22"[[--FH%F(#DD!::6CSU]_cddNFF99:JFTZ[[&( 	=DDu__DD\$0055uD==&&
  	cF!::6CSU]  `E  F  FNFF>>>!%!I!I$++V]_eJfJf!g!ggggggg!%!B!B4;;wX^C_C_!`!```````!DDT[[QXZ`EaEabbbbbbbbHZ x44OOD+r::	q#i..)) 	9 	9A |HMM$--h778888--fhOOOr  rG  c                    |                      |d          }|                     ||          }|d         }|                     |dd          }|                     |dd          }|                     |dd          }t          j        ||          }|                     |dd	          }	t          j        |	|          }
|                     |d
d          }|                     |dd          }|                     |dd          }|                     |d          }|                     |          }| 	                    t          j
        |                     |dd                              }|                     |dd          }|                      |d          }d }|
|dk    rdnd}d }|d         r2|dk    rt          j        ||          }nt          j        ||          }n}|dk    r<t          j        t          j        d|          t          j        d|                    }n;t          j        t          j        d|          t          j        d|                    }t          j        t          j        ||          |          }|                      |d|          }t          j        ||          }|                     |d          }|                     i d|d|                      |d          d|d | 	                    |          d|d!|                     |d"          d#| 	                    |          d|d
|d$| 	                    |          d%| 	                    |          d| 	                    |          d&d d'| 	                    |          d(d d)|                     |d*d+          d,| 	                    |	          | 	                    |
          | 	                    |          | 	                    |          | 	                    |          d |rd-nd.||                      |d/          d0k    d d d d1          S )2Nr  positionMarginpositionMarginRvr  valueRvmaintMarginReqmaintMarginReqRrassignedPosBalanceassignedPosBalanceRvliquidationPriceliquidationPriceRp	markPricemarkPriceRpsizesizeRqr  r   
leverageRravgEntryPriceavgEntryPriceRprh  Buylongshortr   r  unRealisedPnlRvcrossMarginr  r4   execSeq	contractsrealizedPnlcurTermRealisedPnlRvunrealizedPnl
collateralnotional	lastPrice
entryPricer_  lastUpdateTimestampr  rp  initialMargincrossisolatedposModeHedged)initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior`  r   rh  r   r   r   r   )r  r  r  r/   rM  
string_divr  r*  r}  r  
string_abs
string_subsafe_positionr  rw  )r  rG  r  r  r  rd  notionalString!maintenanceMarginPercentageStringmaintenanceMarginStringinitialMarginStringinitialMarginPercentageStringrQ  markPriceStringr`  r  r  r   entryPriceStringrawSiderh  	priceDiffrc  apiUnrealizedPnlrq  isCrosss                            r  rD  zphemex.parse_position  s   P ##Hh77!!(F33!''2BDVWW
++HgyII,0,>,>xIY[m,n,n)")"4^Ef"g"g"00;OQghh(/(:;NP^(_(_%--h8JL`aa,,X{MRR&&xBB	v~>>!22<@@$$W%79K9KHV`bn9o9o%q%qrr--hIZ[[""8V44%..66WD
 	( 
	Dv~~#.@PQQ		#./?QQ		 v~~#.w/A#GW/X/XZaZlmp  sB  [C  [C  D  D		#.w/A#/W/WY`Yklo  rB  ZC  ZC  D  D	*7+=i+S+SUghh++H6GWW()@*MM//(M::!! #
H#
$""8Y77#
 f#
 **955	#

 L#
 4++H6LMM#
 T../?@@#
 #
  0#
 $++J77#
 )).99#
 **?;;#
 #
 $++,<==#
 #
  "4#<#<XGWYa#b#b!#
" T../BCC##
$ (,'8'89V'W'W!%!2!23J!K!K+/+<+<=^+_+_,,[99%,<''*&&x;;xG!#9#
 #
 #
   	r  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|"|dk    rt	          | j        dz             ||d<   d}|d         d	k    p|d         d
k    }|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }	|                     |	dg           }
g }t          dt          |
                    D ]}|
|         }|                     |d          }|                     |dd          }|                     |                     |d                    }|                    ||                     |d          |||                     |          d|                     |||          d           |S )am  
        fetch the history of funding payments paid and received on self account

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#futureDataFundingFeesHist

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/?id=funding-history-structure>`
        Nz1 fetchFundingHistory() requires a symbol argumentr  r4   r   z7 fetchFundingHistory() limit argument cannot exceed 200r   r  r  r  r  r  r   
createTimer  r  r!  )r  r  rH  r_  r`  r4   r  )r$   r4   rr  r  r%   $privateGetApiDataGFuturesFundingFeesr1  #privateGetApiDataFuturesFundingFeesr*  r/  r0  r  r  r  r  r2  rb  parse_funding_fee_to_precision)r  r  r  r   r3  r  rx  rO  ry  r  r  r>  r?  entryr_  execFeecurrencyCodes                    r  fetch_funding_historyzphemex.fetch_funding_history,  sH      >#DG.a$abbb!!!!!!!!!V$$fTl

 s{{ +d!deee$GG *f4Rx8HF8R 	d!FFt{{SZ\bGcGcddddddddHH!EEdkkRY[aFbFbccccccccH. x44tVR00q#d))$$ 	 	AGE))%>>I(([IIG2243C3CE:3V3VWWLMM**5(;;$& LL33==gv|\\      r  r  c                     |||S |d         dk    p|d         dk    }|s[|                      |          }|                     |d         d          }|                     |          }t          j        ||          }|S )Nr  r  r  r  r  )r9  r  rL  r/   rM  )r  r  r  r  ry  r!  r  tickPrecisions           r  r  z%phemex.parse_funding_fee_to_precisiont  s    =L0L *f4Rx8HF8R 	=)),77H$$Xf%5|DDE 0077M&um<<Er  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}i }|d         s0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetch the current funding rate
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        NrC   z0 fetchFundingRate() supports swap contracts onlyr  r4   r   r>  )	rr  r  r&   r4   r  r1  r  r*  parse_funding_rater  s          r  fetch_funding_ratezphemex.fetch_funding_rate  s      !!!!!!!!!V$$f~ 	ZDG&XXYYYfTl
 h 	T!33DKK4P4PQQQQQQQQHH!55dkk'66R6RSSSSSSSSH0 8R88&&vv666r  c                    |                      |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 iS )Nr  r_  rp  markEpindexEpfundingRateErpredFundingRateErr  rS  rT  
indexPriceindexPriceRpinterestRateestimatedSettlePricer`  fundingRatefundingRateRrfundingTimestampfundingDatetimenextFundingRatepredFundingRateRrnextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r  rw  rW  r  r  rb  )
r  r  r  r  r  r_  r  r  r  nextFundingRateErs
             r  r  zphemex.parse_funding_rate  s   L ##Hh77!!(F33--hXNN	d..xBBFKK,,t//)DDfMMT%5%5h%P%PRXYY LL)9)9(DW)X)XZ`aa
H
f
 ))(M6JJ
 $**8^WMM	

 D
 #D
 
 Y//
 4++Ho}UU
 
 t
 t//:MO`aa
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
r  c                 X  K   |                                   d{V  |                     |          }|d         |                     ||          d}|                     |                     ||                     d{V }|                     |                     ||          d|i          S )a5  
        Either adds or reduces margin in an isolated position in order to set the margin to a specific value

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#assign-position-balance-in-isolated-marign-mode

        :param str symbol: unified market symbol of the market to set margin in
        :param float amount: the amount to set the margin to
        :param dict [params]: parameters specific to the exchange API endpoint
        :returns dict: A `margin structure <https://docs.ccxt.com/?id=margin-structure>`
        Nr4   )r  posBalanceEvr  )rr  r  r  privatePostPositionsAssignr1  parse_margin_modification)r  r  r  r3  r  rx  rO  s          r  
set_marginzphemex.set_margin  s       !!!!!!!!!V$$Tl JJvv66
 
 88Wf9U9UVVVVVVVV {{499(FKKfN
   	r  c                 8    ddi}|                      |||          S )N0r  r[  r\  s      r  parse_margin_statuszphemex.parse_margin_status  s(    
 &&999r  r  c                    |                      d |          }|                     |d          }|rdnd}||                     d |          ddd d ||         |                     |                     |d                    d d d
S )Nr  r  r  setrk  rH  )
r  r  r  r   r  r1  rH  r  r_  r`  )r  r*  r  r  r  )r  r  r  r  codeCurrencys        r  r  z phemex.parse_margin_modification  s     !!$////&)44!(5vvg&&tV44$<(..t/?/?f/M/MNN
 
 	
r  r   c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         st	          | j        dz             |                                }|dk    r|dk    rt          | j        dz             d|d	         i}|dk    }|                     |d
         ddg          r|                     |d          }|t          | j        dz             |r&t          j
        t          j        |                    nt          j        |          |d<   |                     |                     ||                     d{V S |                     |d          }|dk    rd}|t          | j        dz             ||d<   |                     |                     ||                     d{V S )a]  
        set margin mode to 'cross' or 'isolated'

        https://phemex-docs.github.io/#set-leverage

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentrC   z- setMarginMode() supports swap contracts onlyrk  rj  z@ setMarginMode() marginMode argument should be isolated or crossr  r4   r  r  r  r   zA setMarginMode() requires a "leverage" parameter for USDT marketsrW  r   z. setMarginMode() requires a leverage parameter)r$   r4   rr  r  r&   lowerr%   in_arrayr  r/   
string_negrs  privatePutGPositionsLeverager1  r  privatePutPositionsLeverage)	r  r   r  r3  r  rx  r  currentLeverager   s	            r  set_margin_modezphemex.set_margin_mode*  s      >#DG.[$[\\\!!!!!!!!!V$$f~ 	WDG&UUVVV%%''
##
g(=(=TW'iijjjfTl
 '==)FF+;<< 	Y"..vzBBO&'2u(uvvv_f  %PG$6w7I/7Z7Z$[$[$[lsl~  @O  mP  mPGL!::4;;wPV;W;WXXXXXXXXX$$VZ88  H#DG.^$^___&
55dkk'66R6RSSSSSSSSSr  r   c                 d  K   |                      d|d           |                                  d{V  |                     |          }|d         dk    rt          | j        dz             d|d         i}|rd|d	<   nd
|d	<   |                     |                     ||                     d{V S )a  
        set hedged to True or False for a market

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#switch-position-mode-synchronously

        :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   r  Nr  r  z5 setPositionMode() supports USDT settled markets onlyr4   rm  targetPosModeOneWay)check_required_argumentrr  r  r&   r4   %privatePutGPositionsSwitchPosModeSyncr1  )r  r   r  r3  r  rx  s         r  set_position_modezphemex.set_position_modeP  s       	$$%6III!!!!!!!!!V$$(v%%DG&]]^^^fTl
  	0'/GO$$'/GO$??GU[@\@\]]]]]]]]]r  c                   K   |                                   d{V  |N|                     |d          }|                     |          }|d         dk    rt          | j        dz             |                     |           d{V }|                     |di           }|                     |d          }|                     ||d          S )	a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/?id=leverage-tiers-structure>`, indexed by market symbols
        Nr   r  r  z7 fetchLeverageTiers() supports USD settled markets onlyr  r  r  )rr  r*  r  r&   r4   publicGetCfgV2Productsr,  parse_leverage_tiers)r  r  r3  r  r  rO  r  r  s           r  fetch_leverage_tierszphemex.fetch_leverage_tiersi  s       !!!!!!!!!OOGQ//E[[''Fh5((*c cddd44V<<<<<<<<^ x44^^D,77
((WhGGGr  c                    |                      |d          }|                     ||          }|d         d         }g }d}t          dt          |                    D ]}||         }|                     |d          }	|                    |                     |d          |                     ||          |d         ||	|                      |d          d	|d
           |	}|S )zq
        :param dict info: Exchange market response for 1 market
        :param dict market: CCXT market
        r  r  r  r   r   r   r  ro  N)tierr  r!  minNotionalmaxNotionalmaintenanceMarginRater  r  )r  r  r/  r0  r  r2  r  r  )
r  r  r  r  r  tiersr  r?  r  r  s
             r  parse_market_leverage_tiersz"phemex.parse_market_leverage_tiers  s      ##D(33!!(F33Vn\2
q#j//** 	& 	&Aa=D++D'::KLLA**8V<<"8,**)-)9)9$@S)T)T#	 	 	 	 	 &KKr  r   GETc                    |                      ||                     |                    }d|                     ||          z   }|}	d}
|dk    s|dk    s|dk    s|	dk    r|r|                     |          }
|	d|
z   z  }	|dk    rQ|                                  |                                 }|                     | j        d	d
          }|                     ||          }t          |          }| j
        |d}d}|dk    r||dk    p|dk    p|dk    }|rL|                     |d          6|                     | j        dd          }||                                 z   |d<   |                     |          }|}d|d<   ||
z   |z   |z   }|                     |                     |          |                     | j                  t"          j                  |d<   |                     | j        d         |                   |	z   }	|	|||dS )Nr  r  r  DELETEPUTz/positions/assign?r   r  r  )zx-phemex-access-tokenr  POSTr   r   r   ro  r  r  zapplication/jsonzContent-Typezx-phemex-request-signaturer   )r   r@  bodyheaders)r  extract_paramsimplode_paramsurlencode_with_array_repeatcheck_required_credentialsr  r  r  r  r  r  r  r  jsonhmacencoder  hashlibsha256implode_hostnamer   )r  pathr   r@  r3  r  r  r  requestPathr   queryStringr_  xPhemexRequestExpiryr  expiryStringpayloadisOrderPlacementr4   auths                      r  signzphemex.sign  s9   		&$"5"5d";";<<D//f===eOO8!3!35cUhNhNh )">>uEEs[(()++---I#'#4#4T\C\^`#a#a XXi)=>>Fv;;L)-+7 G G$(J$6#hDM<Q#hW[_gWg # ?''	::B!--dlJUU,.,>y)))F++*<',|;gED48IIdkk$>O>OQUQ\Q\]a]hQiQikrky4z4zG01##DIe$4S$9::S@fdwOOOr  r   c                   K   |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  d{V  |                     |dd          }|                     |d          }|                     |d	          }|                     |          }d
|d         i}d}	|d         dk    s|d         dk    rR|s
||||d<   n||n|}
||n|}|
|d<   ||d	<   |                     |                     ||                     d{V }	n4||d<   | 	                    |                     ||                     d{V }	|	S )a'  
        set the level of leverage for a market

        https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#set-leverage

        :param float leverage: the rate of leverage, 100 > leverage > -100 excluding numbers between -1 to 1
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.hedged]: set to True if hedged position mode is enabled(by default long and short leverage are set to the same value)
        :param float [params.longLeverageRr]: *hedged mode only* set the leverage for long positions
        :param float [params.shortLeverageRr]: *hedged mode only* set the leverage for short positions
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentir  z6 setLeverage() leverage should be between -100 and 100r   FlongLeverageRrshortLeverageRrr  r4   r  r  r  rW  r   )
r$   r4   r%   rr  r  r  r  r  r1  r  )r  r   r  r3  isHedgedr  r  r  rx  rO  longVarshortVars               r  set_leveragezphemex.set_leverage  s       >#DG.Y$YZZZtOOCTW'__```!!!!!!!!!>>&(E::**63CDD++F4EFFV$$fTl
 (v%%)9V)C)C 6 6?;R(0%%-;-G..h/>/J??QY,3()-5)*!>>t{{7TZ?[?[\\\\\\\\HH"*GJ!==dkk'SY>Z>Z[[[[[[[[Hr  fromAccount	toAccountc           	        K   |                                   d{V  |                     |          }|                     | j        di           }|                     |||          }|                     |||          }	|                     ||          }
d}d}|dk    r	|	dk    rd}n|dk    r|	dk    rd}|i|d         ||
d}|                     |                     ||                     d{V }|                     |d	i           }|                     ||          }ng||	|
|d         |                     |d
d          d}| 	                    |                     ||                     d{V }|                     |          }|                     | j        di           }| 
                    |dd          }|r4|d         ||d<   |d         ||d<   |d         ||d<   |d         ||d<   |S )a!  
        transfer currency internally between wallets on the same account

        https://phemex-docs.github.io/#transfer-between-spot-and-futures
        https://phemex-docs.github.io/#universal-transfer-main-account-only-transfer-between-sub-to-main-main-to-sub-or-sub-to-sub

        :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
        :param str [params.bizType]: for transferring between main and sub-acounts either 'SPOT' or 'PERPETUAL' default is 'SPOT'
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        Nr  rA   rD   r   r   r4   )r!  moveOpr/  r  bizTypeSPOT)
fromUserIdtoUserIdr/  r!  r  r   r  Tr  r  r  r!  )rr  r!  r*  r  r  r  privatePostAssetsTransferr1  parse_transfer"privatePostAssetsUniversalTransferr  )r  rH  r  r  r  r3  r!  r  fromIdtoIdscaledAmmount	directionr   rx  rO  r  transferOptionsr  s                     r  r   zphemex.transfer;  sf      !!!!!!!!!==&&7GLL!!.+{KK	9EE

6844	V 0 0IIxDFNNI $TN#) G
 ";;DKKQW<X<XYYYYYYYYH ??8VR88D**4::HH % )$TN++FIvFF G "DDT[[QXZ`EaEabbbbbbbbH **844H//$,
BGG"&..B[]a"b"b" 	,&.*5'$,(1%!)%+"
#+'+$r  c                   K   |                                   d{V  |t          | j        dz             |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )	a1  
        fetch a history of internal transfers made on an account

        https://phemex-docs.github.io/#query-transfer-history

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of  transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        Nz* fetchTransfers() requires a code argumentr!  r4   r  r   r  r  )	rr  r$   r4   r!  privateGetAssetsTransferr1  r*  r,  parse_transfers)
r  rH  r  r   r3  r!  rx  rO  r  	transferss
             r  fetch_transferszphemex.fetch_transfers  s      !!!!!!!!!<#DG.Z$Z[[[==&&
 $GG$GG66t{{7F7S7STTTTTTTT* x44NN444	##IxFFFr  r   c                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|                      |d          }|                     ||          }|                     |d          }	d }
d }|	dk    rd}
d}n
|	d	k    rd}
d}|                     |d
          }||||                     |          |||
||                     |          d	S )NlinkKeyr  r/  r!  rh  r   rC   rA   r   r  )	r  r4   r_  r`  r!  r  r  r  r  )r  rV  r  r  rb  parse_transfer_status)r  r   r!  r4   r  r/  amountTransferedr(  rH  rh  r  r  r_  s                r  r  zphemex.parse_transfer  s   4 h	22!!(H55##Hj99<<11%%h
;;
&&z8<<  622199FDDQYYFD%%h==	"Y//&!0088

 

 
	
r  c                 >    ddddd}|                      |||          S )NrO  rT  r  r  )rV  rY  rc  11r[  r\  s      r  r  zphemex.parse_transfer_status  s4    	
 
 &&999r  c           
        K   |t          | j        dz             |                                  d{V  |                     |          }|d         dk    p|d         dk    }|d         st	          | j        dz             d}|                     |d	d
          \  }}|r!|                     d	|||d|d           d{V S d}|rd|d         z   dz   }nd|d         z   dz   }d|i}	|||	d<   |||	d<   |                     d|	|          \  }	}d}
|r0|                     | 	                    |	|                     d{V }
n/| 
                    | 	                    |	|                     d{V }
|                     |
di           }|                     |d          }g }t          dt          |                    D ]b}||         }|                     |d          }|                    |||                     |d          ||                     |          d           c|                     |d          }|                     ||||          S )a  
        fetches historical funding rate prices

        https://phemex-docs.github.io/#query-funding-rate-history-2

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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)
        :param int [params.until]: timestamp in ms of the latest funding rate
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr  r  r  rC   z7 fetchFundingRateHistory() supports swap contracts onlyFrj   paginate8hr  .r4   FR8Hr  r  r  r   endr  r  r   fundingTimer  )r  r  r  r_  r`  r_  )r$   r4   rr  r  r%   rB  "fetch_paginated_call_deterministichandle_until_option(v2GetApiDataPublicDataFundingRateHistoryr1  (v1GetApiDataPublicDataFundingRateHistoryr*  r/  r0  r  r2  r  rb  rc  filter_by_symbol_since_limit)r  r  r  r   r3  r  isUsdtSettledr  customSymbolrx  rO  r  ratesr>  r?  itemr_  sorteds                     r  fetch_funding_rate_historyz!phemex.fetch_funding_rate_history  s      >#DG.e$efff!!!!!!!!!V$$x(F2PfX6F&6Pf~ 	bTW'``aaa88AZ\fgg& 	E@@AZ\bdikprvx~  AD  E  E  E  E  E  E  E  E  E 	;-6LL!11F:Ll
 $GG$GG225'6JJ 	i!JJ4;;W^`fKgKghhhhhhhhHH!JJ4;;W^`fKgKghhhhhhhhH" x44f--q#e**%% 		 		A8D))$>>IMM #//mDD& LL33      fk2200NNNr  r
  r  c                   K   |                      ||          \  }}|                                  d{V  |                     |           |                     |          }d}|                     |          \  }}d}||                     |          }|                     | j        d          }	|6|                     ||	          s	|d         }nt          | j
        dz             |d         |||                                d}
|||
d<   |                     |                     |
|                     d{V }|                     |di           }|                     ||          S )a  
        make a withdrawal

        https://phemex-docs.github.io/#create-withdraw-request

        :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 phemex api endpoint
        :param str [params.network]: unified network code
        :returns dict: a `transaction structure <https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure>`
        Nr  r4   z8 withdraw() requires an extra argument params["network"])r!  r
  r  r	  
addressTagr  )handle_withdraw_tag_and_paramsrr  r  r!  handle_network_code_and_paramsnetwork_code_to_idr*  r  r  r$   r4   upper1privatePostPhemexWithdrawWalletsApiCreateWithdrawr1  r+  r=  )r  rH  r  r
  r  r3  r!  networkCoder<  r  rx  rO  r  s                r  r   zphemex.withdrawE  s      99#vFFV!!!!!!!!!7###==&&"AA&IIV	"//<<IoodlMBBMM$44 n$TN		'2l(lmmm "**	
 
 ?$'GL!OOPTP[P[\cekPlPlmmmmmmmm8 ~~h33%%dH555r  c                 l  K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |d          }|                     ||          S )aZ  
        retrieves the open interest of a trading pair

        https://phemex-docs.github.io/#query-24-hours-ticker

        :param str symbol: unified CCXT market symbol
        :param dict [params]: exchange specific parameters
        :returns dict} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure:
        Nr  z: fetchOpenInterest is only supported for contract markets.r  r4   r>  )rr  r  r%   r4   r  r1  r+  parse_open_interestr  s          r  fetch_open_interestzphemex.fetch_open_interest  s       !!!!!!!!!V$$j! 	eTW'ccdddfTl
 11$++gv2N2NOOOOOOOO, (33''777r  c                 <   |                      |d          dz  }|                     |d          }|                     ||                     ||          |                     |d          d |                     |d          d ||                     |          d|          S )Nr_  i@B r  r  openInterestRv)r  r  r  r  openInterestAmountopenInterestValuer_  r`  )r  r  safe_open_interestr  rb  )r  interestr  r_  r4   s        r  r!  zphemex.parse_open_interest  s    $ %%h<<wF	h11&&&&r622**8Z@@"&"2"28=M"N"N!%"Y//	(
 	(
 	 	 		r  fromCodetoCodec                   K   |                                   d{V  |                     |          }|                     |          }|                     |d          }|||                     ||          d}|                     |                     ||                     d{V }	|                     |	di           }
|                     |
||          S )a)  
        fetch a quote for converting from one currency to another

        https://phemex-docs.github.io/#rfq-quote

        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float amount: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `conversion structure <https://docs.ccxt.com/?id=conversion-structure>`
        Nr  )fromCurrency
toCurrencyfromAmountEvr  )rr  r!  r  r  privateGetAssetsQuoter1  r+  parse_conversion)r  r)  r*  r  r3  r,  r-  r  rx  rO  r  s              r  fetch_convert_quotezphemex.fetch_convert_quote  s       !!!!!!!!!}}X..]]6**
&&|\BB
$  JJvz::
 

 33DKK4P4PQQQQQQQQ& ~~h33$$T<DDDr  c                 f  K   |                                   d{V  |                     |          }|                     |          }|                     |d          }|||d}	||                     ||          |	d<   |                     |                     |	|                     d{V }
|                     |
di           }|                     |d          }|                     ||          }|                     |d          }|                     ||          }| 	                    |||          S )aU  
        convert from one currency to another

        https://phemex-docs.github.io/#convert

        :param str id: the id of the trade that you want to make
        :param str fromCode: the currency that you want to sell and convert from
        :param str toCode: the currency that you want to buy and convert into
        :param float [amount]: how much you want to trade in units of the from currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `conversion structure <https://docs.ccxt.com/?id=conversion-structure>`
        Nr  )rH  r,  r-  r.  r  r,  r-  )
rr  r!  r  r  privatePostAssetsConvertr1  r+  r  r9  r0  )r  r4   r)  r*  r  r3  r,  r-  r  rx  rO  r  fromCurrencyId
fromResulttoCurrencyIdr  s                   r  create_convert_tradezphemex.create_convert_trade  sN      !!!!!!!!!}}X..]]6**
&&|\BB
$ 
 

 &*jj&D&DGN#66t{{7F7S7STTTTTTTT  ~~h33))$??''EE
''l;;j99$$T:r:::r  c                   K   |                                   d{V  i }|||d<   |||d<   |||d<   |                     d||          \  }}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     ||dd||          S )	a  
        fetch the users history of conversion trades

        https://phemex-docs.github.io/#query-convert-history

        :param str [code]: the unified currency code
        :param int [since]: the earliest time in ms to fetch conversions for
        :param int [limit]: the maximum number of conversion structures to retrieve, default 20, max 200
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.until]: the end time in ms
        :param str [params.fromCurrency]: the currency that you sold and converted from
        :param str [params.toCurrency]: the currency that you bought and converted into
        :returns dict[]: a list of `conversion structures <https://docs.ccxt.com/?id=conversion-structure>`
        Nr,  	startTimer   endTimer  r  r-  )rr  r  privateGetAssetsConvertr1  r+  r,  parse_conversions)	r  rH  r  r   r3  rx  rO  r  r  s	            r  fetch_convert_trade_historyz"phemex.fetch_convert_trade_history,  s       !!!!!!!!!&*GN##(GK $GG229gvNN55dkk'66R6RSSSSSSSS. ~~h33~~dFB//%%dD.,PUW\]]]r  
conversionr,  r-  c                 "   |                      |di           }|                     |d          }|                     |d|          }|                     |d|                     |d                    }|                     ||          }|                     |d|                     |d                    }	|                     |	|          }
|                     |d          }|                     |d          }|                     |                     |d          |          }|,|*|                     |                     |d	          |          }|                     |                     |d
          |          }|,|*|                     |                     |d          |          }|||                     |          |                     |d          ||                     |          |
|                     |          |                     |d          d d
S )N	quoteArgs	requestAtr  r,  rH  r-  r  r.  origin
toAmountEvproceedsr   )
r  r_  r`  r4   r,  
fromAmountr-  toAmountr   rJ  )r+  r  r  r  r
  rb  r  r  )r  r>  r,  r-  r@  requestTimer_  fromCoinr)  toCoinr*  fromValueScaletoValueScalerE  rF  s                  r  r0  zphemex.parse_conversion_  s   V NN:{B??	''	;??%%j,LL	##J@P@PQ]_e@f@fgg**8\BB!!*lD<L<LZY_<`<`aa((<<**<FF((\BB\\$"2"2:~"N"NP^__
)"7d&6&6y(&K&K^\\J<< 0 0\ J JLYY	 5||D$4$4Y
$K$K\ZZH"Y//"":v66$++J77 ))(33%%i99
 
 	
r  c                   K   |                                   d{V  |                     |dddd          }d}|                     |ddd          }|                     |ddg          }d}d}|                     |d          }|&|                     |          }|d         }|d         }n|                     |dd|          \  }}|                     d||          \  }}|dk    }|rd}n|d	k    rd	}n|
|d
k    rdnd	}|                     |          }	d|	d         i}
d}|rd}|                     |ddd          \  }}|dk    r0| 	                    | 
                    |
|                     d{V }n_|                     | 
                    |
|                     d{V }n/|                     | 
                    |
|                     d{V }|                     |di           }|                     |dg           }g }t          dt          |                    D ]2}||         }|                    |                     |                     3|                     |d|d          S )aq  
        fetches the auto deleveraging rank and risk percentage for a list of symbols

        https://phemex-docs.github.io/#query-account-positions
        https://phemex-docs.github.io/#query-trading-account-and-positions
        https://phemex-docs.github.io/#query-account-positions-with-unrealized-pnl

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.code]: the currency code to fetch ranks for, USD, BTC or USDT, USDT is the default
        :param str [params.method]: *USDT contracts only* 'privateGetGAccountsAccountPositions' or 'privateGetGAccountsAccountPositions' default is 'privateGetGAccountsAccountPositions'
        :returns dict: an array of `auto de leverage structures <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        NTr!  rH  r  r   r  r   r?  r   r  r4   r@  rC  r  rA  r  F)rr  rB  r  r  r  r  rB  r  r!  rC  r1  rC  rD  r*  r/  r0  r2  parse_adl_rankfilter_by_array_adl_ranks)r  r  r3  r  rH  r  r  rF  r  r!  rx  rO  r@  r  ranksr>  r?  ranks                     r  fetch_positions_adl_rankzphemex.fetch_positions_adl_rank  s      !!!!!!!!!%%gtT4FF!!&*ffEE6J#788&&w22"[[--FH%F(#DD!::6CZ\dfjkkNFF99:QSY[abb&( 	=DDu__DD\$0055uD==&&
  J	cF!::6CZ\d  gL  M  MNFF>>>!%!I!I$++V]_eJfJf!g!ggggggg!%!B!B4;;wX^C_C_!`!```````H "DDT[[QXZ`EaEabbbbbbbbHd x44k266q#e**%% 	5 	5A8DMM$--d334444--fhOOOr  r  c           	          |                      |d          }||                     ||d d          d d |                     |dd          d d dS )Nr  r  deleveragePercentileRrdeleveragePercentileEr)r  r  rP  ratingr   r_  r`  )r  r  r  )r  r  r  r  s       r  rM  zphemex.parse_adl_ranks  sf    j ##D(33&&xzJJ,,T3KMeff
 
 	
r  httpCodereasonr   r@  r  r  c
                 d   |d S |                      |d|          }
|                     |
d          }|                     |
d          }|f|dk    r`| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )NerrorrH  msgr  r  r  r  )r*  r  r4   throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr    )r  rV  rW  r   r@  r  r  rO  requestHeadersrequestBodyrY  	errorCodemessagefeedbacks                 r  handle_errorszphemex.handle_errors  s    4 '8<<$$UF33	""5%00!	S(8(8w}t+H001I9V^___001I7T\]]])))tr  r|  )r   r   N)Nr\  r]  r   r   N)NN)r__name__
__module____qualname__r   r  r  dictr  r  r   r   rC  r	   rT  r[  rk  r  r   r   rz  r  r  r  r
  rW  rV  r  r  r  r  r   r  r  r   r   r  r   r  r*  r9  r@  r   rG  r   r^  r  rm  r  r  r  r   r  r   r   floatr   r  r  r  r  r  r  r  r  r  r   r  r   r  r  r&  r
   r=  r   rH  rD  r  r  r   r  r  r   r  r  r  r  boolr  r   r  r   r  r  rK  r  r   r   r  r  r  r  r   r"  r!  r   r1  r7  r=  r0  r   rQ  rM  rb  __classcell__)r  s   @r  r1   r1      ss       f	# f	 f	 f	 f	 f	 f	P* * * *J J J J JXc c c c cJ *, b bV b b b bH -/ @ @: @ @ @ @D	
 	
F 	
 	
 	
 	
   KQ    & @DB 8 8S 8 8S\ 8 8 8 8t4 4 48 8D 8 8 8 8
7 76 7 7 7 7
  I I& I I I I
I I& I I I I
I I& I I I I

 
 
4 
 
 
 
8 ?CQUdhqs NL NL NL NL3 NL^a NLx|  ~B  yC NL NL NL NL`U U4 U U6 U U U Un 68 E1 E1 E1F E1 E1 E1 E1N 6:" 3 37 3 3 3 3 3@ <@d[] *? *? *?S *? *?bfglbm *? *? *? *?XZ Z Zv Z Z Z Z Zx1) 1) 1)f-) -) -)^ *, c1 c1 c1 c1 c1 c1J: : : : :.3S 3 3 3 3"Hs H H H Hj jd jF j j j jX3 3 3l lf l l l l\4 4 4v 4 4 4 4 4 mqy{ R. R. R.I R.Y R.X] R.fi R. R. R. R.h fjx|  FH =. =.3 =. =.9 =.I =._b =.ru =. =. =. =.~ 9=R $. $.S $.# $. $. $. $.L 59 9
 9
c 9
 9
 9
 9
v 8<B ,/ ,/C ,/ ,/ ,/ ,/ ,/\ 04$UYbd != != !=C !=s !=imnsit != != != !=F 59tZ^gi 'A 'Ac 'A 'ATW 'Anrsxny 'A 'A 'A 'AR 7;\`ik MA MA MA3 MAVY MAptuzp{ MA MA MA MA^ 37TX\eg X= X=C X=s X=RU X= X= X= X=t =? 1
 1
 1
> 1
 1
 1
 1
f 04$UYbd #E #E #EC #Es #Eimnyiz #E #E #E #EJ 37TX\eg #E #EC #Es #ERU #Elpq|l} #E #E #E #EJ:s : : : :(q
 q
T q
X q
Q\ q
 q
 q
 q
f 8<B DP DPW DP4PX> DP DP DP DPLN Nt NV N N N N` 9=4^bkm F F# FS FX[ F F F FP
 
F 
Y\ 
 
 
 
 <> +7 +7s +7+ +7 +7 +7 +7Z@
 @
6 @
[ @
 @
 @
 @
D CE  s E I[    :: : :
 
d 
F 
N` 
 
 
 
0 DHPR $T $T $TS $T $T $T $TL CGr ^ ^d ^C ^ ^ ^ ^2 =A ^H ^H' ^HP] ^H ^H ^H ^H@# # #$|J\ # # # #J &eBSW  P  P  P  PD ?C2 ) )3 ) ) ) ) )V ac N N3 N NC NTW Ngt N N N N` 154VZce .G .G# .GS .GPS .Gjno|j} .G .G .G .G`4
 4
t 4
x 4
= 4
 4
 4
 4
l:C :C : : : : >BPTcgpr IO IOs IO# IO]` IO IO IO IOV QU]_ B6 B63 B6 B6 B6# B6do B6 B6 B6 B6H =? (8 (8 (8 (8 (8 (8T F    > SW_a )E )E# )Es )EC )Efp )E )E )E )EV ]aik -; -;S -;C -; -;VY -;pz -; -; -; -;^ =Atbfoq 1^ 1^c 1^ 1^\_ 1^vz  |F  wG 1^ 1^ 1^ 1^fE
 E
4 E
x E
\d E
pz E
 E
 E
 E
N AER KP KPg KPTXY\T] KP KP KP KPZ~
 ~
4 ~
 ~
3 ~
 ~
 ~
 ~
@c 3 S # X\ dg        r  r1   )8 ccxt.async_support.base.exchanger   ccxt.abstract.phemexr   r(  r  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   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/   r1    r  r  <module>rr     s   6 5 5 5 5 5 , , , , , ,    e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e  e       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * - - - - - - + + + + + + . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %eS eS eS eS eSX{ eS eS eS eS eSr  