
    !:h                       d dl mZ d dlmZ d dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d dl&m'Z' d dl(m)Z) d dl(m*Z* d dl(m+Z+ d d	l(m,Z, d d
l(m-Z- d dl(m.Z. d dl(m/Z/ d dl(m0Z0 d dl(m1Z1 d dl(m2Z2 d dl(m3Z3 d dl(m4Z4 d dl(m5Z5 d dl(m6Z6 d dl(m7Z7 d dl(m8Z8 d dl(m9Z9 d dl:m;Z; d dl<m=Z=  G d dee      Z>y)    )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                       e Zd Zdef fdZi fdefdZi fdee   fdZ	i fdZ
i fdZdefdZi fdefdZd	i fd
ededefdZd	i fdedefdZi fd
edefdZdvdededefdZdvdededefdZi fdefdZi fdZd	d	i fd
edededee   fdZdvdedefdZ dd	d	i fd
edededee   fdZ!d	i fd
ede"de#de$de%f
d Z&i fd!ee'   fd"Z(d	i fd
ede"de#de$de%f
d#Z)i fd
ed$e$fd%Z*d	i fd&ed
e+fd'Z,d( Z-d	i fd
e+fd)Z.d*e+fd+Z/dvd,edede0fd-Z1d	d	d	i fd
e+dededee0   fd.Z2d	d	d	i fd
e+dededee0   fd/Z3d	i fd&ed
e+fd0Z4d	d	d	i fd
e+dedefd1Z5d2 Z6dvd3ed4e7de8fd5Z9d	d	d	i fd6e+dededee8   fd7Z:dvd4e7de;fd8Z<i fd6ede;fd9Z=d	d	d	i fd6e+dedefd:Z>d	d	d	i fd6e+dededee?   fd;Z@d	d	d	i fd6e+dededee?   fd<ZAd*e+fd=ZBdvd>ed4e7de?fd?ZCd*e+de+fd@ZDdvdAed4e7deEfdBZFi fd6ede$dCedDedeEf
dEZGd	i fd6ede$dFede?fdGZHd	d	d	d	i fd6e+d
e+dededeeI   f
dHZJdvdIededeIfdJZKi fd6edeLfdKZMi fdeNfdLZOdvd4e7fdMZPdN ZQi fd
edeRfdOZSi fd
edeRfdPZTdvdedeRfdQZUdR ZVd	d	d	i fd
e+dedefdSZWi fd
edeXfdTZYdvdUededeXfdVZZd	i fdedee[   fdWZ\i fd
efdXZ]dvdYedefdZZ^d	i fd[ed
e+fd\Z_d	d	d	i fd6e+dededeeE   fd]Z`d	i fdedeafd^Zbi fd
edeec   fd_Zddvdedeec   fd`Zei d	f fda	Zfd	i fdbefdcZgdwddZhi fd
ede$deifdeZji fd
ede$deifdfZki fd
edeifdgZldvdhededeifdiZmd	d	d	i fd
e+dedefdjZndvdefdkZod	i fdled
e+fdmZpg dni d	d	fdoZqdperdqedredsedtef
duZs xZtS )x	digifinexreturnc                    | j                  t        t        |          dddgddi dd ddd	dd
dddddddddddddddddddddddddddi ddddddddddddddd dd!dd"dd#dd$dd%dd&d'd(dd)dd*di d+dd,dd-dd.dd/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;di d<dd=dd>dd?dd@ddAddBddCddDddEddFddGddHddIddJddKddLdddddddddMdNdOdPdQdRdSdTdUdVdW	dXdYdZid[d\gd]d^d_d`g daid`g dbidcg ddg dedfg dgg dhdfdcdidddd dddd dddddjddddddddkdldmiddndodpddqddddddrdd ddddsddtdodpddddud dvdnidw	dxdyidydzdd{ddtdodod|d}diddtd~ddoddvdtiddxdidxdidd d ddddd| j	                  d      | j	                  d      dit
        i dt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgi dt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt         dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgdt        dgt        dgt        dgt        dgt        dgt        dgt        dgt         dgt"        dgt"        dgt         dgt$        dgt        dgt        dgt        dgdٜi dڜdg dۢddNdddޜi ddddddddddddddddddddddddddddddddddi ddddddd dddddddddd	d
dddddddddddddddddddddd      S (  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?   rA   )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   )	sandboxrJ   rK   ro   rr   rq   rt   fetchClosedOrdersrp   extendsdefault   )r   r   )r   r   r   r   r   )r   r   )r   r   )r   rK   ro   rr   rq   rt   rp   forDerivatives)linearinverse)r   r?   r   rA   rB   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?   r@   otc23)r?   r@   OTCARBITRUMArbitrum	AVALANCECzAVAX-CCHAIN	AVALANCEXzAVAX-XCHAINBEP20BSCCARDANOCardanoCELOCeloCHILIZChilizCOSMOSCRC20z
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)defaultTypetypes!createMarketBuyOrderRequiresPriceaccountsByTypenetworkszBlack House TestEpanusFreeRossDAOzMobilian CoinTEL666)BHTEPSFREEMBNTEL)idname	countriesversion	rateLimithas
timeframesurlsr   featuresr   precisionMode
exceptionsoptionscommonCurrencies)deep_extendsuperr8   describeparse_numberr5   r)   r%   r1   r&   r3   r0   r'   r-   r+   r*   r$   r,   r2   )self	__class__s    V/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/digifinex.pyr`  zdigifinex.describe$   s1   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",\ *%&!eyD
 y y	    c                   K   | j                  |       d{   }| j                  |dg       }i }t        dt        |            D ]  }||   }| j	                  |d      }| j                  |      }| j                  |dd      }	| j                  |dd      }
|	dkD  }|
dkD  }|xr |}| j	                  |d      }| j	                  |d	      }| j	                  |d
      }| j                  |      }| j                  |      }| j                  |      }t        j                  |t        j                  ||            }| j                  |      }| j	                  |d      }d}|| j                  |      }||||||||ddd|dd|dddd	}||v r||   d   }t        |t              r|j                  |       n||g}|r,d||   d<   t        ||   d   d   d   |      ||   d   d   d<   |r,d||   d<   t        ||   d   d   d   |      ||   d   d   d<   |r7d||   d<   n.|||dd|||| j                  |      dddd|dd|dddi d||<   ||||   d   |<   nD|||   d<   | j                  |      ||   d<   |||   d<   |||   d<   ddd|dd|ddd||   d<   ||   d   |nt        ||   d   |      ||   d<    |S 7 w)z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Ndatar   currencydeposit_status   withdraw_statusmin_withdraw_feemin_withdraw_amountmin_deposit_amountchainminr   )amountr   deposit)	inforQ  networkactivefee	precisionrs  r   limitsrt  Tr   ry  rq  rs  rv  )rQ  codert  typerR  rv  rs  r   rw  rx  ry  rH  rH  rw  rx  )publicSpotGetCurrencies
safe_valuerangelensafe_stringsafe_currency_codesafe_integerra  r6   
string_minnetwork_id_to_code
isinstancelistappendrq  r   )rb  paramsresponserg  resultirh  rQ  rz  depositStatuswithdrawStatusrs  r   rv  	feeStringminWithdrawStringminDepositString
minDepositminWithdrawrw  minFoundPrecisionrx  	networkIdnetworkCoderu  resultCodeInfos                             rd  fetch_currencieszdigifinex.fetch_currencies  s     55f==L x4q#d)$ m	HAAwH!!(J7B**2.D --h8H!LM!..x9JANN#a'G%)H)F((3EFI $ 0 0;P Q#//:NO**+;<J++,=>K##I.C ' 2 29g>P>PQact>u v))*;<I((7;IK$"55i@ & &"$  $#
  +#!
  *# G0 v~!'f!5nd3"))(3&4h%?N/3F4L,@CF4LQYDZ[eDfglDmoz@{F4L*:6u=.2F4L+?B6$<PXCYZcCdejCkmw?xF4L*95e<-1F4L*  $  $& (,,Y7!% $(#'#
 $/#'%
 $.#'$ !#3 t6 $6=tZ(3)/tX&&*&7&7	&BtU#*1tY'+3tZ(  $#
  +#!
  *# *tX& 7=Tl;6O6W	^abhimbnozb{  ~G  _HF4L%[m	H\ m >s   KKJ5Kc                    K   | j                  | j                  di       }| j                  |dd      }|dk(  r| j                  |       d{   S | j	                  |       d{   S 7 7 w)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
        rm   methodfetch_markets_v2N)r}  r\  r  r  fetch_markets_v1)rb  r  r\  r  s       rd  fetch_marketszdigifinex.fetch_markets~  sm      //$,,C!!'85GH''..v666**6222 72s$   A
A.A*A.%A,&A.,A.c                 0  K   | j                  | j                  d      }| j                  d|      \  }}g }|!|j                  | j	                  |             n |j                  | j                  |             |j                  | j                  |             t        j                  |  d {   }|d   }|d   }| j                  |dg       }	| j                  |dg       }
| j                  |	|
      }g }t        dt        |            D ]  }||   }| j                  |dd      }| j                  |d	d
      }| j                  |dd      }| j                  |d      }| j                  |      }| j                  |      }| j                  |      }| j                  |dd      }|dk(  rdnd}|d u }| }|dnd }|dz   |z   }d }d }|r>d}|dz   |z   dz   |z   }| j                  |d      }|sdnd}| j                  |d      }|rd}|j                  i d|d|d|d|d|d|d|d|d|d|d|d|d dd!dd"|rdndd#|d$||| j!                  |d%      d d d d | j#                  | j%                  | j                  |d&                  | j#                  | j%                  | j                  |d'                  d(d d d)| j'                  |d*d+      d d)| j!                  |d,      d d)| j!                  |d-      d d)d.d |d/
        |S 7 ew)0NrD  fetchMarketsV2r   rj  symbol_listrg  symbolinstrument_id
