
    !:h                    @   d dl mZ d dlm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 d dlmZ d dlmZ d dlmZ d dlm Z  d d	lm!Z! d d
lm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dl)m*Z* d dl+m,Z,  G d dee      Z-y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntMarginModificationMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickers
OrderBooksTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)OrderNotFound)RateLimitExceeded)OnMaintenance)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdefdZdUdedede	fdZ
i fded	ede	fd
Zi fded	ede	fdZi fdefdZi fdZi fdZd Zdi fdefdZdi fdefdZdUdefdZi fdefdZi fdee   fdZdddi fdedededee   fdZdUdede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di fdedede%fd Z&dUd!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+dUd%edede,fd&Z-ddi fdedededee,   fd'Z.dddi fde/dedefd(Z0i fded)e1d*efd+Z2i fded*efd,Z3i fded*efd-Z4di fded.e5d)e1d	ed/e6f
d0Z7di fd1ede/fd2Z8di fd1ede/fd3Z9dddi fd1ede/dedefd4Z:dddi fde/dededee;   fd5Z<d6 Z=d7 Z>dUd8edede;fd9Z?dddi fde/dedefd:Z@ddi fd1eded.e5d)e1d	e6d/e6fd;ZAi fd<edeBfd=ZCd> ZDdi fd<ed	ed?edeEfd@ZFdAe/fdBZGdUdCededeEfdDZHdddi fd<e/dededeeE   fdEZIdddi fd<e/dededeeE   fdFZJdi fd1ed<e/fdGZKdi fd1ed<e/fdHZLdddi fd<e/dededeeE   fdIZMdJdKi ddfdLZNdM ZOdNePdOedPedQedRedSefdTZQ xZRS )Vexmoreturnc                 r   | 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dMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d[d\d]d\d^d_gd`dadbdcddgidbg deidfg dgidhdbdd| j	                  di      | j	                  di      djdddkdldmdndodpdqidrdidsdddd dddd dddddtddddddddud ddd d ddvdddddwdd ddddxd d dydzid{	d d d|d d d|d}d~dit
        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        it        t        t        ddd      S )Nr)   EXMOLTd   zv1.1CORSspotTmarginswapFfutureoption	addMargincancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchAccountsfetchBalancefetchCanceledOrdersfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMargin	setMargintransferwithdraw1515304560120180240DWM)1m5m15m30m45m1h2h3h4h1d1w1Mzchttps://user-images.githubusercontent.com/1294454/27766491-1b0ea956-5eda-11e7-9225-40d67b481b8d.jpgzhttps://api.exmo.comzhttps://exmo.me)publicprivatewebzhttps://exmo.me/?ref=131685z%https://exmo.me/en/api_doc?ref=131685zhttps://exmo.com/en/docs/fees)logoapiwwwreferraldocfeesgetzctrl/feesAndLimitszen/docs/fees)	currencyzcurrency/list/extended
order_bookpair_settingstickertradescandles_historyrequired_amountzpayments/providers/crypto/listpost)(	user_infoorder_createorder_cancelstop_market_order_createstop_market_order_canceluser_open_ordersuser_tradesuser_cancelled_ordersorder_tradesdeposit_addresswithdraw_cryptwithdraw_get_txidexcode_createexcode_load
code_checkwallet_historywallet_operationszmargin/user/order/createzmargin/user/order/updatezmargin/user/order/cancelzmargin/user/position/closezmargin/user/position/margin_addz"margin/user/position/margin_removezmargin/currency/listzmargin/pair/listzmargin/settingszmargin/funding/listzmargin/user/infozmargin/user/order/listzmargin/user/order/historyzmargin/user/order/tradeszmargin/user/order/max_quantityzmargin/user/position/listz'margin/user/position/margin_remove_infoz$margin/user/position/margin_add_infozmargin/user/wallet/listzmargin/user/wallet/historyzmargin/user/trade/listzmargin/tradeszmargin/liquidation/feed)r   r   r   z0.004)feeSide	tierBased
percentagemakertaker)r   r   )tradingtransactionERC20TRC20)ETHTRXmethodfetchPrivateTradingFeesfillResponseFromRequest)networksri   r1   )IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceiceberg)r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   r     )	sandboxr<   createOrdersrV   rZ   rY   fetchOrdersfetchClosedOrdersrW   )linearinverse)r0   r2   r3   GMTz	GMT Token14033314043440005400094001540016400174003240033400345005250054503045017350277503195032150381)zrange period is too longzinvalid syntaxzAPI rate limit exceeded)exactbroad)idname	countries	rateLimitversionhas
timeframesurlsr   r   optionsfeaturescommonCurrenciesprecisionMode
exceptions)deep_extendsuperr)   describeparse_numberr&   r!   r   r   r%   r   r$   r   r#   r    r"   )self	__class__s    C/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/exmo.pyr  zexmo.describe   s   dD : <EEE $E 	E
 %E %E TE tE E 'E 'E /E ,TE tE 'E  (!E" "4#E$ T%E&  'E( )E* &t+E, "4-E. /E0 &t1E2 (3E4 1%5E6  7E8 +D9E: *:;E< +D=E> &u?E@ #EAEB *5CED $UEEF "5GEH "5IEJ KEL !%MEN  OEP dQER +ESET "4UEV jWEX !$YEZ "4[E\ #D]E^  _E` 'aEb $UcEd !%eEf (gEh %eiEj )%kEl tmEn oEp tqEr "5sEt #DuEv 'wEx $ZyEz  {E| !%}E~ "4E@ #DAEB CED UEEF EGEH DIEN  ~45,
 )9; 8  ,&  
  )+)@F  %!%"&!..w7!..w7 "'"'  #"
 7% .t  %&*(,,0,1).+06:#'#'"&#'	( #(/4$)$(+/27#()$, %)&*!$$(%)*.& ',#($)*/	# ',!%#($)*/( $()-#_2h ##
 ##q<| {! 'lj 0 \	
 ] ] 0 - - . . . ] ] \  \!" \#$ \%* 1;&0/@+G^?
 ^ ^	    symbolc                    | j                          | j                  |      }|d   |d}d }|dk(  r"| j                  | j                  ||            }n&|dk(  r!| j	                  | j                  ||            }| j                  ||      }| j                  | j                  di       }	| j                  |	dd      }
|
r
||d<   ||d	<   |S )
Nr   )position_idquantityaddreducer1   r   Ttypeamount)	load_marketsmarket&privatePostMarginUserPositionMarginAddextend)privatePostMarginUserPositionMarginRemoveparse_margin_modification
safe_valuer   	safe_bool)r  r  r  r  paramsr  requestresponser1   r   r   s              r  modify_margin_helperzexmo.modify_margin_helper=  s    V$!$<
 5=BB4;;wX^C_`HXEEdkkRY[aFbcH //&A//$,,"="&..:SUY"Z"!F6N%F8r  Ndatar  c                 \    || j                  d |      d dd d | j                  |d      dd d d
S )Nisolatedquoteok)
infor  r  r   r  totalcodestatus	timestampdatetime)safe_symbolr  )r  r  r  s      r  r  zexmo.parse_margin_modificationT  sD    
 &&tV4$OOFG4
 	
r  r  c                 *    | j                  ||d|      S )a  
        remove margin from a position

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#eebf9f25-0289-4946-9482-89872c738449

        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        r  r  r  r  r  r  s       r  reduce_marginzexmo.reduce_margine  s     ((6JJr  c                 *    | j                  ||d|      S )a  
        add margin

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#143ef808-79ca-4e49-9e79-a60ea4d8c0e3

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        r  r(  r)  s       r  
add_marginzexmo.add_marginr  s     ((GGr  c                     | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j                  |d      }|dk(  r| j	                  |      S | j                  |      S )a  
        fetch the trading fees for multiple markets

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#90927062-256c-4b03-900f-2b99131f9a54
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#7de7e75c-5833-45a8-b937-c2276d235aaa

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        ri   r   r   )r  r   safe_stringomitfetch_private_trading_feesfetch_public_trading_fees)r  r  r   defaultMethodr   s        r  fetch_trading_feeszexmo.fetch_trading_fees  s     //$,,0BBG(((<UV!!&(MB68,..226::11&99r  c                    | j                          | j                  |      }| j                  |dg       }i }t        dt	        |            D ]  }||   }| j                  |d      }| j                  |d d      }| j                  |d      }	| j                  |d      }
| j                  t        j                  |	d            }| j                  t        j                  |
d            }||||ddd	||<    |S )
Npairsr   r   _trade_maker_feetrade_taker_fee100Tr   r  r   r   r   r   )
r  privatePostMarginPairListr  rangelenr.  r&  r  r'   
string_div)r  r  r  r5  resultipairmarketIdr  makerStringtakerStringr   r   s                r  r0  zexmo.fetch_private_trading_fees  s   11&9< '26q#e*% 	A8D''f5H%%hc:F**41BCK**41BCK%%g&8&8e&LME%%g&8&8e&LME "!F6N	  r  c                    | j                          | j                  |      }i }t        dt        | j                              D ]  }| j                  |   }| j                  |      }| j                  ||d   i       }| j                  |d      }| j                  |d      }	| j                  t        j                  |d            }
| j                  t        j                  |	d            }|||
|ddd||<    |S )Nr   r   commission_maker_percentcommission_taker_percentr9  Tr:  )r  publicGetPairSettingsr<  r=  symbolsr  r  r.  r  r'   r>  )r  r  r  r?  r@  r  r  feerC  rD  r   r   s               r  r1  zexmo.fetch_public_trading_fees  s    --f5  q#dll+, 	A\\!_F[[(F//(F4L"=C**30JKK**30JKK%%g&8&8e&LME%%g&8&8e&LME "!F6N	  r  c                     ||dk(  ry |dk(  ry|j                  d      dk\  }|j                  d      }|d   j                  dd      }t        |      }|dkD  r|rt	        | j
                  dz   |z         |S )N- r   % zN parseFixedFloatValue() detected an unsupported non-zero percentage-based fee )findsplitreplacefloatr   r   )r  inputisPercentagepartsvaluer?  s         r  parse_fixed_float_valuezexmo.parse_fixed_float_value  s    Mu|B;

31,C a  b)uQJL*z z  ~C  !C  D  Dr  codesc                 H   | j                          | j                  |      }i }t        |j                               }t	        dt        |            D ]  }||   }|| j                  ||      sddd||<   | j                  |      }| j                  |d      }	| j                  ||	g       }
t	        dt        |
            D ]D  }|
|   }| j                  |d      }| j                  |d      }| j                  |      }|||   |<   F |
||   d<    || j                  d<   |S )	a  
 @deprecated
        please use fetchDepositWithdrawFees instead

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#4190035d-24b1-453d-833b-37e0a52f88e2

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction fees structures <https://docs.ccxt.com/#/?id=fees-structure>`
        r   Ndepositrs   r   r  commission_descr   transactionFees)r  $publicGetPaymentsProvidersCryptoListlistkeysr<  r=  in_arrayr   r.  r  rX  r   )r  rY  r  
