
    E#iۮ                       S SK Jr  S SKJr  S SKrS SKrS SKrS SKJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)  S SK(J*r*  S SK(J+r+  S S	K(J,r,  S S
K(J-r-  S SK(J.r.  S SK(J/r/  S SK(J0r0  S SK(J1r1  S SK(J2r2  S SK(J3r3  S SK(J4r4  S SK(J5r5  S SK(J6r6  S SK(J7r7  S SK(J8r8  S SK(J9r9  S SK:J;r;  S SK<J=r=   " S S\\5      r>g)    )Exchange)ImplicitAPIN)AnyBalancesBorrowInterestCrossBorrowRateCrossBorrowRates
CurrenciesCurrencyDepositAddressIntLedgerEntryLeverageTierLeverageTiersMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)NetworkError)DDoSProtection)RateLimitExceeded)InvalidNonce)BadResponse)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S\\	   4S jjr
0 4S jr0 4S jrS\4S jr0 4S\4S	 jjrS
0 4S\S\S\4S jjrS
0 4S\S\4S jjr0 4S\S\4S jjrS{S\S\	S\4S jjrS{S\S\	S\4S jjr0 4S\4S jjr0 4S jrS
S
0 4S\S\S\S\\   4S jjrS{S\	S\ 4S jjr!SS
S
0 4S\S\S\S\S\\    4
S jjr"S
0 4S\S\#S\$S \%S!\&4
S" jjr'0 4S#\\(   4S$ jjr)S
0 4S\S\#S\$S \%S!\&4
S% jjr*0 4S\S&\%4S' jjr+S
0 4S(\S\,4S) jjr-S* r.S
0 4S+\\   S\,4S, jjr/S-\,4S. jr0S{S/\S\	S\14S0 jjr2S
S
S
0 4S\,S\S\S\\1   4S1 jjr3S
S
S
0 4S\,S\S\S\\1   4S2 jjr4S
0 4S(\S\,4S3 jjr5S
S
S
0 4S\,S\S\4S4 jjr6S5 r7S{S6\S7\8S\94S8 jjr:S
S
S
0 4S9\,S\S\S\\9   4S: jjr;S{S7\8S\<4S; jjr=0 4S9\S\<4S< jjr>S
S
S
0 4S9\,S\S\4S= jjr?S
S
S
0 4S9\,S\S\S\\@   4S> jjrAS
S
S
0 4S9\,S\S\S\\@   4S? jjrBS-\,4S@ jrCS{SA\S7\8S\@4SB jjrDS-\,S\,4SC jrES{SD\S7\8S\F4SE jjrG0 4S9\S \%SF\SG\S\F4
SH jjrHS
0 4S9\S \%SI\SJ\,S\@4
SK jjrIS
S
S
S
0 4S9\,S\,S\S\S\\J   4
SL jjrKS{SM\S\	S\J4SN jjrL0 4S9\S\M4SO jjrN0 4S\O4SP jjrPS{S7\84SQ jjrQSR rR0 4S\S\S4SS jjrT0 4S\S\S4ST jjrUS{S\	S\S4SU jjrVSV rWS
S
S
0 4S\,S\S\4SW jjrX0 4S\S\Y4SX jjrZS{SY\S\	S\Y4SZ jjr[S
0 4S\S\\\   4S[ jjr]0 4S\4S\ jjr^S{S]\S\	4S^ jjr_S
0 4S_\`S\,4S` jjraS
S
S
0 4S9\,S\S\S\\F   4Sa jjrbS
0 4S\S\c4Sb jjrd0 4S\S\\e   4Sc jjrfS{S\	S\\e   4Sd jjrg0 S
4U 4Se jjrhS
0 4Sf\4Sg jjriS|Sh jrj0 4S\S \%S\k4Si jjrl0 4S\S \%S\k4Sj jjrm0 4S\S\k4Sk jjrnS{Sl\S\	S\k4Sm jjroS
S
S
0 4S\,S\S\4Sn jjrpS{S\	4So jjrqS
0 4Sp\S\,4Sq jjrr/ Sr0 S
S
4Ss jrsSt\`Su\Sv\Sw\Sx\4
Sy jrtSzruU =rv$ )}	digifinex"   returnc                 0  > U R                  [        [        U ]  5       SSS/SS0 SS _SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S_S$S_S%S_S&S'_S(S_S)S_S*S_E0 S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_E0 S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_ESSSSSSSSM.ESNSOSPSQSRSSSTSUSVSW.	SXSYSZ0S[S\/S]S^S_.S`/ SaQ0S`/ SbQ0Sc./ SdQ/ SeQSf./ SgQ/ ShQSf.Sc.Si.SSSS SSSS SSSSSj.SSSSSSSSk.SlSm0SSnSoSpSSq.SSSSSSr.SS SSSSs.SStSoSpSSSSu.S SvSn0Sw.	SxSy0SySzSS{.SStSoSoS|.S}S0SStS~.SSoS.SvSt0S.SxS0SxS0S.S S S.S.SSSU R	                  S5      U R	                  S5      S.0[
        0 S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_0 S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[         S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_S[        S/_E[        S/[        S/[        S/[        S/[        S/[        S/[         S/["        S/["        S/[         S/[$        S/[        S/[        S/[        S/S.E0 S.S/ SQSSNSSS.0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_GS GS_GSGS_GSS_GSGS_GSGS_GS	GS
_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_EGSGSSSSSGSSGS.GS.GSGSGSGSGSGS.GS.5      $ (  Nr8   	DigiFinexSGv3i  CORSspotTmarginswapfutureFoption	addMargincancelOrdercancelOrderscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransfersfetchWithdrawals)reduceMarginsetLeverage	setMarginsetMarginModesetPositionModetransferwithdraw151530602407201D1W)	1m5m15m30m1h4h12h1d1wzdhttps://user-images.githubusercontent.com/51840849/87443315-01283a00-c5fe-11ea-8628-c2a0feaf07ac.jpgrestzhttps://openapi.digifinex.comzhttps://www.digifinex.comzhttps://docs.digifinex.comzWhttps://digifinex.zendesk.com/hc/en-us/articles/360000328422-Fee-Structure-on-DigiFinexz>https://www.digifinex.com/en-ww/from/DhOzBg?channelCode=ljaUPp)logoapiwwwdocfeesreferralget)z{market}/symbolsklinezmargin/currencieszmargin/symbolsmarkets
order_bookpingzspot/symbolstimetradesztrades/symbolsticker
currencies)zpublic/api_weightzpublic/candleszpublic/candles_historyzpublic/depthzpublic/funding_ratezpublic/funding_rate_historyzpublic/instrumentzpublic/instrumentszpublic/tickerzpublic/tickerszpublic/timezpublic/trades)r@   rB   )z{market}/financelogz{market}/mytradesz{market}/orderz{market}/order/detailz{market}/order/currentz{market}/order/historyzmargin/assetszmargin/financelogzmargin/mytradeszmargin/orderzmargin/order/currentzmargin/order/historyzmargin/positionszotc/financelogzspot/assetszspot/financelogzspot/mytradesz
spot/orderzspot/order/currentzspot/order/historyzdeposit/addresszdeposit/historyzwithdraw/history)z{market}/order/cancelz{market}/order/newz{market}/order/batch_newzmargin/order/cancelzmargin/order/newzmargin/position/closezspot/order/cancelzspot/order/newr   zwithdraw/newzwithdraw/cancel)r   post)
zaccount/balancezaccount/positionszaccount/finance_recordzaccount/trading_fee_ratezaccount/transfer_recordzaccount/funding_feeztrade/history_ordersztrade/history_tradesztrade/open_ordersztrade/order_info)zaccount/transferzaccount/leveragezaccount/position_modezaccount/position_marginztrade/batch_cancel_orderztrade/batch_orderztrade/cancel_orderztrade/order_placezfollow/sponsor_orderzfollow/close_orderzfollow/cancel_orderzfollow/user_center_currentzfollow/user_center_historyz follow/expert_current_open_orderzfollow/add_algozfollow/cancel_algozfollow/account_availablezfollow/plan_taskzfollow/instrument_list)publicprivate)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceicebergmax
     i    )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   
marketTyper   )r   r   r   r   r   d   )r   r   r   r   r   r   r   r   )	sandboxrK   rL   rp   rs   rr   ru   fetchClosedOrdersrq   extendsdefault   )r   r   )r   r   r   r   r   )r   r   )r   r   )r   rL   rp   rs   rr   ru   rq   forDerivatives)linearinverse)r   r@   r   rB   rC   tradingz0.002)	tierBased
percentagemakertaker10001z=Wrong request method, please check it's a GET ot POST request10002zInvalid ApiKey10003zSign doesn't match10004zIllegal request parameters10005z#Request frequency exceeds the limit10006z$Unauthorized to execute self request10007zIP address Unauthorized10008zETimestamp for self request is invalid, timestamp must within 1 minute10009z+Unexist endpoint, please check endpoint URL10011z?ApiKey expired. Please go to client side to re-create an ApiKey20001z'Trade is not open for self trading pair20002z'Trade of self trading pair is suspended20003zInvalid price or amount20007zPrice precision error20008zAmount precision error20009z+Amount is less than the minimum requirement20010z0Cash Amount is less than the minimum requirement20011zInsufficient balance20012z*Invalid trade type, valid value: buy/sell)20013zNo order info found20014z'Invalid date, Valid format: 2018-07-25)20015zDate exceeds the limit20018z2Your trading rights have been banned by the system20019zQWrong trading pair symbol. Correct format:"usdt_btc". Quote asset is in the front20020zYou have violated the API operation trading rules and temporarily forbid trading. At present, we have certain restrictions on the user's transaction rate and withdrawal rate.50000zException error20021zInvalid currency20022z?The ending timestamp must be larger than the starting timestamp20023zInvalid transfer type20024zInvalid amount20025z/This currency is not transferable at the moment20026z#Transfer amount exceed your balance20027zAbnormal account status20028zBlacklist for transferz'Transfer amount exceed your daily limitz)You have no position on self trading pairzWithdrawal limitedzWrong Withdrawal IDz1Withdrawal service of self crypto has been closedzWithdrawal limitzWithdrawal cancellation failedz[The withdrawal address, Tag or chain type is not included in the withdrawal management listz/The withdrawal address is not on the white listz#Can't be canceled in current statuszFWithdraw too frequently; limitation: 3 times a minute, 100 times a dayz!Beyond the daily withdrawal limitz1Current trading pair does not support API tradingzInvalid Parameter)20029200302003220033200342003520036200372003820039200402004120042400002)exactbroad)r@   rA   otc23)r@   rA   OTCARBITRUMArbitrum	AVALANCECzAVAX-CCHAIN	AVALANCEXzAVAX-XCHAINBEP20BSCCARDANOCardanoCELOCeloCHILIZChilizCOSMOSCRC20
Crypto.comCRONOSDOGECOIN	DogeChainERC20ETHETHWIOTAMIOTAKLAYTNKLAYMATICPolygonMETISMetisDAOMOONBEAMGLMR	MOONRIVER	MoonriverOPTIMISMOPETHPOLYGONRIPPLEXRPSOLANASOLSTELLARStellaTERRACLASSICTerraClassicTERRATerraTONTonTRC20TRONTRXVECHAINVechain)rA  rC  r  r  r#  r$  r+  r  )defaultTypetypes!createMarketBuyOrderRequiresPriceaccountsByTypenetworksnetworksByIdzBlack House TestEpanusFreeRossDAOzMobilian CoinTEL666)BHTEPSFREEMBNTEL)idname	countriesversion	rateLimithas
timeframesurlsr   featuresr   precisionMode
exceptionsoptionscommonCurrencies)deep_extendsuperr8   describeparse_numberr5   r)   r%   r1   r&   r3   r0   r'   r-   r+   r*   r$   r,   r2   )self	__class__s    V/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/digifinex.pyrc  digifinex.describe$   sR   i ? ALLL $L 	L
 %L %L TL tL L /L ,UL 0L tL L &tL  (!L" '#L$ (%L& "5'L( )L* &t+L, +E-L. )%/L0 '1L2 (3L4 "45L6 &t7L8 (9L: 1%;L<  =L> *:?L@ +DALB &tCLD 'ELF (GLH #DILJ *4KLL $UMLN "5OLP *5QLR +ESLT tULV  WLX %dYLZ "5[L\ +D]L^ _L` !%aLb  cLd deLf "4gLh diLj !$kLl tmLn  oLp $UqLr !$sLt %euLv )%wLx tyLz t{L| }L~ TL@ tALB "4CLD #EELF !$GLH #DILJ !%#"!%#(  WL\ 
 ; 30 r\   $   %"J 2!5'R !"SLIqh  %&*(-,0,1).+06:#(#("&#(	( #(/4$)$)+027#()$. r% '+!$$*%'*/& '+#($)&**.# '+!%#($)*/( '+!$$*%'#($)*/$ *.#u=~ y  )!&+%
 ',!$$*%+	& %e# ',!$(
 ',$*$
  #/#: "#3 "#3 	 ##KiV !%"&!..w7!..w7	 '1j*ij113CD1 13GH1 j*FG	1
 n.ST1 .0VW1 .0IJ1 l,st1 l,YZ1 .0qr1 .0YZ1 .0YZ1 l,EF1 l,CD1 l,DE1  l,YZ!1" l,^_#1$ /1GH%1& j*VW'1( l,AB)1* j*ST+1, j*BC-1. .0de/10 i)|}112 n  /_  `314 m->?516 j*<=718 j*kl91: j*AB;1< j*:;=1> j*[\?1@ /1VWA1B .0IJC1D .0HIE1F /0YZ(*UV.0DE(*?@.0cd.0BC+-MN,  /L  M,._`+-RS/1yz.0ST')\])+>?a1dg5n  &259!#
"
""  " W	"
 7" y" F" h" h" \" l" " W" 7" F"  G!"" f#"$ Y%"& Z'"( )"*  +", -". y/"0 e1"2 e3"4 x5"6 #N7"8 W9": 5;"< W="> G?"@ 7A"B yC"H %"$"$"("*	!Y6p *%&!yCD
 C C	    c                   #    U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  US5      n[        UR	                  5       5      n0 n[        S[        U5      5       H  nXW   nXH   n	U R                  U5      n
0 n[        S[        U	5      5       H  nX   nU R                  USS5      nU R                  U5      nUUSU R                  US5      S:H  U R                  US5      S:H  U R                  US	5      SU R                  US
5      SS.U R                  US5      SS.S.US.	X'   M     U R                  UU
U	US.5      Xj'   M     U$  GNG7f)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
Ndatacurrencyr   chaindeposit_status   withdraw_statusmin_withdraw_feemin_withdraw_amountminr   min_deposit_amountr   deposit)	rT  networkactiverw  r   fee	precisionlimitsinfo)rT  coder}  rJ  )publicSpotGetCurrencies	safe_listgroup_bylistkeysrangelensafe_currency_codesafe_string_2network_id_to_codesafe_integersafe_numbersafe_currency_structure)re  paramsresponserk  groupedByIdr  resultirT  networkEntriesr~  rJ  jnetworkEntry	networkIdnetworkCodes                   rg  fetch_currenciesdigifinex.fetch_currencies  s     55f==R ~~h3mmD*5K$$&'q#d)$AB(_N**2.DH1c.12-0 ..|WjQ	"55i@#*"#00?OPTUU $ 1 1,@Q RVW W++L:LM!% $(#3#3LBW#X#'%
 $(#3#3LBV#W#'$	 )%)%	 30  77&$	9 FL; %F a >s   E!EEE!c                    #    U R                  U R                  S0 5      nU R                  USS5      nUS:X  a  U R                  U5      I Sh  vN $ U R	                  U5      I Sh  vN $  N N7f)z
retrieves data on all markets for digifinex
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
rn   methodfetch_markets_v2N)
safe_valuer_  safe_stringr  fetch_markets_v1)re  r  r_  r  s       rg  fetch_marketsdigifinex.fetch_marketsB  sk      //$,,C!!'85GH''..v666**6222 72s$   AA/A+A/&A-'A/-A/c                 f  #    U R                  U R                  S5      nU R                  SU5      u  p4/ nUb!  UR                  U R	                  U5      5        O UR                  U R                  U5      5        UR                  U R                  U5      5        [        R                  " U6 I S h  vN nUS   nUS   nU R                  US/ 5      n	U R                  US/ 5      n
U R                  X5      n/ n[        S[        U5      5       GH  nX   nU R                  USS5      nU R                  US	S
5      nU R                  USS5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  U5      nU R                  USS5      nUS:X  a  SOSnUS L nU(       + nUb  SOS nUS-   U-   nS nS nU(       aH  SnUS-   U-   S-   U-   nU R                  US5      nU(       d  SOSnU R                  US5      nU(       a  SnUR                  0 SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S S_S!S_S"U(       a  SOS_S#U_S$U_UU R!                  US%5      S S S S U R#                  U R%                  U R                  US&5      5      5      U R#                  U R%                  U R                  US'5      5      5      S(.S S S).U R'                  US*S+5      S S).U R!                  US,5      S S).U R!                  US-5      S S).S..S US/.
E5        GM     U$  GN7f)0NrF  fetchMarketsV2r   ro  symbol_listrk  symbolinstrument_id
base_assetbase_currencyquote_assetquote_currencyclear_currencyis_allowrA   r@   T/rB   :
is_inverseF	isTradingrT  basequotesettlebaseIdquoteIdsettleIdtyperC   rD   ry  contractr   contract_valueamount_precisionprice_precision)amountpricers  minimum_amountmin_order_amount	tick_sizeminimum_valuer   r  r  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTyper{  r|  createdr}  )r  r_  handle_margin_mode_and_paramsappendpublicSpotGetMarginSymbolspublicSpotGetTradesSymbolspublicSwapGetPublicInstrumentsasynciogatherr  array_concatr  r  r  r  r  r  rd  parse_precisionsafe_number_2)re  r  rF  r   querypromisesRawpromisesspotMarketsswapMarketsspotDataswapDatar  r  r  marketrT  r  r  r  r  r  r  	isAllowedr  r@   rB   rA   r  	isInverseisLinearr  s                                  rg  r  digifinex.fetch_markets_v2N  s    &&t||]C >>?OQWX
!t>>uEFt>>uEF4>>vFG 55qkqkj ??;rB??;;$$X8q#h-(A[F##FHoFB''oNF((@PQG''0@AH**62D++G4E,,X6F ))&*a@I +x 78fDT>D8D(4T4FCZ%'FIHe+c1F: OOFLA	(14 OOFK@	 !IMM 0b0&0 0 	0
 &0 &0 70 H0 0 0 &0 0 %0 %0 )$0  D!0" (#0$ % $ 0 09I J"&""//0D0DTEUEUV\^pEq0rs!..t/C/CDDTDTU[]nDo/pq  $#!
  $11&:JL^_#
  $//D#
  $//H#$  _0 0G )h _ 6s   B-L1/L.0I?L1c                   #    U R                  U5      I S h  vN nU R                  US/ 5      n/ n[        S[        U5      5       GH5  nX5   nU R	                  US5      nUR                  S5      u  pU R                  U5      n
U R                  U	5      nUR                  0 SU_SU
S-   U-   _SU
_S	U_S
S _SU_SU	_SS _SS_SS_SS _SS_SS_SS_SS _SS_SS _S S S S S S U R                  U R                  U R	                  US5      5      5      U R                  U R                  U R	                  US5      5      5      S.S S S.U R                  US5      S S.S S S.U R                  US5      S S.S.US .	E5        GM8     U$  GNk7f)!Nrk  r   r  _rT  r  r  r  r  r  r  r  r  r  r@   TrA   rB   FrC   rD   ry  r  r   r  volume_precision)r  r  rs  
min_volume
min_amountr  )	r   r  r  r  r  r  r{  r|  r}  )publicSpotGetMarketsr  r  r  r  splitr  r  rd  r  r  )re  r  r  r   r  r  r  rT  r  r  r  r  s               rg  r  digifinex.fetch_markets_v1  sE    226::  //(FB7q#g,'AZF!!&(3B hhsmOF**62D++G4EMM /b/$*u,/ / 	/
 $/ &/ 7/ D/ / / $/ / %/ %/ $/  E!/" $#/$   $"&"!..t/C/CDDTDTU[]nDo/pq"//0D0DTEUEUV\^pEq0rs  $#!
  $//E#
  $#
  $//E#$ ]/ / (l Q ;s   FFE+Fc                 h   SU0n[        S[        U5      5       H  nX   nU R                  US5      nU R                  U5      nU R	                  5       nU R                  USS5      nU R                  USS5      n	XS'   [        R                  " X5      US'   XS'   XrU'   M     U R                  U5      $ )	Nr}  r   rl  freeavail_balancetotalequityused)	r  r  r  r  accountr  r6   
string_subsafe_balance)
re  r  r  r  balance
currencyIdr~  r  r  r  s
             rg  parse_balancedigifinex.parse_balance3  s    2 )q#h-(AkG))':>J**:6DllnG%%gvGD&&wBE"FO%00=GFO$G"4L )   ((ri  c                   #    U R                  5       I Sh  vN   SnU R                  SSU5      u  p!U R                  SU5      u  p4SnUc  US:X  a  SnU R                  U5      I Sh  vN nOXUS:X  a  U R	                  U5      I Sh  vN nO8US:X  a  U R                  U5      I Sh  vN nO[        U R                  S-   5      eUS:X  a  SOSnU R                  XV/ 5      nU R                  U5      $  N N Nn NP7f)	a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://docs.digifinex.com/en-ww/spot/v3/rest.html#spot-account-assets
https://docs.digifinex.com/en-ww/spot/v3/rest.html#margin-assets
https://docs.digifinex.com/en-ww/swap/v2/rest.html#accountbalance

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
NrR   rA   r@   rB   z, fetchBalance() not support self market typerk  r  )
load_marketshandle_market_type_and_paramsr  privateSpotGetMarginAssetsprivateSpotGetSpotAssetsprivateSwapGetAccountBalancer/   rT  r  r  )re  r  r   r   r  r  balanceRequestbalancess           rg  fetch_balancedigifinex.fetch_balanceZ  s     !!!
!??PTV\]
 >>~vV
!Z8%;!J!<<UCCH6!!::5AAH6!!>>uEEHtww)WWXXJ %/&$8v??8R@!!(++i 	" DAEsG   C:C2AC:'C4(C:C6C:'C8(AC:4C:6C:8C:Nr  r   c                 &  #    U R                  5       I Sh  vN   U R                  U5      nU R                  SXC5      u  pV0 nUb  X'S'   SnUS:X  a1  US   US'   U R                  U R	                  Xv5      5      I Sh  vN nO0US   US'   U R                  U R	                  Xv5      5      I Sh  vN nSn	Sn
US:X  a&  U R                  US0 5      n
U R                  U
S	5      n	OUn
U R                  US
5      n	U R                  XS   U	5      $  N N Na7f)aC  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://docs.digifinex.com/en-ww/spot/v3/rest.html#get-orderbook
https://docs.digifinex.com/en-ww/swap/v2/rest.html#orderbook

: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
Nrt   r   rB   rT  r  r  rk  	timestampdate)
r  r  r  publicSwapGetPublicDepthextendpublicSpotGetOrderBookr  r  safe_timestampparse_order_book)re  r  r   r  r  r   r  requestr  r  	orderBooks              rg  fetch_order_bookdigifinex.fetch_order_book  s,     !!!V$ >>?OQW`
$G'-d|GO$!::4;;w;VWWH &tGH!88W9TUUHN 		&"=I)))[AI I++Hf=I$$Yx0@)LLw 	" X Vs5   DDA%D<D=0D-D.ADDDsymbolsc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  US5      nSnUb  U R                  U5      nSnU R	                  SXB5      u  pR0 nSnUS:X  a)  U R                  U R                  Xb5      5      I Sh  vN nO(U R                  U R                  Xb5      5      I Sh  vN n0 nU R                  USS/ 5      n	U R                  US5      n
[        S[        U	5      5       H3  nU R                  SU
0X   5      nU R                  U5      nUS   nXU'   M5     U R                  USU5      $  GN6 N N7f)	a&  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.digifinex.com/en-ww/spot/v3/rest.html#ticker-price
https://docs.digifinex.com/en-ww/swap/v2/rest.html#tickers

: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}   rB   r   rk  r  r  )r  market_symbolsr  r  r  publicSwapGetPublicTickersr  publicSpotGetTickersafe_value_2r  r  r  parse_tickerfilter_by_array_tickers)re  r	  r  firstr  r  r  r  r  tickersr  r  	rawTickerr   r  s                  rg  fetch_tickersdigifinex.fetch_tickers  sa     !!!%%g.  !,[['F99.&Y6>!<<T[[=YZZH!55dkk'6RSSHb ##HhC  62q#g,'A%zI &&y1FH%F#6N ( ++FHgFFQ 	" [Ss5   EEB EE(E EBEEEc                 F  #    U R                  5       I Sh  vN   U R                  U5      n0 nSnUS   (       a1  US   US'   U R                  U R                  XB5      5      I Sh  vN nO0US   US'   U R	                  U R                  XB5      5      I Sh  vN nU R                  US5      nU R                  US/ 5      nU R                  US0 5      nU R                  US	0 5      n	Sn
US   (       a  Un
OU R                  SU0U	5      n
U R                  X5      $  GN N N7f)
a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.digifinex.com/en-ww/spot/v3/rest.html#ticker-price
https://docs.digifinex.com/en-ww/swap/v2/rest.html#ticker

: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>`
NrB   rT  r  r  r  r   rk  r   )r  r  publicSwapGetPublicTickerr  r  r  r  r  )re  r  r  r  r  r  r  r  rk  firstTickerr  s              rg  fetch_tickerdigifinex.fetch_ticker9  s     !!!V$&>'-d|GO$!;;DKK<XYYH &tGH!55dkk'6RSSH\   62//(Hb9x4oogq"5&>F[[&$=F  00A 	" Z Ts5   D!DAD!%D&0D!DBD!D!D!r   r  c           	      J   U R                  US5      nUb  SOSnU R                  USS5      nU R                  XRS U5      nU R                  XRS U5      nU R	                  US5      nUS   (       a  U R                  US5      nU R                  US	5      nU R                  0 SU_SU_S
U R                  U5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  US5      _SU R                  USS5      _SU R                  US5      _SS _SU R                  US5      _SU_S	U_SS _SS _SU R                  USS 5      _S!S _U R                  US"S#5      U R                  US$5      U R                  US%5      UUS&.EU5      $ )'Nindex_pricer  r@   r  r  r  rB   r  lastdatetimehighhigh_24hlowlow_24hbidbuybest_bid	bidVolumebest_bid_sizeasksellbest_ask	askVolumebest_ask_sizevwapopenopen_24hclosepreviousClosechanger   price_change_percentaveragevol
volume_24hbase_vol
mark_price)
baseVolumequoteVolume	markPrice
indexPricer}  )
r  safe_string_upper_2safe_symbolsafe_marketr  r  r  safe_tickeriso8601r  )	re  r   r  r<  r   marketIdr  r  r  s	            rg  r  digifinex.parse_ticker  s<   P %%fm<
$.$:Z
++FHoN!!(D*E!!(D*E''7	&>))&+>I/ !
f!
!
 Y/!
 D&&vvzB	!

 4%%feY?!
 4%%feZ@!
 ))&/B!
 4%%ffjA!
 ))&/B!
 D!
 D$$VZ8!
 T!
 D!
 T!
 d!
  $,,VX?UV!!