base_assetbase_currencyquote_assetquote_currencyclear_currencyis_allowr@   r?   T/rA   :
is_inverseF	isTradingrQ  basequotesettlebaseIdquoteIdsettleIdr{  rB   rC   rv  contractr   contract_valueamount_precisionprice_precision)rr  pricerp  minimum_amountmin_order_amount	tick_sizeminimum_valuer   rr  r  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTyperx  ry  createdrt  )r  r\  handle_margin_mode_and_paramsr  publicSpotGetMarginSymbolspublicSpotGetTradesSymbolspublicSwapGetPublicInstrumentsasynciogatherr}  array_concatr~  r  safe_string_2r  r  safe_numberra  parse_precisionsafe_number_2)rb  r  rD  r   querypromisesRawpromisesspotMarketsswapMarketsspotDataswapDatar  r  r  marketrQ  r  r  r  r  r  r  	isAllowedr{  r?   rA   r@   r  	isInverseisLinearr  s                                  rd  r  zdigifinex.fetch_markets_v2  s    &&t||]C >>?OQWX
E!t>>uEFt>>uEF4>>vFG 55qkqkj ??;rB??;;$$Xx8q#h-( S	A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S	h _ 6s   B,L.L/I%Lc                   K   | j                  |       d {   }| j                  |dg       }g }t        dt        |            D ]6  }||   }| j	                  |d      }|j                  d      \  }}	| j                  |      }
| j                  |	      }|j                  i d|d|
dz   |z   d|
d	|d
d d|d|	dd dddddd dddddddd dddd d d d d d d | j                  | j                  | j	                  |d                  | j                  | j                  | j	                  |d                  dd d d| j                  |d      d dd d d| j                  |d      d dd|d 	       9 |S 7 kw)!Nrg  r   r  _rQ  r  r  r  r  r  r  r  r  r{  r?   Tr@   rA   FrB   rC   rv  r  r   r  volume_precision)r  rr  rp  
min_volume
min_amountr  )	r   r  r  r  r  r  rx  ry  rt  )publicSpotGetMarketsr}  r~  r  r  splitr  r  ra  r  r  )rb  r  r  r   r  r  r  rQ  r  r  r  r  s               rd  r  zdigifinex.fetch_markets_v1$  sO    226::  //(FB7q#g,' 5	AQZF!!&(3B hhsmOFG**62D++G4EMM /b/$*u,/ / 	/
 $/ &/ 7/ D/ / / $/ / %/ %/ $/  E!/" $#/$   $"&"!..t/C/CDDTDTU[]nDo/pq"//0D0DTEUEUV\^pEq0rs  $#!
  $//E#
  $#
  $//E#$ ]/ /5	l Q ;s   FFE+Fc                 l   d|i}t        dt        |            D ]  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |dd      }| j                  |dd      }	||d<   t        j                  |	|      |d<   |	|d<   |||<    | j                  |      S )	Nrt  r   rh  freeavail_balancetotalequityused)	r~  r  r  r  accountr  r6   
string_subsafe_balance)
rb  r  r  r  balance
currencyIdrz  r  r  r  s
             rd  parse_balancezdigifinex.parse_balanceo  s    2 )q#h-( 
	#AqkG))':>J**:6DllnG%%gvGD&&wBE"GFO%00=GFO$GG"F4L
	#   ((re  c                   K   | j                          d{    d}| j                  dd|      \  }}| j                  d|      \  }}d}||dk(  rd}| j                  |       d{   }nV|dk(  r| j	                  |       d{   }n7|dk(  r| j                  |       d{   }nt        | j                  dz         |dk(  rdnd}| j                  ||g       }| j                  |      S 7 7 7 m7 Pw)	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>`
        NrQ   r@   r?   rA   z, fetchBalance() not support self market typerg  r  )
load_marketshandle_market_type_and_paramsr  privateSpotGetMarginAssetsprivateSpotGetSpotAssetsprivateSwapGetAccountBalancer/   rQ  r}  r  )rb  r  r   r   r  r  balanceRequestbalancess           rd  fetch_balancezdigifinex.fetch_balance  s     !!!
!??PTV\]
F >>~vV
E!Z8%;!J!<<UCCH6!!::5AAH6!!>>uEEHtww)WWXXJ %/&$8v??8^R@!!(++i 	" DAEsG   C8C0AC8'C2(C8C4C8%C6&AC82C84C86C8Nr  r   c                 ,  K   | j                          d{    | j                  |      }| j                  d||      \  }}i }|||d<   d}|dk(  r2|d   |d<   | j                  | j	                  ||             d{   }n1|d   |d<   | j                  | j	                  ||             d{   }d}	d}
|dk(  r&| j                  |di       }
| j                  |
d	      }	n|}
| j                  |d
      }	| j                  |
|d   |	      S 7 7 7 aw)a  
        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
        Nrs   r   rA   rQ  r  r  rg  	timestampdate)
r  r  r  publicSwapGetPublicDepthextendpublicSpotGetOrderBookr}  r  safe_timestampparse_order_book)rb  r  r   r  r  r   r  requestr  r  	orderBooks              rd  fetch_order_bookzdigifinex.fetch_order_book  s=     !!!V$ >>?OQWY_`
E$GG'-d|GO$!::4;;wPU;VWWH &tGH!88We9TUUHN 		&"=I)))[AI I++Hf=I$$Yx0@)LLw 	" X Vs5   DDA'D>D?1D0D1ADDDsymbolsc                   K   | j                          d{    | j                  |      }| j                  |d      }d}|| j                  |      }d}| j	                  d||      \  }}i }d}|dk(  r*| j                  | j                  ||             d{   }n)| j                  | j                  ||             d{   }i }| j                  |ddg       }	| j                  |d      }
t        dt        |	            D ]4  }| j                  d|
i|	|         }| j                  |      }|d   }|||<   6 | j                  |d|      S 7 87 7 w)	a^  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

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

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   r|   rA   r   rg  r  r  )r  market_symbolsr  r  r  publicSwapGetPublicTickersr  publicSpotGetTickersafe_value_2r  r~  r  parse_tickerfilter_by_array_tickers)rb  r   r  firstr  r{  r  r  r  tickersr  r  	rawTickerr   r  s                  rd  fetch_tickerszdigifinex.fetch_tickers   sw     !!!%%g.  !,[['F99.&RXYf6>!<<T[[RX=YZZH!55dkk'66RSSHb ##HhC  62q#g,' 	$A%qzI &&y1FH%F#F6N	$ ++FHgFFQ 	" [Ss5   EEBEE)EEBEEEc                 6  K   | j                          d{    | j                  |      }i }d}|d   r2|d   |d<   | j                  | j                  ||             d{   }n1|d   |d<   | j	                  | j                  ||             d{   }| j                  |d      }| j                  |dg       }| j                  |di       }| j                  |d	i       }	d}
|d   r|}
n| j                  d|i|	      }
| j                  |
|      S 7 7 7 w)
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>`
        NrA   rQ  r  r  r  r   rg  r   )r  r  publicSwapGetPublicTickerr  r  r  r}  r  )rb  r  r  r  r  r  r  r	  rg  firstTickerr  s              rd  fetch_tickerzdigifinex.fetch_tickeru  s)     !!!V$&>'-d|GO$!;;DKKQW<XYYH &tGH!55dkk'66RSSH\   62//(Hb9x4oogq"5&>F[[&$=F  00A 	" Z Ts5   DDA
D!D"1DDB DDDr   r  c           	      B   | j                  |d      }|dnd}| j                  |dd      }| j                  ||d |      }| j                  ||d |      }| j	                  |d      }|d   r| j                  |d      }| j                  |d	      }| j                  i d|d|d
| j                  |      d| j                  |dd      d| j                  |dd      d| j                  |dd      d| j                  |d      d| j                  |dd      d| j                  |d      dd d| j                  |d      d|d	|dd dd d| j                  |dd       d!d | j                  |d"d#      | j                  |d$      | j                  |d%      ||d&|      S )'Nindex_pricer  r?   r  r  r  rA   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
indexPricert  )
r  safe_string_upper_2safe_symbolsafe_marketr  r  r  safe_tickeriso8601r  )	rb  r   r  r1  r   marketIdr  r  r  s	            rd  r  zdigifinex.parse_ticker  s@   P %%fm<
$.$:Z
++FHoN!!(FD*E!!(FD*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?))&,?$-!
. / 	re  tradec                 "   | j                  |dd      }| j                  |d      }| j                  |d      }| j                  |g d      }| j                  |dd      }| j	                  ||      }|| j                  |      }| j                  |dd	      }	| j                  |d
d      }
d }d }|d
   dk(  r| j                  |d      }	| j                  |d      }| j                  |d      }| j                  |d      }|	|dk(  rdnd }|dk(  rd}n
