
    E#i
                     $   S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJ r   S SKJ!r!  S SK"J#r#  S SK"J$r$  S SK"J%r%  S SK&J'r'   " S S\\5      r(g)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransactionMarketInterface)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InvalidAddress)InvalidOrder)ExchangeNotAvailable)TRUNCATE)DECIMAL_PLACES)SIGNIFICANT_DIGITS)Precisec                     ^  \ rS rSrS\4U 4S jjrS@S\S\S\S\S\4
U 4S	 jjjr	S
 r
0 4S\\   4S jjrS\4S jr0 4S\4S jjrS0 4S\S\S\4S jjrSAS\S\S\4S jjrS0 4S\S\4S jjr0 4S\S\4S jjrSAS\S\4S jjrSSS0 4S\S\S\S\S\\   4
S jjrSAS\S\S\4S jjrSS0 4S\S\S\S\\   4S jjr S0 4S\S\!S\"S \#S!\$4
S" jjr%S0 4S#\S\4S$ jjr&S%\4S& jr'SAS'\S\S\(4S( jjr)SSS0 4S\S\S\S\\(   4S) jjr*S0 4S#\S\4S* jjr+0 4S'\(4S+ jjr,S0 4S,\S \#S-\S.\S\-4
S/ jjr.SAS0\S1\/S\-4S2 jjr0S3 r1S4 r2S5S60 SS4S7 jr3S8\4S9\S:\S;\S<\S=\4S> jr5S?r6U =r7$ )Bbithumb   returnc                 z  > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_S0 SS
_SS
_SS_SS_SS_SS_SS_SS_SS_SS_SS
_SS_SS_SS
_SS
_SS_SS_0 SS_SS
_S S_S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_E0 S/S_S0S_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S
_S?S_E0 S@S_SAS_SBS_SCS
_SDS_SES_SFS_SGS
_SHS_SIS_SJS
_SKS
_SLS_SMS_SNS_SOS_SPS_E0 SQS_SRS_SSS_STS_SUS
_SVS
_SWS
_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_ESS
Sb.E_ScSd_SeSfSgShSi.SjSkSlSm._SnSo/ SpQ0Sq/ SrQ0Si._SsStU R	                  Su5      U R	                  Su5      Sv.0_Sw[
        _SxSSSS SSSS SSSSSy.SSSSSSSSz.S S SSSS
S{.SS|SSS
S}.S S S~S|0S.	S S S.S S S.S._S[        [        [        [        [        [        [        [        [        [        [        [        [        S._SSSSSSSSSSS.	_SSSSSSS.00SSSSS.00SSS S S.00S.0_SSSSS._5      $ )Nidr$   nameBithumb	countriesKR	rateLimiti  proThasCORSspotmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreateReduceOnlyOrderfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistory
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTransferfetchTransfersfetchVolatilityHistoryreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionMode)transferwithdrawhostnamezbithumb.comurlszOhttps://github.com/user-attachments/assets/c9e0eefb-4777-46b9-8f09-9d7f7c4af82dz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feesr   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_limitr   tradingz0.0025)makertakerprecisionModefeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventioniceberg)r   triggerr   symbolRequiredi  )r   limitr   r   r   r   )	sandboxr>   createOrdersfetchMyTradesrm   rj   fetchOrdersfetchClosedOrdersrf   )linearinverse)r1   r3   r4   
exceptions)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
timeframes1m3m5m10m30m1h6h12h24h)	r   r   r   r   r   r   r   r   1doptionsquoteCurrencieslimitscostg-C6*?d   minmaxl    rT )BTCKRWUSDTcommonCurrenciesArchLootFTC2z	Soda Coin)ALTFTCSOC)deep_extendsuperr$   describeparse_numberr!   r   r   r   r   r   r   )self	__class__s    F/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/bithumb.pyr   bithumb.describe   s   gt = ? JB
)JB
IJB
 $JB
 	JB

 4JB
  XXX %X 	X
 %X %X UX $UX 'X X tX $UX  X $TX tX  7!X" 9%#X$ (%X& 'X( &u)X* "5+X, +E-X. )%/X0 #E1X2 ,U3X4 '5X6 (7X8 "59X: &u;X< '=X> (?X@ #EAXB *5CXD $UEXF uGXH "5IXJ *5KXL +EMXN )%OXP  QXR !%SXT %eUXV $UWXX &uYXZ -e[X\ /]X^ "5_X` #EaXb +EcXd eXf !%gXh "5iXj &ukXl +EmXn doXp $UqXr +EsXt %euXv "4wXx uyXz #E{X| d}X~ !$X@  AXB 'CXD $UEXF !%GXH *5IXJ (KXL %eMXN )%OXP )%QXR tSXT UXV tWXX  YXZ !%[X\ )%]X^ _X` #EaXb &ucXd ueXf UgXh  iXj "5kXl " oXJB
~ JB
@ i=7 14J	AJB
T  $  %%UJB
` !..x8!..x8aJB
l /mJB
p $&+(-,0,1).+06:#(#("'#(	( #($)$)27+0/4#()$, %)%)&+#($)*.	# ',!%#($)*.( $()-#S,\ ##
 ##e6qJB
^ $.+5+>1"52B3A/?!5%/%!. ER_JB
| 
}JB
R ! "'-'*%# !"'*'1%# !"'+'+%##$SJB
J !"!KJB
 J J	    NmarketIdmarket	delimiter
marketTypec                 .   > [         [        U ]  XUS5      $ )Nr1   )r   r$   safe_market)r   r   r   r   r   r   s        r   r   bithumb.safe_market(  s    
 Wd/)VTTr   c                 `    U R                  U[        U R                  U   S   S   [        5      $ )N	precisionamount)decimal_to_precisionr   marketsr    )r   symbolr   s      r   amount_to_precisionbithumb.amount_to_precision/  s/    ((4<<;OP[;\]e;fhvwwr   c                    / nU R                  U R                  S0 5      n[        UR                  5       5      n/ n[	        S[        U5      5       H8  nSXF   0nUR                  U R                  U R                  Xq5      5      5        M:     Un[	        S[        U5      5       GH?  nXF   n	U	n
X   nU R                  US5      nU R                  X90 5      n[        UR                  5       5      n[	        S[        U5      5       H  nX   nUS:X  a  M  UU   nU R                  U5      nSn[        U[        5      (       a  [        U5      nUS:X  a  SnU R                  0 SU_S	US
-   U	-   _SU_SU	_SS_SU_SU
_SS_SS_SS_SS_SS_SS_SS_SU_SS_SS_SSSSSS[        S5      [        S5      S.SSS.SSS.SSS.0 S.SUS.
EU5      nUR                  U5        M     GMB     U$ )a+  
retrieves data on all markets for bithumb

https://apidocs.bithumb.com/v1.2.0/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
r   r   quoteIddatadateTFr(   r   /basequotesettleNbaseIdsettleIdtyper1   r2   r3   r4   r5   activecontractr   4)r   pricer   )r   r   r   r   )
r   contractSizeexpiryexpiryDateTimestrike
optionTyper   r   createdinfo)	safe_dictr   listkeysrangelenappendpublicGetTickerALLQuoteIdextendsafe_currency_code
isinstancer   int)r   paramsresultr   quotespromisesirequestresultsr   r   responser   	extensioncurrencyIdsj
currencyIdr   r   r   numElementsentrys                         r   fetch_marketsbithumb.fetch_markets2  s    ..7H"Mo**,-q#f+&A69G OOD::4;;w;WXY	 'P q#f+&AIEGzH>>(F3DrBItyy{+K1c+./(^
'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 0 'B r   c                    SU0nU R                  US5      n[        U R                  R                  5       5      n[	        S[        U5      5       H  nXE   nU R                  5       nU R                  U5      nU R                  US5      n	U R                  USU	-   5      US'   U R                  USU	-   5      US'   U R                  US	U	-   5      US
'   XrU'   M     U R                  U5      $ )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_balancebithumb.parse_balance  s    )>>(F3T__))+,q#e*%A8DllnG}}T*H"44XtDO#//(_:TUGG"..x_9TUGFO"..x9WXGFO"4L &   ((r   c                     U R                  5         SS0nU R                  U R                  X!5      5      nU R                  U5      $ )ah  
query for balance and get the amount of funds available for trading or funds locked in orders

https://apidocs.bithumb.com/v1.2.0/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_balancebithumb.fetch_balance  sH     	
 ..t{{7/KL!!(++r   r   r   c           	         U R                  5         U R                  U5      nUS   US   S.nUb  X%S'   U R                  U R                  XS5      5      nU R	                  US0 5      nU R                  US5      nU R                  XqUSSS	S
5      $ )a+  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://apidocs.bithumb.com/v1.2.0/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   countr   	timestampbidsasksr   quantity)r0  r   publicGetOrderbookBaseIdQuoteIdr  r   safe_integerparse_order_book)	r   r   r   r  r   r  r  r   r7  s	            r   fetch_order_bookbithumb.fetch_order_book  s     	V$X&i(
 $G77G8TU* ~~h3%%dK8	$$T9ffgWabbr   tickerc                    U R                  US5      nU R                  S U5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU R	                  U5      _S	U R                  US
5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SS _SS _SU_SU_SU_SS _SS _SS _SS _UUUS.EU5      $ )Nr   opening_priceclosing_priceunits_traded_24Hacc_trade_value_24Hr   r7  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   r@  r   r7  r   rR  rS  rY  rZ  s	            r   parse_tickerbithumb.parse_ticker  s   & %%ff5	!!$/8  9%%f.@A
&&v/DE !
f!
!
 Y/!
 D$$V[9	!

 4##FK8!
 4##FK8!
 !
 4##FL9!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ %&)!
* + 	r   symbolsc           	         U R                  5         0 nU R                  U R                  S0 5      n[        UR	                  5       5      n/ n[        S[        U5      5       H8  nSXW   0nUR                  U R                  U R                  X5      5      5        M:     Un	[        S[        U5      5       H  nXW   n
X   nU R                  US0 5      nU R                  US5      nU R                  US5      n[        UR	                  5       5      n[        S[        U5      5       HQ  nUU   nUU   nU R                  U5      nUS-   U
-   nU R                  U5      nUUS'   U R                  UU5      UU'   MS     M     U R                  USU5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://apidocs.bithumb.com/v1.2.0/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>`
r   r   r   r   r   r   r   )r0  r   r   r  r  r  r  r  r  r  r<  omitr  r   r^  filter_by_array_tickers)r   r`  r  r  r   r  r  r  r  	responsesr   r  r   r7  tickersr  r  r  r@  r   r   r   s                         r   fetch_tickersbithumb.fetch_tickers&  s    	..7H"Mo**,-q#f+&A69G OOD::4;;w;WXY	 '
 	q#f+&AIE |H, >>(FB7D))$7Iiif-Gw||~.K1c+./(^
j)..z:e+))&1!*v!%!2!266!Bv 09 'H ++FHgFFr   c                     U R                  5         U R                  U5      nUS   US   S.nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://apidocs.bithumb.com/v1.2.0/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   r5  r   )r0  r   publicGetTickerBaseIdQuoteIdr  r   r^  )r   r   r  r   r  r  r   s          r   fetch_tickerbithumb.fetch_tickera  su     	V$X&i(
 44T[[5QR( ~~h3  ..r   c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr                  )r<  safe_number)r   ohlcvr   s      r   parse_ohlcvbithumb.parse_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
r   r   	timeframesincec                    U R                  5         U R                  U5      nUS   US   U R                  U R                  X"5      S.nU R	                  U R                  Xu5      5      nU R                  US/ 5      n	U R                  XX#U5      $ )aU  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://apidocs.bithumb.com/v1.2.0/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   )r0  r   r&  r   )publicGetCandlestickBaseIdQuoteIdIntervalr  	safe_listparse_ohlcvs)
r   r   rv  rw  r   r  r   r  r  r   s
             r   fetch_ohlcvbithumb.fetch_ohlcv  s     	V$X&i((()O

 AA$++gB^_0 ~~h3  yGGr   tradec                    S nU R                  US5      nUbk  UR                  S5      n[        U5      nUS:  a6  US   nUS   n[        U5      S:  a  SU-   nU R                  US-   U-   5      nOU R	                  USS5      nUb  US-  nS n	U R                  US	5      n
U
S
:X  a  SOSn
U R                  US5      nU R                  S U5      nU R                  US5      nU R                  U R                  USS5      5      nU R                  US5      nS nU R                  US5      nUb(  U R                  US5      nU R                  U5      nUUS.nU R                  UUUU R                  U5      US   S U	U
S UUUUS.U5      $ )Ntransaction_date rm  r      0MbP?ibr   rN  sellbuycont_nor   units_tradedunitsr  feefee_currency)r   r$  r   )r(   r   r7  rF  r   orderr   sidetakerOrMakerr   r   r   r  )r&  splitr  	parse8601safe_integer_productr   fix_comma_numbersafe_string_2common_currency_code
safe_trader]  )r   r  r   r7  transactionDatetimepartsnumPartstransactionDatetransactionTimer   r  r(   priceStringamountString
costStringr  feeCostStringfeeCurrencyIdfeeCurrencyCodes                      r   parse_tradebithumb.parse_trade  s   0 	"..u6HI*'--c2E5zH!|"'("'('!+&)O&;O NN?S+@?+RS	 55e=OQVW	 $Iv.%-veeY/!!$/&&ug6,,T-?-?~W^-_`%%eW5
((6$ ,,UNCM"77FO%+C "Y/X&  " 
  	r   c                     U R                  5         U R                  U5      nUS   US   S.nUb  X6S'   U R                  U R                  Xd5      5      nU R	                  US/ 5      nU R                  XX#5      $ )a  
get the list of most recent trades for a particular symbol

https://apidocs.bithumb.com/v1.2.0/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   r5  r6  r   )r0  r   (publicGetTransactionHistoryBaseIdQuoteIdr  r{  parse_trades	r   r   rw  r   r  r   r  r  r   s	            r   fetch_tradesbithumb.fetch_trades  s     	V$X&i(
 $G@@WA]^ ~~h3  u<<r   r   r  r   r   c                    U R                  5         U R                  U5      nUS   US   US.nSn	US:X  a  XXS'   US:X  a  SOS	US
'   OSU R                  U5      -   n	[        X	5      " U R	                  X5      5      n
U R                  U
S5      nUc  [        U R                  S-   5      eU R                  U
UUUUS.U5      $ )ac  
create a trade order

https://apidocs.bithumb.com/v1.2.0/reference/%EC%A7%80%EC%A0%95%EA%B0%80-%EC%A3%BC%EB%AC%B8%ED%95%98%EA%B8%B0
https://apidocs.bithumb.com/v1.2.0/reference/%EC%8B%9C%EC%9E%A5%EA%B0%80-%EB%A7%A4%EC%88%98%ED%95%98%EA%B8%B0
https://apidocs.bithumb.com/v1.2.0/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 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   )order_currencypayment_currencyr  privatePostTradePlacer   r   r  rK  rN  r   privatePostTradeMarketorder_idz) createOrder() did not return an order id)r   r   r   r  r(   )	r0  r   
capitalizegetattrr  r&  r   r(   
safe_order)r   r   r   r  r   r   r  r   r  methodr  r(   s               r   create_orderbithumb.create_order9  s      	V$$Tl &w

 )7?$G(,eEGFO-0EEF4(W)EFh
3:tww)TTUU 
  	r   r(   c                 @   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUSUS   US   S.nU R	                  U R                  XS5      5      nU R                  US5      nU R                  U R                  USU05      U5      $ )a  
fetches information on an order made by the user

https://apidocs.bithumb.com/v1.2.0/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 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 argumentrm  r   r   )r  r6  r  r  r   r  )r   r(   r0  r   privatePostInfoOrderDetailr  r   parse_order)r   r(   r   r  r   r  r  r   s           r   fetch_orderbithumb.fetch_orderb  s     >#DGG.X$XYYV$$Vn &w	
 224;;w3OP8 ~~h/D:r2B CVLLr   statusc                 2    SSSS.nU R                  X!U5      $ )NrR  closedcanceled)Pending	CompletedCancel)r&  )r   r  statusess      r   parse_order_statusbithumb.parse_order_status  s'    ! 

 &99r   r  c                    U R                  USS5      nU R                  USS5      nUS:X  a  SOSnU R                  U R                  US5      5      nU R                  US	S
