
    E#i                       S SK Jr  S SKJ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'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K9J: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    H/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/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      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$ )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
datacurrencyr   chainN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    //7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 ri  c                     U R                  U R                  S0 5      nU R                  USS5      nUS:X  a  U R                  U5      $ U R	                  U5      $ )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_v2)
safe_valuer_  safe_stringr  fetch_markets_v1)re  r  r_  r  s       rg  fetch_marketsdigifinex.fetch_marketsA  sZ     //$,,C!!'85GH''((00$$V,,ri  c                 &   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        U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$ )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publicSwapGetPublicInstrumentsr  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_v2M  s   &&t||]C >>?OQWX
!t>>uEFt>>uEF4>>vFG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 ri  c                    U R                  U5      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$ )!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  s9   ,,V4  //(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 ri  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_balance2  s    2 )q#h-(AkG))':>J**:6DllnG%%gvGD&&wBE"FO%00=GFO$G"4L )   ((ri  c                    U R                  5         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      nOHUS:X  a  U R	                  U5      nO0US:X  a  U R                  U5      nO[        U R                  S-   5      eUS:X  a  SOSnU R                  XV/ 5      nU R                  U5      $ )	a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://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_balanceY  s     	
!??PTV\]
 >>~vV
!Z8%;!J66u=H6!44U;H6!88?Htww)WWXXJ %/&$8v??8R@!!(++ri  Nr  r   c                    U R                  5         U R                  U5      nU R                  SXC5      u  pV0 nUb  X'S'   SnUS:X  a)  US   US'   U R                  U R	                  Xv5      5      nO(US   US'   U R                  U R	                  Xv5      5      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      $ )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
rt   Nr   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4T[[5PQH &tGH224;;w3NOHN 		&"=I)))[AI I++Hf=I$$Yx0@)LLri  symbolsc                 d   U R                  5         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      nO U R                  U R                  Xb5      5      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      $ )	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>`
r   Nr}   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  sC    	%%g.  !,[['F99.&Y6>66t{{77STH//G0LMHb ##HhC  62q#g,'A%zI &&y1FH%F#6N ( ++FHgFFri  c                     U R                  5         U R                  U5      n0 nSnUS   (       a)  US   US'   U R                  U R                  XB5      5      nO(US   US'   U R	                  U R                  XB5      5      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      $ )
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_ticker8  s     	V$&>'-d|GO$55dkk'6RSH &tGH//G0LMH\   62//(Hb9x4oogq"5&>F[[&$=F  00ri  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  orderrH  r  r  r  takerOrMakerrz  )r  r  safe_string_nr;  r<  r=  safe_timestamp_2r  r  r  r  
safe_trader?  )re  rB  r  rT  orderIdpriceStringamountStringr@  r  r  rH  r  rR  	orderType	tradeRolerL  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                 H    U R                  U5      nU R                  US5      $ )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
server_time)publicSpotGetTimer  )re  r  r  s      rg  
fetch_timedigifinex.fetch_timeO  s)     ))&1 ""8];;ri  c                 l    U R                  U5      nU R                  US5      nUS:X  a  SOSnUSSSUS.$ )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>`
r~  r   okmaintenanceN)statusupdatedetaurlr}  )publicSpotGetPingr  )re  r  r  r~  rj  s        rg  fetch_statusdigifinex.fetch_status^  sN     ))&1   62!)-
 	
ri  sincec                    U R                  5         U R                  U5      n0 nUb  US   (       a  [        US5      OUUS'   SnUS   (       a)  US   US'   U R                  U R	                  Xd5      5      nO(US   US'   U R                  U R	                  Xd5      5      nU R                  US/ 5      nU R                  XX#5      $ )	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  rq  r   r  r  r  r  rk  s	            rg  fetch_tradesdigifinex.fetch_tradesu  s     	V$28.s5#eGG&>'-d|GO$55dkk'6RSH &tGH//G0LMHT ~~h3  u<<ri  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         U R                  U5      n0 nSnUS   (       a@  US   US'   X'S'   Ub  [        US5      US'   U R                  U R	                  Xu5      5      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      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      $ )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  rq  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? 66t{{77STH%%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..t{{7/KLH8 &>??8VR8DoodIr:Gooh;G  &UJJri  r  rH  r  r  c                 v   U R                  5         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      nO&U	b  U R                  U
5      nOU R                  U
5      nU R                  X5      nUS   US'   X,S'   X<S'   XLS'   X\S	'   U$ )
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>`
rK   r   NrB   r  r  rH  r  r  )r  r  r  create_order_requestprivateSwapPostTradeOrderPlaceprivateSpotPostMarginOrderNewprivateSpotPostSpotOrderNewparse_order)re  r  r  rH  r  r  r  r  marginResultr   r  r  rQ  s                rg  create_orderdigifinex.create_order.  s    ( 	V$99-P!!_
++F$V&>::7CH%==gF;;GD    2 *hff hgri  ordersc           	         U R                  5         / 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      nO7Ub  SOSUS'   US   US'   U R                  U5      US'   U R                  U5      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      $ )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  rH  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_idsrE  r  )r  r  r  r  r)   rT  r  r  r  r  r  privateSwapPostTradeBatchOrderjson"privateSpotPostMarketOrderBatchNewr  parse_orders)re  r  r  ordersRequestsr  r   r  rawOrderr@  r  rH  r  r  orderParamsr  currentMarginModeorderRequestr  r  r  rk  r  individualOrders                          rg  create_ordersdigifinex.create_ordersf  st    	
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$&>::>JH-7-C&GH &tGH"ii7GFO>>wGH, &>??8VR8D??8["=Dq#f+&AyH$&O*.q'OJ'/5d|OO,(,(8(88(LOH%'+'7'7''JOG$MM/* '   00ri  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  rz  ry  r   r      	   r      GTC   r   Tr  rJ  rG   _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  rH  r  r  r  r  r   r   r  rB   isMarketOrderisLimitOrdermarketIdRequestr  postOnlyParsedr  r   rY  requestTypesuffixquantityrH  r  rX  rW  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         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      $ )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>`
r@   z9 createMarketBuyOrderWithCost() supports spot orders onlyFrH  r  r"  N)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  s`     	V$f~tww)ddee6;23  5$fMMri  rT  c                 n   U R                  5         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      n	OfUS
:X  a!  U R                  U R                  Xh5      5      n	O?US:X  a!  U R                  U R                  Xh5      5      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      $ )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   rE  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}  rV  )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<<T[[=XYH6!::4;;w;VWH6!;;DKK<WXHtww)VVWW, & jH&<!__Xy"EN #N 3 A%#DGG.?$?"$D|$STT--h7F>>&!,,?? ++Hf=$  ri  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  rj  zorder-idrE  failedzclient-order-id)r}  rT  rj  clientOrderId)r  r  r  r  r  r  r  )re  r  r  r  r  r  rQ  s          rg  r  digifinex.parse_cancel_ordersq  s    ..95x1q#g,'AJEMM$//$+   ( q#e*%AHEMM$//((
JG"!%!1!1%9J!K	+   & ri  idsc                 0   U R                  5         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      nU R                  U5      $ )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>`
rF  r@   r  ,)r  rE  )r  r  r_  r  joinr  r  r  )re  r  r  r  rF  rY  r  r  s           rg  cancel_ordersdigifinex.cancel_orders  s     	&&t||]FK$$VV[A	66*
 66t{{77ST ''11ri  rj  c                 6    SSSSSS.nU R                  X!U5      $ )Nr,  closedr  )rM  r   r  r  rN  r  re  rj  statusess      rg  parse_order_statusdigifinex.parse_order_status  s-    
 &99ri  rQ  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   rJ  r  r         r  r   ro  ry  rz  r{  r  r            r  r  r   r|  r   r  r   z	open longr  z
open shortr  z
close longrN  zclose shortinsert_time
time_stampcreated_datefinished_dater  r}  rT  rE  rk  r  r  r  lastTradeTimestampr   r  rH  r  r   r  rG  filledexecuted_amount
filled_qty	remainingr  	avg_price	price_avgrj  staterz  )r2  rj  rz  r   )r  r  r<  r  r  r  r  r  r  r?  r  r  r  )re  rQ  r  r  r  r   r  rH  r@  r  rY  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         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      nOfUS:X  a!  U R                  U R                  X5      5      nO?US:X  a!  U R                  U R                  X5      5      nO[        U R                  S-   5      eU R                  US/ 5      nU R                  XX#5      $ )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  rq  r   r  r  r   r   r  r  rB   r  r  rk  s                 rg  fetch_open_ordersdigifinex.fetch_open_orders3  s^    	[[(F
!??@QSYb
 >>?PRXY
f$ -2)* #(  *H15o8O'-d|G$!Z8%;!J<<T[[=XYH6!::4;;w;VWH6!99$++g:UVHtww)ZZ[[h ~~h3  u<<ri  c                    U R                  5         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      nOfUS:X  a!  U R                  U R                  X5      5      nO?US:X  a!  U R                  U R                  X5      5      nO[        U R                  S-   5      eU R                  US/ 5      nU R                  XX#5      $ )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  rq  r   r  r  r   r   r  r  r  r  rk  s                rg  fetch_ordersdigifinex.fetch_orders  sy    	[[(F
!??v^
 >>}fU
 -2)* *H (,(9(9%$,(G%2<2FoXO'-d|G$$G!Z8%;!J<<T[[=XYH6!::4;;w;VWH6!<<T[[=XYHtww)VVWWh ~~h3  u<<ri  c                    U R                  5         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      n	OfUS	:X  a!  U R                  U R                  X5      5      n	O?US:X  a!  U R                  U R                  X5      5      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      $ )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   rE  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  rQ  s               rg  fetch_orderdigifinex.fetch_order  sw    	[[(F
!??f]
 >>|VT

 !+1$<( *H"
h(>!J55dkk'6QRH6!33DKK4OPH6!88W9TUHtww)UUVVb x0#v-DOOD!4L=*@ @3r7 J\ YZZ..ri  c                    U R                  5         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      nOfUS:X  a!  U R                  U R                  Xi5      5      nO?US:X  a!  U R                  U R                  Xi5      5      nO[        U R                  S-   5      eUS:X  a  SOSnU R                  X/ 5      nU R                  XX#5      $ )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  ru  )re  r  rq  r   r  r  r  r   r   r  r  r  responseRequestrk  s                 rg  fetch_my_tradesdigifinex.fetch_my_tradesO	  s    	[[(F
!??QW`
 >>PVW
 -2)* *H (,(9(9%$,(G%.8F.B/'-d|G$$G!Z8%;!J88W9TUH6!66t{{77RSH6!<<T[[=XYHtww)XXYY\ &06%9&~~h<  u<<ri  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  numr0  r  r   r  )r}  rT  rL  r  referenceIdreferenceAccountr  rl  r  beforeafterrj  r  r  rz  )
r#  r  r  safe_currencyr  r  r  r  safe_ledger_entryr?  )	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                     U R                  5         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      nOfUS:X  a!  U R                  U R                  XX5      5      nO?US:X  a!  U R                  U R                  XX5      5      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      $ )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~  rq  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::4;;w;VWH6!88W9TUH6!>>t{{7?Z[Htww)VVWWD __Xvr:F??8VR8D__T9b9F  5@@ri  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=  r?  r  r~  s          rg  parse_deposit_addressdigifinex.parse_deposit_address2
  sc     "">9=~|<++NJG
&&z2"
 	
ri  c                 J   U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      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$ )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>`
rl  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_addressG
  s     	==&
 44T[[5QR x4008H7IJ	//)2? +b!bei!i  m@  "@  A  Ari  c                 h   U R                  5         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      nO U R                  U R	                  Xu5      5      nU R                  US/ 5      n	U R                  XX4SU05      $ )NrT  rl  r   rG  rw  rk  r  )r  rl  rt  privateSpotGetDepositHistoryr  privateSpotGetWithdrawHistoryr  parse_transactions)
re  r  r~  rq  r   r  rl  r  r  rk  s
             rg  fetch_transactions_by_type$digifinex.fetch_transactions_by_typeh
  s    
 }}T*H"*4.GJ!#uoGFO988W9UVH99$++g:VWH* ~~h3&&tufd^TTri  c                 (    U R                  SXX45      $ )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  rN  re  r~  rq  r   r  s        rg  fetch_depositsdigifinex.fetch_deposits
  s     ..y$uUUri  c                 (    U R                  SXX45      $ )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>`

withdrawalrQ  rR  s        rg  fetch_withdrawalsdigifinex.fetch_withdrawals
  s     ..|T%XXri  c                 4    SSSSS.nU R                  X!U5      $ )Npendingrh  r  )r   r  r  rN  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addressFromr?  tagTotagFromr  rj  rk  )internalcommentrz  )r  r  r@  r  	parse8601r[  r  r?  )re  r]  rl  rT  r=  r?  rb  r  r~  r  rk  rj  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      $ )NrM  rh  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   ry  r  transfer_idrl  r  transfer_amountr~  )	r}  rT  r  r  rl  r  fromAccount	toAccountrj  )r  r  r  r?  r  r  rn  )re  r   rl  rs  rt  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  rs  rt  c                 b   U R                  5         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(       a[  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      nO0X{S'   XS'   XS'   XS'   U R                  U R                  X5      5      nU R                  X5      $ )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>`
rT  rI  rB   Nr   z[ transfer() supports transferring between spot and swap, spot and margin, spot and OTC onlyro  ry  r  rl  rr  r(  r)  fromto)r  rl  r  r_  r  currency_to_precisionr$   rT  privateSwapPostAccountTransferr  privateSpotPostTransferru  )re  r~  r  rs  rt  r  rl  r  rI  fromIdtoIdr  fromSwaptoSwapr  rX  s                   rg  r   digifinex.transfer,  sE    	==&d^
7GL!!.{K9E6)v%11$?v#DCK#DGG  /L  %L  M  M#)aqGFO",J)5%& ::4;;w;WXH'1O$)EN$FO DM 33DKK4PQH""866ri  r=  r?  c                 ,   U R                  XE5      u  pEU R                  U5        U R                  5         U R                  U5      nUU R	                  X5      US   S.nUb  XGS'   U R                  U R                  Xu5      5      nU R                  X5      $ )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>`
rT  )r=  r  rl  r`  )handle_withdraw_tag_and_paramscheck_addressr  rl  rz  privateSpotPostWithdrawNewr  rk  )	re  r~  r  r=  r?  r  rl  r  r  s	            rg  r   digifinex.withdrawc  s     99#F7#==& 00> 	
 ?!FO224;;w3OP %%h99ri  c                    U R                  5         0 nS nUb  U R                  U5      nUS   US'   U R                  U R                  Xe5      5      nU R	                  US5      n	U R                  X5      n
U R                  XX45      $ )NrT  r  	positions)r  r  privateSpotGetMarginPositionsr  r  parse_borrow_interestsfilter_by_currency_since_limit)re  r~  r  rq  r   r  r  r  r  rowsinterests              rg  fetch_borrow_interestdigifinex.fetch_borrow_interest  s    [[(F &tGH55dkk'6RS, x5..t<2285PPri  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  r@  rX  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                 H   U R                  5         0 nU R                  U R                  X25      5      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      $ )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>`
r  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     	224;;w3OP$ x4q#d)$AGEz2d: % ==&%%f77ri  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  US5      $ )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>`
r  rl  )r  r  r  parse_borrow_rates)re  r  r  r  s       rg  fetch_cross_borrow_rates"digifinex.fetch_cross_borrow_rates  sG     	226:$ 626&&vz::ri  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  r?  )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                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )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>`
rB   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_rate0  s     	V$f~DGG&XXYYVD\
 66t{{77ST ~~h3&&t44ri  c                 $    U R                  X5      $ )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>`
)r  )re  r  r  s      rg  fetch_funding_interval digifinex.fetch_funding_intervalQ  s     &&v66ri  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  r9  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  r?  parse_funding_interval)	re  r  r  r@  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         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      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      $ )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>`
z5 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  r?  sort_byfilter_by_symbol_since_limit)re  r  rq  r   r  r  r  r  rk  r  ratesr  r  r@  symbolInnerr  sorteds                    rg  fetch_funding_rate_history$digifinex.fetch_funding_rate_history  st    >#DGG.e$effV$f~DGG&__``VD\
 ).%&$G==dkk'>Z[  x4;q#f+&AIE''o>H**84K))%8ILL%#//v>& LL3  ' e[100NNri  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )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>`
rB   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\
 ;;DKK<XY x4%%d33ri  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  r@  r  s        rg  r  digifinex.parse_trading_fee  s^     ##C9!!(3%%c+;<%%c+;<
 	
ri  c                 H   U R                  5         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      nO?US:X  a!  U R                  U R                  X95      5      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      $ )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99$++g:UVH6!::4;;w;VWHtww)YYZZl &06%9&OOHrB	q#i.)AMM$--ilFCD *--fhOOri  c                 n   U R                  5         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      n	O?US:X  a!  U R                  U R                  XG5      5      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$ )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_positionZ  sS    	V$
!??QW`
 >>PVW