|dk(  rd}nd }|
dk(  s|dk(  rd}
nx|
dk(  s|dk(  rd}
nk|
dk(  s|dk(  rd}
n^|
dk(  s|dk(  rTd}
nQ|
j                  d      }| j                  |d      }
| j                  |d      }|d}| j                  |d      }|rdnd}d }| j                  |d      }|,| j                  |d       }d }|| j                  |      }||d!}| j                  |||	| j                  |	      ||||
||d ||d"|      S )#NrQ  trade_idorder_idr  )rr  volumesizer  r  r  r  r{  siderA   
trade_time
order_type
match_role	direction0r   r   r   r  r   r  r  r  4r  r   rj  is_makerrw  fee_currency)r  rh  )rQ  rt  r  r  r  r{  orderr>  r  rr  r  takerOrMakerrw  )r  r  safe_string_nr2  r3  r4  safe_timestamp_2r  r  r}  r  
safe_trader6  )rb  r8  r  rQ  orderIdpriceStringamountStringr7  r  r  r>  r{  rH  	orderType	tradeRolerB  partsisMakerrw  feeCostStringfeeCurrencyIdfeeCurrencyCodes                         rd  parse_tradezdigifinex.parse_trade  s   p tZ8""5*5&&ug6))%1MN++E8_M!!(F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/ "( 
  	re  c                 d   K   | j                  |       d{   }| j                  |d      S 7 w)a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        Nserver_time)publicSpotGetTimer  )rb  r  r  s      rd  
fetch_timezdigifinex.fetch_time  s5      //77 ""8];; 8s   0.0c                    K   | j                  |       d{   }| j                  |d      }|dk(  rdnd}|ddd|dS 7 'w)a  
        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>`
        Nrz  r   okmaintenance)statusupdatedetaurlrt  )publicSpotGetPingr  )rb  r  r  rz  r^  s        rd  fetch_statuszdigifinex.fetch_status  sZ      //77   62!)-
 	
 8s   A?(Asincec                   K   | j                          d{    | j                  |      }i }||d   rt        |d      n||d<   d}|d   r2|d   |d<   | j                  | j	                  ||             d{   }n1|d   |d<   | j                  | j	                  ||             d{   }| j                  |dg       }| j                  ||||      S 7 7 _7 /w)	at  
        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>`
        NrA   r   r   rQ  r  r  rg  )r  r  rq  publicSwapGetPublicTradesr  publicSpotGetTrades	safe_listparse_trades)	rb  r  rd  r   r  r  r  r  rg  s	            rd  fetch_tradeszdigifinex.fetch_trades  s      !!!V$28.s5#eGG&>'-d|GO$!;;DKKQW<XYYH &tGH!55dkk'66RSSHT ~~h3  vue<<m 	" Z Ts4   CCA"C9C:1C+C,,CCCc           	         |d   rh| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )NrA   r   rj              )r  r  r  )rb  ohlcvr  s      rd  parse_ohlcvzdigifinex.parse_ohlcv  s     &>!!%+  *  *  *  *  *  ##E1-  *  *  *  *  * re  r   c                   K   | j                          d{    | j                  |      }i }d}|d   rI|d   |d<   ||d<   |t        |d      |d<   | j                  | j	                  ||             d{   }n-| j                  |d      }	|d   |d	<   | j                  | j                  ||      |d
<   |}
| j                  |      }|
)||	%|	|	n| j                         }||nd}|||z  dz  z
  }
|
x| j                  |
dz        }
|
|d<   ||	[|	A| j                  |	dz        }|%| j                  |
||z        }t        ||      |d<   n||d<   n| j                  |
||z        |d<   | j                  |d      }| j                  | j	                  ||             d{   }d}|d   r'| j                  |di       }| j                  |dg       }n| j                  |dg       }| j                  |||||      S 7 7 7 `w)a8  
        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
        NrA   rQ  r  granularityr   r   untilr  period     
start_timeend_timerg  candles)r  r  rq  publicSwapGetPublicCandlesr  r  r  rW  parse_timeframemillisecondsparse_to_intsumomitpublicSpotGetKliner}  parse_ohlcvs)rb  r  	timeframerd  r   r  r  r  r  rt  	startTimedurationendTime
startLimit
endByUntil
endByLimitrz  rg  s                     rd  fetch_ohlcvzdigifinex.fetch_ohlcv  sW     !!!V$&>'-d|GO$%.GM" #&uc? !<<T[[RX=YZZH%%fg6E &tGH $ 0 0)Y WGHI++I6H %5+<(-(9e@Q@Q@SG+0+<3J ':+@4+G HI$ --i$.>?	(1%%5+<(%)%6%6ut|%D
 ,)-)UX=M)NJ25j*2MGJ/2<GJ/.2hhy%(BR.S
+YYvw/F!44T[[&5QRRH8 &>??8VR8DoodIr:Gooh;G  &)UEJJK 	" [4 Ss6   H	HA H	7H8D.H	&H'AH	H	H	r{  r>  rr  r  c                   K   | j                          d{    | j                  |      }| j                  d|      }|d   }	| j                  ||||||      }
d}|d   r| j	                  |
       d{   }n5|	| j                  |
       d{   }n| j                  |
       d{   }| j                  ||      }|d   |d<   ||d<   ||d<   ||d<   ||d	<   |S 7 7 l7 R7 :w)
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>`
        NrJ   r   rA   r  r{  r>  rr  r  )r  r  r  create_order_requestprivateSwapPostTradeOrderPlaceprivateSpotPostMarginOrderNewprivateSpotPostSpotOrderNewparse_order)rb  r  r{  r>  rr  r  r  r  marginResultr   r  r  rG  s                rd  create_orderzdigifinex.create_orderk  s    ( !!!V$99-P!!_
++FD$vV&>!@@IIH%!%!C!CG!LL!%!A!A'!JJ    62 *hff hgE 	" J MJsF   C'CAC'4C!5C'C#C'*C%+5C'!C'#C'%C'ordersc           	        K   | j                          d{    g }d}d}t        dt        |            D ]  }||   }| j                  |d      }||}n||k7  rt	        | j
                  dz         | j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d	i       }| j                  d
|      }|d   }|"||}n||k7  rt	        | j
                  dz         | j                  ||	|
|||      }|j                  |        | j                  |      }i }d}|d   r| j                  |       d{   }n>|dnd|d<   |d   |d<   | j                  |      |d<   | j                  |       d{   }g }|d   r| j                  |dg       }n| j                  |dg       }g }t        dt        |            D ]T  }||   }i }||   |d<   |d   |d<   | j                  |d      |d<   | j                  |d      |d<   |j                  |       V | j                  ||      S 7 ;7 7 w)aN  
        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{  r>  rr  r  r  rK   zS createOrders() requires all orders to have the same margin mode(isolated or cross)rA   r@   r?   r  rQ  r  rg  	order_idsr;  r  )r  r~  r  r  r)   rQ  r}  r  r  r  r  privateSwapPostTradeBatchOrderjson"privateSpotPostMarketOrderBatchNewr  parse_orders)rb  r  r  ordersRequestsr  r   r  rawOrderr7  r{  r>  rr  r  orderParamsr  currentMarginModeorderRequestr  r  r  rg  r  individualOrders                          rd  create_orderszdigifinex.create_orders  s     !!!
q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==nkZL ,Q ,%!2J!%66(  4I  *I  J  J44XtT6SXZefL!!,/-	0. V$&>!@@PPH-7-C&GH &tGH"ii7GFO!DDWMMH, &>??8VR8D??8["=Dq#f+& 	+AayH$&O*.q'OJ'/5d|OO,(,(8(88(LOH%'+'7'7''JOG$MM/*	+   00Q 	"> Q
 Ns5   IIEII >IIB3IIIc                 
   | j                  |      }d}d}	| j                  d||      \  }}| j                  d|      \  }	}|	d}i }
|dk(  }|dk(  }|dk(  }|rdnd}|d	   |
|<   | j                  |d
|      }d}|r| j	                  |dd
      }| j                  |d      }d}|dk(  r|rdnd}||
d<   n|rdnd}||
d<   |rd}|dk(  r|rdnd}n|dk(  r|rdnd}n|dk(  s|rd}n|dk(  rd}|| j                  ||      |
d<   ||
d<   ||
d<   | j                  |ddg      }n/|du rdnd}||
d<   d }|dk(  rd!}n| j                  ||      |
d<   ||z   |
d<   d}d}| j                  |dd"d      \  }}|r|dk(  r| j                  |d#      }| j                  |d#      }|| j                  ||      }n|rt|t        | j                  d$z         | j                  |      }| j                  |      }| j                  t        j                   ||            }| j                  ||      }n%| j                  ||      }n| j#                  ||      }||
d%<   |r|r||
d&<   n||
d&<   | j                  |d'g      }| j%                  |
|      S )(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createOrderRequestr@   rA   r  r   r  r  rQ  F
reduceOnlyr   r  rn  rj  r{  rm  rl  r   r      	   r      GTC   r   Tr  r@  r=   _marketrF  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 argumentrr  	post_onlypostOnly)r  r  r  is_post_only	safe_boolr  price_to_precisionr  handle_option_and_paramsr  cost_to_precisionr-   rQ  number_to_stringra  r6   
string_mulamount_to_precisionr  )rb  r  r{  r>  rr  r  r  r  r   r   r  rA   isMarketOrderisLimitOrdermarketIdRequestr  postOnlyParsedr  r   rO  requestTypesuffixquantityrF  r  rN  rM  costRequests                               rd  r  zdigifinex.create_order_request  s;    V$

!??@TV\^de
F!??@TV\]
F!!Jf$)-1/x#)$< $$]E6BeDJ**6=AKIu}$.aQ"-$.aQ"-	e#"/BQ	%"/BQ	&M	$ #'#:#:65#I $-GL!$GFOYYvm'DEF#+t#3Q!N *GHFx"#'#:#:65#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5ffEH33FFC (GH'5$'/$6J<0{{7F++re  r  c                    K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|       d{   S 7 U7 w)a  
        create a market buy order by providing the symbol and cost

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

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr?   z9 createMarketBuyOrderWithCost() supports spot orders onlyFrF  r  r  )r  r  r/   rQ  r  )rb  r  r  r  r  s        rd  !create_market_buy_order_with_costz+digifinex.create_market_buy_order_with_costS  sy      !!!V$f~tww)ddee6;23&&vxdFSSS 	"
 Ts"   A0A,AA0'A.(A0.A0rQ  c                   K   | j                          d{    d}|| j                  |      }t        |      }d}| j                  d||      \  }}d|i}|dk(  r#|t	        | j
                  dz         |d   |d<   n||d<   | j                  d|      \  }}d}	||d	k(  r,d	}| j                  | j                  ||             d{   }	nv|d
k(  r*| j                  | j                  ||             d{   }	nG|dk(  r*| j                  | j                  ||             d{   }	nt        | j
                  dz         |d
k(  s|d	k(  rd| j                  |	dg       }
t        |
      }|dk7  rt        | j
                  dz   |z   dz         | j                  |	      }| j!                  |d      S | j#                  |	| j%                  |	d      d      S 7 7 7 7 w)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>`
        NrE   r;  rA   z) cancelOrder() requires a symbol argumentrQ  r  r  r@   r?   z+ cancelOrder() not support self market typesuccessrj  z cancelOrder() 
 not foundr   rg  )rt  rL  )r  r  strr  r(   rQ  r   privateSpotPostMarginOrderCancelr  privateSpotPostSpotOrderCancelprivateSwapPostTradeCancelOrderr/   r}  r  r.   parse_cancel_orders	safe_dict