" t#!
$ ,,VULI++FJ?))&,?$-!
. / 	ri  tradec                 L   U R                  USS5      nU R                  US5      nU R                  US5      nU R                  U/ SQ5      nU R                  USS5      nU R	                  Xr5      nUc  U R                  U5      nU R                  USS	5      n	U R                  US
S5      n
S nS nUS
   S:X  a  U R                  US5      n	U R                  US5      nU R                  US5      nU R                  US5      nUb
  US:X  a  SOS nUS:X  a  SnOUS:X  a  SnOS nU
S:X  d  US:X  a  Sn
OU
S:X  d  US:X  a  Sn
OuU
S:X  d  US:X  a  Sn
OfU
S:X  d  US:X  a  Sn
OWU
R                  S5      nU R                  US5      n
U R                  US5      nUc  SnU R                  US5      nU(       a  SOSnS nU R                  US5      nUb-  U R                  US 5      nS nUb  U R                  U5      nUUS!.nU R                  UUU	U R                  U	5      UUUU
UUS UUS".U5      $ )#NrT  trade_idorder_idr  )r  volumesizer  r  r  r  r  siderB   
trade_time
order_type
match_role	direction0r   r   r   r  r   r$  r)  r  4r  r   ro  is_makerrz  fee_currency)r  rl  )rT  r}  r  r  r  r  orderrJ  r  r  r  takerOrMakerrz  )r  r  safe_string_nr=  r>  r?  safe_timestamp_2r  r  r  r  
safe_traderA  )re  rD  r  rT  orderIdpriceStringamountStringrB  r  r  rJ  r  rT  	orderType	tradeRolerN  partsisMakerrz  feeCostStringfeeCurrencyIdfeeCurrencyCodes                         rg  parse_tradedigifinex.parse_trade  s   p tZ8""5*5&&ug6))%1MN++E8_M!!(3>%%h/F))%E	!!%8&>V#))%>I((=I((=I((<I$#,#3w$C&c!&#c!1#+9#3#+9#3#+9#3JJsOE##E1-D##E1-D|ooeZ8G&-77L((6$ ,,UNCM"O("&"9"9-"H%+C "Y/ "( 
  	ri  c                 d   #    U R                  U5      I Sh  vN nU R                  US5      $  N7f)z