5      nSn[        R
                  " US5      (       a  SnU R                  U R                  USS5      5      n	U R                  U R                  US5      5      n
U
c  US:X  a  Sn
OUS:w  a  U	n
S nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nUb  Ub  US-   U-   nUc  U R                  S U5      nUS   nU R                  US5      nU R                  US/ 5      nU R                  0 SU_SU_SS _SU_SU R                  U5      _SS _SU_SU_SS _S S _SU_S
U_S!S _S"U	_S#S _S$S _S%S _U
US US&.EU5      $ )'N
order_dater  r   r  rK  r  r  order_statusorder_pricer   r   r  r   	order_qtyr  units_remainingr  r  r  r  r   r   r  r   r   r(   clientOrderIdr7  rF  lastTradeTimestampr   postOnlyr   r   r   rX  filled)	remainingr  r  trades)r  r  r  r&  r"   string_equalsr  r  r   r{  r  r]  )r   r  r   r7  sidePropertyr  r  r   r   r   r  r   r   r   r   r   r(   	rawTradess                     r   r  bithumb.parse_order  s   R --e\5I	))%@%.uV(()9)9%)PQ""5-A  ,,D&&t'9'9%g'VW))$*:*:5BS*TU	!	:%"	!!%)9:""5*<=&&v.''05#4CZ%'F>%%dF3FH%FeZ0NN5*b9	  
E 
" 
 T 
 	 

 Y/ 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
 D 
 f 
 D 
  t! 