safe_orderr  )rb  rQ  r  r  r  r   r  r   r  r  canceledOrdersnumCanceledOrdersr  s                rd  cancel_orderzdigifinex.cancel_ordere  s     !!![[(FW
!??vW]^
F
 ~'2](]^^'-d|GO$ *GH >>}fU
E!Z8%;!J!BB4;;wX]C^__H6!!@@WV[A\]]H6!!AA$++gW\B]^^Htww)VVWW, & jH&<!__Xy"EN #N 3 A%#DGG.?$?"$D|$STT--h7F>>&!,,?? ++Hf=$  q 	"( `]^sG   G GB1G G	.G 7G8.G &G'B0G G G G c                    | j                  |d      }| j                  |d      }g }t        dt        |            D ]+  }||   }|j                  | j	                  ||dd             - t        dt        |            D ]M  }||   }|j                  | j	                  || j                  |dd      d| j                  |d	      d
             O |S )Nr  errorr   canceled)rt  rQ  r^  zorder-idr;  failedzclient-order-id)rt  rQ  r^  clientOrderId)rh  r~  r  r  r  r  r  )rb  r  r  r  r  r  rG  s          rd  r  zdigifinex.parse_cancel_orders  s    ..95x1q#g,' 	AAJEMM$//$+  	 q#e*% 	A!HEMM$//((
JG"!%!1!1%9J!K	+  	 re  c                 b  K   | j                          d{    | j                  | j                  dd      }| j                  |d|      }| j                  |d      }|dj	                  |      d}| j                  | j                  ||             d{   }| j                  |      S 7 7 w)aD  
        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>`
        NrD  r?   r{  ,)r  r;  )r  r  r\  r  joinr  r  r  )rb  idsr  r  rD  rO  r  r  s           rd  cancel_orderszdigifinex.cancel_orders  s      !!!&&t||]FK$$VV[A	66*
 <<T[[RX=YZZ ''11+ 	" [s"   B/B+A>B/B-B/-B/r^  c                 8    dddddd}| j                  |||      S )Nr#  closedr  )rC  r   r  r  rD  r  rb  r^  statusess      rd  parse_order_statuszdigifinex.parse_order_status  s/    
 &&99re  rG  c                    d }d }d }d }| j                  |d      }| j                  |dd      }| j                  ||      }	| j                  |	      }|d   dk(  r| j	                  |d      }
|
q|
dk(  s|
dk(  s|
dk(  s
|
d	k(  s|
d
k(  rd}n2|
dk(  s|
dk(  s|
dk(  s
|
dk(  s|
dk(  rd}n|
dk(  s|
dk(  s
|
dk(  s|
dk(  rd}|
dk(  s|
dk(  s|
dk(  s|
dk(  s
|
dk(  s|
dk(  rd}nd}|dk(  rd}n|dk(  rd}n|dk(  rd }n|d!k(  rd"}| j	                  |d#      }| j	                  |d$      }nT| j                  |d%      }| j                  |d&      }|.|j                  d'      }t        |      }|dkD  r|d   }|d   }nd}| j                  i d(|d)| j                  |d*d+      d,d d-|d.| j                  |      d/|d|	d|d0|d1d d2|d3| j                  |d3      d4d d5| j                  |d5d6      d7| j                  |d8d9      d:d d;d | j                  |d<d=      | j                  | j                  |d>d?            d;| j                  |d@      id dA|      S )BNr{  r  r  rA   r@  r  r         r  r   rj  rl  rm  rn  r  r            r  r  r   ro  r   r  r   z	open longr  z
open shortr  z
close longrD  zclose shortinsert_time
time_stampcreated_datefinished_dater  rt  rQ  r;  rg  r  r  r  lastTradeTimestampr   r  r>  r  r   rr  r=  filledexecuted_amount
filled_qty	remainingr  	avg_price	price_avgr^  staterw  )r)  r^  rw  r   )r  r  r3  r  r  r  r  r  r  r6  r  r  r  )rb  rG  r  r  r  r   r{  r>  r7  r  rO  rQ  numPartss                rd  r  zdigifinex.parse_order  sl   @ 	!v.%%eXG!!(F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 	re  c                   K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}| j                  d|      \  }}i }	|dk(  }
|
r|||	d<   |||	d<   n||	d<   ||
rdnd}|d	   |	|<   d}||d
k(  r,d
}| j	                  | j                  |	|             d{   }nv|dk(  r*| j                  | j                  |	|             d{   }nG|dk(  r*| j                  | j                  |	|             d{   }nt        | j                  dz         | j                  |dg       }| j                  ||||      S 7 F7 7 x7 Kw)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>`
        Nrq   rA   start_timestampr   r  r  r  rQ  r@   r?   z/ fetchOpenOrders() not support self market typerg  )r  r  r  r   privateSpotGetMarginOrderCurrentr  privateSpotGetSpotOrderCurrentprivateSwapGetTradeOpenOrdersr/   rQ  rh  r  )rb  r  rd  r   r  r  r   r   r  r  rA   r  r  rg  s                 rd  fetch_open_orderszdigifinex.fetch_open_ordersp  s     !!![[(F
!??@QSY[ab
F >>?PRXY
Ef$ -2)* #(  *GH15o8O'-d|GO$!Z8%;!J!BB4;;wX]C^__H6!!@@WV[A\]]H6!!??GUZ@[\\Htww)ZZ[[h ~~h3  vue<<c 	", `]\sG   E%EB"E%9E:.E%(E!).E%E#AE%E%!E%#E%c                   K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}| j                  d|      \  }}i }	|dk(  r|$||	d<   n||	d<   || j	                  |dz        |	d<   ||dk(  rdnd	}
|d
   |	|
<   |||	d<   d}||dk(  r,d}| j                  | j                  |	|             d{   }nv|dk(  r*| j                  | j                  |	|             d{   }nG|dk(  r*| j                  | j                  |	|             d{   }nt        | j                  dz         | j                  |dg       }| j                  ||||      S 7 `7 7 x7 Kw)a  
        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>`
        Nrt   rA   r  r  rw  rx  r  r  rQ  r   r@   r?   z+ fetchOrders() not support self market typerg  )r  r  r  r  r~   privateSpotGetMarginOrderHistoryr  privateSpotGetSpotOrderHistory privateSwapGetTradeHistoryOrdersr/   rQ  rh  r  )rb  r  rd  r   r  r  r   r   r  r  r  r  rg  s                rd  fetch_orderszdigifinex.fetch_orders  s     !!![[(F
!??vW]^
F >>}fU
E -2)* *GH (,(9(9%$,(G%2<2FoXO'-d|GO$$GG!Z8%;!J!BB4;;wX]C^__H6!!@@WV[A\]]H6!!BB4;;wX]C^__Htww)VVWWh ~~h3  vue<<e 	". `]_sG   E?E6B<E?E9.E?E;.E?1E=2AE?9E?;E?=E?c                 $  K   | j                          d{    d}|| j                  |      }d}| j                  d||      \  }}| j                  d|      \  }}d|i}|dk(  r||d   |d<   n||d<   d}	||dk(  r,d}| j	                  | j                  ||             d{   }	nv|d	k(  r*| j                  | j                  ||             d{   }	nG|dk(  r*| j                  | j                  ||             d{   }	nt        | j                  d
z         | j                  |	d      }
|dk(  r|
n| j                  |
d      }|'t        | j                  dz   t        |      z   dz         | j                  ||      S 7 q7 7 7 w)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>`
        Nrr   r;  rA   rQ  r  r  r@   r?   z* fetchOrder() not support self market typerg  r   z fetchOrder() order r  )r  r  r  r  privateSpotGetMarginOrderr  privateSpotGetSpotOrderprivateSwapGetTradeOrderInfor/   rQ  r}  r.   r  r  )rb  rQ  r  r  r  r   r   r  r  r  rg  rG  s               rd  fetch_orderzdigifinex.fetch_order1	  s     !!![[(F
!??fV\]
F >>|VT
E
 !+1$<( *GH"
h(>!J!;;DKKQV<WXXH6!!99$++gu:UVVH6!!>>t{{7TY?Z[[Htww)UUVVb x0#v-DOOD!4L=*@ @3r7 J\ YZZv..[ 	"$ YV[sG   FFBF%F
&.FF.FFBF
FFFc                   K   | j                          d{    d}i }|| j                  |      }d}| j                  d||      \  }}| j                  d|      \  }}	|dk(  r|$||d<   n||d<   || j	                  |dz        |d<   |dk(  rdnd	}
||d
   ||
<   |||d<   d}||dk(  r,d}| j                  | j                  ||	             d{   }nv|dk(  r*| j                  | j                  ||	             d{   }nG|dk(  r*| j                  | j                  ||	             d{   }nt        | j                  dz         |dk(  rdnd}| j                  ||g       }| j                  ||||      S 7 i7 7 7 Tw)aP  
        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>`
        Nro   rA   r  r  rw  rx  r  r  rQ  r   r@   r?   z- fetchMyTrades() not support self market typerg  r  )r  r  r  r  r~  privateSpotGetMarginMytradesr  privateSpotGetSpotMytrades privateSwapGetTradeHistoryTradesr/   rQ  rh  ri  )rb  r  rd  r   r  r  r  r   r   r  r  r  responseRequestrg  s                 rd  fetch_my_tradeszdigifinex.fetch_my_trades	  s     !!![[(F
!??QWY_`
F >>PVW
E -2)* *GH (,(9(9%$,(G%.8F.B/'-d|GO$$GG!Z8%;!J!>>t{{7TY?Z[[H6!!<<T[[RW=XYYH6!!BB4;;wX]C^__Htww)XXYY\ &06%9&~~h<  vue<<[ 	". \Y_sG   FE?B<FF.FF.F1F2AFFFFc                 ,    i }| j                  |||      S Nr  )rb  r{  rE  s      rd  parse_ledger_entry_typez!digifinex.parse_ledger_entry_type	  s    tT22re  itemrh  c                    | j                  | j                  |dd            }| j                  |dd      }| j                  ||      }| j                  ||      }| j	                  |dd      }| j                  |d      }| j                  |d      }|| j                  |d	      }| j                  |d d d d d |||d |d || j                  |      d d
|      S )Nr{  finance_typecurrency_markrh  numr'  r  r   r  )rt  rQ  rB  r  referenceIdreferenceAccountr{  rh  rr  beforeafterr^  r  r  rw  )
r  r  r  safe_currencyr  r  r  r  safe_ledger_entryr6  )	rb  r  rh  r{  r  rz  rr  r  r  s	            rd  parse_ledger_entryzdigifinex.parse_ledger_entry	  s    * ++D,>,>tV^,\]''ozJ
&&z8<%%j(;##D%:  y1''f5	))$<I%% $"Y/'
  ! 	re  rz  c                 Z  K   | j                          d{    i }d}| j                  dd|      \  }}| j                  d|      \  }}|dk(  r|$||d<   n||d<   || j                  |dz        |d<   |dk(  rdnd	}	d}