cryptoListr?  cryptoListKeysr@  r"  r   
currencyId	providersjprovider	typeInnercommissionDescrJ  s                   r  fetch_transaction_feeszexmo.fetch_transaction_fees  sE    	>>vF
F joo/0q#n-. 	-A!!$D tU)C F4L }}T*H))(D9J
JCI1c)n- .$Q< ,,Xv>	!%!1!1(<M!N22>B*-tY'. $-F4L #	-& +1&'r  c                     | j                          | j                  |      }| j                  ||      }|| j                  d<   |S )a  
        fetch deposit and withdraw fees

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#4190035d-24b1-453d-833b-37e0a52f88e2

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction fees structures <https://docs.ccxt.com/#/?id=fees-structure>`
        r^  )r  r_  parse_deposit_withdraw_feesr   )r  rY  r  r  r?  s        r  fetch_deposit_withdraw_feesz exmo.fetch_deposit_withdraw_fees?  sH     	<<VD( 11(EB*0&'r  r   c                 ,   | j                  |      }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j	                  || j                  |d            }| j                  |d      }	g }
d }|	!|	j                  d      }
t        |
      }|dk\  }| j                  |d   |      }|d d d	d d d	d
|d   |<   | j                  | j                  |
d            |d	|d   |   |<    | j                  |      S )Nr   r  r   r"  r]  rN     r   )rJ  r   )rs   r\  )	deposit_withdraw_feer<  r=  r.  network_id_to_coderQ  r  rX  $assign_default_deposit_withdraw_fees)r  rJ  r   r?  r@  rh  r  	networkIdnetworkCoderj  splitCommissionDescr   splitCommissionDescLengthnetworks                 r  parse_deposit_withdraw_feezexmo.parse_deposit_withdraw_feec  sV   " **3/q#c(# 	A1vH##Hf5D((6:I11)T=M=MhX^=_`K!--h8IJN"$J)&4&:&:3&?#,/0C,D)6!;
oofZ&8+FG  $&*!
  $&* 	3z";/ 33D4D4DEXZ[4\](5F:{+D11	8 88@@r  c                    | j                  |      }| j                  |      }i }t        dt        |            D ]  }||   }| j	                  |d      }| j	                  |d      }| j                  ||      }	d}