fetches the current integer timestamp in milliseconds from the exchange server
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
Nserver_time)publicSpotGetTimer  )re  r  r  s      rg  
fetch_timedigifinex.fetch_timeP  s4      //77 ""8];; 8s   0.0c                    #    U R                  U5      I Sh  vN nU R                  US5      nUS:X  a  SOSnUSSSUS.$  N(7f)z
the latest known information on the availability of the exchange API
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
Nr~  r   okmaintenance)statusupdatedetaurlr}  )publicSpotGetPingr  )re  r  r  r~  rl  s        rg  fetch_statusdigifinex.fetch_status_  sY      //77   62!)-
 	
 8s   AA )Asincec                   #    U R                  5       I Sh  vN   U R                  U5      n0 nUb  US   (       a  [        US5      OUUS'   SnUS   (       a1  US   US'   U R                  U R	                  Xd5      5      I Sh  vN nO0US   US'   U R                  U R	                  Xd5      5      I Sh  vN nU R                  US/ 5      nU R                  XX#5      $  N N\ N-7f)	a,  
get the list of most recent trades for a particular symbol

https://docs.digifinex.com/en-ww/spot/v3/rest.html#get-recent-trades
https://docs.digifinex.com/en-ww/swap/v2/rest.html#recenttrades

: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>`
NrB   r   r   rT  r  r  rk  )r  r  rt  publicSwapGetPublicTradesr  publicSpotGetTradesr  parse_trades)	re  r  rs  r   r  r  r  r  rk  s	            rg  fetch_tradesdigifinex.fetch_tradesv  s      !!!V$28.s5#eGG&>'-d|GO$!;;DKK<XYYH &tGH!55dkk'6RSSHT ~~h3  u<<m 	" Z Ts4   C$CA,C$C 0C$4C"5*C$ C$"C$c           	         US   (       ah  U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )NrB   r   ro              )r  r  r  )re  ohlcvr  s      rg  parse_ohlcvdigifinex.parse_ohlcv  s     &>!!%+  *  *  *  *  *  ##E1-  *  *  *  *  * ri  r   	timeframec                 (  #    U R                  5       I Sh  vN   U R                  U5      n0 nSnUS   (       aH  US   US'   X'S'   Ub  [        US5      US'   U R                  U R	                  Xu5      5      I Sh  vN nGO/U R                  US5      n	US   US	'   U R                  U R                  X"5      US
'   Un
U R                  U5      nU
c,  Uc  U	b&  U	b  U	OU R                  5       nUb  UOSnXU-  S-  -
  n
U
bw  U R                  U
S-  5      n
XS'   Uc  U	bY  U	b?  U R                  U	S-  5      nUb#  U R                  XU-  5      n[        X5      US'   OXS'   OU R                  XU-  5      US'   U R                  US5      nU R                  U R	                  Xu5      5      I Sh  vN nSnUS   (       a'  U R                  US0 5      nU R                  US/ 5      nOU R                  US/ 5      nU R                  UXbX45      $  GN GN Nc7f)a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.digifinex.com/en-ww/spot/v3/rest.html#get-candles-data
https://docs.digifinex.com/en-ww/swap/v2/rest.html#recentcandle

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest candle to fetch
:returns int[][]: A list of candles ordered, open, high, low, close, volume
NrB   rT  r  granularityr   r   untilr  period     
start_timeend_timerk  candles)r  r  rt  publicSwapGetPublicCandlesr  r  r  rZ  parse_timeframemillisecondsparse_to_intsumomitpublicSpotGetKliner  parse_ohlcvs)re  r  r  rs  r   r  r  r  r  r  	startTimedurationendTime
startLimit
endByUntil
endByLimitr  rk  s                     rg  fetch_ohlcvdigifinex.fetch_ohlcv  s;     !!!V$&>'-d|GO$%.M" #&uc? !<<T[[=YZZH%%fg6E &tGH $ 0 0) WGHI++I6H %5+<(-(9e@Q@Q@SG+0+<3J '+@4+G HI$ --i$.>?	(1%%5+<(%)%6%6ut|%D
 ,)-)X=M)NJ25j2MGJ/2<J/.2hhy(BR.S
+YYvw/F!44T[[5QRRH8 &>??8VR8DoodIr:Gooh;G  &UJJK 	" [4 Ss6   HH
A$H;H<D0H,H-AHHHr  rJ  r  r  c                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  SU5      nUS   n	U R                  XX4XV5      n
SnUS   (       a  U R	                  U
5      I Sh  vN nO6U	b  U R                  U
5      I Sh  vN nOU R                  U
5      I Sh  vN nU R                  X5      nUS   US'   X,S'   X<S'   XLS'   X\S	'   U$  N Nh NM N57f)
a@  
create a trade order

https://docs.digifinex.com/en-ww/spot/v3/rest.html#create-new-order
https://docs.digifinex.com/en-ww/swap/v2/rest.html#orderplace

: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 you want to trade in units of the base currency, spot market orders use the quote currency, swap requires the number of contracts
: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.timeInForce]: "GTC", "IOC", "FOK", or "PO"
:param bool [params.postOnly]: True or False
:param bool [params.reduceOnly]: True or False
:param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
:param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrK   r   rB   r  r  rJ  r  r  )r  r  r  create_order_requestprivateSwapPostTradeOrderPlaceprivateSpotPostMarginOrderNewprivateSpotPostSpotOrderNewparse_order)re  r  r  rJ  r  r  r  r  marginResultr   r  r  rS  s                rg  create_orderdigifinex.create_order/  s     ( !!!V$99-P!!_
++F$V&>!@@IIH%!%!C!CG!LL!%!A!A'!JJ    2 *hff hgE 	" J MJsF   C%CAC%6C7C%C!C%-C#.0C%C%!C%#C%ordersc           	        #    U R                  5       I Sh  vN   / nSnSn[        S[        U5      5       H  nX   nU R                  US5      nUc  UnOXH:w  a  [	        U R
                  S-   5      eU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  US	0 5      nU R                  S
U5      nUS   nUb#  Uc  UnOX_:w  a  [	        U R
                  S-   5      eU R                  XXX5      nUR                  U5        M     U R                  U5      n0 nSnUS   (       a  U R                  U5      I Sh  vN nO?Ub  SOSUS'   US   US'   U R                  U5      US'   U R                  U5      I Sh  vN n/ nUS   (       a  U R                  US/ 5      nOU R                  US/ 5      n/ n[        S[        U5      5       HT  nX   n0 nUU   US'   US   US'   U R                  US5      US'   U R                  US5      US'   UR                  U5        MV     U R                  UU5      $  GNH N N7f)a  
create a list of trade orders(all orders should be of the same symbol)

https://docs.digifinex.com/en-ww/spot/v3/rest.html#create-multiple-order
https://docs.digifinex.com/en-ww/swap/v2/rest.html#batchorder

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  z; createOrders() requires all orders to have the same symbolr  rJ  r  r  r  rL   zS createOrders() requires all orders to have the same margin mode(isolated or cross)rB   rA   r@   r  rT  r  rk  	order_idsrG  r  )r  r  r  r  r)   rT  r  r  r  r  r  privateSwapPostTradeBatchOrderjson"privateSpotPostMarketOrderBatchNewr  parse_orders)re  r  r  ordersRequestsr  r   r  rawOrderrB  r  rJ  r  r  orderParamsr  currentMarginModeorderRequestr  r  r  rk  r  individualOrders                          rg  create_ordersdigifinex.create_ordersg  s     !!!
q#f+&AyH''(;H~!%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==nkZL ,Q ,%!2J!6(  4I  *I  J  J44XTSXfL!!,/- '. V$&>!@@PPH-7-C&GH &tGH"ii7GFO!DDWMMH, &>??8VR8D??8["=Dq#f+&AyH$&O*.q'OJ'/5d|OO,(,(8(88(LOH%'+'7'7''JOG$MM/* '   00Q 	"> Q
 Ns5   I%IEI%%I!&?I%%I#&B9I%!I%#I%c                    U R                  U5      nSnSn	U R                  SXv5      u  pU R                  SU5      u  pU	b  Sn0 n
US:H  nUS:H  nUS:H  nU(       a  SOSnUS	   X'   U R                  US
U5      nSnU(       a  U R	                  USS
5      nU R                  US5      nSnUS:X  a  U(       a  SOSnUU
S'   OU(       a  SOSnUU
S'   U(       a  SnUS:X  a  U(       a  SOSnO*US:X  a  U(       a  SOSnOUS:X  d  U(       a  SnOUS:X  a  SnUb  U R                  X5      U
S'   UU
S'   XJS'   U R                  USS/5      nGO;USL a  SOSnXS'   S nUS:X  a  S!nOU R                  X5      U
S'   UU-   U
S'   SnSnU R                  USS"S5      u  nnU(       a  US:X  a  U R                  US#5      nU R                  US#5      nUb  U R                  UU5      nOU(       av  Uc  [        U R                  S$-   5      eU R                  U5      nU R                  U5      nU R                  [        R                   " UU5      5      nU R                  UU5      nO#U R                  X5      nOU R#                  X5      nUU
S%'   U(       a  U(       a  UU
S&'   OXS&'   U R                  US'/5      nU R%                  X5      $ )(a  
@ignore
       helper function to build request
       :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 you want to trade in units of the base currency, spot market orders use the quote currency, swap requires the number of contracts
       :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
       :returns dict: request to be sent to the exchange
       NcreateOrderRequestrA   rB   r  r   r  r  rT  F
reduceOnlyr   r$  r}  ro  r  r|  r{  r   r      	   r      GTC   r   Tr  rL  rI   _marketrH  r  a	   createOrder() requires a price argument for market buy orders on spot markets to calculate the total amount to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentr  	post_onlypostOnly)r  r  r  is_post_only	safe_boolr  price_to_precisionr  handle_option_and_paramsr  cost_to_precisionr-   rT  number_to_stringrd  r6   
string_mulamount_to_precisionr  )re  r  r  rJ  r  r  r  r  r   r   r  rB   isMarketOrderisLimitOrdermarketIdRequestr  postOnlyParsedr  r   r[  requestTypesuffixquantityrH  r  rZ  rY  costRequests                               rg  r  digifinex.create_order_request  s"    V$

!??@TV\e
!??@TV\]
!!Jf$)-1/x#)$< $$]E6BeDJ**6=AKIu}$.aQ"-$.aQ"-	e#"/BQ	%"/BQ	&M	$ #'#:#:6#I $-GL!$FOYYvm'DEF#+t#3Q!N *HFx"#'#:#:6#I "VmGFOH04-8<8U8UV\^r  uX  Z^  9_5-v$%-''7662##55fdCH6}*477  6A  ,A  B  B'+'<'<V'D&*&;&;E&B&*&7&78J8J<Yd8e&f#'#9#9&+#N#55fEH33FC (GH'5$'/$6J<0{{7++ri  r  c                    #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS'   U R	                  USSUSU5      I Sh  vN $  NZ N7f)a  
create a market buy order by providing the symbol and cost

https://docs.digifinex.com/en-ww/spot/v3/rest.html#create-new-order

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr@   z9 createMarketBuyOrderWithCost() supports spot orders onlyFrH  r  r$  )r  r  r/   rT  r  )re  r  r  r  r  s        rg  !create_market_buy_order_with_cost+digifinex.create_market_buy_order_with_cost  sw      !!!V$f~tww)ddee6;23&&vxdFSSS 	"
 Ts"   A5A1AA5,A3-A53A5rT  c                   #    U R                  5       I Sh  vN   SnUb  U R                  U5      n[        U5      nSnU R                  SXC5      u  pSSU0nUS:X  a$  Uc  [	        U R
                  S-   5      eUS   US'   OXVS'   U R                  SU5      u  pxSn	Uc  US	:X  a+  S	nU R                  U R                  Xh5      5      I Sh  vN n	OvUS
:X  a)  U R                  U R                  Xh5      5      I Sh  vN n	OGUS:X  a)  U R                  U R                  Xh5      5      I Sh  vN n	O[        U R
                  S-   5      eUS
:X  d  US	:X  ae  U R                  U	S/ 5      n
[        U
5      nUS:w  a  [        U R
                  S-   U-   S-   5      eU R                  U	5      nU R!                  US5      $ U R#                  U	U R%                  U	S5      S.5      $  GN GN N N7f)a  
cancels an open order

https://docs.digifinex.com/en-ww/spot/v3/rest.html#cancel-order
https://docs.digifinex.com/en-ww/swap/v2/rest.html#cancelorder

:param str id: order id
:param str symbol: not used by digifinex cancelOrder()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrF   rG  rB   z) cancelOrder() requires a symbol argumentrT  r  r  rA   r@   z+ cancelOrder() not support self market typesuccessro  z cancelOrder() 
 not foundr   rk  )r}  rX  )r  r  strr  r(   rT  r   privateSpotPostMarginOrderCancelr  privateSpotPostSpotOrderCancelprivateSwapPostTradeCancelOrderr/   r  r  r.   parse_cancel_orders	safe_dict
safe_orderr  )re  rT  r  r  r  r   r  r   r  r  canceledOrdersnumCanceledOrdersr  s                rg  cancel_orderdigifinex.cancel_order)  s     !!![[(FW
!??v^

 ~'2](]^^'-d|GO$ *H >>}fU
!Z8%;!J!BB4;;wC^__H6!!@@WA\]]H6!!AA$++gB]^^Htww)VVWW, & jH&<!__Xy"EN #N 3 A%#DGG.?$?"$D|$STT--h7F>>&!,,?? ++Hf=$  q 	"( `]^sG   G#GB1G#G	.G#7G8.G#&G!'B3G#G#G#!G#c                    U R                  US5      nU R                  US5      n/ n[        S[        U5      5       H+  nX%   nUR                  U R	                  UUSS.5      5        M-     [        S[        U5      5       HM  nX5   nUR                  U R	                  UU R                  USS5      SU R                  US	5      S
.5      5        MO     U$ )Nr  errorr   canceled)r}  rT  rl  zorder-idrG  failedzclient-order-id)r}  rT  rl  clientOrderId)r  r  r  r  r  r  r  )re  r  r  r  r  r  rS  s          rg  r  digifinex.parse_cancel_ordersr  s    ..95x1q#g,'AJEMM$//$+   ( q#e*%AHEMM$//((
JG"!%!1!1%9J!K	+   & ri  idsc                 `  #    U R                  5       I Sh  vN   U R                  U R                  SS5      nU R                  USU5      nU R                  US5      nUSR	                  U5      S.nU R                  U R                  Xc5      5      I Sh  vN nU R                  U5      $  N N7f)a  
cancel multiple orders
:param str[] ids: order ids
:param str symbol: not used by digifinex cancelOrders()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NrF  r@   r  ,)r  rG  )r  r  r_  r  joinr  r  r  )re  r  r  r  rF  r[  r  r  s           rg  cancel_ordersdigifinex.cancel_orders  s      !!!&&t||]FK$$VV[A	66*
 <<T[[=YZZ ''11+ 	" [s"   B.B*A=B.B,B.,B.rl  c                 6    SSSSSS.nU R                  X!U5      $ )Nr.  closedr  )rO  r   r  r  rP  r  re  rl  statusess      rg  parse_order_statusdigifinex.parse_order_status  s-    
 &99ri  rS  c                    S nS nS nS nU R                  US5      nU R                  USS5      nU R                  X5      n	U R                  U	5      nUS   S:X  a  U R	                  US5      n
U
b  U
S:X  d  U
S:X  d  U
S:X  d  U
S	:X  d  U
S
:X  a  SnO;U
S:X  d  U
S:X  d  U
S:X  d  U
S:X  d  U
S:X  a  SnOU
S:X  d  U
S:X  d  U
S:X  d  U
S:X  a  SnU
S:X  d  U
S:X  d  U
S:X  d  U
S:X  d  U
S:X  d  U
S:X  a  SnOSnUS:X  a  SnOUS:X  a  SnOUS:X  a  S nOUS!:X  a  S"nU R	                  US#5      nU R	                  US$5      nOVU R                  US%5      nU R                  US&5      nUb/  UR                  S'5      n[        U5      nUS:  a  US   nUS   nOSnU R                  0 S(U_S)U R                  US*S+5      _S,S _S-U_S.U R                  U5      _S/U_SU	_SU_S0U_S1S _S2U_S3U R                  US35      _S4S _S5U R                  US5S65      _S7U R                  US8S95      _S:S _S;S _U R                  US<S=5      U R                  U R                  US>S?5      5      S;U R                  US@5      0S SA.EU5      $ )BNr  r  r  rB   rL  r  r         r  r   ro  r{  r|  r}  r  r            r  r  r   r~  r   r  r   z	open longr  z
open shortr  z
close longrP  zclose shortinsert_time
time_stampcreated_datefinished_dater  r}  rT  rG  rk  r  r  r  lastTradeTimestampr   r  rJ  r  r   r  rI  filledexecuted_amount
filled_qty	remainingr  	avg_price	price_avgrl  staterz  )r4  rl  rz  r   )r  r  r>  r  r  r  r  r  r  rA  r  r  r  )re  rS  r  r  r  r   r  rJ  rB  r  r[  r]  numPartss                rg  r  digifinex.parse_order  sj   @ 	!v.%%eXG!!(3V$&>V#))%>I$N	RY"_R[_aRagptvgv"'K1n)q.i1nR[_`R`fosufu"'K1n)q.i1nR[_aRa"'KN	QINPY]^P^dmqrdr  yB  FH  yH"D#Ds{"##$))%?I!%!2!25,!G++E>BI!%!4!4UO!L

3u:a< 8D 8D"D  
E 
$$$UJ? 
 T 
 	 

 Y/ 
 !"4 
 f 
 D 
 ; 
  
 D 
 T%%eW5 
 D 
 d((&A 
 d((0A<P 
  ! 
" D# 
$ ))%kJ--d.@.@RY.Z[((6 / 
0 1 	ri  c                   #    U R                  5       I Sh  vN   SnUb  U R                  U5      nSnU R                  SXT5      u  pdU R                  SU5      u  px0 n	US:H  n
U
(       a  Ub  X)S'   Ub  X9S'   OXiS'   Ub  U
(       a  SOSnUS	   X'   SnUc  US
:X  a+  S
nU R	                  U R                  X5      5      I Sh  vN nOvUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOGUS:X  a)  U R                  U R                  X5      5      I Sh  vN nO[        U R                  S-   5      eU R                  US/ 5      nU R                  XX#5      $  GNL N Nv NI7f)a  
fetch all unfilled currently open orders

https://docs.digifinex.com/en-ww/spot/v3/rest.html#current-active-orders
https://docs.digifinex.com/en-ww/swap/v2/rest.html#openorder

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch open orders for
:param int [limit]: the maximum number of  open orders structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nrr   rB   start_timestampr   r  r  r  rT  rA   r@   z/ fetchOpenOrders() not support self market typerk  )r  r  r  r   privateSpotGetMarginOrderCurrentr  privateSpotGetSpotOrderCurrentprivateSwapGetTradeOpenOrdersr/   rT  r  r  )re  r  rs  r   r  r  r   r   r  r  rB   r  r  rk  s                 rg  fetch_open_ordersdigifinex.fetch_open_orders4  s     !!![[(F
!??@QSYb
 >>?PRXY
f$ -2)* #(  *H15o8O'-d|G$!Z8%;!J!BB4;;wC^__H6!!@@WA\]]H6!!??G@[\\Htww)ZZ[[h ~~h3  u<<c 	", `]\sG   E+E"B*E+E%.E+0E'1.E+E) AE+%E+'E+)E+c                    #    U R                  5       I Sh  vN   SnUb  U R                  U5      nSnU R                  SXT5      u  pdU R                  SU5      u  px0 n	US:X  a  Ub  X)S'   OXiS'   Ub  U R	                  US-  5      U	S'   Ub  US:X  a  SOS	n
US
   X'   Ub  X9S'   SnUc  US:X  a+  SnU R                  U R                  X5      5      I Sh  vN nOvUS:X  a)  U R                  U R                  X5      5      I Sh  vN nOGUS:X  a)  U R                  U R                  X5      5      I Sh  vN nO[        U R                  S-   5      eU R                  US/ 5      nU R                  XX#5      $  GN_ N Nv NI7f)aR  
fetches information on multiple orders made by the user

https://docs.digifinex.com/en-ww/spot/v3/rest.html#get-all-orders-including-history-orders
https://docs.digifinex.com/en-ww/swap/v2/rest.html#historyorder

: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>`
Nru   rB   r
  r  r  r  r  r  rT  r   rA   r@   z+ fetchOrders() not support self market typerk  )r  r  r  r  r   privateSpotGetMarginOrderHistoryr  privateSpotGetSpotOrderHistory privateSwapGetTradeHistoryOrdersr/   rT  r  r  )re  r  rs  r   r  r  r   r   r  r  r  r  rk  s                rg  fetch_ordersdigifinex.fetch_orders  s     !!![[(F
!??v^
 >>}fU
 -2)* *H (,(9(9%$,(G%2<2FoXO'-d|G$$G!Z8%;!J!BB4;;wC^__H6!!@@WA\]]H6!!BB4;;wC^__Htww)VVWWh ~~h3  u<<e 	". `]_sG   E>E5B=E>E8.E>E:.E>2E<3AE>8E>:E><E>c                 &  #    U R                  5       I Sh  vN   SnUb  U R                  U5      nSnU R                  SXC5      u  pSU R                  SU5      u  pgSU0nUS:X  a  Ub  US   US'   OXXS'   Sn	Uc  US:X  a+  SnU R	                  U R                  X5      5      I Sh  vN n	OvUS	:X  a)  U R                  U R                  X5      5      I Sh  vN n	OGUS:X  a)  U R                  U R                  X5      5      I Sh  vN n	O[        U R                  S
-   5      eU R                  U	S5      n
US:X  a  U
OU R                  U
S5      nUc'  [        U R                  S-   [        U5      -   S-   5      eU R                  X5      $  GNr N N N7f)a  
fetches information on an order made by the user

https://docs.digifinex.com/en-ww/spot/v3/rest.html#get-order-status
https://docs.digifinex.com/en-ww/swap/v2/rest.html#orderinfo

: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
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nrs   rG  rB   rT  r  r  rA   r@   z* fetchOrder() not support self market typerk  r   z fetchOrder() order r  )r  r  r  r  privateSpotGetMarginOrderr  privateSpotGetSpotOrderprivateSwapGetTradeOrderInfor/   rT  r  r.   r  r  )re  rT  r  r  r  r   r   r  r  r  rk  rS  s               rg  fetch_orderdigifinex.fetch_order  s     !!![[(F
!??f]
 >>|VT

 !+1$<( *H"
h(>!J!;;DKK<WXXH6!!99$++g:UVVH6!!>>t{{7?Z[[Htww)UUVVb x0#v-DOOD!4L=*@ @3r7 J\ YZZ..[ 	"$ YV[sG   FFBF%F&.FF.FFBFFFFc                   #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nSnU R                  SXT5      u  ptU R                  SU5      u  pUS:X  a  Ub  X&S'   OXvS'   Ub  U R	                  US-  5      US'   US:X  a  SOS	n
Ub  US
   Xj'   Ub  X6S'   SnUc  US:X  a+  SnU R                  U R                  Xi5      5      I Sh  vN nOvUS:X  a)  U R                  U R                  Xi5      5      I Sh  vN nOGUS:X  a)  U R                  U R                  Xi5      5      I Sh  vN nO[        U R                  S-   5      eUS:X  a  SOSnU R                  X/ 5      nU R                  XX#5      $  GNh N N NR7f)a  
fetch all trades made by the user

https://docs.digifinex.com/en-ww/spot/v3/rest.html#customer-39-s-trades
https://docs.digifinex.com/en-ww/swap/v2/rest.html#historytrade

: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>`
Nrp   rB   r
  r  r  r  r  r  rT  r   rA   r@   z- fetchMyTrades() not support self market typerk  r  )r  r  r  r  r  privateSpotGetMarginMytradesr  privateSpotGetSpotMytrades privateSwapGetTradeHistoryTradesr/   rT  r  rw  )re  r  rs  r   r  r  r  r   r   r  r  r  responseRequestrk  s                 rg  fetch_my_tradesdigifinex.fetch_my_tradesP	  s     !!![[(F
!??QW`
 >>PVW
 -2)* *H (,(9(9%$,(G%.8F.B/'-d|G$$G!Z8%;!J!>>t{{7?Z[[H6!!<<T[[=XYYH6!!BB4;;wC^__Htww)XXYY\ &06%9&~~h<  u<<[ 	". \Y_sG   FE>B=FF.FF.F2F3AFFFFc                 *    0 nU R                  X!U5      $ Nr  )re  r  rG  s      rg  parse_ledger_entry_type!digifinex.parse_ledger_entry_type	  s    T22ri  itemrl  c                    U R                  U R                  USS5      5      nU R                  USS5      nU R                  XB5      nU R                  XB5      nU R	                  USS5      nU R                  US5      nU R                  US5      nUc  U R                  US	5      nU R                  US S S S S UUUS US UU R                  U5      S S
.U5      $ )Nr  finance_typecurrency_markrl  numr2  r  r   r  )r}  rT  rN  r  referenceIdreferenceAccountr  rl  r  beforeafterrl  r  r  rz  )
r%  r  r  safe_currencyr  r  r  r  safe_ledger_entryrA  )	re  r'  rl  r  r  r~  r  r/  r  s	            rg  parse_ledger_entrydigifinex.parse_ledger_entry	  s    * ++D,>,>tV^,\]''ozJ
&&z<%%j;##D%:  y1''f5	))$<I%% $"Y/'
  ! 	ri  r~  c                 Z  #    U R                  5       I Sh  vN   0 nSnU R                  SSU5      u  pdU R                  SU5      u  pxUS:X  a  Ub  X%S'   OXeS'   Ub  U R                  US-  5      US'   US:X  a  SOS	n	Sn
Ub  U R	                  U5      n
U
S
   XY'   Ub  X5S'   SnUc  US:X  a+  SnU R                  U R                  XX5      5      I Sh  vN nOvUS:X  a)  U R                  U R                  XX5      5      I Sh  vN nOGUS:X  a)  U R                  U R                  XX5      5      I Sh  vN nO[        U R                  S-   5      eSnUS:X  a  U R                  US/ 5      nO&U R                  US0 5      nU R                  US/ 5      nU R                  XX#5      $  GN N N Nx7f)af  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

https://docs.digifinex.com/en-ww/spot/v3/rest.html#spot-margin-otc-financial-logs
https://docs.digifinex.com/en-ww/swap/v2/rest.html#bills

:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
Nri   rB   r
  r  r  r  rl  r*  rT  r   rA   r@   z+ fetchLedger() not support self market typerk  finance)r  r  r  r  rl  privateSpotGetMarginFinancelogr  privateSpotGetSpotFinancelog"privateSwapGetAccountFinanceRecordr/   rT  r  parse_ledger)re  r~  rs  r   r  r  r   r   r  currencyIdRequestrl  r  ledgerrk  s                 rg  fetch_ledgerdigifinex.fetch_ledger	  s     !!!
!??tU[\
 >>}fU
 -2)* *H (,(9(9%$,(G%+5+?Jo}}T*H)1$G&$G!Z8%;!J!@@WA\]]H6!!>>t{{7?Z[[H6!!DDT[[QXE`aaHtww)VVWWD __Xvr:F??8VR8D__T9b9F  5@@I 	", ^[asG   F+F"B;F+F%.F+F'.F+0F)1A2F+%F+'F+)F+c                     U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nUUS UUS.$ )Naddress
addressTagrl  )r}  rl  rx  r?  tag)r  safe_string_upperr  )re  depositAddressrl  r?  rA  r  r~  s          rg  parse_deposit_addressdigifinex.parse_deposit_address3
  sc     "">9=~|<++NJG
&&z2"
 	
ri  c                 z  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  XcS   /5      nU R	                  Xq5      nUc  [        U R                  S-   U-   S-   5      eU$  N Nb7f)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
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nrl  rT  rk  r~  z5 fetchDepositAddress() did not return an address for zQ - create the deposit address in the user settings on the exchange website first.)r  rl  privateSpotGetDepositAddressr  r  parse_deposit_addressesr,   rT  )	re  r~  r  rl  r  r  rk  	addressesr?  s	            rg  fetch_deposit_addressdigifinex.fetch_deposit_addressH
  s      !!!==&
 ::4;;w;WXX x4008H7IJ	//)2? +b!bei!i  m@  "@  A  A1 	"
 Ys"   B;B7?B;B9A!B;9B;c                   #    U R                  5       I S h  vN   S n0 nUb  U R                  U5      nUS   US'   Ub  [        SU5      US'   S nUS:X  a)  U R                  U R	                  Xu5      5      I S h  vN nO(U R                  U R	                  Xu5      5      I S h  vN nU R                  US/ 5      n	U R                  XX4SU05      $  N NW N07f)NrT  rl  r   rI  rw  rk  r  )r  rl  rt  privateSpotGetDepositHistoryr  privateSpotGetWithdrawHistoryr  parse_transactions)
re  r  r~  rs  r   r  rl  r  r  rk  s
             rg  fetch_transactions_by_type$digifinex.fetch_transactions_by_typei
  s     !!!
 }}T*H"*4.GJ!#uoGFO9!>>t{{7?[\\H!??G@\]]H* ~~h3&&tufd^TTO 	" ]]s4   CCA!C8C9(C!C"-CCCc                 D   #    U R                  SXX45      I Sh  vN $  N7f)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>`
rw  NrP  re  r~  rs  r   r  s        rg  fetch_depositsdigifinex.fetch_deposits
  s"      44YU[[[[     c                 D   #    U R                  SXX45      I Sh  vN $  N7f)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>`

withdrawalNrS  rT  s        rg  fetch_withdrawalsdigifinex.fetch_withdrawals
  s#      44\4PU^^^^rW  c                 4    SSSSS.nU R                  X!U5      $ )Npendingrj  r  )r   r  r  rP  r  r  s      rg  parse_transaction_status"digifinex.parse_transaction_status
  s,     	
 &99ri  transactionc                    U R                  USS5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  Xr5      nU R	                  U R                  US5      5      n	U R	                  U R                  US5      5      n
U R                  U R                  US	5      5      nU R                  US
5      nU R                  US5      nS nUb  XS.nU R                  US5      n0 SU_SU_SU_SU	_SU R                  U	5      _SU_SU_SU_SS _SU_SU_SS _SS _S
U_SU_SU_SU
_S S US.E$ )NrT  withdraw_idr?  memohashrl  r  r  r  r  rz  )rl  r  rm  r}  txidr  r  rx  	addressToaddressFromrA  tagTotagFromr  rl  rm  )internalcommentrz  )r  r  rB  r  	parse8601r^  r  rA  )re  r`  rl  rT  r?  rA  re  r  r~  r  rm  rl  r  feeCostrz  rx  s                   rg  parse_transactiondigifinex.parse_transaction
  s   2 T=A"";	:{F3V4++KD
&&z<NN4#3#3K#PQ	..!1!1+!OP..t/?/?W/UV!!+x8"";6#5C"";8
K
"
 D
 	

 Y/
 w
 w
 
 4
 3
 S
 t
 D
 f
 
  f!
" w#
$ )
 	
ri  c                 .    SS0nU R                  X!U5      $ )NrO  rj  r  r  s      rg  parse_transfer_statusdigifinex.parse_transfer_status
  s#    
 &99ri  r   c                    S nS nU R                  USU5      nU R                  US5      nUS:X  a  SnSnO
US:X  a  SnSnU R                  US5      nUU R                  US5      UU R                  U5      U R	                  U R                  US	5      U5      U R                  US
S5      UUU R                  U R                  US5      5      S.	$ )Nrk  r  ro  r@   rB   r{  r  transfer_idrl  r  transfer_amountr~  )	r}  rT  r  r  rl  r  fromAccount	toAccountrl  )r  r  r  rA  r  r  rq  )re  r   rl  rv  rw  rk  r  r  s           rg  parse_transferdigifinex.parse_transfer
  s    : 	~~h9  v.19 KIQY KI%%h<	""8];"Y///0@0@z0RT\]((x9JK&"001A1A(F1ST

 
	
ri  rv  rw  c                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  U R                  S0 5      nU R	                  XU5      n	U R	                  XU5      n
0 nUS:H  nUS:H  nSnU R                  X5      nU(       d  U(       ac  U	S:w  a  U
S:w  a  [        U R                  S-   5      eU(       a  SOSUS	'   X{S
'   XS'   U R                  U R                  X5      5      I Sh  vN nO8X{S'   XS'   XS'   XS'   U R                  U R                  X5      5      I Sh  vN nU R                  X5      $  GN5 NQ N7f)an  
transfer currency internally between wallets on the same account

https://docs.digifinex.com/en-ww/spot/v3/rest.html#transfer-assets-among-accounts
https://docs.digifinex.com/en-ww/swap/v2/rest.html#accounttransfer

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: 'spot', 'swap', 'margin', 'OTC' - account to transfer from
:param str toAccount: 'spot', 'swap', 'margin', 'OTC' - account to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
NrT  rI  rB   r   z[ transfer() supports transferring between spot and swap, spot and margin, spot and OTC onlyro  r{  r  rl  ru  r*  r+  fromto)r  rl  r  r_  r  currency_to_precisionr$   rT  privateSwapPostAccountTransferr  privateSpotPostTransferrx  )re  r~  r  rv  rw  r  rl  r  rI  fromIdtoIdr  fromSwaptoSwapr  rZ  s                   rg  r   digifinex.transfer-  sf     !!!==&d^
7GL!!.{K9E6)v%11$?v#DCK#DGG  /L  %L  M  M#)aqGFO",J)5%& "@@WA]^^H'1O$)EN$FO DM "99$++g:VWWH""866O 	"6 _ Xs4   EEC%E<E=8E5E6EEEr?  rA  c                 \  #    U R                  XE5      u  pEU R                  U5        U R                  5       I Sh  vN   U R                  U5      nUU R	                  X5      US   S.nUb  XGS'   U R                  U R                  Xu5      5      I Sh  vN nU R                  X5      $  Nm N7f)aO  
make a withdrawal
:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
NrT  )r?  r  rl  rc  )handle_withdraw_tag_and_paramscheck_addressr  rl  r}  privateSpotPostWithdrawNewr  rn  )	re  r~  r  r?  rA  r  rl  r  r  s	            rg  r   digifinex.withdrawd  s      99#F7#!!!==& 00> 	
 ?!FO88W9UVV %%h99# 	" Ws"   8B,B(AB,B*B,*B,c                 <  #    U R                  5       I S h  vN   0 nS nUb  U R                  U5      nUS   US'   U R                  U R                  Xe5      5      I S h  vN nU R	                  US5      n	U R                  X5      n
U R                  XX45      $  N N;7f)NrT  r  	positions)r  r  privateSpotGetMarginPositionsr  r  parse_borrow_interestsfilter_by_currency_since_limit)re  r~  r  rs  r   r  r  r  r  rowsinterests              rg  fetch_borrow_interestdigifinex.fetch_borrow_interest  s     !!![[(F &tGH;;DKK<XYY, x5..t<2285PP= 	" Zs"   BBABB:BBr}  c           
      2   U R                  US5      nU R                  US5      nU R                  US5      n[        R                  " XE5      n[        R                  " XF5      nUc  S OUS   nU R	                  X25      n	UU	US SU R                  U5      S S S S.	$ )Nr  r  leverage_ratior  MbP?)	r}  r  rl  r  interestRateamountBorrowedr   r  r  )r  r6   
string_divr  r>  rd  )
re  r}  r  rB  rZ  leverageStringamountInvestedr  rl  r  s
             rg  parse_borrow_interestdigifinex.parse_borrow_interest  s     ##D(3''h7))$0@A ++LI ++LI"N4!!(3 !"//?

 
	
ri  c                 x  #    U R                  5       I Sh  vN   0 nU R                  U R                  X25      5      I Sh  vN nU R                  US/ 5      n/ n[	        S[        U5      5       H!  nXW   nU R                  US5      U:X  d  M  UnM#     U R                  U5      n	U R                  Xi5      $  N Nw7f)ae  
fetch the rate of interest to borrow a currency for margin trading

https://docs.digifinex.com/en-ww/spot/v3/rest.html#margin-assets

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `borrow rate structure <https://github.com/ccxt/ccxt/wiki/Manual#borrow-rate-structure>`
Nr  r   rl  )	r  r  r  r  r  r  r  rl  parse_borrow_rate)
re  r~  r  r  r  rk  r  r  entryrl  s
             rg  fetch_cross_borrow_rate!digifinex.fetch_cross_borrow_rate  s      !!!88W9UVV$ x4q#d)$AGEz2d: % ==&%%f777 	"Vs(   B:B6)B: B8A	B:)B:8B:c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  US5      $  NB N+7f)a)  
fetch the borrow interest rates of all currencies

https://docs.digifinex.com/en-ww/spot/v3/rest.html#margin-assets

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
Nr  rl  )r  r  r  parse_borrow_rates)re  r  r  r  s       rg  fetch_cross_borrow_rates"digifinex.fetch_cross_borrow_rates  s[      !!!88@@$ 626&&vz::) 	"@s   AAAA*AAc                     U R                  5       nU R                  US5      nU R                  XB5      SSUU R                  U5      US.$ )Nrl  r  i \&)rl  rater  r  r  r}  )r  r  r  rA  )re  r}  rl  r  r  s        rg  r  digifinex.parse_borrow_rate  sT     %%'	%%dJ7
//
E"Y/
 	