|| j	                  |      }
|
d
   ||	<   |||d<   d}||dk(  r,d}| j                  | j                  ||             d{   }nv|dk(  r*| j                  | j                  ||             d{   }nG|dk(  r*| j                  | j                  ||             d{   }nt        | j                  dz         d}|dk(  r| j                  |dg       }n&| j                  |di       }| j                  |dg       }| j                  ||
||      S 7 7 7 7 yw)a  
        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>`
        Nrh   rA   r  r  rw  rx  rh  r  rQ  r   r@   r?   z+ fetchLedger() not support self market typerg  finance)r  r  r  r~  rh  privateSpotGetMarginFinancelogr  privateSpotGetSpotFinancelog"privateSwapGetAccountFinanceRecordr/   rQ  r}  parse_ledger)rb  rz  rd  r   r  r  r   r   r  currencyIdRequestrh  r  ledgerrg  s                 rd  fetch_ledgerzdigifinex.fetch_ledger
  s     !!!
!??tU[\
F >>}fU
E -2)* *GH (,(9(9%$,(G%+5+?Jo}}T*H)1$G%&$GG!Z8%;!J!@@WV[A\]]H6!!>>t{{7TY?Z[[H6!!DDT[[QXZ_E`aaHtww)VVWWD __Xvr:F??8VR8D__T9b9F  5%@@I 	", ^[asG   F+F"B:F+F%.F+ F'.F+/F)0A3F+%F+'F+)F+c                     | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }||d ||dS )Naddress
addressTagrh  )rt  rh  ru  r  tag)r  safe_string_upperr  )rb  depositAddressrh  r  r   r  rz  s          rd  parse_deposit_addresszdigifinex.parse_deposit_addresso
  sc     "">9=~|<++NJG
&&z2"
 	