!!J.8F.B/#)$< :#999$++g:UVH6!::4;;w;VWHtww)XXYYh ",v!5fKxb9&&tAw7O%)%5%5h%IH\"&*&6&6x&OH]#Ori  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  rH  go_longlonggo_shortshortr}  rT  notionalr  r   liquidationPriceliquidation_price
entryPriceavg_costentry_priceunrealizedPnlunrealized_pnl	contractsavail_positionr  r9  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  r?  )re  r  r  r@  r  r   r  rH  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         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      $ )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
z) 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  rH  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   rH  s	            rg  set_leveragedigifinex.set_leverage  s]    >#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[\224;;w3OPPri  c                    U R                  5         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      nU R	                  US/ 5      nU R                  XX#5      $ )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~  rq  r   r  rl  r  r  	transferss	            rg  fetch_transfersdigifinex.fetch_transfers7  s     	..t4H"*4.GJ).%&$G;;DKK<XY  NN8VR8	##IFFri  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  U5      nU R	                  XAS5      $ )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
rk  r  )r  r  r  r	  parse_leverage_tiers)re  r  r  r  rk  s        rg  fetch_leverage_tiersdigifinex.fetch_leverage_tiers`  sW     	66v>< x4%%g.((HHri  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xc5      $ )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>`
rB   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\
 55dkk'6RS8 x4//==ri  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  r,  r@  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         U R                  U5      nU R                  US5      nU R                  XA5      $ )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>`