" d# 
$ #+ 
, - 	r   c                 4   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUc  SnUUS   US   S.nUb  X&S'   U R	                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#5      $ )a  
fetch all unfilled currently open orders

https://apidocs.bithumb.com/v1.2.0/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>`
z- fetchOpenOrders() requires a symbol argumentr   r   r   )r6  r  r  afterr   )r   r(   r0  r   privatePostInfoOrdersr  r{  parse_ordersr  s	            r   fetch_open_ordersbithumb.fetch_open_orders  s     >#DGG.]$]^^V$=E$Vn &w

 $G--dkk'.JK$ ~~h3  u<<r   c                 d   Uc  [        U R                  S-   5      eSU;   nU(       d  [        U R                  S-   5      eU R                  U5      nUS   S:X  a  SOSnU R                  USS/5      nUUUS   US	   S
.nU R	                  U R                  Xs5      5      nU R                  SU05      $ )a{  
cancels an open order

https://apidocs.bithumb.com/v1.2.0/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>`
z) cancelOrder() requires a symbol argumentr  z7 cancelOrder() requires a `side` parameter(sell or buy)r  rK  rN  r$  r   r   )r  r   r  r  r   )r   r(   r   rb  privatePostTradeCancelr  r  )	r   r(   r   r  side_in_paramsr   r  r  r  s	            r   cancel_orderbithumb.cancel_order(  s     >#DGG.Y$YZZ F*#DGG.g$ghhV$50uu6FJ#78 $Vn &w	
 ..t{{7/KL H 
  	r   c                 `    SUS   0nU R                  US   US   U R                  X25      5      $ )Nr  r(   r   )r  r  )r   r  r  r  s       r   cancel_unified_orderbithumb.cancel_unified_orderL  s:    E&M
   teHot{{7?[\\r   r*  addresstagc                    U R                  XE5      u  pEU R                  U5        U R                  5         U R                  U5      nUUUS   S.nUS:X  d  US:X  d  US:X  d  US:X  d  US:X  a=  U R	                  US5      nUc!  Uc  [        U R                  S	-   U-   S
-   5      eUb  XGS'   U R                  U R                  Xu5      5      n	U R                  X5      $ )a  
make a withdrawal

https://apidocs.bithumb.com/v1.2.0/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(   )r  r  r$  XRPXMREOSSTEEMTONdestinationr  zA withdraw() requires a tag argument or an extra destination param)
handle_withdraw_tag_and_paramscheck_addressr0  r$  r&  r   r(   privatePostTradeBtcWithdrawalr  parse_transaction)
r   r*  r   r  r  r  r$  r  r  r  s
             r   r   bithumb.withdrawR  s     99#F7#==& 

 5=DEMTU]dgoQUY^Q^**6=AK+"5'#(<  @C  )C  D  D),&55dkk'6RS %%h99r   transactionr$  c                     U R                  S U5      n0 SS _SS _SS _SS _SS _SS _SS _SS _S	S _S
S _SUS   _SS _SS _SS _SS _SS _SS _S S US.E$ )Nr(   txidr7  rF  networkaddressFromr  	addressTor   r   r$  r*  r  updatedtagFromr  tagTocomment)internalr  r   )safe_currency)r   r  r$  s      r   r  bithumb.parse_transactiont  s     %%dH5
$
D
 
 	

 t
 4
 t
 
 d
 D
 (
 d
 t
 t
 4
  T!
" t#
$ )
 	
r   c                     Uc  g UnUR                  S5      S:  a)  UR                  SS5      nUR                  S5      S:  a  M)  U$ )N, )findreplace)r   	numberStrfinalNumberStrs      r   r  bithumb.fix_comma_number  sP    "!!#&++33C<N !!#&+r   c                 "    U R                  5       $ N)milliseconds)r   s    r   noncebithumb.nonce  s      ""r   r   GETc                    SU R                  X5      -   nU R                  U R                  S   U   5      U-   nU R                  X@R	                  U5      5      n	US:X  a  U	(       a  USU R                  U	5      -   -  nOU R                  5         U R                  U R                  SU0U	5      5      n[        U R                  5       5      n
US-   U-   S-   U
-   nU R                  U R                  U5      U R                  U R                  5      [        R                  5      nU R                  U5      nSSU R                   UU
S	.nXXeS
.$ )Nr   r   r   ?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   rb  extract_params	urlencodecheck_required_credentialsr  strr
  hmacencodesecrethashlibsha512string_to_base64apiKey)r   pathr   r  r  r  r  r  r  queryr
  auth	signaturesignature64s                 r   signbithumb.sign  s5   ,,T::##DIIe$4S$9:XE		&"5"5d";<(?sT^^E222++->>$++H/# D 

%Ed?T)D058D		$++d"3T[[5Mw~~^I//	:K, C;;'"G dOOr   httpCodereasonr  r  r  r  c
                 ,   Uc  g SU;   a  U R                  US5      n
U R                  US5      nU
bc  U
S:X  a  g US:X  a  g U R                  S-   U-   nU R                  U R                  X5        U R                  U R                  X5        [	        U5      eg )Nr  message0000u8   거래 진행중인 내역이 존재하지 않습니다.r  )r&  r(   throw_exactly_matched_exceptionr   r   )r   r)  r*  r  r  r  r  r  requestHeadersrequestBodyr  r,  feedbacks                r   handle_errorsbithumb.handle_errors  s    x %%h9F&&x;G!V# ZZ77S=7244T__fW44T__gX#H--r    )NNNNr  )8__name__
__module____qualname____firstlineno__r   r   r   r	   r   r   r   r   r  r   r,  r2  r  r   r   r>  dictr   r^  r   r   rf  rj  r  rt  r}  r   r  r  r   r   floatr
   r  r  r  r   r  r  r  r  r   r   r   r  r  r
  r'  r
  r2  __static_attributes____classcell__)r   s   @r   r$   r$      s.   K# KZUC U URU Ujm U  zI U Ux $& w$v, wr) ) $& ,( ,  :>b *cs *c3 *cY *cX.4 . .6 .` 04B 9GW 9G7 9Gv 02 %/3 %/f %/N
 
4 
( 9=4^bkm -H# -H# -HS -HX[ -Hrvw{r| -H^F Fv F FP 6:UW $=3 $=s $=# $=\`af\g $=L gksu '3 'i 'y 'RW '`c 'R 26b 2Mc 2M3 2Mh: :Z Zv Z Zx /3TXac ,= ,=3 ,=c ,=hlmrhs ,=\ 37r "s "C "H 9; ]% ] KOWY  :S  :%  :#  :C  :^i  :D
T 
X 
Q\ 
<# &eBSW P2c 3 S # X\ dg  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   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r   ccxt.base.decimal_to_precisionr   r    r!   ccxt.base.preciser"   r$   r4  r   r   <module>rD     se    ( -  r  r  r  r  r  * 0 - . ' + ) 1 3 9 = %qh qr   