
    i                     (   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 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'dS )    )Exchange)ImplicitAPIN)BalancesCurrencyIntMarketMarketInterfaceNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InvalidAddress)InvalidOrder)ExchangeNotAvailable)TRUNCATE)DECIMAL_PLACES)SIGNIFICANT_DIGITS)Precisec                   <    e Zd Z fdZd0dededededef
 fdZ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d1d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d1dedefdZdddi fdededede	e         fdZd1dedefdZ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#d! Z$d1dede%fd"Z&dddi fdededede	e%         fd#Z'di fdedefd$Z(i fd%Z)di fd&ede fd'Z*d1d(e+de,fd)Z-d* Z.d+ Z/d,d-i ddfd.Z0d/ Z1 xZ2S )2bithumbc                    |                      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	d	d	d	dddd	d	d	d	d	d	d	dd)d*d+d,d-d.d/d0d1d2d3g d4id5g d6id.d7|                     d8          |                     d8          d9it
          t          t          t          t          t          t          t          t          t          t          t          t          t          d:d;d<d=d>d?d@dAdBdCdD	dEdFdGdHdIdJiidFdGddKdJiidLidMdNdOdPdQ          S )RNr#   BithumbKRi  TCORSspotmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrdercreateReduceOnlyOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchMarketsfetchMarkOHLCV
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchPosition)fetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTransferfetchTransfersreduceMarginsetLeveragesetMarginModesetPositionModetransferwithdrawzbithumb.comzchttps://user-images.githubusercontent.com/1294454/30597177-ea800172-9d5e-11e7-804c-b9d4fa9b56b0.jpgzhttps://api.{hostname}/publiczhttps://api.{hostname})publicprivatezhttps://www.bithumb.comzhttps://apidocs.bithumb.comz0https://en.bithumb.com/customer_support/info_fee)logoapiwwwdocfeesget)zticker/ALL_{quoteId}zticker/{baseId}_{quoteId}zorderbook/ALL_{quoteId}zorderbook/{baseId}_{quoteId}z&transaction_history/{baseId}_{quoteId}znetwork-infozassetsstatus/multichain/ALLz"assetsstatus/multichain/{currency}zwithdraw/minimum/ALLzwithdraw/minimum/{currency}zassetsstatus/ALLzassetsstatus/{baseId}z)candlestick/{baseId}_{quoteId}/{interval}post)zinfo/accountzinfo/balancezinfo/wallet_addresszinfo/tickerzinfo/orderszinfo/user_transactionszinfo/order_detailztrade/placeztrade/cancelztrade/btc_withdrawalztrade/krw_depositztrade/krw_withdrawalztrade/market_buyztrade/market_sellztrade/stop_limittradingz0.0025)makertaker)zBad Request(SSL)zBad Request(Bad Method)zBad Request.(Auth Data)z
Not MemberzInvalid ApikeyzMethod Not Allowed.(Access IP)zMethod Not Allowed.(BTC Adress)zMethod Not Allowed.(Access)zDatabase FailzInvalid Parameter5600zUnknown ErrorzpAfter May 23th, recent_transactions is no longer, hence users will not be able to connect to recent_transactions1m3m5m10m30m1h6h12h24h)	rd   re   rf   rg   rh   ri   rj   rk   1dquoteCurrencieslimitscostg-C6*?d   minmaxl    rT )BTCKRWArchLootFTC2z	Soda Coin)ALTFTCSOC)idname	countries	rateLimitprohashostnameurlsrZ   r]   precisionMode
exceptions
timeframesoptionscommonCurrencies)deep_extendsuperr#   describeparse_numberr    r   r   r   r   r   r   )self	__class__s    R/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/bithumb.pyr   zbithumb.describe   s   gt 4 4 = = ? ?111 %1 	1
 %1 %1 U1 t1 $U1  1 $T1 t1 (1 1 +E1  )%!1" '#1 1$ (%1& &u'1( #E)1* *5+1, $U-1. "5/10 *5112 +E314  516 718 !%91: d;1< +E=1> "4?1@ dA1B !$C1D  E1 1F #(&+*/# $#!&"' %$!&#(! a1 1 1d &}=7  14J	 	    $    %% %N !..x88!..x88  0$.+5+>1"52B3A/?!5%/%!. ER   
 
 " "'-'*% %# !"'*'1% %#$ $* ""! !}cB
 cB
 c c c	    NmarketIdmarket	delimiter