ri  c                     0 n[        S[        U5      5       H>  nX   nU R                  XR5      nU R                  U5      nU R	                  U5      nXU'   M@     U$ )Nr   )r  r  r  r  r  )	re  r}  codeKeyr  r  r'  rl  r~  
borrowRates	            rg  r  digifinex.parse_borrow_rates  sc     q#d)$A7D''6H**84D//5J%4L % ri  c                 N  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      I Sh  vN nU R                  US0 5      nU R                  Xc5      $  N N*7f)a=  
fetch the current funding rate

https://docs.digifinex.com/en-ww/swap/v2/rest.html#currentfundingrate

: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>`
NrB   z0 fetchFundingRate() supports swap contracts onlyr  rT  rk  )r  r  r*   rT  publicSwapGetPublicFundingRater  r  parse_funding_ratere  r  r  r  r  r  rk  s          rg  fetch_funding_ratedigifinex.fetch_funding_rate1  s      !!!V$f~DGG&XXYYVD\
 <<T[[=YZZ ~~h3&&t44+ 	" ["   B%B!A!B%8B#9)B%#B%c                 @   #    U R                  X5      I Sh  vN $  N7f)aF  
fetch the current funding rate interval

https://docs.digifinex.com/en-ww/swap/v2/rest.html#currentfundingrate

: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>`
N)r  )re  r  r  s      rg  fetch_funding_interval digifinex.fetch_funding_intervalR  s      ,,V<<<<s   c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " Xv5      n0 SU_SU R	                  X25      _SS _SS _SS _S	S _S
S _SS _SU R                  US5      _SU_SU R                  U5      _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _SU R                  U5      0E$ )Nr  funding_timenext_funding_timer}  r  r;  r<  r  estimatedSettlePricer  r  fundingRatefunding_ratefundingTimestampfundingDatetimenextFundingRatenext_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r  r6   r  r>  r  rA  parse_funding_interval)	re  r  r  rB  r  nextTimestampfundingTimeStringnextFundingTimeStringmillisecondsIntervals	            rg  r  digifinex.parse_funding_rate^  s    ##Ho>%%h?	))(4GH ,,X~F $ 0 0;N O&112G[
H
d&&x8
 
 $	

 D
 #D
 
 
 4++HnE
 	
 t||I6
 t//:MN
 #M
 "4<<#>
 "4
  '!
