
    !:h                        d dl mZ d dlm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 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CurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)	TICK_SIZE)Precisec                       e Zd Zdef fdZd Zi fdefdZi fde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ede	defdZi fd	edefdZdi fdedefdZd;d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e	defdZdddi fd	eded
edee   fdZdefdZd;dede	de fdZ!di fded	efdZ"d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dee    fd Z$di fd	ed!e%d"e&d#e'd$e(f
d%Z)di fded	efd&Z*i f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,fd+Z.d;d,ed-e/de,fd.Z0defd/Z1di fd0edee2   fd1Z3d2d3i ddfd4Z4d'e5d5ed6ed7ed8ed9efd:Z6 xZ7S )<indodaxreturnc                    | j                  t        t        |          dddg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	d/d	d0dd1d	d2d	d3dd4dd5dd6d	d7d	d8d	d9d	d:d	i d;d	d<d	d=d	d>d	d?dd@ddAddBd	dCd	dDddEd	dFd!dGd	dHd	dId	dJd	dKd	d	d	d	d	d	ddLdMdNdOdPdQdRdSdTdUdVdWdWdWdWdWdWdWdWdWdX	idYdZdZd[dZdZdZdZdZdZdZdZdZdZd\idQd]d	dd^d_d`it        t
        t        t        t        dat        t        dbdcddd^d	dedfdgdhdidjdkdldmdndodpdqdr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	d	dwd d	dxdyd[d d	d	ddzd{d|id}	d d d~d d d~dddddddt        d      S )Nr!   INDODAXID2   CORSspotTmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositfetchDepositAddressemulatedfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTicker	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsreduceMargin)setLeverage	setMarginsetMarginModesetPositionModetransferwithdrawz2.0zdhttps://user-images.githubusercontent.com/51840849/87070508-9358c880-c221-11ea-8dc5-5391afbbb422.jpgzhttps://indodax.comzhttps://indodax.com/tapi)publicprivatezhttps://www.indodax.comz2https://github.com/btcid/indodax-official-api-docsz)https://indodax.com/ref/testbitcoincoid/1)logoapiwwwdocreferralget   )	zapi/server_timez	api/pairszapi/price_incrementszapi/summarieszapi/ticker/{pair}zapi/ticker_allzapi/trades/{pair}zapi/depth/{pair}ztradingview/history_v2post      )getInfotransHistorytradetradeHistory
openOrdersorderHistorygetOrderr/   withdrawFeewithdrawCoinlistDownlinecheckDownlinecreateVouchertradingr   g~jth?)	tierBased
percentagemakertaker)invalid_pairzInsufficient balance.zinvalid order.z:Invalid credentials. API not found or session has expired.zInvalid credentials. Bad sign.)zMinimum pricezMinimum order)exactbroadi  zStellar Tokenbep20trc20polygon)XLMBSCTRC20MATIC11530602401D3D1W)1m15m30m1h4h1d3d1w)
recvWindowtimeDifferenceadjustForTimeDifferencenetworks
timeframes)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceiceberg)r   triggerr   symbolRequired)r   limitr   r   r     i )r   r   daysBackdaysBackCanceled	untilDaysr   r   r   r   i  )	sandboxr4   createOrdersfetchMyTradesrT   rS   rV   r<   
fetchOHLCV)linearinverse)r(   r*   r+   r   BCHBSVDASHXEM)STRBCHABCBCHSVDRKNEM)idname	countries	rateLimithasversionurlsru   fees
exceptionsoptionsfeaturescommonCurrenciesprecisionMode)
deep_extendsuperr!   describer   r   r   r   r   r   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/indodax.pyr   zindodax.describe   s   gt = ? KKK %K 	K
 %K %K UK "5K tK K $UK  K 'K tK (K  '!K" (#K$ "5%K& 'K( +E)K* )%+K, $T-K. '/K0 (1K2 3K4 &z5K6 (7K8 1%9K:  ;K< +D=K> &u?K@ #EAKB *5CKD $UEKF "5GKH *5IKJ +EKKL  MKN %eOKP "5QKR SKT !%UKV +EWKX "4YKZ d[K\ !$]K^ u_K`  aKb 'cKd $UeKf !%gKh *5iKj (kKl %emKn )%oKp tqKr TsKt tuKv "5wKx #EyKz &t{K| '}K~ $ZK@  AKB !%CKD "5EKF #EGKH IKJ  %"!&#(! UKX ~39 1KG	 +,%&01)*-.*+-.,-23
 #$()!"()&'()$%'('(()())*)*B !&"&"	 %.->&3Re6I &2%1 '"#+0*"$&	& 	- F  %&+(-,0,1).+06:#'#("'#(	( #(/4$)$)+027#()$, %)%)&+#($)*.	# ',!%#($)*/( $(&+!%$*,-%)#($)*.	*  #e5n ##
 ##w?B ! 'y}B
 } }	    c                 B    | j                         | j                  d   z
  S )Nr   )millisecondsr   )r   s    r   noncezindodax.nonce  s       "T\\2B%CCCr   c                 H    | j                  |      }| j                  |d      S )ay  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://github.com/btcid/indodax-official-api-docs/blob/master/Public-RestAPI.md#server-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        server_time)publicGetApiServerTimesafe_integerr   paramsresponses      r   