marketTypereturnc                 Z    t          t          |                               |||d          S )Nr(   )r   r#   safe_market)r   r   r   r   r   r   s        r   r   zbithumb.safe_market   s)    
 Wd##//&)VTTTr   c                 t    |                      |t          | j        |         d         d         t                    S )N	precisionamount)decimal_to_precisionr   marketsr   )r   symbolr   s      r   amount_to_precisionzbithumb.amount_to_precision   s0    ((4<;OP[;\]e;fhvwwwr   c                    g }|                      | j        di           }t          |                                          }t	          dt          |                    D ]}||         }|}|                      ||i           }d|i}	|                     |                     |	|                    }
|                      |
d          }t          |                                          }t	          dt          |                    D ]}||         }|dk    r||         }|                     |          }d}t          |t                    rt          |          }|dk    rd}| 
                    i d|d	|d
z   |z   d|d|ddd|d|ddddddddddddddd|ddddddddddt          d          t          d          ddddddddddi dd|d
|          }|                    |           |S )aP  
        retrieves data on all markets for bithumb
        :see: https://apidocs.bithumb.com/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-all
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        rn   r   quoteIddatadateTFr|   r   /basequotesettleNbaseIdsettleIdtyper(   r)   r*   r+   r,   activecontractlinear4)r   pricerr   )leverager   r   rp   )
inversecontractSizeexpiryexpiryDateTimestrike
optionTyper   ro   createdinfo)
safe_valuer   listkeysrangelenpublicGetTickerALLQuoteIdextendsafe_currency_code
isinstancer   intappend)r   paramsresultrn   quotesir   r   	extensionrequestresponser   currencyIdsj
currencyIdr   r   r   numElementsentrys                       r   fetch_marketszbithumb.fetch_markets   s    //$,8I2NNo**,,--q#f++&& C	% C	%A1IEGCCI7G 55dkk'66R6RSSH??8V44Dtyy{{++K1c+..// 9% 9%(^
''j)..z::fd++ '"%f++K"a''!&(( -**-*dSj50-* D-* U	-*
 d-* j-* w-* -* F-* D-* e-* E-* e-* e-* f-*  !-*" d#-*$  $$("&*""&"%c((!$S" " $(#'% %
 $(#'# #
 $(#'" " !#   $"Y-* -* -*Z [- -\ e$$$$s9%t r   c                 ,   d|i}|                      |d          }t          | j                                                  }t	          dt          |                    D ]}||         }|                                 }|                     |          }|                     |d          }	| 	                    |d|	z             |d<   | 	                    |d|	z             |d<   | 	                    |d	|	z             |d
<   |||<   | 
                    |          S )Nr   r   r   r|   total_totalin_use_used
available_free)r   r   
currenciesr   r   r   accountcurrencysafe_string_lowersafe_stringsafe_balance)
r   r   r   balancescodesr   coder   r   lowerCurrencyIds
             r   parse_balancezbithumb.parse_balance  s   (#??8V44T_))++,,q#e**%% 	# 	#A8DllnnG}}T**H"44XtDDO#//(_:TUUGG"..x_9TUUGFO"..x9WXXGFO"F4LL  (((r   c                     |                                   ddi}|                     |                     ||                    }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://apidocs.bithumb.com/reference/%EB%B3%B4%EC%9C%A0%EC%9E%90%EC%82%B0-%EC%A1%B0%ED%9A%8C
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        r   ALL)load_marketsprivatePostInfoBalancer   r   )r   r   r   r   s       r   fetch_balancezbithumb.fetch_balance*  sY     	
 ..t{{7F/K/KLL!!(+++r   r   limitc           	      f   |                                   |                     |          }|d         |d         d}|||d<   |                     |                     ||                    }|                     |di           }|                     |d          }|                     |||dd	d