" &t#
$ 334HI%
 	
ri  c                 6    SSSSSS.nU R                  X!U5      $ )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )re  r  	intervalss      rg  r   digifinex.parse_funding_interval  s-    
	 	X>>ri  c           
      
  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   (       d  [	        U R                  S-   5      eSUS   0nUb  X&S'   Ub  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R                  US	0 5      nU R                  US
/ 5      n	/ n
[        S[        U	5      5       Hr  nX   nU R                  US5      nU R                  U5      nU R                  US5      nU
R                  UUU R                  US5      UU R                  U5      S.5        Mt     U R!                  U
S5      nU R#                  UXU5      $  GNM N7f)a  
fetches historical funding rate prices
: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
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
Nz5 fetchFundingRateHistory() requires a symbol argumentrB   z7 fetchFundingRateHistory() supports swap contracts onlyr  rT  r
  r   rk  funding_ratesr   r   r  )r}  r  r  r  r  r  )r(   rT  r  r  r*   %publicSwapGetPublicFundingRateHistoryr  r  r  r  r  r>  r  r  r  rA  sort_byfilter_by_symbol_since_limit)re  r  rs  r   r  r  r  r  rk  r  ratesr  r  rB  symbolInnerr  sorteds                    rg  fetch_funding_rate_history$digifinex.fetch_funding_rate_history  s     >#DGG.e$eff!!!V$f~DGG&__``VD\
 ).%&$GCCDKKPWD`aa  x4;q#f+&AIE''o>H**84K))%8ILL%#//v>& LL3  ' e[100NNW 	" bs#   /FE>A/F!F"CFFc                 N  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      I Sh  vN nU R                  US0 5      nU R                  Xc5      $  N N*7f)a(  
fetch the trading fees for a market

https://docs.digifinex.com/en-ww/swap/v2/rest.html#tradingfee

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
NrB   z- fetchTradingFee() supports swap markets onlyr  rT  rk  )r  r  r)   rT  #privateSwapGetAccountTradingFeeRater  r  parse_trading_feer  s          rg  fetch_trading_feedigifinex.fetch_trading_fee  s      !!!V$f~TWW'VVWWVD\
 AA$++gB^__ x4%%d33' 	" `r  rz  c                     U R                  US5      nU R                  X25      nUUU R                  US5      U R                  US5      S S S.$ )Nr  maker_fee_ratetaker_fee_rate)r}  r  r   r   r   r   )r  r>  r  )re  rz  r  rB  r  s        rg  r  digifinex.parse_trading_fee  s^     ##C9!!(3%%c+;<%%c+;<
 	