d}ddddddd}d}d}d}|	d	}
d
}nt        dt        |	            D ]  }|	|   }| j	                  |d      }| j	                  |d      }| j	                  |d      }t        j                  |d      rd}| j                  |d      }|dk(  r|r|sd	}n|sd}n|dk(  r|r|sd	}n|sd}|sd	}
| j                  ||   d         }||   d   t        j                  ||      s|||   d<   |||   d<   |dk(  s| j	                  |d      }| j                  |      } | j                  |      }|||||
|||| j                  d      ||	i d||<    |S )a  
        fetches all available currencies on an exchange

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#7cdf0ca8-9ff6-4cf3-aa33-bcec83155c49
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#4190035d-24b1-453d-833b-37e0a52f88e2

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   r   descriptionFcryptoNminmaxr[  Tfiatr  r~  r  z0.0enabledr\  rs   r]  1e-8)r   r"  r   r  activer\  rs   rJ  	precisionlimitsr   r   )publicGetCurrencyListExtendedr_  r<  r=  r.  r  r'   	string_eqnumber_to_string	string_ltrX  safe_currency_coder  )r  r  currencyListrc  r?  r@  r   re  r   rf  r  r  r  rJ  depositEnabledwithdrawEnabledrg  rh  ri  minValuemaxValueactiveProviderlimitMinrj  r"  s                            r  fetch_currencieszexmo.fetch_currencies  sh    99&A >>vF
2 q#l+, A	A#AH))(F;J##Hm<D
J?IFD  
  	F C!N"O q#i.1 SA(|H $ 0 06 BI#//%@H#//%@H((59#'%)__Xy%IN I-).-1N!/-2N"j0)/.2O!/.3O%!%#'#8#8	9J59Q#R"9-e4<'BSBST\^fBg7?F9-e47?F9-e4(J6151A1A(L]1^&*&B&B>&R5S6 **:6D  )+!..v6 !F4LiA	D r  c                 \   | j                  |      }i }| j                  d      r5| j                  |      }| j                  |d      }| j	                  |d      }t        |j                               }g }t        dt        |            D ]  }||   }	||	   }
| j                  ||	      }|	j                  dd      }|j                  d      \  }}| j                  |      }| j                  |      }| j                  |
d      }| j                  |
d      }| j                  |
d	      }| j                  |d
      }|j                  i d|	d|d|d|ddd|d|ddddddd|duddddddddddddd| j                  t        j                   |d            | j                  t        j                   |d            ddddd| j                  d      | j                  | j#                  | j                  |
d                   d!d| j%                  |
d"      d#| j%                  |
d$      | j                  t        j&                  ||            d#| j%                  |
d%      | j%                  |
d&      d#| j%                  |
d'      | j%                  |
d(      d#d)d|
d*       ! |S )+a;  
        retrieves data on all markets for exmo

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#7de7e75c-5833-45a8-b937-c2276d235aaa

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Fr5  r   r   r6  /rG  rF  max_quantitymax_order_quantityr   r  baser  settleNbaseIdquoteIdsettleIdr  r0   Tr1   r2   r3   r4   r  contractr   r9  r  price_precision)r  pricer   r}  min_quantity	min_price	max_price
min_amount
max_amount)r   r  r  cost)r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr   )rH  check_required_credentialsr;  r  index_byr`  ra  r<  r=  rR  rQ  r  r.  appendr  r'   r>  parse_precisionsafe_number
string_max)r  r  r  marginPairsDictmarginPairsr5  ra  r?  r@  r   r  marginMarketr  r  r  r  r  rD  rC  maxQuantitymarginMaxQuantitys                        r  fetch_marketszexmo.fetch_markets  sS    --f5  !#**5188@K< OOK9E"mmE6:OHMMO$q#d)$ >	AaBb\F???B?LZZS)F$ll3/OFG**62D++G4E**63MNK**63MNK**6>BK $ 0 0?S TMM 2b2&2 2 	2
 $2 &2 72 D2 2 2 ,d22 2 %2 %2 $2  E!2" $#2$  **7+=+=k5+QR**7+=+=k5+QR $"&""//7!..t/C/CDDTDTU[]nDo/pq  $#//
C!
  $//G#001C1CKQb1cd
  $//D#//D
  $//E#//E$  c2 2>	~ r  r   sincer   c                    | j                          | j                  |      }| j                  |dd      }|du}|d   | j                  | j                  ||      d}	d}
| j                  |      }| j                  | j                         dz        }|5|rt        ||      n|}|d}nt        ||
      }|||z  z
  dz
  |	d	<   ||	d
<   na| j                  |dz        dz
  |	d	<   |rt        ||      |	d
<   n5||
}nt        ||
      }| j                  |||z        }t        ||      |	d
<   | j                  |d      }| j                  | j                  |	|            }| j                  |dg       }| j                  |||||      S )a
  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#65eeb949-74e5-4631-9184-c38387fe53e8

        :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
        untilgMbP?Nr   )r  
resolutioni  r      fromtocandles)r  r  safe_integer_productr.  r   parse_timeframeparse_to_intmillisecondsr~  sumr/  publicGetCandlesHistoryr  	safe_listparse_ohlcvs)r  r  	timeframer  r   r  r  r  untilIsDefinedr  maxLimitdurationnowr  r  r  s                   r  fetch_ohlcvzexmo.fetch_ohlcv  s    	V$))&'5At+Tl**4??IyQ
 ''	2 1 1 3d :;=$2UCB}E8, EH$459GFOGDM"//=AGFO #E3=$Ex0EXXeUX%56 #B67+//GV0LM ..9b9  &)UEJJr  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Ntohlcv)safe_integerr  )r  ohlcvr  s      r  parse_ohlcvzexmo.parse_ohlcv  sn     eS)UC(UC(UC(UC(UC(
 	
r  c                    d|i}| j                  |d      }|t        |j                               }t        dt	        |            D ]q  }||   }||   }| j                  |      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   | j                  |d      |	d<   |	||<   s n| j                  |di       }
| j                  |d	i       }t        |
j                               }t        dt	        |            D ]_  }||   }| j                  |      }| j                         }	||
v r| j                  |
|      |	d<   ||v r| j                  ||      |	d<   |	||<   a | j                  |      S )
Nr   walletsr   usedfreebalancer!  balancesreserved)	r  r`  ra  r<  r=  r  accountr.  safe_balance)r  r  r?  r  currencyIdsr@  re  itemr   r  r  r  r"  s                r  parse_balancezexmo.parse_balance  s   )//(I6w||~.K1c+./ +(^
z*22:>,,."&"2"24"@"&"2"24"@#'#3#3D)#D #*x + ??8Z<D??8Z<Dtyy{+K1c+./ '(^
..z:,,.%&*&6&6tZ&HGFO%&*&6&6tZ&HGFO&t'   ((r  c                     | j                          d}| j                  d|      \  }}|dk(  rt        | j                  dz         d}|dk(  r| j	                  |      }n| j                  |      }| j                  |      S )aF  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#59c5160f-27a1-4d9a-8cfb-7979c7ffaac6
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#c8388df7-1f9f-4d41-81c4-5a387d171dc6

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: *isolated* fetches the isolated margin balance
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrB   crossz does not support cross marginr  )r  handle_margin_mode_and_paramsr   r   privatePostMarginUserWalletListprivatePostUserInfor  )r  r  r   r  s       r  fetch_balancezexmo.fetch_balance  s     	
!??PVW
F TWW'GGHH#;;FCH //7H !!(++r  c                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||d         }| j                  ||d   ddd      S )a[  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#c60c51a8-e683-4f45-a000-820723d37871

        :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
        rA  r   Nr   r  bidask)r  r  publicGetOrderBookr  	safe_dictparse_order_book)r  r  r   r  r  r  r  r?  s           r  fetch_order_bookzexmo.fetch_order_book  s     	V$F4L
 $GG**4;;w+GH&,7$$VVH-=tUERRr  rI  c                 `   | j                          d}|edj                  | j                        }t        |      dkD  r^t        | j                        }t	        | j
                  dz   t        |      z   dz         | j                  |      }dj                  |      }d|i}|||d<   | j                  | j                  ||            }i }t        |j                               }	t        dt        |	            D ]3  }
|	|
   }| j                  |      }| j                  ||   |dd	d
      ||<   5 |S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data for multiple markets

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#c60c51a8-e683-4f45-a000-820723d37871

        :param str[]|None symbols: list of unified market symbols, all symbols fetched if None, default is None
        :param int [limit]: max number of entries per orderbook to return, default is None
        :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 symbol
        N,i   z fetchOrderBooks() has zy symbols exceeding max URL length, you are required to specify a list of symbols in the first argument to fetchOrderBooksrA  r   r   r  r  )r  joinidsr=  r   r   str
market_idsr  r  r`  ra  r<  r&  r  )r  rI  r   r  r  numIdsr  r  r?  	marketIdsr@  rB  r  s                r  fetch_order_bookszexmo.fetch_order_books2  s=    	?((488$C3x$TXX#DGG.G$G#f+$U  YT  %T  U  U//'*C((3-CC
 $GG**4;;w+GH)	q#i.) 	cA |H%%h/F!228H3EvtUZ\abF6N	c r  r   c                    | j                  |d      }| j                  d |      }| j                  |d      }| j                  i d|d   d|d| j	                  |      d| j                  |d      d| j                  |d      d| j                  |d	      d
d d| j                  |d      dd dd dd d|d|dd dd dd d| j                  |d      | j                  |d      | j                  |d      |d|      S )Nupdated
last_trader  r$  r%  highlowr  	buy_price	bidVolumer  
sell_price	askVolumevwapopencloselastpreviousClosechanger   averageavgvolvol_curr)
baseVolumequoteVolumer   )safe_timestampsafe_marketr.  safe_tickeriso8601)r  r   r  r$  r  s        r  parse_tickerzexmo.parse_tickerV  s    ''	:	!!$/5 !
fX&!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FK8!
 !
 4##FL9!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t''6#!