re  c                 ~  K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||d   g      }| j	                  ||      }|t        | j                  dz   |z   dz         |S 7 7 cw)a9  
        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>`
        Nrh  rQ  rg  rz  z5 fetchDepositAddress() did not return an address for zQ - create the deposit address in the user settings on the exchange website first.)r  rh  privateSpotGetDepositAddressr  r}  parse_deposit_addressesr,   rQ  )	rb  rz  r  rh  r  r  rg  	addressesr  s	            rd  fetch_deposit_addresszdigifinex.fetch_deposit_address
  s      !!!==&
 ::4;;wPV;WXX x4008H7IJ	//)T2? +b!bei!i  m@  "@  A  A1 	"
 Ys#   B=B9A B=B;A"B=;B=c                   K   | j                          d {    d }i }|| j                  |      }|d   |d<   |t        d|      |d<   d }|dk(  r*| j                  | j	                  ||             d {   }n)| j                  | j	                  ||             d {   }| j                  |dg       }	| j                  |	|||d|i      S 7 7 Z7 2w)NrQ  rh  r   r=  rs  rg  r{  )r  rh  rq  privateSpotGetDepositHistoryr  privateSpotGetWithdrawHistoryrh  parse_transactions)
rb  r{  rz  rd  r   r  rh  r  r  rg  s
             rd  fetch_transactions_by_typez$digifinex.fetch_transactions_by_type
  s     !!!
 }}T*H"*4.GJ!#uoGFO9!>>t{{7TZ?[\\H!??GU[@\]]H* ~~h3&&tXuefd^TTO 	" ]]s4   CCAC6C7)C C!/CCCc                 H   K   | j                  d||||       d{   S 7 w)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>`
        rs  Nr-  rb  rz  rd  r   r  s        rd  fetch_depositszdigifinex.fetch_deposits
  s(      44YeUTZ[[[[   " "c                 H   K   | j                  d||||       d{   S 7 w)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>`
        
withdrawalNr/  r0  s        rd  fetch_withdrawalszdigifinex.fetch_withdrawals
  s)      44\4PUW]^^^^r2  c                 6    ddddd}| j                  |||      S )Npendingr\  r  )r   r  r  rD  r  r  s      rd  parse_transaction_statusz"digifinex.parse_transaction_status
  s.     	
 &&99re  transactionc                    | j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j	                  | j                  |d            }	| j	                  | j                  |d            }
| j                  | j                  |d	            }| j                  |d
      }| j                  |d      }d }|||d}| j                  |d      }i d|d|d|d|	d| j                  |	      d|d|d|dd d|d|dd dd d
|d|d|d|
d d |dS )NrQ  withdraw_idr  memohashrh  r  r  r  rr  rw  )rh  r  ro  rt  txidr  r  ru  	addressToaddressFromr   tagTotagFromr{  r^  r_  )internalcommentrw  )r  r  r!  r  	parse8601r8  r  r6  )rb  r9  rh  rQ  r  r   r>  r  rz  r  r_  r^  rr  feeCostrw  ru  s                   rd  parse_transactionzdigifinex.parse_transaction
  s   2 T=A"";	:{F3V4++KD
&&z8<NN4#3#3K#PQ	..!1!1+!OP..t/?/?W/UV!!+x8"";6#W5C"";8
K
"
 D
 	

 Y/
 w
 w
 
 4
 3
 S
 t
 D
 f
 
  f!
" w#
$ )
 	
re  c                 0    ddi}| j                  |||      S )NrC  r\  r  r  s      rd  parse_transfer_statuszdigifinex.parse_transfer_status/  s%    
 &&99re  r   c                    d }d }| j                  |d|      }| j                  |d      }|dk(  rd}d}n	|dk(  rd}d}| j                  |d      }|| j                  |d      || j                  |      | j	                  | j                  |d	      |      | j                  |d
d      ||| j                  | j                  |d            d	S )Nrg  r{  rj  r?   rA   rl  r  transfer_idrh  rr  transfer_amountrz  )	rt  rQ  r  r  rh  rr  fromAccount	toAccountr^  )r  r  r  r6  r  r  rI  )rb  r   rh  rM  rN  rg  r{  r  s           rd  parse_transferzdigifinex.parse_transfer5  s    : 	~~h9  v.19 KIQY KI%%h<	""8];"Y///0@0@z0RT\]((x9JK&"001A1A(F1ST

 
	
re  rM  rN  c                   K   | j                          d{    | j                  |      }|d   }| j                  | j                  di       }| j	                  |||      }	| j	                  |||      }
i }|dk(  }|dk(  }d}| j                  ||      }|s|r_|	dk7  r|
dk7  rt        | j                  dz         |rdnd|d	<   ||d
<   ||d<   | j                  | j                  ||             d{   }n=||d<   ||d<   |	|d<   |
|d<   | j                  | j                  ||             d{   }| j                  ||      S 7 07 W7 w)a  
        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>`
        NrQ  rG  rA   r   z[ transfer() supports transferring between spot and swap, spot and margin, spot and OTC onlyrj  rl  r{  rh  rL  r  r  fromto)r  rh  r}  r\  r  currency_to_precisionr$   rQ  privateSwapPostAccountTransferr  privateSpotPostTransferrO  )rb  rz  rr  rM  rN  r  rh  r  rG  fromIdtoIdr  fromSwaptoSwapr  rN  s                   rd  r   zdigifinex.transferi  s     !!!==&d^
7GL!!.+{K	9E6)v%11$?v#DCK#DGG  /L  %L  M  M#)aqGFO",GJ)5G%& "@@WV\A]^^H'1GO$)GEN$GFO GDM "99$++gv:VWWH""8X66O 	"6 _ Xs4   EECE1E	2=E/E0E	EEr  c                 f  K   | j                  ||      \  }}| j                  |       | j                          d{    | j                  |      }|| j	                  ||      |d   d}|||d<   | j                  | j                  ||             d{   }| j                  ||      S 7 p7 w)a  
        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>`
        NrQ  )r  rr  rh  r<  )handle_withdraw_tag_and_paramscheck_addressr  rh  rS  privateSpotPostWithdrawNewr  rG  )	rb  rz  rr  r  r   r  rh  r  r  s	            rd  r   zdigifinex.withdraw  s      99#vFV7#!!!==& 00v> 	
 ?!GFO88Wf9UVV %%h99# 	" Ws"   :B1B-AB1B/B1/B1c                 B  K   | j                          d {    i }d }|| j                  |      }|d   |d<   | j                  | j                  ||             d {   }| j	                  |d      }	| j                  |	|      }
| j                  |
|||      S 7 7 >w)NrQ  r  	positions)r  r  privateSpotGetMarginPositionsr  r}  parse_borrow_interestsfilter_by_currency_since_limit)rb  rz  r  rd  r   r  r  r  r  rowsinterests              rd  fetch_borrow_interestzdigifinex.fetch_borrow_interest  s     !!![[(F &tGH;;DKKQW<XYY, x5..tV<228T5%PP= 	" Zs"   BBABB=BBrt  c           
      2   | j                  |d      }| j                  |d      }| j                  |d      }t        j                  ||      }t        j                  ||      }|d n|d   }| j	                  ||      }	||	|d d| j                  |      d d d d	S )Nr  rr  leverage_ratior  MbP?)	rt  r  rh  rd  interestRateamountBorrowedr   r  r  )r  r6   
string_divr  r3  ra  )
rb  rt  r  r7  rN  leverageStringamountInvestedrj  rh  r  s
             rd  parse_borrow_interestzdigifinex.parse_borrow_interest  s     ##D(3''h7))$0@A ++L.I ++L.I"N4!!(F3 !"//?

 
	
re  c                 v  K   | j                          d{    i }| j                  | j                  ||             d{   }| j                  |dg       }g }t	        dt        |            D ]  }||   }| j                  |d      |k(  s|}! | j                  |      }	| j                  ||	      S 7 7 uw)a  
        fetch the rate of interest to borrow a currency for margin trading

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `borrow rate structure <https://github.com/ccxt/ccxt/wiki/Manual#borrow-rate-structure>`
        Nr  r   rh  )	r  r  r  r}  r~  r  r  rh  parse_borrow_rate)
rb  rz  r  r  r  rg  r  r  entryrh  s
             rd  fetch_cross_borrow_ratez!digifinex.fetch_cross_borrow_rate  s      !!!88Wf9UVV$ x4q#d)$ 	AGEz2d:	 ==&%%fh777 	"Vs(   B9B5*B9B7AB9(B97B9c                    K   | j                          d{    | j                  |       d{   }| j                  |dg       }| j                  |d      S 7 B7 +w)aQ  
        fetch the borrow interest rates of all currencies

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        Nr  rh  )r  r  r}  parse_borrow_rates)rb  r  r  r  s       rd  fetch_cross_borrow_ratesz"digifinex.fetch_cross_borrow_rates(  s]      !!!88@@$ 626&&vz::) 	"@s   AAAA*AAc                     | j                         }| j                  |d      }| j                  ||      dd|| j                  |      |dS )Nrh  rh  i \&)rh  rateru  r  r  rt  )r}  r  r  r6  )rb  rt  rh  r  r  s        rd  rp  zdigifinex.parse_borrow_rateG  sV     %%'	%%dJ7
//
HE"Y/
 	