d          S )a`  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://apidocs.bithumb.com/reference/%ED%98%B8%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C
        :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
        r   r   r   r   Ncountr   	timestampbidsasksr   quantity)r   r   publicGetOrderbookBaseIdQuoteIdr   r   safe_integerparse_order_book)	r   r   r   r   r   r   r   r   r   s	            r   fetch_order_bookzbithumb.fetch_order_book8  s     	V$$X&i(
 
 $GG77GV8T8TUU* x44%%dK88	$$T69ffgWabbbr   c                 n   |                      |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|          S )Nr   opening_priceclosing_priceunits_traded_24Hacc_trade_value_24Hr   r   datetimehigh	max_pricelow	min_pricebid	buy_price	bidVolumeask
sell_price	askVolumevwapopencloselastpreviousClosechange
percentageaverage)
baseVolumequoteVolumer   )r   safe_symbolr   safe_tickeriso8601)	r   tickerr   r   r   r  r  r  r  s	            r   parse_tickerzbithumb.parse_tickerb  s   & %%ff55	!!$//88  99%%f.@AA
&&v/DEE !
f!
!
 Y//!
 D$$V[99	!

 4##FK88!
 4##FK88!
 !
 4##FL99!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r   symbolsc                 P   |                                   i }|                     | j        di           }t          |                                          }t          dt          |                    D ]}||         }|}d|i}	|                     |                     |	|                    }
|                     |
di           }| 	                    |d          }| 
                    |d          }t          |                                          }t          dt          |                    D ]b}||         }||         }|                     |          }|dz   |z   }|                     |          }||d<   |                     ||          ||<   c |                     |d|          S )aK  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://apidocs.bithumb.com/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-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>`
        rn   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   omitr   r   r  filter_by_array_tickers)r   r  r   r   rn   r   r   r   r   r   r   r   r   tickersr   r   r   r  r   r   r   s                        r   fetch_tickerszbithumb.fetch_tickers  s    	//$,8I2NNo**,,--q#f++&& '	C '	CA1IEG7G 55dkk'66R6RSSH, ??8VR88D))$77Iiif--Gw||~~..K1c+..// C C(^
j)..z::e+))&11!*v!%!2!266!B!BvC ++FHgFFFr   c                 "   |                                   |                     |          }|d         |d         d}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://apidocs.bithumb.com/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C
        :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   publicGetTickerBaseIdQuoteIdr   	safe_dictr  )r   r   r   r   r   r   r   s          r   fetch_tickerzbithumb.fetch_ticker  s     	V$$X&i(
 
 44T[[&5Q5QRR( ~~h33  v...r   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr                  )r   safe_number)r   ohlcvr   s      r   parse_ohlcvzbithumb.parse_ohlcv  s     eQ''UA&&UA&&UA&&UA&&UA&&
 	
r   rd   sincec                 ^   |                                   |                     |          }|d         |d         |                     | j        ||          d}|                     |                     ||                    }|                     |dg           }	|                     |	||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://apidocs.bithumb.com/reference/candlestick-rest-api
        :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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   r   )r   r   intervalr   )r   r   r   r   )publicGetCandlestickBaseIdQuoteIdIntervalr   	safe_listparse_ohlcvs)
r   r   	timeframer%  r   r   r   r   r   r   s
             r   fetch_ohlcvzbithumb.fetch_ohlcv  s     	V$$X&i((()YOO
 

 AA$++gW]B^B^__0 ~~h33  vy%GGGr   c                    d }|                      |d          }||                    d          }t          |          }|dk    rD|d         }|d         }t          |          dk     rd|z   }|                     |dz   |z             }n|                     |dd          }||dz  }d }	|                      |d	          }
|
d
k    rdnd}
|                      |d          }|                     d |          }|                      |d          }|                     |                     |dd                    }|                      |d          }d }|                      |d          }|0|                      |d          }|                     |          }||d}| 	                    |||| 
                    |          |d         d |	|