$ **659++FJ?)!
* + 	r  c                 ~   | j                          | j                  |      }| j                  |      }i }t        |j	                               }t        dt        |            D ]F  }||   }| j                  |dd      }|d   }	| j                  ||      }
| j                  |
|      ||	<   H | j                  |d|      S )a9  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#4c8e6459-3503-4361-b012-c34bb9f7e385

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   Nr6  r  )r  market_symbolspublicGetTickerr`  ra  r<  r=  r  r  r  filter_by_array_tickers)r  rI  r  r  r?  r  r@  rB  r  r  r   s              r  fetch_tickerszexmo.fetch_tickers~  s     	%%g.''/  )	q#i.) 	?A |H%%hc:FH%F__Xx8F!..vv>F6N	? ++FHgFFr  c                     | j                          | j                  |      }| j                  |      }| j                  ||d      |      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#4c8e6459-3503-4361-b012-c34bb9f7e385

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   )r  r  r  r  )r  r  r  r  r  s        r  fetch_tickerzexmo.fetch_ticker  sJ     	''/V$  &,!7@@r  tradec                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }	d }
| j                  |d	      }| j                  ||d
      }|d   }| j	                  |d      }d }||rdnd}| j                  |d|      }d }| j                  |d      }|T| j                  |d      }| j                  |      }| j                  |d      }|t        j                  |dd      }|||d}| j                  |||| j                  |      |||
|	|||||d|      S )Ndatetrade_idorder_idr  r
  r  r  
trade_typerA  r6  r  is_makerr   r   	exec_typecommission_amountcommission_currencycommission_percent1000   )r  r   rate)r   r   r$  r%  r  orderr  sidetakerOrMakerr  r  r  rJ  )
r  r.  safe_string_2r  r  r  r'   r>  
safe_trader  )r  r  r  r$  r   orderIdpriceStringamountString
costStringr)  r  rB  r  isMakertakerOrMakerDefaultr*  rJ  feeCostStringfeeCurrencyIdfeeCurrencyCodefeeRateStrings                        r  parse_tradezexmo.parse_trade  s   T ''v6	eZ0""5*5&&ug6''z:%%eX6
!!%>##E62!!(FC8!//%4"-4''''{<OP((0CD$ ,,U4IJM"55mDO ,,U4HIM( ' 2 2=&" M%+%C
 "Y/( " 
  	r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||d   g       }| j                  ||||      S )aE  
        get the list of most recent trades for a particular symbol

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#5a5a9c0d-cf17-47f6-9d62-6d4404ebd5ac

        :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>`
        rA  r   )r  r  publicGetTradesr  r  parse_trades)	r  r  r  r   r  r  r  r  r  s	            r  fetch_tradeszexmo.fetch_trades
  sz     	V$F4L
 ''GV(DE. ~~htb9  vue<<r  c                     |t        | j                  dz         d}| j                  d|      \  }}|dk(  rt        | j                  dz         | j	                          | j                  |      }|d   }|dk7  }|d}i }	|r||	d	<   n||	d