ri  c                   #    U R                  5       I Sh  vN   U R                  U5      n0 nSnSnUbY  Sn[        U[        5      (       a/  [	        U5      nUS:  a  [        U R                  S-   5      eUS   nOUnU R                  U5      nU R                  SXB5      u  pRU R                  SU5      u  pUb  SnUb  US:X  a  SOS	n
US
   X:'   SnUS:X  d  US:X  a)  U R                  U R                  X95      5      I Sh  vN nOGUS:X  a)  U R                  U R                  X95      5      I Sh  vN nO[        U R                  S-   5      eUS:X  a  SOSnU R                  X/ 5      n/ n[        S[	        U5      5       H&  nUR!                  U R#                  X   U5      5        M(     U R%                  US	US5      $  GN N N7f)a  
fetch all open positions

https://docs.digifinex.com/en-ww/spot/v3/rest.html#margin-positions
https://docs.digifinex.com/en-ww/swap/v2/rest.html#positions

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
Nro  zD fetchPositions() symbols argument cannot contain more than 1 symbolr   rx   rA   rB   r  r  rT  r@   z. fetchPositions() not support self market typerk  r  F)r  r  
isinstancer  r  r)   rT  r  r  r  r  r  privateSwapGetAccountPositionsr/   r  r  r  parse_positionfilter_by_array_positions)re  r	  r  r  r  r   r  symbolsLengthr   r  r  r  positionRequestr  r  r  s                   rg  fetch_positionsdigifinex.fetch_positions  s     !!!%%g.
F'4(( #G 1$$TWW/u%uvv  [[(F!??@PRXa
 >>?OQWX