d ||||d|          S )Ntransaction_date r  r      0MbP?ibr   r   sellbuycont_nor   units_tradedunitsr   feefee_currency)rp   r   r   )r|   r   r   r   r   orderr   sidetakerOrMakerr   r   rp   r8  )r   splitr   	parse8601safe_integer_productr   fix_comma_numbersafe_string_2common_currency_code
safe_trader  )r   trader   r   transactionDatetimepartsnumPartstransactionDatetransactionTimer   r;  r|   priceStringamountString
costStringr8  feeCostStringfeeCurrencyIdfeeCurrencyCodes                      r   parse_tradezbithumb.parse_trade.  s    0 	"..u6HII*'--c22E5zzH!||"'("'(''!++&)O&;O NN?S+@?+RSS		 55e=OQVWW	 $Iv..%--vveeY//!!$//&&ug66,,T-?-?~W^-_-_``%%eW55
((66$ ,,UNCCM"77FFO%+ C "Y//X&  " 
  
   	r   c                 4   |                                   |                     |          }|d         |d         d}|||d<   |                     |                     ||                    }|                     |dg           }|                     ||||          S )aJ  
        get the list of most recent trades for a particular symbol
        :see: https://apidocs.bithumb.com/reference/%EC%B5%9C%EA%B7%BC-%EC%B2%B4%EA%B2%B0-%EB%82%B4%EC%97%AD
        :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   Nr   r   )r   r   (publicGetTransactionHistoryBaseIdQuoteIdr   r)  parse_trades	r   r   r%  r   r   r   r   r   r   s	            r   fetch_tradeszbithumb.fetch_tradesv  s     	V$$X&i(
 
 $GG@@WV\A]A]^^ ~~h33  vue<<<r   r   r;  r   r   c                    |                                   |                     |          }|d         |d         |d}d}	|dk    r||d<   |dk    rdnd	|d
<   nd|                     |          z   }	 t          | |	          |                     ||                    }
|                     |
d          }|t          | j        dz             |                     |
||||d|          S )a  
        create a trade order
        :see: https://apidocs.bithumb.com/reference/%EC%A7%80%EC%A0%95%EA%B0%80-%EC%A3%BC%EB%AC%B8%ED%95%98%EA%B8%B0
        :see: https://apidocs.bithumb.com/reference/%EC%8B%9C%EC%9E%A5%EA%B0%80-%EB%A7%A4%EC%88%98%ED%95%98%EA%B8%B0
        :see: https://apidocs.bithumb.com/reference/%EC%8B%9C%EC%9E%A5%EA%B0%80-%EB%A7%A4%EB%8F%84%ED%95%98%EA%B8%B0
        :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 fullfilled, 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   )order_currencypayment_currencyr7  privatePostTradePlacer   r   r4  r   r   r   privatePostTradeMarketorder_idNz) createOrder() did not return an order id)r   r   r   r;  r|   )	r   r   