<   |||	d<   | j                  |dd      }
|
|	d<   d}|r"| j                  | j                  |	|            }n3| j                  | j                  |	|            }| j                  |d      }g }t        |j                               }t        dt        |            D ]E  }||   }| j                  |dd      }||   }| j!                  ||||      }| j#                  ||      }G | j%                  |||      S )aG  
        fetch all trades made by the user

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#b8d8d9af-4f46-46a1-939b-ad261d79f452  # spot
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#f4b1aaf8-399f-403b-ab5e-4926d967a106  # margin

        :param str symbol: a symbol is required but it can be a single string, or a non-empty array
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: *required for margin orders* the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint

 EXCHANGE SPECIFIC PARAMETERS
        :param int [params.offset]: last deal offset, default = 0
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nz+ fetchMyTrades() requires a symbol argumentrV   r  z" only isolated margin is supportedr   r  r.   rA  	pair_namer   offsetr   r   r6  )r   r   r  r   r  r  r  privatePostUserTradesr  privatePostMarginTradesr  r`  ra  r<  r=  r  r:  array_concatfilter_by_since_limit)r  r  r  r   r  r   r  rA  isSpotr  r>  r  responseFromExchanger?  marketIdsInnerr@  rB  resultMarketitemsr   s                       r  fetch_my_tradeszexmo.fetch_my_trades5  s     >#DGG.[$[\\
!??QWX
F TWW'KKLLV$d|z)=E"GFO#'GK $GG""68Q7"11$++gv2NOH2 $(#?#?GU[@\#] & ';XFHhmmo.q#n-. 	7A%a(H++HdC@LX&E&&ulE5IF&&vv6F	7 ))&%??r  r)  r  c                 v    | j                          | j                  |d|i      }| j                  |d||d|      S )a1  
        create a market order by providing the symbol, side and cost

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#80daa469-ec59-4d0a-b229-6a311d8dd1cd

        :param str symbol: unified symbol of the market to create an order in
        :param str side: 'buy' or 'sell'
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  Nr  r  create_order)r  r  r)  r  r  s        r  create_market_order_with_costz"exmo.create_market_order_with_cost  s?     	Vfd^4  4tVLLr  c                 v    | j                          | j                  |d|i      }| j                  |dd|d|      S )a  
        create a market buy order by providing the symbol and cost

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#80daa469-ec59-4d0a-b229-6a311d8dd1cd

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  buyNrJ  r  r  r  r  s       r  !create_market_buy_order_with_costz&exmo.create_market_buy_order_with_cost  s?     	Vfd^4  5$fMMr  c                 v    | j                          | j                  |d|i      }| j                  |dd|d|      S )a  
        create a market sell order by providing the symbol and cost

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#80daa469-ec59-4d0a-b229-6a311d8dd1cd

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  sellNrJ  rO  s       r  "create_market_sell_order_with_costz'exmo.create_market_sell_order_with_cost  s?     	Vfd^4  64vNNr  r  r  c                    | j                          | j                  |      }|dk(  xr |du }d}	| j                  d|      \  }	}|	dk(  rt        | j                  dz         |	dk7  }
| j                  |g d      }| j                  |d      }d	|d
   i}|| j                  |d   |      |d<   n| j                  |d   |      |d<   | j                  |dd      }|2| j                  |dd      }|t        | j                  dz         ||d<   | j                  |d      }|
s|t        | j                  dz         | j                  |g d      }|| j                  |d   |      |d<   d}|
r|Z|dk(  rt        | j                  dz         ||d<   | j                  ||      |d<   | j                  | j!                  ||            }n%| j                  |d      }d}| j#                  |dk(  |dk(  |      \  }}| j                  |d      }|rdn| j                  |d   |      |d<   |dk(  r||d<   n|dk(  r|dnd}d|z   |z   |d<   |rd|d<   n|||d<   | j%                  | j!                  ||            }nu|7| j                  ||      |d<   |dk(  r	d |z   |d<   n/|dk(  r	d!|z   |d<   n!||d<   n|dk(  s|dk(  r|d"z   |z   |d<   n||d<   | j'                  | j!                  ||            }| j)                  ||      S )#a/  
        create a trade order

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#80daa469-ec59-4d0a-b229-6a311d8dd1cd
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#de6f4321-eeac-468c-87f7-c4ad7062e265  # stop market
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#3561b86c-9ff1-436e-8e68-ac926b7eb523  # margin

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at
        :param str [params.timeInForce]: *spot only* 'fok', 'ioc' or 'post_only'
        :param boolean [params.postOnly]: *spot only* True for post only orders
        :param float [params.cost]: *spot only* *market orders only* the cost of the order in the quote currency for market orders
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  Nr<   r   only supports isolated marginr  r   	stopPrice
stop_pricer  rA  r   r  r
  	client_idclientOrderIdzC createOrder() client order id must be an integer / numeric literalr   zI createOrder requires an extra param params["leverage"] for margin orders)rW  rX  r   r   rY  rZ  r  r  r   zI createOrder() cannot create stop limit orders for spot, only stop marketr  trigger_pricer!  	post_onlyr   r   _totalrM  market_rX  stop_limit_stop_r6  )r  r  r  r   r   safe_string_nr.  amount_to_precisioncost_to_precisionsafe_value_2safe_integer_2r  r   r/  price_to_precision privatePostStopMarketOrderCreater  handle_post_onlyprivatePostOrderCreate privatePostMarginUserOrderCreateparse_order)r  r  r  r)  r  r  r  r  isMarketr   rC  r   r  r  rZ  r   r  execType
isPostOnlyr   marketSuffixs                        r  rK  zexmo.create_order  s   ( 	V$H$95D=
!??vV
F TWW'GGHH
*))&2]^/F4L
 <"&":":6(;KV"TGJ"&"8"89I4"PGJ))&+O$ //_UM$ +p!pqq'4$##FJ78+#DGG.y$yzz6  $D  E#66vh7GOGG'7?$TWW/z%z{{&*GFO/3/F/Fv|/\GO,@@WV\A]^++FK@!
%)%:%:48;KXYdMdfl%m"
F"..v}E(01d6M6MfU]N^`e6f 7?&*GFOX%040@8rL&/$&6&EGFO+6GK( ,+6GK(66t{{7F7ST'(,(?(?(U%7?&3d&:GFOX%&-nGFO&*GFO7?dh&6&*Sj4&7GFO&*GFO<<T[[RX=YZH&11r  r   c                    | j                          i }| j                  |dd      }| j                  |ddg      }d}| j                  d|      \  }}|dk(  rt	        | j
                  dz         d}|dk(  r'||d<   | j                  | j                  ||            }nO|r'||d	<   | j                  | j                  ||            }n&||d<   | j                  | j                  ||            }| j                  |      S )
a#  
        cancels an open order

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#1f710d4b-75bc-4b65-ad68-006f863a3f26
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#a4d0aae8-28f7-41ac-94fd-c4030130453d  # stop market
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#705dfec5-2b35-4667-862b-faf54eca6209  # margin

        :param str id: order id
        :param str symbol: not used by exmo cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True to cancel a trigger order
        :param str [params.marginMode]: set to 'cross' or 'isolated' to cancel a margin order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   stopNr6   r  rU  r  r  parent_order_id)r  rd  r/  r  r   r    privatePostMarginUserOrderCancelr   privatePostStopMarketOrderCancelprivatePostOrderCancelrk  )r  r   r  r  r  r   r   r  s           r  cancel_orderzexmo.cancel_order&  s    	##FIv>6Iv#67