re  c                     i }t        dt        |            D ]@  }||   }| j                  ||      }| j                  |      }| j	                  |      }|||<   B |S )Nr   )r~  r  r  r  rp  )	rb  rt  codeKeyr  r  r  rh  rz  
borrowRates	            rd  rt  zdigifinex.parse_borrow_rates[  sn     q#d)$ 	&A7D''g6H**84D//5J%F4L	& re  c                 H  K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)am  
        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>`
        NrA   z0 fetchFundingRate() supports swap contracts onlyr  rQ  rg  )r  r  r*   rQ  publicSwapGetPublicFundingRater  r  parse_funding_raterb  r  r  r  r  r  rg  s          rd  fetch_funding_ratezdigifinex.fetch_funding_ratem  s      !!!V$f~DGG&XXYYVD\
 <<T[[RX=YZZ ~~h3&&tV44+ 	" ["   B"BAB"4B 5*B" B"c                 B   K   | j                  ||       d{   S 7 w)av  
        fetch the current funding rate interval

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        N)r  )rb  r  r  s      rd  fetch_funding_intervalz digifinex.fetch_funding_interval  s!      ,,VV<<<<s   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        j                  ||      }i d|d| j	                  ||      dd dd dd d	d d
d dd d| j                  |d      d|d| j                  |      d| j                  |d      d|d| j                  |      dd dd dd d| j                  |      iS )Nr  funding_timenext_funding_timert  r  r0  r1  ri  estimatedSettlePricer  r  fundingRatefunding_ratefundingTimestampfundingDatetimenextFundingRatenext_funding_ratenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)r  r  r6   r  r3  r  r6  parse_funding_interval)	rb  r  r  r7  r  nextTimestampfundingTimeStringnextFundingTimeStringmillisecondsIntervals	            rd  r}  zdigifinex.parse_funding_rate  s    ##Ho>%%h?	))(4GH ,,X~F $ 0 0;N O&112GIZ[
H
d&&x8
 
 $	

 D
 #D
 
 
 4++HnE
 	
 t||I6
 t//:MN
 #M
 "4<<#>
 "4
  '!
" &t#
$ 334HI%
 	
re  c                 8    dddddd}| j                  |||      S )Nr   r   8h16h24h)360000014400000288000005760000086400000r  )rb  r  	intervalss      rd  r  z digifinex.parse_funding_interval  s/    
	 	8X>>re  c           
         K   |t        | j                  dz         | j                          d{    | j                  |      }|d   st	        | j                  dz         d|d   i}|||d<   |||d<   | j                  | j                  ||             d{   }| j                  |d	i       }| j                  |d
g       }	g }
t        dt        |	            D ]r  }|	|   }| j                  |d      }| j                  |      }| j                  |d      }|
j                  ||| j                  |d      || j                  |      d       t | j!                  |
d      }| j#                  ||||      S 7 I7 ߭w)aI  
        fetches historical funding rate prices
        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentrA   z7 fetchFundingRateHistory() supports swap contracts onlyr  rQ  r  r   rg  funding_ratesr   r   rw  )rt  r  r  r  r  r  )r(   rQ  r  r  r*   %publicSwapGetPublicFundingRateHistoryr  r}  r~  r  r  r3  r  r  r  r6  sort_byfilter_by_symbol_since_limit)rb  r  rd  r   r  r  r  r  rg  r  ratesr  rq  r7  symbolInnerr  sorteds                    rd  fetch_funding_rate_historyz$digifinex.fetch_funding_rate_history  s     >#DGG.e$eff!!!V$f~DGG&__``VD\
 ).G%&$GGCCDKKPWY_D`aa  x4;q#f+& 	A1IE''o>H**84K))%8ILL%#//v>& LL3 	 e[100NNW 	" bs#   .E>E9A+E>E<CE><E>c                 H  K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)aX  
        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>`
        NrA   z- fetchTradingFee() supports swap markets onlyr  rQ  rg  )r  r  r)   rQ  #privateSwapGetAccountTradingFeeRater  r}  parse_trading_feer~  s          rd  fetch_trading_feezdigifinex.fetch_trading_fee  s      !!!V$f~TWW'VVWWVD\
 AA$++gW]B^__ x4%%dF33' 	" `r  rw  c                     | j                  |d      }| j                  ||      }||| j                  |d      | j                  |d      d d dS )Nr  maker_fee_ratetaker_fee_rate)rt  r  r   r   r   r   )r  r3  r  )rb  rw  r  r7  r  s        rd  r  zdigifinex.parse_trading_fee   s`     ##C9!!(F3%%c+;<%%c+;<
 	
re  c                 ~  K   | j                          d{    | j                  |      }i }d}d}|Sd}t        |t              r.t	        |      }|dkD  rt        | j                  dz         |d   }n|}| j                  |      }| j                  d||      \  }}| j                  d|      \  }}	|d}||dk(  rdnd	}
|d
   ||
<   d}|dk(  s|dk(  r*| j                  | j                  ||	             d{   }nG|dk(  r*| j                  | j                  ||	             d{   }nt        | j                  dz         |dk(  rdnd}| j                  ||g       }g }t        dt	        |            D ]&  }|j!                  | j#                  ||   |             ( | j%                  |d	|d      S 7 7 7 w)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>`
        Nrj  zD fetchPositions() symbols argument cannot contain more than 1 symbolr   rw   r@   rA   r  r  rQ  r?   z. fetchPositions() not support self market typerg  r_  F)r  r  r  r  r  r)   rQ  r  r  r  r`  r  privateSwapGetAccountPositionsr/   r}  r~  r  parse_positionfilter_by_array_positions)rb  r   r  r  r  r   r  symbolsLengthr   r  r  r  positionRequestr_  r  r  s                   rd  fetch_positionszdigifinex.fetch_positions3  s     !!!%%g.
F'4( #G 1$$TWW/u%uvv  [[(F!??@PRXZ`a
F >>?OQWX
E!!J2<2FoXO'-d|GO$:#9!??GUZ@[\\H6!!@@WV[A\]]Htww)YYZZl &06%9&OOHorB	q#i.) 	EAMM$--ilFCD	E--fhOOo 	"0 ]]s5   F=F6C"F=9F9:.F=(F;)BF=9F=;F=c                   K   | j                          d{    | j                  |      }i }d}| j                  d||      \  }}| j                  d|      \  }}|d}|dk(  rdnd}|d   ||<   d}	|dk(  s|dk(  r*| j	                  | j                  ||             d{   }	nG|dk(  r*| j                  | j                  ||             d{   }	nt        | j                  d	z         |dk(  rd
nd}
| j                  |	|
g       }| j                  |d   |      }|dk(  r|S | j                  |	d      |d<   | j                  |	d      |d<   |S 7 ;7 7 w)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>`
        Nru   r@   rA   r  r  rQ  r?   z- fetchPosition() not support self market typerg  r_  r   
collateralmargin_ratemarginRatio)r  r  r  r  r`  r  r  r/   rQ  r}  r  r  )rb  r  r  r  r  r   r   r  r  r  dataRequestrg  positions                rd  fetch_positionzdigifinex.fetch_position  s     !!!V$
!??QWY_`
F >>PVW
E!!J.8F.B/#)$< :#9!??GUZ@[\\H6!!@@WV[A\]]Htww)XXYYh ",v!5fKxb9&&tAw7O%)%5%5h%IH\"&*&6&6x&OH]#OY 	" ]]s5   EEB	E E!.EEBEEEr  c                    | j                  |dd      }| j                  ||      }|d   }| j                  |d      }|
|dk(  rdnd}nd}| j                  |d      }| j                  |d      }|d	k(  rd
}n|dk(  rd}| j	                  i d|dd d|d| j                  |d      d|d| j                  |d      d| j                  |dd      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d|dd d|d| j                  |      d | j                  |d!      d"| j                  |d#      d d d | j                  |d$d%      | j                  |d&      d d d d'      S )(Nr  r  margin_modecrossedcrossisolatedr  r>  go_longlonggo_shortshortrt  rQ  notionalrr  r   liquidationPriceliquidation_price
entryPriceavg_costentry_priceunrealizedPnlunrealized_pnl	contractsavail_positionr  r0  r  r   r  maintenanceMarginr@   maintenanceMarginPercentagemaint_margin_ratior   rg  margin_ratio)r  initialMargininitialMarginPercentager   r  r   r   r   )r  r4  r  r  safe_positionr  r  r6  )rb  r  r  r7  r  r   r  r>  s           rd  r  zdigifinex.parse_position  s>   N %%hJ!!(F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#
  	re  r   c                   K   |t        | j                  dz         | j                          d{    | j                  |      }|d   dk7  rt	        | j                  dz         |dk  s|dkD  rt        | j                  dz         |d	   |d
}| j                  | j                  dd      }| j                  |dd|      }|"|dk(  rdnd}||d<   | j                  |ddg      }|dk(  rB| j                  |d      }|||d<   | j                  |d      }n| j                  d|dddg       | j                  | j                  ||             d{   S 7 %7 w)a#  
        set the level of leverage for a market

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

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: either 'cross' or 'isolated', default is cross
        :param str [params.side]: either 'long' or 'short', required for isolated markets only
        :returns dict: response from the exchange
        Nz) setLeverage() requires a symbol argumentr{  rA   z+ setLeverage() supports swap contracts onlyrj  r   z% leverage should be between 1 and 100rQ  )r  r   r   defaultMarginModer  r  r  r  r>  r   r  r  )r(   rQ  r  r  r*   r)   r  r\  safe_string_lower_2r  r  check_required_argumentprivateSwapPostAccountLeverager  )	rb  r   r  r  r  r  r  r   r>  s	            rd  set_leveragezdigifinex.set_leverageA  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%/GM"YYv6I'JKF###FF3D"&662,,]D&6SZJ[\88Wf9UVVV/ 	". Ws"   .EEDEEEEc                 <  K   | j                          d{    d}i }|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||||      S 7 7 -w)aS  
        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>`
        NrQ  rh  r  r   rg  )r  r  #privateSwapGetAccountTransferRecordr  rh  parse_transfers)	rb  rz  rd  r   r  rh  r  r  	transferss	            rd  fetch_transferszdigifinex.fetch_transferst  s      !!!..t4H"*4.GJ).G%&$GGAA$++gW]B^__  NN8VR8	##IxFF7 	" `s"   BBAB,B-,BBc                    K   | j                          d{    | j                  |       d{   }| j                  |dg       }| j                  |      }| j	                  ||d      S 7 T7 =w)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
        Nrg  r  )r  r  r}  r  parse_leverage_tiers)rb  r   r  r  rg  s        rd  fetch_leverage_tierszdigifinex.fetch_leverage_tiers  sp      !!!<<VDD< x4%%g.((wHHC 	"Ds   A/A+A/A-<A/-A/c                 H  K   | j                          d{    | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||             d{   }| j                  |di       }| j                  ||      S 7 7 +w)a  
        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>`
        NrA   z6 fetchMarketLeverageTiers() supports swap markets onlyr  rQ  rg  )r  r  r)   rQ  publicSwapGetPublicInstrumentr  r}  parse_market_leverage_tiersr~  s          rd  fetch_market_leverage_tiersz%digifinex.fetch_market_leverage_tiers  s      !!!V$f~TWW'__``VD\
 ;;DKKQW<XYY8 x4//f==I 	" Zr  c                 t   g }| j                  |di       }t        dt        |            D ]  }||   }| j                  |d      }| j	                  ||      }|j                  | j                  |d      | j                  ||d d      |d   d | j                  |d      d | j                  |d      |d	        |S )
Nopen_max_limitsr   r  rj  rA   r  	max_limitr   )tierr  rh  minNotionalmaxNotionalmaintenanceMarginRatemaxLeveragert  )	r}  r~  r  r  r4  r  r  r3  r  )rb  rt  r  tiersbracketsr  r  r7  s           rd  r  z%digifinex.parse_market_leverage_tiers  s    2 ??4):B?q#h-( 	AA;D''o>H%%h7FLLA**8VT6J"8,##//kB)-#//jA	 			 re  c                     | j                  | j                  d      }| j                  |dd      }d}t        t        |   |||      \  }}|!|dk7  rt        | j                  dz         ||gS |dk(  s|du rd}||gS )aR  
 @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
        rD  r@   FNr  z only cross margin is supportedT)r  r\  r  r_  r8   r  r/   rQ  )rb  
methodNamer  defaultValuerD  isMarginr   rc  s          rd  r  z'digifinex.handle_margin_mode_and_params%  s     &&t||]C>>&(E:
"9dQR\^dfrs
F!W$"477-N#NOO F## x'X-=$
F##re  codesc                    K   | j                          d{    | j                  |       d{   }| j                  |d      }| j                  ||      S 7 A7 *w)a  
        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>`
        Nrg  )r  r|  rh  parse_deposit_withdraw_fees)rb  r  r  r  rg  s        rd  fetch_deposit_withdraw_feesz%digifinex.fetch_deposit_withdraw_fees8  s\      !!!55f==< ~~h///e<<A 	"=s   AAAA)AAc                    i }| j                  |      }t        dt        |            D ]  }||   }| j                  |d      }| j	                  |      }|| j                  ||      s@| j                  ||      }	|	| j                  i       ||<   g ||   d<   ||   d   }