capitalizegetattrr   r   r   r|   
safe_order)r   r   r   r;  r   r   r   r   r   methodr   r|   s               r   create_orderzbithumb.create_order  s    	V$$$Tl &w
 

 )7??$GG(,eeEGFOO-0E0EEF(74((Wf)E)EFFh
33:tw)TTUUU 
  
   	r   r|   c                    |t          | j        dz             |                                  |                     |          }|d|d         |d         d}|                     |                     ||                    }|                     |d          }|                     |                     |d|i          |          S )	a  
        fetches information on an order made by the user
        :see: https://apidocs.bithumb.com/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%83%81%EC%84%B8-%EC%A1%B0%ED%9A%8C
        :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>`
        Nz( fetchOrder() requires a symbol argumentr  r   r   )r[  r   rW  rX  r   r[  )r   r|   r   r   privatePostInfoOrderDetailr   r  parse_order)r   r|   r   r   r   r   r   r   s           r   fetch_orderzbithumb.fetch_order  s     >#DG.X$XYYYV$$$Vn &w	
 
 224;;w3O3OPP8 ~~h//D:r2B C CVLLLr   c                 <    dddd}|                      |||          S )Nr  closedcanceled)Pending	CompletedCancel)r   )r   statusstatusess      r   parse_order_statuszbithumb.parse_order_status  s1    ! 
 

 &&999r   c           	         |                      |dd          }|                     |dd          }|dk    rdnd}|                     |                     |d                    }|                     |d	d
          }d}t          j        |d          rd}|                     |                     |dd                    }	|                     |                     |d                    }
|
|dk    rd}
n|dk    r|	}
d }|                     |d          }|                     |d          }|                     |          }|                     |          }|
||dz   |z   }|| 	                    d |          }|d         }|                     |d          }| 
                    |dg           }|                     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&|          S )'N
order_dater2  r   r;  r   r4  r3  order_statusorder_pricer   r   r1  r   	order_qtyr7  units_remainingrf  rg  rW  rX  r   r   r[  r   r   r|   clientOrderIdr   r   lastTradeTimestamptimeInForcepostOnly	stopPricetriggerPricer   rp   r
  )filled	remainingrk  r8  trades)r?  safe_value_2rm  r   rA  r!   string_equalsr@  r   r   r   r^  r  )r   r:  r   r   sidePropertyr;  rk  r   r   r   r{  r   r   r   r   r   r|   	rawTradess                     r   rc  zbithumb.parse_order  s   R --e\5II	((??%..uuV(()9)9%)P)PQQ""5-AA ,, 	D&&t'9'9%g'V'VWW))$*:*:5BS*T*TUU	!!		:%%"	!!%)9::""5*<==&&v..''005#4CZ%'F>%%dF33FH%FeZ00OOE:r::	  
E 
" 
 T 
 	 

 Y// 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
  
 D 
 f 
  D! 
" t# 
$ "- 
  
  
. /  	r   c                 p   |t          | j        dz             |                                  |                     |          }|d}||d         |d         d}|||d<   |                     |                     ||                    }|                     |dg           }|                     ||||          S )	aE  
        fetch all unfilled currently open orders
        :see: https://apidocs.bithumb.com/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%A1%B0%ED%9A%8C
        :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 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>`
        Nz- fetchOpenOrders() requires a symbol argumentrq   r   r   )r   rW  rX  afterr   )r   r|   r   r   privatePostInfoOrdersr   r)  parse_ordersrT  s	            r   fetch_open_orderszbithumb.fetch_open_ordersW  s     >#DG.]$]^^^V$$=E$Vn &w
 

 $GG--dkk'6.J.JKK$ ~~h33  vue<<<r   c                 `   |t          | j        dz             d|v }|st          | j        dz             |                     |          }|d         dk    rdnd}|                     |ddg          }|||d	         |d
         d}|                     |                     ||                    S )a  
        cancels an open order
        :see: https://apidocs.bithumb.com/reference/%EC%A3%BC%EB%AC%B8-%EC%B7%A8%EC%86%8C%ED%95%98%EA%B8%B0
        :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>`
        Nz) cancelOrder() requires a symbol argumentr;  z7 cancelOrder() requires a `side` parameter(sell or buy)r4  r   r   r   r   r   )r[  r   rW  rX  )r   r|   r   r  privatePostTradeCancelr   )r   r|   r   r   side_in_paramsr   r;  r   s           r   cancel_orderzbithumb.cancel_order  s     >#DG.Y$YZZZ F* 	i#DG.g$ghhhV$$500uuu6FJ#788 $Vn &w	
 
 **4;;w+G+GHHHr   c                     d|d         i}|                      |d         |d         |                     ||                    S )Nr;  r|   r   )r  r   )r   r:  r   r   s       r   cancel_unified_orderzbithumb.cancel_unified_order  sC    E&M
   teHot{{7TZ?[?[\\\r   r   c                    |                      ||          \  }}|                     |           |                                  |                     |          }|||d         d}|dk    s|dk    s|dk    s|dk    r>|                     |d          }||t          | j        d	z   |z   d
z             |||d<   |                     |                     ||                    }	| 	                    |	|          S )a  
        make a withdrawal
        :see: https://apidocs.bithumb.com/reference/%EC%BD%94%EC%9D%B8-%EC%B6%9C%EA%B8%88%ED%95%98%EA%B8%B0-%EA%B0%9C%EC%9D%B8
        :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|   )r7  addressr   XRPXMREOSSTEEMdestinationNr/  zA withdraw() requires a tag argument or an extra destination param)
handle_withdraw_tag_and_paramscheck_addressr   r   r   r   r|   privatePostTradeBtcWithdrawalr   parse_transaction)
r   r   r   r  tagr   r   r   r  r   s
             r   rV   zbithumb.withdraw  s&    99#vFFV7###==&& 
 

 5==DEMMTU]]dgoo**6=AAK+"5'#(<  @C  )C  D  D  D),&55dkk'66R6RSS %%h999r   r   c                     |                      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 d d |dS )Nr|   txidr   r   networkaddressFromr  	addressTor   r   r   r   rk  updatedtagFromr  tagTocomment)internalr8  r   )safe_currency)r   transactionr   s      r   r  zbithumb.parse_transaction  s
    %%dH55
$
D
 
 	

 t
 4
 t
 
 d
 D
 (
 d
 t
 t
 4
  T!
" t#
$ )
 
 
 	
r   c                     |d S |}|                     d          dk    r/|                    dd          }|                     d          dk    /|S )N, )findreplace)r   	numberStrfinalNumberStrs      r   r@  zbithumb.fix_comma_number  sa    4"!!#&&+++33C<<N !!#&&++r   c                 *    |                                  S N)milliseconds)r   s    r   noncezbithumb.nonce  s      """r   rW   GETc                    d|                      ||          z   }|                     | j        d         |                   |z   }|                     ||                     |                    }	|dk    r|	r|d|                     |	          z   z  }n|                                  |                     |                     d|i|	                    }t          | 	                                          }
|dz   |z   dz   |
z   }| 
                    |                     |          |                     | j                  t          j                  }|                     |          }dd| j        ||
d	}||||d
S )Nr   rZ   rW   ?endpoint zapplication/jsonz!application/x-www-form-urlencoded)AcceptzContent-TypezApi-KeyzApi-Signz	Api-Nonce)urlr_  bodyheaders)implode_paramsimplode_hostnamer   r  extract_params	urlencodecheck_required_credentialsr   strr  hmacencodesecrethashlibsha512string_to_base64apiKey)r   pathrZ   r_  r   r  r  r  r  queryr  auth	signaturesignature64s                 r   signzbithumb.sign  st   ,,T6:::##DIe$4S$9::XE		&$"5"5d";";<<(?? 3sT^^E2222++--->>$++H/# #  D 

%%Ed?T)D058D		$++d"3"3T[[5M5Mw~^^I//	::K, C;'" G fdwOOOr   c
                 :   |d S d|v r|                      |d          }
|                      |d          }|
d|
dk    rd S |dk    rd S | j        dz   |z   }|                     | j        |
|           |                     | j        ||           t	          |          d S )Nrk  message0000u8   거래 진행중인 내역이 존재하지 않습니다.r/  )r   r|   throw_exactly_matched_exceptionr   r   )r   httpCodereasonr  r_  r  r  r   requestHeadersrequestBodyrk  r  feedbacks                r   handle_errorszbithumb.handle_errors  s    4x %%h99F&&x;;G!V##4 ZZZ47S=7244T_fhWWW44T_gxXXX#H---tr   )NNNNr  )3__name__
__module____qualname__r   r   r   r	   r   r   r   r   r   r   r   r  r   r   r   r   r  r   r   r  r  r   r$  r,  r   rP  rU  r   r   floatr
   r`  rd  rm  r   rc  r  r  r  rV   r   r   r  r@  r  r  r  __classcell__)r   s   @r   r#   r#      s       d d d d dLU UC U URU Ujm U  zI U U U U U Ux x x $& N N$v, N N N N`) ) ) ) ) $& , ,( , , , , :>b (c (cs (c3 (cY (c (c (c (cT. .6 .V . . . .` 04B 4G 4GW 4G7 4G 4G 4G 4Gl 02 #/ #/3 #/f #/ #/ #/ #/J
 
 
4 
 
 
 
( 26DW[df +H +H# +Hc +HQT +Hkoptku +H +H +H +HZF F F5 F F F FP 6:UW "= "=3 "=s "=# "=\`af\g "= "= "= "=H gksu % %3 %i %y %RW %`c % % % %N 26b /M /Mc /M3 /M /M /M /Mb: : :[ [ [5 [ [ [ [z /3TXac *= *= *=3 *=c *=hlmrhs *= *= *= *=X 37r I Is IC I I I I4 24 ] ] ] ] ?C2 : :S :% : : : :@
 
x 
; 
 
 
 
<  # # # &eBSW P P P P2      r   r#   )(ccxt.base.exchanger   ccxt.abstract.bithumbr   r  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr   r   r    ccxt.base.preciser!   r#    r   r   <module>r     s6   ( ' ' ' ' ' - - - - - -  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m  m       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' + + + + + + ) ) ) ) ) ) 1 1 1 1 1 1 3 3 3 3 3 3 9 9 9 9 9 9 = = = = = = % % % % % %@ @ @ @ @h @ @ @ @ @r   