!??vV
F TWW'GGHH*$"$GJ<<T[[RX=YZH
 -/)*@@WV\A]^
 ')
#66t{{7F7ST ))r  c                     | j                          dt        |      i}| j                  | j                  ||            }| j	                  |      }t        |      |d<   |S )a  
        *spot only* fetches information on an order made by the user

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#cf27781e-28e5-4b39-a52d-3110f5d22459  # spot

        :param str id: order id
        :param str symbol: not used by exmo fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r   )r  r  privatePostOrderTradesr  rk  )r  r   r  r  r  r  r(  s          r  fetch_orderzexmo.fetch_orderV  sa     	B
 ..t{{7F/KL,   *"gdr  c                    d}| j                  d|      \  }}|dk(  rt        | j                  dz         d}|| j                  |      }dt	        |      i}d}	|dk(  r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j                  |	d      }
| j                  |
|||      S )a  
        fetch all the trades made from a single order

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#cf27781e-28e5-4b39-a52d-3110f5d22459  # spot
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#00810661-9119-46c5-aec5-55abe9cb42c7  # margin

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: set to "isolated" to fetch trades for a margin order
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr]   r  rU  r  r  r   )
r  r   r   r  r   privatePostMarginUserOrderTradesr  rx  r  r:  )r  r   r  r  r   r  r   r  r  r  r   s              r  fetch_order_tradeszexmo.fetch_order_trades  s     
!??@RTZ[
F TWW'GGHH[[(FB
 #<<T[[RX=YZH$ 224;;w3OPH4 (3  >>r  c                 x   | j                          d}|| j                  |      }|d   }d}| j                  d|      \  }}|dk(  xs |dk(  }d}g }	|rN| j                  |      }| j	                  |ddi      }| j                  |d      }
| j                  |
||||      }	|	S | j                  |      }t        |j                               }t        d	t        |            D ]V  }||   }| j                  |      }| j	                  |ddi      }| j                  ||   ||||      }| j                  |	|      }	X |	S )
a   
        fetch all unfilled currently open orders

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#0e135370-daa4-4689-8acd-b6876dee9ba1  # spot open orders
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#a7cfd4f0-476e-4675-b33f-22a46902f245  # margin

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: set to "isolated" for margin orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  rY   r  r  r#  r  ordersr   )r  r  r  privatePostMarginUserOrderListr  r  parse_ordersprivatePostUserOpenOrdersr`  ra  r<  r=  r  rA  )r  r  r  r   r  r  r   isMarginr  r~  responseOrdersr  r@  rB  marketInnerparsedOrderss                   r  fetch_open_orderszexmo.fetch_open_orders  s}    	[[(FH%F
!??@QSYZ
F7*I
j0H::6BH8 [[&* F "__Xx@N&&~vueVTF: 7 55f=H$ X]]_-I1c)n- A$Q<"..x8Vf.   $00(1C[RWY^`fg**6<@A r  c                 b    |y ddi}|j                  d      dk\  rd}| j                  |||      S )Ncancel_startedcanceledcancelr   )rP  r.  r  r#  statusess      r  parse_statuszexmo.parse_status!  sC    >j
 ;;x A%F&&99r  c                 J    ddddddddddddddd}| j                  |||      S )NrN  rR  )	limit_buy
limit_sell
market_buymarket_sellstop_buy	stop_sellstop_limit_buystop_limit_selltrailing_stop_buytrailing_stop_sellstop_market_sellstop_market_buyrN  rR  r.  )r  	orderTyper)  s      r  
parse_sidezexmo.parse_side+  sJ     !#%!&"( &$
  i;;r  r(  c           
         | j                  |dd      }| j                  |ddd      }| j                  |d|      }| j                  |dd      }| j                  |      }d }d|v r|d   }n*d	|v r&d
|v r"|dk(  r|d	   dz   |d
   z   }n|d
   dz   |d	   z   }| j	                  ||      }|d   }	| j                  |d      }
|
|dk(  rdnd}| j                  ||      }
| j                  |d      }| j                  |d      }| j                  |dg       }| j                  |d      }| j                  |d      }|dk(  rd }d }|dk7  r|dk7  r|}| j                  i d|d|d| j                  |      d|d| j                  |dd      d| j                  | j                  |d            d|	d|d d d!d d"|d|d#|d$|d|
d%d d&d d |d |d'|      S )(Nr  rr  
event_timer  gư>r  
order_typerA  in_currencyout_currencyrN  r6  r  r
  	in_amount
out_amountr  r  r   rY  rX  0rR  r   rZ  r%  r$  lastTradeTimestampr  r#  order_statusr   postOnlyr)  r   r  filled	remaining)r  r   rJ  r   )r+  safe_integer_product_2r  r  r  r.  r  r  
safe_orderr  r  r  )r  r(  r  r   	eventTimer$  r  r)  rB  r  r  amountFieldr  r  transactionsrZ  r   r  s                     r  rk  zexmo.parse_order>  s   ` z3DE//|YPXY	''y)D	&&uflC	y)U?V}Hu$>U+Bu} /#5n8MM 036}9MM!!(F3!!!%4>*.%-+lK%%e[9F  0x0uh;))%=''|<3LY&%8D  
" 
] 
 Y/ 
 	 

 !$";";E9h"W 
 d''(8(8(OP 
 f 
 D 
 4 
  
 D 
 U 
 L 
 D 
 f 
  d! 
" # 
$ "+ 
, - 	r  c                    | j                          d}| j                  d|      \  }}|dk(  rt        | j                  dz         |d}|dk7  }|| j	                  |      }|d   }d|i}||nd	|d
<   ||d<   d}	|| j	                  |      }	d}
|rJ| j                  | j                  ||            }
| j                  |ddi      }| j                  |
|	|||      S | j                  | j                  ||            }| j                  |d      }| j                  ||	|||      }g }t        d	t        |            D ]!  }||   }|d   dk(  s|j                  |       # |S )a7  
        fetches information on multiple canceled orders made by the user

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#1d2524dd-ae6d-403a-a067-77b50d13fbe5  # margin
        https://documenter.getpostman.com/view/10287440/SzYXWKPi#a51be1d0-af5f-44e4-99d7-f7b04c6067d0  # spot canceled orders

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: set to "isolated" for margin orders
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  rU  r.   r  r  r   r   r>  r#  r  rG  )r  r  r   r   r  privatePostUserCancelledOrdersr  r  !privatePostMarginUserOrderHistoryr  r<  r=  r  )r  r  r  r   r  r   rC  r  r  r  r  responseSwaprG  r~  r?  r@  r(  s                    r  fetch_canceled_orderszexmo.fetch_canceled_orders  s    	
!??vV
F TWW'GGHH=E
*++f-K *FU
 ',&7Ea [[(F::4;;wPV;WXH [[** F $$XvueVLLAA$++gW]B^_L2 OOL':E&&ufeUFKFF1c&k* )q	?j0MM%() Mr  c                    | j                          | j                  |      }d}	| j                  d|      \  }	}|	dk7  rt        | j                  dz         | j                  |g d      }