fetch_timezindodax.fetch_time  s)     ..v6   =99r   c                 \   | j                  |      }g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |      }	| j	                  |      }
| j                  |d      }|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|rdndddddd| j                  |d      dddddd| j                  d      | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  dddd | j                  |d!      dd | j                  |d"      dd ddd d#d|d$        |S )%a7  
        retrieves data on all markets for indodax

        https://github.com/btcid/indodax-official-api-docs/blob/master/Public-RestAPI.md#pairs

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   	ticker_idtraded_currencybase_currencyis_maintenancer   symbol/basequotesettleNbaseIdquoteIdsettleIdtyper(   Tr)   Fr*   r+   r,   activecontractr   trade_fee_percentz1e-8price_roundvolume_precision)amountpricecost)minmaxtrade_min_traded_currencytrade_min_base_currency)r   r	  r
  r  )r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper   	precisionlimitscreatedinfo)
publicGetApiPairsrangelensafe_stringsafe_currency_coder   appendsafe_numberparse_numberparse_precision)r   r   r   resultimarketr   r   r  r   r   isMaintenances               r   fetch_marketszindodax.fetch_markets.  s    ))&16 q#h-( ;	Aa[F!!&+6B%%f.?@F&&v?G**62D++G4E --f6FGMMM 3b3$*u,3 3 	3
 $3 &3 73 D3 3 3 %3 3 %3 %3 =%d3  E!3" $#3$  ))&2EF $"&"""//7!..t/C/CDDTDTU[]jDk/lm --d.B.B4CSCSTZ\nCo.pq  $#!
  $//8ST#
  $//8QR#
  $#$  e3 3;	x r   c                    | j                  |di       }| j                  |di       }| j                  |di       }| j                  |d      }||| j                  |      d}t        |j	                               }t        dt        |            D ]W  }||   }	| j                  |	      }
| j                         }| j                  ||	      |d<   | j                  ||	      |d<   |||
<   Y | j                  |      S )	Nr"   balancebalance_holdr   )r  	timestampdatetimer   freeused)
safe_valuesafe_timestampiso8601listkeysr  r  r  accountr  safe_balance)r   r   balancesr,  r-  r*  r"  currencyIdsr#  
currencyIdcoder3  s               r   parse_balancezindodax.parse_balance  s    ??8Xr:xB7x<''-@	"Y/

 499;'q#k*+ 	#A$QJ**:6DllnG"..tZ@GFO"..tZ@GFO"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#get-info-endpoint

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )load_marketsprivatePostGetInfor9  r   s      r   fetch_balancezindodax.fetch_balance  s3     	**62> !!(++r   Nr   r   c                     | j                          | j                  |      }d|d   |d   z   i}| j                  | j                  ||            }| j	                  ||d   ddd      S )aT  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://github.com/btcid/indodax-official-api-docs/blob/master/Public-RestAPI.md#depth

        :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
        pairr   r   r   Nbuysell)r;  r$  publicGetApiDepthPairextendparse_order_book)r   r   r   r   r$  request	orderbooks          r   fetch_order_bookzindodax.fetch_order_book  sr     	V$F6NVG_4
 ..t{{7F/KL	$$Yx0@$vVVr   tickerr$  c                 :   | j                  d |      }| j                  |d      }d|d   j                         z   }d|d   j                         z   }| j                  |d      }| j	                  i 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d | j                  ||      | j                  ||      |d|      S )Nr   vol_r   r  lastr   r*  r+  highlowbidr@  	bidVolumeaskrA  	askVolumevwapopenclosepreviousClosechanger   average)
baseVolumequoteVolumer  )safe_symbolr/  lowerr  safe_tickerr0  )r   rH  r$  r   r*  rX  rY  rK  s           r   parse_tickerzindodax.parse_ticker  s    !!$/''>	fX.4466
vi06688/ !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FF3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **6:>++FK@)!
* + 	r   c                     | j                          | j                  |      }d|d   |d   z   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://github.com/btcid/indodax-official-api-docs/blob/master/Public-RestAPI.md#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>`
        r?  r   r   rH  )r;  r$  publicGetApiTickerPairrC  	safe_dictr]  )r   r   r   r$  rE  r   rH  s          r   fetch_tickerzindodax.fetch_ticker  s{     	V$F6NVG_4
 ..t{{7F/KL (B7  00r   symbolsc                     | j                          | j                  |      }| j                  |di       }| j                  ||      S )a7  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://github.com/btcid/indodax-official-api-docs/blob/master/Public-RestAPI.md#ticker-all

        :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>`
        tickers)r;  publicGetApiTickerAllr`  parse_tickers)r   rb  r   r   rd  s        r   fetch_tickerszindodax.fetch_tickers-  sG     	" --f5..9b9!!'733r   r   c                 $   | j                  |d      }| j                  | j                  |d      ||| j                  |      | j	                  d |      d | j                  |d      d d | j                  |d      | j                  |d      d d d|      S )Ndatetidr  r
  r	  )r   r  r*  r+  r   r  sideordertakerOrMakerr
  r	  r  fee)r/  
safe_trader  r0  rZ  )r   r   r$  r*  s       r   parse_tradezindodax.parse_tradeL  s    ''v6	""5%0"Y/&&tV4$$UF3 %%eW5&&uh7 
  	r   sincec                     | j                          | j                  |      }d|d   |d   z   i}| j                  | j                  ||            }| j	                  ||||      S )a?  
        get the list of most recent trades for a particular symbol

        https://github.com/btcid/indodax-official-api-docs/blob/master/Public-RestAPI.md#trades

        :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>`
        r?  r   r   )r;  r$  publicGetApiTradesPairrC  parse_trades)r   r   rq  r   r   r$  rE  r   s           r   fetch_tradeszindodax.fetch_trades^  sk     	V$F6NVG_4
 ..t{{7F/KL  65%@@r   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )NTimeOpenHighLowCloseVolume)r/  r  )r   ohlcvr$  s      r   parse_ohlcvzindodax.parse_ohlcvr  sn     v.UF+UF+UE*UG,UH-
 	
r   r   c                    | j                          | j                  |      }| j                  d   }| j                  |||      }| j	                         }	| j                  |d|	      }
| j                  |dg      }|
||d   |d   z   d}|d}|%t        t        j                  |dz              |d<   n| j                  |      }|	||z  z
  dz
  |d<   | j                  | j                  ||            }| j                  |||||      S )	a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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
        r   untilr   r   )totfr   r   fromr}   )r;  r$  r   r  secondsr   omitintmathfloorparse_timeframepublicGetTradingviewHistoryV2rC  parse_ohlcvs)r   r   	timeframerq  r   r   r$  r   selectedTimeframenowr  rE  durationr   s                 r   fetch_ohlcvzindodax.fetch_ohlcv  s    	V$\\,/
 ,,ZINlln!!&'376G9-#Vnvg6

 =E!$**UT\":;GFO++I6H!EH$44q8GFO55dkk'66RS   69eUKKr   statusc                 4    dddd}| j                  |||      S )NrS  closedcanceled)rS  filled	cancelledr  r   r  statusess      r   parse_order_statuszindodax.parse_order_status  s)    #

 &&99r   rl  c                    d }d|v r|d   }| j                  | j                  |dd            }d }d }| j                  |d      }d }d }	| j                  |d      }
| j                  |
|      }|l|d   }|d   }|d   }|d   d	k(  rd
|v rd}|d   d	k(  rd|v rd}| j                  |d|z         }|s*| j                  |d|z         }| j                  |d|z         }	| j                  |d      }d }| j                  |d      }| j	                  i d|d|d| j                  |d      d|d| j                  |      dd d|dddd dd d|d|dd d|dd d|d d |	||d d!      S )"Nr  r  rS  r
  r?  r   r  r   idrorder_rprp	remain_rporder_remain_submit_timeorder_idr  r   clientOrderIdclient_order_idr*  r+  lastTradeTimestampr   r   postOnlyrk  r   r  rW  r	  r  )	remainingr  rn  trades)r  r  safe_marketr   
safe_orderr0  )r   rl  r$  rk  r  r   r  r
  r	  r  marketIdr  r   r*  rn  r   s                   r   parse_orderzindodax.parse_order  sR   T U?=D(()9)9%6)RS  0	##E62!!(F3H%FY'GH%Fy!U*u1Dx E)u0D##E8g+=>D))%F1BC ,,UI4FG	%%e];	eZ0  
E 
" 
 T--e5FG 
 	 

 Y/ 
 !$ 
 f 
 G 
 4 
  
 D 
 U 
 D 
 D 
 t 
  f! 
" d# 
$ #+ 
  	r   r   c                 0   |t        | j                  dz         | j                          | j                  |      }|d   |d}| j	                  | j                  ||            }|d   }| j                  | j                  d|i|d         |      }||d<   |S )a  
        fetches information on an order made by the user

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#get-order-endpoints

        :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>`
        z( fetchOrder() requires a symbol argumentr   )r?  r  r"   rl  r  )r   r   r;  r$  privatePostGetOrderrC  r  )	r   r   r   r   r$  rE  r   ordersrl  s	            r   fetch_orderzindodax.fetch_order  s     >#DGG.X$XYYV$4L
 ++DKK,HI(#  dBZ!I6R fr   c                    | j                          d}i }|| j                  |      }|d   |d<   | j                  | j                  ||            }|d   d   }|sg S || j	                  ||||      S t        |j                               }	g }
t        dt        |	            D ]C  }|	|   }||   }| j                  |      }| j	                  ||||      }| j                  |
|      }
E |
S )a:  
        fetch all unfilled currently open orders

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#open-orders-endpoints

        :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>`
        Nr   r?  r"   r  r   )r;  r$  privatePostOpenOrdersrC  parse_ordersr1  r2  r  r  r  array_concat)r   r   rq  r   r   r$  rE  r   	rawOrders	marketIdsexchangeOrdersr#  r  marketOrdersparsedOrderss                  r   fetch_open_orderszindodax.fetch_open_orders0  s    	[[(F$TlGFO--dkk'6.JKX&x0	I$$YuEE)*	q#i.) 	MA |H$X.L%%h/F,,\65%PL!..~|LN	M r   c                 F   |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  | j                  ||            }| j                  |d   d   |      }| j                  |dd      }| j                  ||||      S )a^  
        fetches information on multiple closed orders made by the user

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#order-history

        :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>`
        z/ fetchClosedOrders() requires a symbol argumentr?  r   r"   r  r  r  )	r   r   r;  r$  privatePostOrderHistoryrC  r  	filter_byfilter_by_symbol_since_limit)	r   r   rq  r   r   r$  rE  r   r  s	            r   fetch_closed_orderszindodax.fetch_closed_ordersU  s     >#DGG._$_``V$F4L
 //GV0LM""8H#5h#?H(;00NNr   r  rk  r	  r
  c                    | j                          | j                  |      }|d   ||d}d}	d}
|dk(  r|dk(  rd}| j                  |d      }| j                  |d      }|| j	                  ||      }nd|t        | j                  dz         | j                  |      }| j                  |      }t        j                  ||      }| j	                  ||      }|||d	   <   nZd
}
nW|dk(  rRd
}	d
}
|dk(  rI| j                  t        j                  | j                  |      | j                  |                  ||d	   <   |	r%|t        | j                  dz   |z   dz         ||d<   |
r| j                  ||      ||d   <   | j                  | j                  ||            }| j                  |di       }| j                  |d      }| j!                  ||d|      S )a  
        create a trade order

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#trade-endpoints

        :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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   )r?  r  r
  Fr$  r@  Nr  zv createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price).r  Tr   z/ createOrder() requires a price argument for a z orderr
  r   r"   r  )r  r   )r;  r$  r  r  cost_to_precisionr   r   number_to_stringr   
string_mulparse_to_numericamount_to_precisionprivatePostTraderC  r.  r  r  )r   r   r  rk  r	  r
  r   r$  rE  priceIsRequiredquantityIsRequiredquoteAmountr  amountStringpriceStringcostRequestr"  datar   s                      r   create_orderzindodax.create_orderm  s/    	V$4L

  "8u}"''7662#"&"8"8"FK}*477  6n  ,n  o  o#'#8#8#@L"&"7"7">K")"4"4\;"OK"&"8"8"MK-8y)*%)"W_"O!%u}-1-B-B7CUCUVZVkVklrVsuy  vK  vK  LQ  vR  DS  .Ty)*}"477-^#^ae#ehp#pqq$GG(,(@(@(PGF8$%&&t{{7F'CDvx4dJ/ 
  	r   c                 j   |t        | j                  dz         | j                  |d      }|t        | j                  dz         | j                          | j	                  |      }||d   |d}| j                  | j                  ||            }| j                  |d      }| j                  |      S )a  
        cancels an open order

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#cancel-order-endpoints

        :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>`
        z) cancelOrder() requires a symbol argumentrk  z- cancelOrder() requires an extra "side" paramr   )r  r?  r  r"   )	r   r   r.  r;  r$  privatePostCancelOrderrC  r`  r  )	r   r   r   r   rk  r$  rE  r   r  s	            r   cancel_orderzindodax.cancel_order  s     >#DGG.Y$YZZvv.<#DGG.]$]^^V$4L

 ..t{{7F/KL( ~~h1%%r   r8  c                 *   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |d      }|| j                  |d      | j                  ||      dS )a}  
        fetch the fee for a transaction

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#withdraw-fee-endpoints

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        currencyr   r"   withdraw_fee)r  rater  )r;  r  privatePostWithdrawFeerC  r.  r  r  r  )r   r8  r   r  rE  r   r  r7  s           r   fetch_transaction_feezindodax.fetch_transaction_fee  s     	==&
 ..t{{7F/KL x26%%dJ7
$$T>://
HE
 	
r   c                 b   | j                          i }|>| j                  |      dd }||d<   | j                  | j                               dd |d<   | j                  | j	                  ||            }| j                  |di       }| j                  |di       }	| j                  |di       }
g }d}|t        |	j                               }t        dt        |            D ]  }||   }| j                  ||	|         } t        |
j                               }t        dt        |            D ]  }||   }| j                  ||
|         } nO| j                  |      }| j                  |	|d	   g       }| j                  |
|d	   g       }| j                  ||      }| j                  ||||      S )
a  
        fetch history of deposits and withdrawals

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#transaction-history-endpoints

        :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   
   startendr"   rq   depositr   )r;  r0  r   privatePostTransHistoryrC  r.  r1  r2  r  r  r  r  parse_transactions)r   r8  rq  r   r   rE  	startTimer   r  rq   r  transactionsr  r2  r#  key	withdrawsdepositss                     r   fetch_deposits_withdrawalsz"indodax.fetch_deposits_withdrawals  s    	U+Ab1I(GG!\\$*;*;*=>qDGEN//GV0LMt x26??4R8//$	26<(D1c$i( N1g#00x}MN 'D1c$i( M1g#00ws|LM }}T*H(4."EIwCH,,YAL&&|XueLLr   addressc                 J   | j                  ||      \  }}| j                  |       | j                          | j                  |      }| j	                         }|d   ||t        |      d}|r||d<   | j                  | j                  ||            }	| j                  |	|      S )a  
        make a withdrawal

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#withdraw-coin-endpoints

        :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  withdraw_amountwithdraw_address
request_idwithdraw_memo)	handle_withdraw_tag_and_paramscheck_addressr;  r  r   strprivatePostWithdrawCoinrC  parse_transaction)
r   r8  r	  r  tagr   r  	requestIdrE  r   s
             r   rq   zindodax.withdrawY  s     99#vFV7#==&
 %%'	 !% 'i.	
 '*GO$//GV0LM  %%h99r   transactionr  c                 J   | j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }d }|| j                  d |      |d d}i d| j	                  |dd      d	| j	                  |d	d
      d|d| j                  |      dd dd d| j                  |d      dd d| j                  |g d      d|dndd| j                  d |      d| j                  |      dd dd dd dd d| j                  |d      d ||dS )Nr  success_timer  
deposit_idrn  )r  r  r  r   withdraw_idtxidtxr*  r+  networkaddressFromr  r  	addressTor	  )r	  r  deposit_amountr  rq   r  r  updatedtagFromr  tagTocommentr  )internalrn  r  )r  safe_timestamp_2r  r  safe_string_2r0  safe_number_nparse_transaction_status)r   r  r  r  r*  	depositIdfeeCostrn  s           r   r  zindodax.parse_transaction  s   T !!+x8))+~}U	$$[,?	"";6 33D(CC

$$$[-N
D&&{FDA
 
 Y/	

 t
 4
 t''5GH
 
 d((6ef
 9#4J9
 //h?
 d33F;
 t
 t
 4
  T!
" t''_E#
$ )
 	
r   c                 0    ddi}| j                  |||      S )Nsuccessokr  r  s      r   r  z indodax.parse_transaction_status  s%    t
 &&99r   codesc                 6   | j                          | j                  |      }| j                  |d      }| j                  |di       }| j                  |di       }t        |j	                               }d|i}t        dt        |            D ]	  }	||	   }
| j                  |
      }| j                  ||
      }|/|| j                  ||      sD| j                  |       d}|
|v r| j                  ||
      }|j                  d      dk\  r_g }|j                  d      }t        dt        |            D ]3  }|j                  | j                  ||         j                                5 n| j                  |      j                         }i |||dd||<    |S )	a  
        fetch deposit addresses for multiple currencies and chain types

        https://github.com/btcid/indodax-official-api-docs/blob/master/Private-RestAPI.md#general-information-on-endpoints

        :param str[] [codes]: list of unified currency codes, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `address structures <https://docs.ccxt.com/#/?id=address-structure>`
        r"   r  r  r  r   N,)r  r  r  r  r  )r;  r<  r`  r1  r2  r  r  r  r  in_arrayr  findsplitr  network_id_to_codeupper)r   r  r   r   r  	addressesr   addressKeysr"  r#  r  r8  r  r  	networkId
networkIdsjs                    r   fetch_deposit_addresseszindodax.fetch_deposit_addresses  s    	**62H ~~h1NN4B7	>>$	269>>+,D
 q#k*+ 	A"1~H**84D&&y(;G#5=dmmDRW>X""7+x' $ 0 08 DI ~~c*a/"$%.__S%9
!&q#j/!: [A#NN4+B+B:a=+Q+W+W+YZ[ #'"9"9)"D"J"J"L $&& t!	. r   rr   GETc                 6   | j                   d   |   }|dk(  rU| j                  || j                  |            }d| j                  ||      z   }	||	z   }|r|d| j	                  |      z   z  }n| j                          | j                  | j                  || j                         | j                  d   d|            }d| j                  | j                  | j                  |      | j                  | j                        t        j                        d}||||d	S )
Nru   rr   r   ?r   )methodr*  r   z!application/x-www-form-urlencoded)zContent-TypeKeySign)urlr  bodyheaders)r   r  extract_paramsimplode_paramsurlencode_with_array_repeatcheck_required_credentials	urlencoderC  r   r   apiKeyhmacencodesecrethashlibsha512)
r   pathru   r  r   r"  r!  r   queryrequestPaths
             r   signzindodax.sign,  s   iis#(?IIfd&9&9$&?@E 3 3D& AAK#CsT==eDDD++->>$++!ZZ\"ll<8/ 	# D !D{{		$++d"3T[[5Mw~~^G
 fdwOOr   reasonr   r  r"  r!  c
                    |y t        |t              ry | j                  |dd      }
d|vr|
dk(  ry | j                  |d      }|dk(  ry | j	                  |dd      dk(  r/d|vr*t        | j                  dz   | j                  |      z         y | j                  d	z   |z   }| j                  | j                  d
   |
|       | j                  | j                  d   |
|       t        |      )Nerror r
  approvedr   r}   r"   z: malformed response:  r   r   )
isinstancer1  r.  r  r   r   r   jsonthrow_exactly_matched_exceptionr   throw_broadly_matched_exception)r   r8  r2  r   r  r"  r!  r   requestHeadersrequestBodyr4  r  feedbacks                r   handle_errorszindodax.handle_errorsB  s    
 h%'26X%5B;!!(I6ZXy!49(#DGG.F$FS[I\$\]]77S=4',,T__W-EuhW,,T__W-EuhWH%%r   )N)8__name__
__module____qualname__r   r   r   r	   r   r   r
   r&  r   r9  r=  r  r   rG  dictr   r]  ra  r   r   rg  r   rp  ru  r1  r~  r  r   r  r   r  r  r  r  r   r   floatr   r  r  r  r   r  rq   r   r  r  r   r  r1  r  r?  __classcell__)r   s   @r   r!   r!      s   ~# ~@D !# :s :$ $& a$v, aF) )( $& ),( ),V :>b Ws W3 WY W&'4 ' '6 'R 02 13 1f 1B 04B 4W 47 4> v  $ 6:UW A3 As A# A\`af\g A(
 
4 
( 26DW[df +L# +Lc +LQT +Lkoptku +LZ: :Z Zv Z Zx 26b c 3 2 /3TXac # #3 #c #hlmrhs #J 154VZce O# OS OPS Ojnotju O0 gksu 93 9i 9y 9RW 9`c 9v 37r ,&s ,&C ,&\ 79  
#  
D 6:[_hj _Ms _M# _MUX _Most  pA _MB DHPR 0:S 0:% 0:# 0:Wb 0:dJ
T J
X J
Q\ J
X:s : 8<B MW M4P^K_ M^ &eBSW P,&# &s & &c &TX &`c &r   r!   )'ccxt.base.exchanger   ccxt.abstract.indodaxr   r,  r  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r!    r   r   <module>rN     s_    ( -   q  q  q  q  q  * 0 . & . ) * 4 %C&h C&r   