!!J2<2FoXO'-d|G$:#9!??G@[\\H6!!@@WA\]]Htww)YYZZl &06%9&OOHrB	q#i.)AMM$--ilFCD *--fhOOo 	"0 ]]s5   GF>C)G G.G/G0BGGGc                   #    U R                  5       I Sh  vN   U R                  U5      n0 nSnU R                  SX25      u  pRU R                  SU5      u  pgUb  SnUS:X  a  SOSnUS   XH'   Sn	US:X  d  US:X  a)  U R	                  U R                  XG5      5      I Sh  vN n	OGUS:X  a)  U R                  U R                  XG5      5      I Sh  vN n	O[        U R                  S	-   5      eUS:X  a  S
OSn
U R                  X/ 5      nU R                  US   U5      nUS:X  a  U$ U R                  U	S5      US'   U R                  U	S5      US'   U$  GN; N N7f)a  

https://docs.digifinex.com/en-ww/spot/v3/rest.html#margin-positions
https://docs.digifinex.com/en-ww/swap/v2/rest.html#positions

fetch data on a single open contract trade position
:param str symbol: unified market symbol of the market the position is held in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nrv   rA   rB   r  r  rT  r@   z- fetchPosition() not support self market typerk  r  r   
collateralmargin_ratemarginRatio)r  r  r  r  r  r  r  r/   rT  r  r  r  )re  r  r  r  r  r   r   r  r  r  dataRequestrk  positions                rg  fetch_positiondigifinex.fetch_position[  sq     !!!V$
!??QW`
 >>PVW
!!J.8F.B/#)$< :#9!??G@[\\H6!!@@WA\]]Htww)XXYYh ",v!5fKxb9&&tAw7O%)%5%5h%IH\"&*&6&6x&OH]#OY 	" ]]s5   EEBEE .EEBEEEr  c                 "   U R                  USS5      nU R                  X25      nUS   nU R                  US5      nUb  US:X  a  SOSnOSnU R                  US5      nU R                  US5      nUS	:X  a  S
nOUS:X  a  SnU R	                  0 SU_SS _SU_SU R                  US5      _SU_SU R                  US5      _SU R                  USS5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU_SS _SU_SU R                  U5      _S U R                  US!5      _S"U R                  US#5      _S S S U R                  US$S%5      U R                  US&5      S S S S'.E5      $ )(Nr  r  margin_modecrossedcrossisolatedr  rJ  go_longlonggo_shortshortr}  rT  notionalr  r   liquidationPriceliquidation_price
entryPriceavg_costentry_priceunrealizedPnlunrealized_pnl	contractsavail_positionr  r;  r  r   r  maintenanceMarginrA   maintenanceMarginPercentagemaint_margin_ratior   r  margin_ratio)r  initialMargininitialMarginPercentager   r  r   r   r   )r  r?  r  r  safe_positionr  r  rA  )re  r  r  rB  r  r   r  rJ  s           rg  r  digifinex.parse_position  s<   N %%hJ!!(3!%%h>
!%/9%<:J"J%%h<	&19DZD!! #
H#
$#
 f#
 ((8<	#

 *#
  0 0;N O#
 $,,Xz=Q#
 T--h8HI#
 ))(4DE#
 D,,V^D#
 ))(F;#
 D#
 d#
 #
 Y/#
   !1!1(H!E!#
" *4+;+;HFZ+[##
$ !'+**8ZAQR++HnE!#3#
  	ri  r   c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   S:w  a  [	        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eUS	   US
.nU R                  U R                  SS5      nU R                  USSU5      nUb"  US:X  a  SOSnXuS'   U R                  USS/5      nUS:X  aB  U R                  US5      nUb  XS'   U R                  US5      nOU R                  SUSSS/5        U R                  U R                  XS5      5      I Sh  vN $  GN) N7f)a  
set the level of leverage for a market

https://docs.digifinex.com/en-ww/swap/v2/rest.html#setleverage

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: either 'cross' or 'isolated', default is cross
:param str [params.side]: either 'long' or 'short', required for isolated markets only
:returns dict: response from the exchange
Nz) setLeverage() requires a symbol argumentr  rB   z+ setLeverage() supports swap contracts onlyro  r   z% leverage should be between 1 and 100rT  )r  r   r   defaultMarginModer  r  r   r  rJ  r   r  r  )r(   rT  r  r  r*   r)   r  r_  safe_string_lower_2r  r  check_required_argumentprivateSwapPostAccountLeverager  )	re  r   r  r  r  r  r  r   rJ  s	            rg  set_leveragedigifinex.set_leverage  st     >#DGG.Y$YZZ!!!V$&>V#DGG&SSTTqLhnTWW'NNOO#D\ 
 !..t||\K^_--flDWYjk
!'1W'<:J%/M"YYv6I'JKF###FF3D"&662,,]D&6SZJ[\88W9UVVV/ 	". Ws"   /EED#EEEEc                 8  #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nUS   US'   Ub  X&S'   Ub  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US/ 5      nU R                  XX#5      $  N N+7f)a  
fetch the transfer history, only transfers between spot and swap accounts are supported

https://docs.digifinex.com/en-ww/swap/v2/rest.html#transferrecord

: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 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>`
NrT  rl  r
  r   rk  )r  r  #privateSwapGetAccountTransferRecordr  r  parse_transfers)	re  r~  rs  r   r  rl  r  r  	transferss	            rg  fetch_transfersdigifinex.fetch_transfers8  s      !!!..t4H"*4.GJ).%&$GAA$++gB^__  NN8VR8	##IFF7 	" `s"   BBAB,B-*BBc                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  U5      nU R	                  XAS5      $  NS N<7f)a  

https://docs.digifinex.com/en-ww/swap/v2/rest.html#instruments

retrieve information on the maximum leverage, for different trade sizes
:param str[]|None symbols: a 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
Nrk  r  )r  r  r  r  parse_leverage_tiers)re  r	  r  r  rk  s        rg  fetch_leverage_tiersdigifinex.fetch_leverage_tiersa  sl      !!!<<VDD< x4%%g.((HHC 	"Ds   A.A*A.A,;A.,A.c                 N  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      I Sh  vN nU R                  US0 5      nU R                  Xc5      $  N N*7f)av  
retrieve information on the maximum leverage, for different trade sizes for a single market

https://docs.digifinex.com/en-ww/swap/v2/rest.html#instrument

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
NrB   z6 fetchMarketLeverageTiers() supports swap markets onlyr  rT  rk  )r  r  r)   rT  publicSwapGetPublicInstrumentr  r  parse_market_leverage_tiersr  s          rg  fetch_market_leverage_tiers%digifinex.fetch_market_leverage_tiers  s      !!!V$f~TWW'__``VD\
 ;;DKK<XYY8 x4//==I 	" Zr  c                 r   / nU R                  US0 5      n[        S[        U5      5       H  nXE   nU R                  US5      nU R	                  Xr5      nUR                  U R                  US5      U R                  XrS S5      US   S U R                  US5      S U R                  US5      US	.5        M     U$ )
Nopen_max_limitsr   r  ro  rB   r  	max_limitr   )tierr  rl  minNotionalmaxNotionalmaintenanceMarginRatemaxLeverager}  )	r  r  r  r  r?  r  r  r>  r  )re  r}  r  tiersbracketsr  r0  rB  s           rg  r*  %digifinex.parse_market_leverage_tiers  s    2 ??4):B?q#h-(A;D''o>H%%h7FLLA**8T6J"8,##//kB)-#//jA	 		 ) ri  c                    > U R                  U R                  S5      nU R                  USS5      nSn[        [        U ]  XU5      u  pbUb"  US:w  a  [        U R                  S-   5      e Xb/$ US:X  d  USL a  SnXb/$ )aM  
@ignore
       marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns Array: the marginMode in lowercase
       rF  rA   FNr  z only cross margin is supportedT)r  r_  r  rb  r8   r  r/   rT  )re  
methodNamer  defaultValuerF  isMarginr   rf  s          rg  r  'digifinex.handle_margin_mode_and_params  s     &&t||]C>>&(E:
"9dQR\frs
!W$"477-N#NOO %
 ## x'X-=$
##ri  codesc                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US5      nU R                  XA5      $  N@ N)7f)ai  
fetch deposit and withdraw fees

https://docs.digifinex.com/en-ww/spot/v3/rest.html#get-currency-deposit-and-withdrawal-information