rk  )r  r  r  parse_deposit_withdraw_fees)re  r9  r  r  rk  s        rg  fetch_deposit_withdraw_fees%digifinex.fetch_deposit_withdraw_fees  sC     	//7< ~~h///<<ri  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  r9  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                 x    U R                  US5      nU R                  SUSSS/5        U R                  XSU5      $ )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>`
rH  rE   r  r   ro  r  r  modify_margin_helperre  r  r  r  rH  s        rg  
add_margindigifinex.add_margini  sD     /$$[$@QR((FCCri  c                 x    U R                  US5      nU R                  SUSSS/5        U R                  XSU5      $ )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>`
rH  r   r  r   ry  rM  rO  s        rg  reduce_margindigifinex.reduce_marginy  sD     /$$^T6FGCTU((FCCri  c                 ~   U R                  5         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      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      $ )
NrH  rT  )r  r  r  rH  r~  r   rh  r  rk  rj  )	r  r  r  r  $privateSwapPostAccountPositionMarginr  r  r  parse_margin_modification)re  r  r  r  r  rH  r  r  r  r~  rj  rk  s               rg  rN  digifinex.modify_margin_helper  s    /V$#D\++F3	
 <<T[[=YZ   62!)(x4{{499$GfJ
  	ri  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~  rj  r  r  )r  r  r<  r  )re  rk  r  r@  rawTypes        rg  rW  #digifinex.parse_margin_modification  sy     ##D/:##D&1&&xvF%lE$&&tX68$
 	
ri  c                 0   U R                  5         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      nU R                  US/ 5      nU R                  XX#5      $ )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>`
end_timestampNrT  r  r   r  rk  )r  handle_until_optionr  privateSwapGetAccountFundingFeer  r  parse_incomes)	re  r  rq  r   r  r  r  r  rk  s	            rg  fetch_funding_historydigifinex.fetch_funding_history  s     	22?GT[[(F'-d|GO$$G).%&77G8TU ~~h3!!$==ri  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  r?  r  )re  incomer  r@  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         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      $ )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
z+ 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\%
 66t{{77STTri  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   POSTrn  ?zContent-Typez!application/x-www-form-urlencoded)z
ACCESS-KEYzACCESS-SIGNzACCESS-TIMESTAMP)rm  r  bodyheaders)implode_paramsr[  r  extract_paramsr  dumps	urlencodekeysortr  r  noncehmacencodesecrethashlibsha256apiKey)re  pathr   r  r  rs  rr  signedendpointpathPartr  payloadrm  r  
urlencodedauthry  	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
statusTextrm  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~  rM  200 r  )r  rT  r4   r$   r  r^  )re  r  r  rm  r  r  responseBodyr  requestHeadersrequestBodyr~  feedbackunknownErrorExceptionClassmessages                  rg  handle_errorsdigifinex.handle_errorsD  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   r`  re  ro  rv  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   r0  r:  r   rB  rH  rN  r!   rS  rW  r[  rk  rn  r"   ru  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   rP  rS  rN  rW  rc  rg  rl  r  r  __static_attributes____classcell__)rf  s   @rg  r8   r8   !   s	   D# DL ') VZ Vp $& 
-$v, 
- ') Xt ') IV%) %)N $& ?,( ?,B :>b GMs GM3 GMY GMR 04B SGW SG7 SGj 02 K13 K1f K1ZH4 H H6 HT~ ~v ~ ~@ !# <s < #% 
. 6:UW C=3 C=s C=# C=\`af\g C=J 4 < 9=4^bkm TK# TK# TKS TKX[ TKrvw{r| TKl gksu 63 6i 6y 6RW 6`c 6p @B S1D$6 S1j os{} Y,3 Y,i Y,y Y,Z_ Y,hk Y,v RT N N5 N$ 37r Gs GC GR* ;?r 2c 2C 2>: :B Bv B BH /3TXac ^= ^=3 ^=c ^=hlmrhs ^=@ *.Dt\^ _=3 _=c _= _=cghmcn _=B 26b Y/c Y/3 Y/v -1tRV_a Z=c Z= Z=C Z=x3.t .x .; .` (,$TZ\ QA QAC QAs QAaefqar QAf
h 
R` 
* 79 # ^ B <@daenp (US (U (U[^ (UT *.Dt\^ 	V3 	Vc 	V 	Vcghsct 	V -1tRV_a 	Yc 	Y 	YC 	Yfjkvfw 	Y	:s 	:=
T =
X =
Q\ =
~:C :C :2
t 2
x 2
= 2
h [] 57S 57% 57c 57c 57an 57n KOWY :S :% :# :C :^i :> 15DW[jnwy Q# Qc QQT Qdg Q  C  DR  S QB
$ 
 
. 
B 9; %8C %8 %8N /1 ;5E ;>
 
($ 68 5 5K 5B :< 
7S 
7 
7#
6 #
[ #
J? 8<$]ajl 6O 6OC 6OWZ 6Op 57 4 4;N 4>
T 
6 
EX 
& 26b bPw bPT(^ bPH 24 WS WrOt OV Ob 9=R &QS &Q# &Qf +/TPT]_ 'GC 'Gs 'G# 'Gdhivdw 'GR 7;2 +IG +I- +IZ ?A .># .>T,EW .>`) )$|J\ )V @BPT $& <@ *= *=X@#D =? D De DCU D  @B DC D DFX D  FH 3 L^ :
d 
F 
N` 
0 37TX\eg '>C '>s '>RU '>R
6 
, >B" U# Us U0  b$T -P^& & &3 &PS &fj & &ri  r8   )>ccxt.base.exchanger   ccxt.abstract.digifinexr   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    ( /   w  w  w  w  w  w  w  w  * 0 - - . ' & . + ) * ) ) + . ) ( 4 %n@&+ n@&ri  