|
j                  |       | j                  |d      }| j                  |d      }||dnd d}d d d}| | j                  |      }||d||   d	   |<   |||   d
<   |||   d<    t        |j                               }t        dt        |            D ]0  }||   }| j                  |      }| j                  ||   |      ||<   2 |S )Nr   rh  rt  ro  rl  F)rw  r   )r   rs  rH  r   rs  )market_codesr~  r  r  r  in_arrayr}  deposit_withdraw_feer  r  r  keysrh  $assign_default_deposit_withdraw_fees)rb  r  r  currencyIdKeydepositWithdrawFeesr  rq  r  rz  depositWithdrawFeedepositWithdrawInfor  withdrawFeewithdrawResultdepositResultr  depositWithdrawCodesrh  s                     rd  r  z%digifinex.parse_deposit_withdraw_feesd  s   6 %'!!%(q#h-( 	IAQKE))%<J**:6D4==u#=%)__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;	I<  $$7$<$<$>?q#234 	wA'*D}}T*H(,(Q(QRefjRkmu(v%	w #"re  c                    K   | j                  |d      }| j                  d|dddg       | j                  ||d|       d{   S 7 w)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>`
        r>  rD   r  r  rj  Nr  r  modify_margin_helperrb  r  rr  r  r>  s        rd  
add_marginzdigifinex.add_margin  sP      /$$[$@QR..vvq&IIII   A A	AA	c                    K   | j                  |d      }| j                  d|dddg       | j                  ||d|       d{   S 7 w)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>`
        r>  r   r  r  rl  Nr  r  s        rd  reduce_marginzdigifinex.reduce_margin  sP      /$$^T6FGCTU..vvq&IIIIr  c                   K   | j                          d {    | j                  |d      }| j                  |      }|d   | j                  |      ||d}| j	                  | j                  ||             d {   }| j                  |d      }	|	dk(  rdnd}
| j                  |di       }| j                  | j                  ||      d	|
i      S 7 7 Xw)
Nr>  rQ  )r  rr  r{  r>  rz  r   r\  r  rg  r^  )	r  r  r  r  $privateSwapPostAccountPositionMarginr  r  r}  parse_margin_modification)rb  r  rr  r{  r  r>  r  r  r  rz  r^  rg  s               rd  r  zdigifinex.modify_margin_helper  s     !!!/V$#D\++F3	
 BB4;;wX^C_``   62!)(x4{{499$GfJ
  	1 	" as#   CCA$C;C<ACCrg  c                     | j                  |d      }| j                  |d      }|| j                  ||d d      |dk(  rdndd| j                  |d      d |d	   d d d d

S )Nr  r{  rA   rj  addreducer  rr  r  )
rt  r  r{  r   rr  r  rz  r^  r  r  )r  r  r3  r  )rb  rg  r  r7  rawTypes        rd  r  z#digifinex.parse_margin_modification  s{     ##D/:##D&1&&xvF%lE$&&tX68$
 	
re  c                 h  K   | j                          d{    i }| j                  d||      \  }}d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j	                  ||             d{   }| j                  |dg       }| j                  ||||      S 7 7 -w)a  
        fetch the history of funding payments paid and received on self account

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

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding payment
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Nend_timestamprQ  r  r   r  rg  )r  handle_until_optionr  privateSwapGetAccountFundingFeer  rh  parse_incomes)	rb  r  rd  r   r  r  r  r  rg  s	            rd  fetch_funding_historyzdigifinex.fetch_funding_history  s      !!!22?GVT[[(F'-d|GO$$GG).G%&==dkk'SY>Z[[ ~~h3!!$u==5 	" \s"   B2B.A+B2B0,B20B2c           
         | j                  |d      }| j                  |d      }| j                  |d      }|| j                  ||d d      | j                  |      || j	                  |      d | j                  |d      dS )Nr  rh  r  rA   rr  )rt  r  rz  r  r  rQ  rr  )r  r  r3  r  r6  r  )rb  incomer  r7  r  r  s         rd  parse_incomezdigifinex.parse_income$  s     ##FO<%%fj9
%%fk:	&&xvF++J7"Y/&&vx8
 	
re  r   c                 (  K   |t        | j                  dz         | j                          d{    | j                  |      }|j	                         }|dk(  rd}|d   |d}| j                  | j                  ||             d{   S 7 ]7 w)aq  
        set margin mode to 'cross' or 'isolated'

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

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentr  r  rQ  )r  r  )r(   rQ  r  r  lower"privateSwapPostAccountPositionModer  )rb  r   r  r  r  r  s         rd  set_margin_modezdigifinex.set_margin_mode:  s      >#DGG.[$[\\!!!V$%%'
 "J#D\%
 <<T[[RX=YZZZ 	" [s"   .BBAB	B
BBGETc                 *   |d   dk(  }|d   }|dk(  rdnd}	d| j                  ||      z   }
|	|
z   }| j                  d   d	   |z   }| j                  || j                  |            }d }|r |	dk(  r|d
k(  rt	        j
                  |      }n | j                  | j                  |            }|rd }d }|	dk(  r<t        | j                               }||z   |z   }|dk(  r|r/|d|z   z  }n&|d
k(  r!||z  }nt        | j                               }|}| j                  | j                  |      | j                  | j                        t        j                        }|dk(  r|r|d|z   z  }n|d
k(  rddi}|r|}| j                   ||d}n
|r|d|z   z  }||||dS )Nr   r   rj  r?   z/v3z/swap/v2r  r   r   POSTr(  ?zContent-Typez!application/x-www-form-urlencoded)z
ACCESS-KEYzACCESS-SIGNzACCESS-TIMESTAMP)ra  r  bodyheaders)implode_paramsrX  r  extract_paramsr  dumps	urlencodekeysortr  r}  noncehmacencodesecrethashlibsha256apiKey)rb  pathr   r  r  r-  r,  signedendpointpathPartr  payloadra  r  
urlencodedauthr3  	signatures                     rd  signzdigifinex.signR  s   Q9$q6%/5j++D&99W$iiv&0		&$"5"5d";<
x:-Ff4DF+JU(;<JDE:%D--/0v~/U?!j 00v%J&DDJJL)!		$++d"3T[[5Mw~~^I3++C6!"$G %D"kk($)G sZ''fdwOOre  
statusCode
statusTextra  r  responseHeadersc
                     |sy | j                  |d      }
|
dk(  s|
dk(  ry | j                  dz   |z   }|
t        |      t        |g}| j	                  | j
                  d   |
|      \  }} ||      )Nrz  rC  200 r
  )r  rQ  r4   r$   r}  r[  )rb  rC  rD  ra  r  rE  responseBodyr  requestHeadersrequestBodyrz  feedbackunknownErrorExceptionClassmessages                  rd  handle_errorszdigifinex.handle_errors  s    &1CKTU]77S=</<h''%x0"&//$//'2JDR^"_W%%re  r  )NN)u__name__
__module____qualname__r   r`  r
   r  r#   r   r  r  r  r   r  r  r  r   r   r  r   r   r  r   r  dictr  r   rV  rZ  rc  rj  r  rq  r  r   r   floatr   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!   r1  r5  r8  rG  rI  r"   rO  r   r   r   re  rn  r   rr  r	   ru  rp  rt  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   r#  r'  rB  intrP  __classcell__)rc  s   @rd  r8   r8   "   s	   z# zx -/ \: \| *, 
3V 
3 -/ Xt -/ IV%) %)N *, ?, ?,B @DB GMS GM GMS\ GMR 6:" SG7 SG SGj 68 K1 K1F K1ZH4 H H6 HT~ ~v ~ ~@ ') <S < )+ 
. <@d[] C= C=S C= C=bfglbm C=J 4 < 8<$]ajl TK TKC TKWZ TKquvzq{ TKl mqy{ 6 6I 6Y 6X] 6fi 6p FH S1$|*< S1j os{} Y,3 Y,i Y,y Y,Z_ Y,hk Y,v XZ Tc T T$ 9=R GS G# GR* 6:" 2s 2>: :B Bv B BH 59tZ^gi ^=c ^= ^=TW ^=nrsxny ^=@ 04$UYbd _= _=C _=s _=imnsit _=B 8<B Y/C Y/ Y/v 37TX\eg Z=C Z=s Z=RU Z=x3.t .x .; .` .2SW`b QAs QA# QAS QAgklwgx QAf
h 
R` 
* =?  > B BFTXgktv (U3 (Uc (Uad (UT 04$UYbd 	\ 	\C 	\s 	\imnyiz 	\ 37TX\eg 	_C 	_s 	_RU 	_lpq|l} 	_	:s 	:=
T =
X =
Q\ =
~:C :C :2
t 2
x 2
= 2
h ac 573 57 57C 57TW 57gt 57n JNVX :3 : : :]h :> 7;$]apt} Q QC QWZ Qjm Q  EI  JX  EY QB
$ 
 
. 
B ?A %8# %8_ %8N 57 ;;K ;>
 
($ <> 5s 5+ 5B @B 
=3 
=k 
=#
6 #
[ #
J? >BPTcgpr 6Os 6O# 6O]` 6Op ;= 4c 4AT 4>
T 
6 
EX 
& 8<B bPW bP4PX> bPH 8: W3 WrOt OV Ob ?C2 &W3 &W &Wf 154VZce 'G# 'GS 'GPS 'Gjno|j} 'GR =A +I' +IP] +IZ EG .> .>4P\K] .>`) )$|J\ )V @BPT $& BFb *=w *=X@#D CE Js JE JI[ J  FH J# Ju JL^ J  LN  Rd :
d 
F 
N` 
0 9=4^bkm '># '>S '>X[ '>R
6 
, DHPR [ [S [0  b$T -P^& & &3 &PS &fj &re  r8   )? ccxt.async_support.base.exchanger   ccxt.abstract.digifinexr   r  r7  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    re  rd  <module>r`     s    6 /    w  w  w  w  w  w  w  w  * 0 - - . ' & . + ) * ) ) + . ) ( 4 %jA&+ jA&re  