:param str[]|None codes: not used by fetchDepositWithdrawFees()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
Nrk  )r  r  r  parse_deposit_withdraw_fees)re  r=  r  r  rk  s        rg  fetch_deposit_withdraw_fees%digifinex.fetch_deposit_withdraw_fees  sX      !!!55f==< ~~h///<<A 	"=s   AAAA(AAc                    0 nU R                  U5      n[        S[        U5      5       H  nX   nU R                  US5      nU R	                  U5      nUb  U R                  X5      (       d  ME  U R                  XH5      n	U	c  U R                  0 5      XH'   / XH   S'   XH   S   n
U
R                  U5        U R                  US5      nU R                  US5      nUUb  SOS S.nS S S.nUb   U R                  U5      nUUS.XH   S	   U'   M  XU   S
'   XU   S'   M     [        UR                  5       5      n[        S[        U5      5       H/  nUU   nU R                  U5      nU R                  XH   U5      XH'   M1     U$ )Nr   rl  r}  rm  rq  F)rz  r   rv  rJ  r   rw  )market_codesr  r  r  r  in_arrayr  deposit_withdraw_feer  r  r  r  rl  $assign_default_deposit_withdraw_fees)re  r  r=  currencyIdKeydepositWithdrawFeesr  r  r  r~  depositWithdrawFeedepositWithdrawInfor  withdrawFeewithdrawResultdepositResultr  depositWithdrawCodesrl  s                     rg  r?  %digifinex.parse_deposit_withdraw_fees(  s   6 %'!!%(q#h-(AKE))%<J**:6D4==#=#=%)__5H%O"%-040I0I"0M'-8:'-f5&9&?&G##**51 ,,UG<	"ooe5GH&,7,C%$(
  "&' ("&"9"9)"DK$2#0J'-j9+F
 =K-j9;H-i8; )<  $$7$<$<$>?q#234A'*D}}T*H(,(Q(QReRkmu(v% 5 #"ri  c                    #    U R                  US5      nU R                  SUSSS/5        U R                  XSU5      I Sh  vN $  N7f)a  
add margin to a position

https://docs.digifinex.com/en-ww/swap/v2/rest.html#positionmargin

:param str symbol: unified market symbol
:param float amount: amount of margin to add
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str params['side']: the position side: 'long' or 'short'
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=margin-structure>`
rJ  rE   r  r  ro  Nr  r  modify_margin_helperre  r  r  r  rJ  s        rg  
add_margindigifinex.add_marginj  sM      /$$[$@QR..vq&IIII   ?AAAc                    #    U R                  US5      nU R                  SUSSS/5        U R                  XSU5      I Sh  vN $  N7f)a  
remove margin from a position

https://docs.digifinex.com/en-ww/swap/v2/rest.html#positionmargin

:param str symbol: unified market symbol
:param float amount: the amount of margin to remove
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str params['side']: the position side: 'long' or 'short'
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=margin-structure>`
rJ  r   r  r  r{  NrQ  rS  s        rg  reduce_margindigifinex.reduce_marginz  sM      /$$^T6FGCTU..vq&IIIIrV  c                   #    U R                  5       I S h  vN   U R                  US5      nU R                  U5      nUS   U R                  U5      UUS.nU R	                  U R                  Xt5      5      I S h  vN nU R                  US5      n	U	S:X  a  SOSn
U R                  US0 5      nU R                  U R                  X5      S	U
05      $  N NX7f)
NrJ  rT  )r  r  r  rJ  r~  r   rj  r  rk  rl  )	r  r  r  r  $privateSwapPostAccountPositionMarginr  r  r  parse_margin_modification)re  r  r  r  r  rJ  r  r  r  r~  rl  rk  s               rg  rR  digifinex.modify_margin_helper  s     !!!/V$#D\++F3	
 BB4;;wC_``   62!)(x4{{499$GfJ
  	1 	" as#   CCA#C:C;ACCrk  c                     U R                  US5      nU R                  US5      nUU R                  X2S S5      US:X  a  SOSSU R                  US5      S US	   S S S S
.
$ )Nr  r  rB   ro  addreducer   r  r  )
r}  r  r  r   r  r  r~  rl  r  r  )r  r  r>  r  )re  rk  r  rB  rawTypes        rg  r\  #digifinex.parse_margin_modification  sy     ##D/:##D&1&&xvF%lE$&&tX68$
 	
ri  c                 `  #    U R                  5       I Sh  vN   0 nU R                  SXT5      u  pTSnUb  U R                  U5      nUS   US'   Ub  X5S'   Ub  X%S'   U R                  U R	                  XT5      5      I Sh  vN nU R                  US/ 5      nU R                  XX#5      $  N N+7f)aJ  
fetch the history of funding payments paid and received on self account

https://docs.digifinex.com/en-ww/swap/v2/rest.html#funding-fee

: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
:param int [params.until]: timestamp in ms of the latest funding payment
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
Nend_timestamprT  r  r   r
  rk  )r  handle_until_optionr  privateSwapGetAccountFundingFeer  r  parse_incomes)	re  r  rs  r   r  r  r  r  rk  s	            rg  fetch_funding_historydigifinex.fetch_funding_history  s      !!!22?GT[[(F'-d|GO$$G).%&==dkk'>Z[[ ~~h3!!$==5 	" \s"   B.B*A)B. B,*B.,B.c           
          U R                  US5      nU R                  US5      nU R                  US5      nUU R                  X2S S5      U R                  U5      UU R	                  U5      S U R                  US5      S.$ )Nr  rl  r  rB   r  )r}  r  r~  r  r  rT  r  )r  r  r>  r  rA  r  )re  incomer  rB  r  r  s         rg  parse_incomedigifinex.parse_income  s     ##FO<%%fj9
%%fk:	&&xvF++J7"Y/&&vx8
 	
ri  r   c                 *  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUR	                  5       nUS:X  a  SnUS   US.nU R                  U R                  XS5      5      I Sh  vN $  N] N7f)a9  
set margin mode to 'cross' or 'isolated'

https://docs.digifinex.com/en-ww/swap/v2/rest.html#positionmode

: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 argumentr  r  rT  )r  r  )r(   rT  r  r  lower"privateSwapPostAccountPositionModer  )re  r   r  r  r  r  s         rg  set_margin_modedigifinex.set_margin_mode  s      >#DGG.[$[\\!!!V$%%'
 "J#D\%
 <<T[[=YZZZ 	" [s"   /BBAB
BBBGETc                 l   US   S:H  nUS   nUS:X  a  SOSn	SU R                  X5      -   n
X-   nU R                  S   S	   U-   nU R                  X@R                  U5      5      nS nU(       a#  U	S:X  a  US
:X  a  [        R
                  " U5      nO U R                  U R                  U5      5      nU(       a  S nS nU	S:X  aB  [        U R                  5       5      nUU-   U-   nUS:X  a  U(       a  USU-   -  nO&US
:X  a  X-  nO[        U R                  5       5      nUnU R                  U R                  U5      U R                  U R                  5      [        R                  5      nUS:X  a  U(       a  USU-   -  nOUS
:X  a  SS0nU(       a  UnU R                   UUS.nOU(       a  USU-   -  nXXeS.$ )Nr   r   ro  r@   z/v3z/swap/v2r  r   r   POSTrs  ?zContent-Typez!application/x-www-form-urlencoded)z
ACCESS-KEYzACCESS-SIGNzACCESS-TIMESTAMP)ro  r  bodyheaders)implode_paramsr[  r  extract_paramsr  dumps	urlencodekeysortr  r  noncehmacencodesecrethashlibsha256apiKey)re  pathr   r  r  rx  rw  signedendpointpathPartr  payloadro  r  
urlencodedauthr~  	signatures                     rg  signdigifinex.sign  s   Q9$q6%/5j++D99$iiv&0		&"5"5d";<
x:-Ff4DF+JU(;<JDE:%D--/0v~/U?!j 00v%&DDJJL)!		$++d"3T[[5Mw~~^I3++C6!"$G %D"kk($)G sZ''dOOri  
statusCode
statusTextro  r  responseHeadersc
                     U(       d  g U R                  US5      n
U
S:X  d  U
S:X  a  g U R                  S-   U-   nU
c  [        U5      e[        U/nU R	                  U R
                  S   X5      u  pU" U5      e)Nr~  rO  200 r  )r  rT  r4   r$   r  r^  )re  r  r  ro  r  r  responseBodyr  requestHeadersrequestBodyr~  feedbackunknownErrorExceptionClassmessages                  rg  handle_errorsdigifinex.handle_errorsE  s}    &1CKTU]77S=</<h''%x0"&//$//'2JD"_W%%ri   r$  )NN)w__name__
__module____qualname____firstlineno__r   rc  r
   r  r#   r   r  r  r  r   r  r  r  r   r   r  r   r   r  r   r  dictr  r   rb  rg  rq  rx  r  r  r  r   r   floatr   r  r   r  r  r  r   r  r  r  r  r   r  r  r  r  r!  r%  r   r   r2  r<  r   rD  rJ  rP  r!   rU  rZ  r^  rn  rq  r"   rx  r   r   r   r  r  r   r  r	   r  r  r  r   r  r  r  r  r  r    r  r  r   r  r  r  intr  r"  r   r&  r   r+  r*  r  r@  r?  r   rT  rX  rR  r\  rh  rl  rq  r  r  __static_attributes____classcell__)rf  s   @rg  r8   r8   "   sA	   D# DL -/ V: Vp *, 
3V 
3 -/ Xt -/ IV%) %)N *, ?, ?,B @DB GMS GM GMS\ GMR 6:" SG7 SG SGj 68 K1 K1F K1ZH4 H H6 HT~ ~v ~ ~@ ') <S < )+ 
. <@d[] C= C=S C= C=bfglbm C=J 4 < ?CQUdhqs TK TK TK3 TK^a TKx|  ~B  yC TKl mqy{ 6 6I 6Y 6X] 6fi 6p FH S1$|*< S1j os{} Y,3 Y,i Y,y Y,Z_ Y,hk Y,v XZ Tc T T$ 9=R GS G# GR* AER 2tCy 2# 2>: :B Bv B BH 59tZ^gi ^=c ^= ^=TW ^=nrsxny ^=@ 04$UYbd _= _=C _=s _=imnsit _=B 8<B Y/C Y/ Y/v 37TX\eg Z=C Z=s Z=RU Z=x3.t .x .; .` .2SW`b QAs QA# QAS QAgklwgx QAf
h 
R` 
* =?  > B BFTXgktv (U3 (Uc (Uad (UT 04$UYbd 	\ 	\C 	\s 	\imnyiz 	\ 37TX\eg 	_C 	_s 	_RU 	_lpq|l} 	_	:s 	:=
T =
X =
Q\ =
~:C :C :2
t 2
x 2
= 2
h ac 573 57 57C 57TW 57gt 57n QU]_ :3 : : :# :do :> 7;$]apt} Q QC QWZ Qjm Q  EI  JX  EY QB
$ 
 
. 
B ?A %8# %8_ %8N 57 ;;K ;>
 
($ <> 5s 5+ 5B @B 
=3 
=k 
=#
6 #
[ #
J? >BPTcgpr 6Os 6O# 6O]` 6Op ;= 4c 4AT 4>
T 
6 
EX 
& 8<B bPW bP4PX> bPH 8: W3 WrOt OV Ob ?C2 &W3 &W &Wf 154VZce 'G# 'GS 'GPS 'Gjno|j} 'GR =A +I' +IP] +IZ EG .> .>4P\K] .>`) )$|J\ )V @BPT $& BFb *=w *=X@#D CE Js JE JI[ J  FH J# Ju JL^ J  LN  Rd :
d 
F 
N` 
0 9=4^bkm '># '>S '>X[ '>R
6 
, DHPR [ [S [0  b$T -P^& & &3 &PS &fj & &ri  r8   )? ccxt.async_support.base.exchanger   ccxt.abstract.digifinexr   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   r   r    r!   r"   typingr#   ccxt.base.errorsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   ccxt.base.decimal_to_precisionr5   ccxt.base.preciser6   r8   r  ri  rg  <module>r     s    6 /    w  w  w  w  w  w  w  w  * 0 - - . ' & . + ) * ) ) + . ) ( 4 %n@&+ n@&ri  