| j                  |ddg      }d|i}|||d	<   || j                  |d
   |      |d<   |
| j                  |d
   |
      |d<   | j                  | j                  ||            }| j                  |      S )a  
        *margin only* edit a trade order

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#f27ee040-c75f-4b59-b608-d05bd45b7899  # margin

        :param str id: order id
        :param str symbol: unified CCXT market symbol
        :param str type: not used by exmo editOrder
        :param str side: not used by exmo editOrder
        :param float [amount]: how much of the currency you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: stop price for stop-market and stop-limit orders
        :param str params['marginMode']: must be set to isolated

 EXCHANGE SPECIFIC PARAMETERS
        :param int [params.distance]: distance for trailing stop orders
        :param int [params.expire]: expiration timestamp in UTC timezone for the order. order will not be expired if expire is 0
        :param str [params.comment]: optional comment for order. up to 50 latin symbols, whitespaces, underscores
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr@   r  z8 editOrder() can only be used for isolated margin ordersrV  r   rW  r  r
  r  r  rX  )r  r  r  r   r   safe_number_nr/  rf   privatePostMarginUserOrderUpdater  rk  )r  r   r  r  r)  r  r  r  r  r   r   r  r  s                r  
edit_orderzexmo.edit_order  s   , 	V$
!??VT
F#TWW'aabb))&2]^6NK#@A
 "(GJ#66vh7GOGG#$($;$;F8<Ll$[GL!88Wf9UV))r  r"  c                     | j                          | j                  |      }| j                  ||      }d}d}|r+|j                  d      }|d   }t	        |      }|dkD  r|d   }| j                  |       ||d||dS )a  
        fetch the deposit address for a currency associated with self account

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#c8f9ced9-7ab6-4383-a6a4-bc54469ba60e

        :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>`
        Nr  r   r  )r   r   rx  addresstag)r  privatePostDepositAddressr.  rQ  r=  check_address)	r  r"  r  r  depositAddressr  r  addressAndTagnumPartss	            r  fetch_deposit_addresszexmo.fetch_deposit_addressF  s     	11&9 ))(D9*005M#A&G=)H!|#A&7#
 	
r  c                     | j                  |d      }t        |j                               }t        |      }|dk(  r| j                  |d      S y )NrA  r  r   )r  r`  ra  r=  markets)r  r   tradesBySymbolrI  
numSymbolss        r  get_market_from_tradeszexmo.get_market_from_tradesj  sK    vv6~**,-\
?<<
++r  r  c                    | j                  ||      \  }}| j                          | j                  |      }||d   |d}|||d<   | j                  | j                  di       }| j                  |d      }	| j                  ||	|	      }	|	|	|d<   | j                  |d      }| j                  | j                  ||            }
| j                  |
|      S )a  
        make a withdrawal

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#3ab9c34d-ad58-4f87-9c57-2e2ea88a8325

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r   )r  r   r  invoicer   rx  	transport)handle_withdraw_tag_and_paramsr  r   r  r   safe_string_upperr.  r/  privatePostWithdrawCryptr  parse_transaction)r  r"  r  r  r  r  r   r  r   rx  r  s              r  rs   zexmo.withdrawr  s     99#vFV==& 

 ?!$GI??4<<R@((;""8Wg>#*GK YYvy1F00Wf1MN%%h99r  r#  c                 8    dddddd}| j                  |||      S )Nr  pending)transferredpaidr  
processing	verifyingr  r  s      r  parse_transaction_statuszexmo.parse_transaction_status  s/     #"
 &&99r  r   c                    | j                  |dd      }| j                  |d      }|t        j                  |      }| j                  |d      }|,| j	                  |di       }| j                  |d      }|dk7  r|}| j                  |d      }| j                  |dd	      }	| j                  |	|      }
d }d }| j                  |d
      }|dk(  r|}nN|dk(  rI|}|E|j                  d      }t        |      }|dk(  r$| j                  |d      }|j                  dd      }d d d d}| j                  d   d   s|dk(  rdnd}| j                  |d      }|B| j	                  | j                  di       }| j	                  ||
i       }| j                  ||      }| j                  |d      }|dk(  rd}|4|dk(  rt        j                  ||      }| j                  |      |d<   |
|d	<   i d|d| j                  |dd      d|d|d	|
d| j                  |d      d| j                  |      d | j                  | j                  |d             d!|d"| j!                  |      d#|d$d d%|d&d d'd d(d d)| j#                  |d)      |d |d*S )+Ndtr  r  txidextrarM  r  currr   r  r\  
withdrawal:rp  r  rO  )r   r  r'  r   r   rs   
commissionr^  rh  cashbackr  r  r   r   r  task_idrx  r#  r$  r%  r  addressFrom	addressTor  tagFromtagTor  )commentinternalrJ  )safe_timestamp_2r.  r'   
string_absr  r+  r  rQ  r=  rR  r   r   
string_subr  r  safe_string_lowerr  r  )r  r   r   r$  r/  r  r  	extraTxidr  re  r"  r  r  r  rV  r  rJ  keyfeeCostr^  codeFeesrh  s                         r  r  zexmo.parse_transaction  sT   h ))+tYG	''X>#"--l;LV4<OOK"=E((7IB V4''VZH
&&z8<"";	:9G\!G"c*u:q="..ua8G%ooc26G
 yy'5!%!5*IC&&{LAG"&//$,,@QSU"V???D"E**8S9''Z@H:%"<'#*#5#5lG#LL"//8F"&J
K
$$$[*iH
 D
 D	

 
 t''Z@
 d''5
 d33D4J4J;X`4ab
 
 Y/
 w
 4
 
 4
 t
  T!
" t**;	B#
$ )
 	
r  c                     | j                          i }|| j                  |dz        |d<   d}|| j                  |      }| j                  | j	                  ||            }| j                  |d   |||      S )a  
        fetch history of deposits and withdrawals

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#31e69a33-4849-4e6a-b4b4-6d574238f6a7

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   r  history)r  r  r   privatePostWalletHistoryr  parse_transactions)r  r"  r  r   r  r  r   r  s           r  fetch_deposits_withdrawalszexmo.fetch_deposits_withdrawals	  s     	"//=GFO}}T*H00Wf1MN> &&x	':HeUSSr  c                    | j                          d}ddi}|||d<   || j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a:  
        fetch all withdrawals made from an account

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#97f1becd-7aad-4e0e-babe-7bbe09e33706

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr  rs   r   r   r   rG  r  r   privatePostWalletOperationsr  r  r  	r  r"  r  r   r  r   r  r  rG  s	            r  fetch_withdrawalszexmo.fetch_withdrawalsL	  s     	J
 $GG}}T*H"*4.GJ33DKK4PQ6 x"5&&uhuEEr  c                    | j                          d}|dd}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      S )a  
        fetch data on a currency withdrawal via the withdrawal id

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#97f1becd-7aad-4e0e-babe-7bbe09e33706

        :param str id: withdrawal id
        :param str code: unified currency code of the currency withdrawn, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nrs   r  r  r   r   rG  r   r  r   r  r  r  r  r  	r  r   r"  r  r   r  r  rG  firsts	            r  fetch_withdrawalzexmo.fetch_withdrawal	  s     	
 }}T*H"*4.GJ33DKK4PQ6 '26ua,%%eX66r  c                    | j                          d}|dd}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }| j                  |di       }| j                  ||      S )a  
        fetch information on a deposit

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#97f1becd-7aad-4e0e-babe-7bbe09e33706

        :param str id: deposit id
        :param str code: unified currency code, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr\  r  r   r   rG  r   r  r  s	            r  fetch_depositzexmo.fetch_deposit	  s     	
 }}T*H"*4.GJ33DKK4PQ6 '26ua,%%eX66r  c                    | j                          d}ddi}|||d<   || j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a/  
        fetch all deposits made to an account

        https://documenter.getpostman.com/view/10287440/SzYXWKPi#97f1becd-7aad-4e0e-babe-7bbe09e33706

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr  r\  r   r   r   rG  r  r  s	            r  fetch_depositszexmo.fetch_deposits	  s     	I
 $GG}}T*H"*4.GJ33DKK4PQ6 x"5&&uhuEEr  r   GETc                    | j                   d   |   dz   }|dk7  r|| j                  dz   z  }||z  }|dk(  s|dk(  r|r|d| j                  |      z   z  }n|dk(  r| j                          | j	                         }| j                  | j                  d|i|            }d| j                  | j                  | j                  |      | j                  | j                        t        j                        d	}||||d
S )Nr   r  r   r   ?r   noncez!application/x-www-form-urlencoded)zContent-TypeKeySign)urlr   bodyheaders)r   r   	urlencoder  r  r  apiKeyhmacencodesecrethashlibsha512)	r  pathr   r   r  r	  r  r  r  s	            r  signz	exmo.sign
  s    iis#c)%<4<<#%%Ct8OsT^^F333I++-JJLE>>$++w.>"GHD C{{		$++d"3T[[5Mw~~^G
 fdwOOr  c                 "    | j                         S N)r  )r  s    r  r  z
exmo.nonce-
  s      ""r  httpCodereasonr  r   r	  r  c
                 <   |y d|v rd|vr| j                  |di       }
| j                  |
d      }| j                  |
d      }| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d   ||       t        |      d|v sd|v r| j                  |dd	      }t        |t              r|d
k(  s|dk(  rd}nd	}|sd }| j                  |dd      }|j                  d      }t        |      }|dkD  r.|d   j                  d      }t        |      }|dkD  r|d   n|d   }| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d   ||       t        |      y )Nerrorr?  msgr"  rO  r   r   errmsgFtruert   Tr  r  r   )r  r.  r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   r  
isinstancer  r+  rQ  r=  )r  r  r  r  r   r	  r  r  requestHeadersrequestBody	errorCodemessageErrorr"  feedbacksuccessmessage
errorPartsr  errorSubPartsnumSubPartss                       r  handle_errorszexmo.handle_errors0
  s   x(h*> '2>I++Iu=L##Iv6Dww}t+H001I4QYZ001I<Yab)) h(&:
 nnXx?G'3'v%7c>"G#G,,XwI$]]3/
z?a<$.qM$7$7$<M"%m"4K0;a=+mTUFVD77S=4/44T__W5MtU]^44T__W5MwX`a#H--r  r  )S__name__
__module____qualname__r   r  r  r  dictr   r   r  rS  r*  r,  r   r3  r0  r1  rX  r   rk  rn  r   ry  r   r  r   r  r
   r`  r  r  r   r  r  r   r  r   r  r   r  r   r  r  r   r7  r;  r   rH  r   rL  rP  rS  r   r   rK  rv  ry  r|  r   r  r  r  rk  r  r  r	   r  r  r   rs   r  r  r  r  r  r  r   r  r  intr)  __classcell__)r  s   @r  r)   r)      s0   _# _B	 FH 3 .
d 
F 
N` 
" @B KC K KFX K =? H He HCU H )+ :{ :& 13 2h 02 #J 7;2 EG EN <@ " "H.A .A` ') pZ pd $& |$v, || 26DW[df 8K# 8Kc 8KQT 8Kkoptku 8Kt
 
4 
() ): $& ,,( ,,\ :>b Ss S3 SY S, 48dSU " " "Zd "H&4 & &6 &P 04B $GW $G7 $GL 02 A3 Af AU Uv U Un 6:UW )=3 )=s )=# )=\`af\g )=V -1tRV_a \@c \@ \@C \@| _a MC My MPU M  RT N N5 N SU O OE O gksu c23 c2i c2y c2RW c2`c c2J 37r .*s .*C .*` 26b 'c '3 'R 9=4^bkm H?S H?# H?S H?X[ H?T /3TXac V V3 Vc Vhlmrhs Vp:<&C Cv C CJ 37TX\eg WC Ws WRU Wr `drv  @B (*S (*# (*Y (*i (*Y\ (*lo (*T 79 "
# "
^ "
H DHPR :S :% :# :Wb :@:s :z
T z
X z
Q\ z
x 6:[_hj 2Ts 2T# 2TUX 2Tost  pA 2Th -1tRV_a 2Fc 2F 2FC 2Ffjkvfw 2Fh 59 173 17c 17f 26b 17 173 17f *.Dt\^ 2F3 2Fc 2F 2Fcghsct 2Fh &eBSW P&#(c (3 (S (# (X\ (dg (r  r)   ).ccxt.base.exchanger   ccxt.abstract.exmor   r  ccxt.base.typesr   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%   ccxt.base.decimal_to_precisionr&   ccxt.base.preciser'   r)    r  r  <module>r8     sn    ( *  j  j  j  j  j  j  * 0 - . ' . ) * . * ) 4 %~(8[ ~(r  