
    !:hN                       d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z  d d
lm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dl%m&Z& d dl'm(Z(  G d dee      Z)y)    )Exchange)ImplicitAPI)AnyBalancesCurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickers
OrderBooksTradeTradingFeeInterfaceTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)AddressPending)InvalidOrder)OrderNotFound)	TICK_SIZE)Precisec                   (    e Zd Zdef fdZi fdefdZi fdefdZi fdefdZi fdefd	Z	i fde
e   fd
ZdedefdZdefdZi fdefdZddi fdededefdZdi fdededefdZdKdededefdZdi fdedefdZi fdedefdZdKdededefdZddi fdededede
e   fdZi fdede fdZ!i fde"fdZ#dKdede$fdZ%dddi fdededede
e$   fd Z&di fded!e'd"e(de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di fdeded$e*d%e+d!e(d"e(de/fd(Z0dddi fde-dedede
e1   fd)Z2di fdede-fd*Z3dddi fde-dedede
e1   fd+Z4di fdede-fd,Z5d-e-fd.Z6dKd/ed0e7de1fd1Z8d-e-fd2Z9dKd3edede/fd4Z:dddi fde-dedede
e/   fd5Z;dddi fde-dedede
e/   fd6Z<dddi fde-dedefd7Z=di fdede-fd8Z>di fd9ede
e?   fd:Z@dKd0e7de?fd;ZAi fdede?fd<ZBi fdede?fd=ZCdi fded!e'd>ede1fd?ZDd@ ZEdAdBi ddfdCZFdDeGdEedFedGedHedIefdJZH xZIS )Lupbitreturnc                    | j                  t        t        |          i ddddddg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d&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0di d1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAdBdCdCdCdCdCdCdCdCdDdEdFdGdHdIdJdKdLdMdMdNdOdPdQdRdSdTi dUdVdWdVdXdVdYdVdZdVd[dVd\dVd]dVd^dVd_dVd`dVdadVdbdVdcdVdddVdedVdfdVdVdVdVdVdVdgii dhdidjdidkdidldidmdidndidodid@didpdidqdidrdidsdidtdidudidvdidwdidxdidydiidzdzdidididididid{did|did}d~dNddd| j	                  d      | j	                  d      dddi i ddddddd dddd dddddddddddddd d dddddddddddd dddddddddddid	d d dd d dddt
        dt        t        t        dt        t        t        t        t        t        t        t        t        t        d
dddddiddddi      S )Nidr&   nameUpbit	countriesKRversionv1	rateLimit2   proThasCORSspotmarginswapFfutureoptioncancelOrdercreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrder	editOrderfetchBalancefetchCanceledOrdersfetchClosedOrdersfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchPositionModefetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchWithdrawalfetchWithdrawalstransferwithdraw
timeframessecondsminutesdaysweeksmonthsyears)1s1m3m5m10m15m30m1h4h1d1w1M1yhostnamezapi.upbit.comurlszchttps://user-images.githubusercontent.com/1294454/49245610-eeaabe00-f423-11e8-9cba-4b0aed794799.jpgzhttps://{hostname})publicprivatezhttps://upbit.comzKhttps://docs.upbit.com/docs/%EC%9A%94%EC%B2%AD-%EC%88%98-%EC%A0%9C%ED%95%9Cz&https://upbit.com/service_center/guide)logoapiwwwdocfeesr   getz
market/all   zcandles/{timeframe}zcandles/{timeframe}/{unit}zcandles/secondszcandles/minutes/{unit}zcandles/minutes/1zcandles/minutes/3zcandles/minutes/5zcandles/minutes/10zcandles/minutes/15zcandles/minutes/30zcandles/minutes/60zcandles/minutes/240zcandles/dayszcandles/weekszcandles/monthszcandles/years)ztrades/tickstickerz
ticker/all	orderbookzorderbook/supported_levelsaccountsgq=
ףp?zorders/chanceorderzorders/closedorders/openorders/uuids	withdrawszwithdraws/chancezwithdraws/coin_addressesdepositszdeposits/chance/coindepositzdeposits/coin_addresseszdeposits/coin_addressztravel_rule/vaspszstatus/walletapi_keysg      @)orderszorders/cancel_and_newzwithdraws/coinzwithdraws/krwzdeposits/krwzdeposits/generate_coin_addressztravel_rule/deposit/uuidztravel_rule/deposit/txid(   )r   r   r   )r   postdeleter   z0.0025)	tierBased
percentagemakertaker)r   r   re   r   )tradingfundingfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventiontrailingiceberg)r   triggerr   symbolRequiredd   )r   limitr   r   r     i       )r   r   daysBackdaysBackCanceled	untilDaysr   r   r   r      )	sandboxr@   createOrdersrR   rV   rU   rY   rD   rS   )linearinverse)r5   r7   r8   precisionMode
exceptions)zThis key has expired.z?Missing request parameter error. Check the required parameters!z1side is missing, side does not have a valid value)
thirdparty_agreement_requiredout_of_scopeorder_not_foundinsufficient_fundsinvalid_access_keyjwt_verificationcreate_ask_errorcreate_bid_errorvolume_too_largeinvalid_funds)exactbroadoptionsKRWgMb@?)!createMarketBuyOrderRequiresPricetradingFeesByQuoteCurrencycommonCurrenciesTONzTokamak Network)deep_extendsuperr&   describeparse_numberr#   r   r   r!   r   r"   r   r   )self	__class__s    D/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/upbit.pyr   zupbit.describe   s@   eT ; = D@
'D@
GD@
 $D@
 t	D@

 D@
 4D@
  333 $3 	3
 %3 %3 t3 '3 /3 $T3 ,U3 03 t3 T3 3  &t!3" $T#3$ %3& &t'3( ()3* 1%+3,  -3. &u/30 #E132 *5334 $U536 "5738 "593: ;3< !%=3>  ?3@ dA3B +EC3D "4E3F dG3H !$I3J "4K3L uM3N $UO3P )%Q3R tS3T U3V tW3X "4Y3Z #D[3\ $U]3^ "4_3` #Da3b Ec3d De3D@
x    yD@
V WD@
X }23 +d@	YD@
l   $a-q 5a *1	
 1! ,Q ,Q ,Q -a -a -a -a .q ' (  )!!" (#$ )*"#&'%&67-6"D'   (	
 &t ' $T #D +D 3D #D / "4 24 0  ,T!" (#$ #D%* #&14*.)-(,:>4848	 "&')(,?$;BmD@
r !&"&!..x8!..x8	 "'"' "!	sD@
N $&+(-,0,1).+06:#'#'"'#(	( #($)+027/4$)#()$, %)%)&+#($)*/	# '+!$#($)*/( $(&+!%$*,-%&#($)*/	*  #e5n ##
 ##w?OD@
N YOD@
P -@WaIU 6F$4'4*;*=(;(5(5(4%1QD@
v 596/wD@
B (!CD@
 D D	    codec                 n    | j                          | j                  |      }| j                  |d   |      S Nr)   )load_marketscurrencyfetch_currency_by_id)r   r   paramsr   s       r   fetch_currencyzupbit.fetch_currency   s5     	==&(($@@r   r)   c                    d|i}| j                  | j                  ||            }| j                  |di       }| j                  |di       }| j                  |di       }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }d}||sd	}n|	d
k7  rd	}n|
|
rd	}n||rd	}| j                  |d      }| j                  |d|      }| j                  |d|      }d }t	        j
                  |d      r|}n|}| j                  |d      }| j                  |      }|||||| j                  |d      d d| j                  |d      | j                  |      didS )Nr   member_levelwithdraw_limitcan_withdrawwallet_statewallet_lockedlockedTFworkingonetimedailyremaining_daily0r   withdraw_feere   minimumminmax)infor)   r   r*   activefee	precisionlimits)	privateGetWithdrawsChanceextend
safe_valuesafe_stringr$   	string_gtsafe_currency_codesafe_numberr   )r   r)   r   requestresponse
memberInfocurrencyInfowithdrawLimitscanWithdrawwalletStatewalletLockedr   r   maxOnetimeWithdrawalmaxDailyWithdrawalremainingDailyWithdrawalmaxWithdrawLimit
currencyIdr   s                      r   r   zupbit.fetch_currency_by_id'  s    
 11$++gv2NON __X~rB
xR@3CRHoonnE&&|^Dz?CX6#[FI%F&LF fF#//	J!--ngG[\#'#3#3NDUWi#j 5s;71%%lF;
&&z2##L.A++NIF,,-=>
 	
r   symbolc                 n    | j                          | j                  |      }| j                  |d   |      S r   )r   marketfetch_market_by_id)r   r
  r   r  s       r   fetch_marketzupbit.fetch_market~  s5     	V$&&vd|V<<r   c                    d|i}| j                  | j                  ||            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j	                  |	      }| j	                  |
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  t        j                  ||            }| j                  i d|d	|d
z   |z   d|d|dd d|	d|
dd ddddddddddddd|dk(  dddd d ||d d d d d | j                  d      | j                  d      dd d d| j                  |d      d dd d d| j                  |d      | j                  |d       d|d!d"
      S )#Nr  bidaskr)   r   statebid_feeask_feer
  /basequotesettlebaseIdquoteIdsettleIdtyper5   Tr6   Fr7   r8   r9   r   contractr   1e-8)amountpricer   	min_total	max_total)r   r  r   costr   )
r   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper   r   )
privateGetOrdersChancer   r   r   r   r   r$   
string_maxsafe_market_structurer   )r   r)   r   r   r   
marketInfor  r  marketIdr  r  r  r  r  bidFeeaskFeer   s                    r   r  zupbit.fetch_market_by_id  s    b
 ..t{{7F/KLB __Xx8
ooj%0ooj%0##J5!!#z2""3
3&&v.''0  W5!!(I6!!(I6 2 266 BC)) 1+
(1+
dSj5(1+
 D1+
 U	1+

 d1+
 f1+
 w1+
 1+
 F1+
 D1+
 e1+
 E1+
 e1+
 e1+
 u(1+
  !1+
" d#1+
$  "++F3**62  
  ++C=
  
  ++C=++JD !#=1+
 1 1	r   c                 F    | j                  |      }| j                  |      S )u[  

        https://docs.upbit.com/kr/reference/마켓-코드-조회
        https://global-docs.upbit.com/reference/listing-market-list

        retrieves data on all markets for upbit
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )publicGetMarketAllparse_marketsr   r   r   s      r   fetch_marketszupbit.fetch_markets  s'     **62 !!(++r   r  c                 `   | j                  |d      }|j                  d      \  }}| j                  |      }| j                  |      }| j                  i d|d|dz   |z   d|d|dd d	|d
|dd dddddddddddddddddd d | j	                  | j
                  d   || j                  d   d         | j	                  | j
                  d   || j                  d   d         d d d d d | j                  d      | j                  d      dd d dd d dd d dd d ddd |d      S ) Nr  -r)   r
  r  r  r  r  r  r  r  r  r5   Tr6   Fr7   r8   r9   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   createdr   )r   splitr   r+  r   r   r   r   )r   r  r)   r  r  r  r  s          r   parse_marketzupbit.parse_market  s
   fh/((3-&&v.''0)) 2+
"2+
dSj5(2+
 D2+
 U	2+

 d2+
 f2+
 w2+
 2+
 F2+
 D2+
 e2+
 E2+
 e2+
 e2+
 d2+
  !2+
" d#2+
$ %%dll3O&PRWY]YbYbclYmnuYvw%%dll3O&PRWY]YbYbclYmnuYvw "**62++F3  
  
  
  $ c2+
 2 2	r   c                 2   |d d d}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )N)r   	timestampdatetimer   r   balancefreer   used)rangelenr   r   accountsafe_balance)r   r   resultir=  r	  r   rB  s           r   parse_balancezupbit.parse_balance;  s    

 q#h-( 	#AqkG))':>J**:6DllnG"..w	BGFO"..wAGFO"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )u  

        https://docs.upbit.com/kr/reference/전체-계좌-조회
        https://global-docs.upbit.com/reference/overall-account-inquiry

        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )r   privateGetAccountsrF  r3  s      r   fetch_balancezupbit.fetch_balanceK  s3     	**62 !!(++r   Nsymbolsr   c           
      l   | j                          d}|dj                  | j                        }n"| j                  |      }dj                  |      }d|i}| j	                  | j                  ||            }i }t        dt        |            D ]  }||   }	| j                  |	d      }
| j                  |
dd      }| j                  |	d      }|| j                  | j                  |	d   d	d
      dd      | j                  | j                  |	d   dd      d      || j                  |      dd||<    |S )u  

        https://docs.upbit.com/kr/reference/호가-정보-조회
        https://global-docs.upbit.com/reference/order-book-list

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data for multiple markets
        :param str[]|None symbols: list of unified market symbols, all symbols fetched if None, default is None
        :param int [limit]: not used by upbit fetchOrderBooks()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbol
        N,marketsr   r  r6  r;  orderbook_units	bid_pricebid_sizeT	ask_priceask_size)r
  bidsasksr;  r<  nonce)r   joinids
market_idspublicGetOrderbookr   r@  rA  r   safe_symbolsafe_integersort_byparse_bids_asksiso8601)r   rJ  r   r   rW  r   r   rD  rE  r   r-  r
  r;  s                r   fetch_order_bookszupbit.fetch_order_bookse  sH    	?((488$C//'*C((3-Cs
 **4;;w+GH: q#h-( 	A I''	8<H%%hc:F)))[AI T%9%9)DU:VXceo%prsuyzT%9%9)DU:VXceo%prst& LL3F6N	 r   c                 N    | j                  |g||      }| j                  ||      S )uv  

        https://docs.upbit.com/kr/reference/호가-정보-조회
        https://global-docs.upbit.com/reference/order-book-list

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :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
  r   r   
orderbookss        r   fetch_order_bookzupbit.fetch_order_book  s+     ++VHeVD
z622r   r   c                 P   | j                  |d      }| j                  |dd      }| j                  ||d      }| j                  |d      }| j	                  i d|d   d|d| j                  |      d	| j                  |d
      d| j                  |d      dd dd dd dd dd d| j                  |d      d|d|d| j                  |d      d| j                  |d      d| j                  |d      dd | j                  |d      | j                  |d      |d|      S ) Ntrade_timestampr  r   r6  trade_pricer
  r;  r<  high
high_pricelow	low_pricer  	bidVolumer  	askVolumevwapopenopening_pricecloselastpreviousCloseprev_closing_pricechangesigned_change_pricer   signed_change_rateaverageacc_trade_volume_24hacc_trade_price_24h)
baseVolumequoteVolumer   )r[  safe_string_2safe_marketr   safe_tickerr^  )r   r   r  r;  r-  rp  s         r   parse_tickerzupbit.parse_ticker  s   : %%f.?@	%%fh?!!(FC86 !
fX&!
!
 Y/!
 D$$V\:	!

 4##FK8!
 4!
 !
 4!
 !
 D!
 D$$V_=!
 T!
 D!
 T--f6JK!
 d&&v/DE!
  $**63GH!!
" t#!
$ **63IJ++F4IJ)!
* + 	r   c                    | j                          | j                  |      }d}|dj                  | j                        }n"| j	                  |      }dj                  |      }d|i}| j                  | j                  ||            }i }t        dt        |            D ]   }| j                  ||         }|d   }	|||	<   " | j                  |d|      S )uN  

        https://docs.upbit.com/kr/reference/ticker현재가-정보
        https://global-docs.upbit.com/reference/tickers

        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :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>`
        NrL  rM  r   r
  )r   market_symbolsrV  rW  rX  publicGetTickerr   r@  rA  r~  filter_by_array_tickers)
r   rJ  r   rW  r   r   rD  tr   r
  s
             r   fetch_tickerszupbit.fetch_tickers  s     	%%g.?((488$C//'*C((3-Cs
 ''GV(DE: q#h-( 	$A&&x{3FH%F#F6N	$ ++FHgFFr   c                 L    | j                  |g|      }| j                  ||      S )u  

        https://docs.upbit.com/kr/reference/ticker현재가-정보
        https://global-docs.upbit.com/reference/tickers

        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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   tickerss       r   fetch_tickerzupbit.fetch_ticker)  s)     $$fXv6w//r   tradec                 @   | j                  |dd      }d }| j                  |d      }|!| j                  | j                  |d            }d }| j	                  |dd      }|dk(  rd}n|d	k(  rd
}| j                  |d      }| j                  |dd      }	| j                  |dd      }
| j                  |dd      }| j                  ||d      }d }| j                  ||dz         }||d   |d}| j                  ||||| j                  |      |d   d |d |	|
||d|      S )Nsequential_iduuidr;  
created_atask_bidsider  sellr  buyfundsre  r   trade_volumevolumer  r   r6  _feer  r   r#  r
  )r)   r   r   r;  r<  r
  r  r  takerOrMakerr   r  r#  r   )r{  r[  	parse8601r   safe_string_lower_2r|  
safe_trader^  )r   r  r  r)   orderIdr;  r  askOrBidr#  r   r  r-  r   feeCosts                 r   parse_tradezupbit.parse_trade7  sj   : ?%%e[9	t'7'7|'LMI++E9fEuDDw/""5-A##E>8D%%eXv>!!(FC8""5(V*;<"7OC "Y/X&  
  	r   sincec                     | j                          | j                  |      }|d}|d   |d}| j                  | j                  ||            }| j	                  ||||      S )ue  

        https://docs.upbit.com/kr/reference/최근-체결-내역
        https://global-docs.upbit.com/reference/today-trades-history

        get the list of most recent trades for a particular symbol
        :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  count)r   r  publicGetTradesTicksr   parse_trades)r   r
  r  r   r   r  r   r   s           r   fetch_tradeszupbit.fetch_trades{  so     	V$=ETl
 ,,T[[&-IJ.   65%@@r   c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j	                  |d      }t        j                  ||      }| j	                  |d      }	| j	                  |d      }
t        j                  |	|
      }||| j                  |      | j                  |      ddd	S )
u  

        https://docs.upbit.com/kr/reference/주문-가능-정보
        https://global-docs.upbit.com/reference/available-order-information

        fetch the trading fees for a market
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r  r)   r  r  maker_ask_feemaker_bid_feeTF)r   r
  r   r   r   r   )r   r  r)  r   r   r$   r*  r   )r   r
  r   r  r   r   r/  r.  r   makerAskFeemakerBidFeer   s               r   fetch_trading_feezupbit.fetch_trading_fee  s     	V$fTl
 ..t{{7F/KLF !!(I6!!(I6""662&&xA&&xA"";<&&u-&&u-
 	
r   c                 h   | j                          | j                  |      }i }t        dt        |            D ]v  }i }| j	                  ||   d      |d<   | j	                  ||   d      |d<   | j                  ||   d      |d<   d|d<   d|d<   ||   |d	<   ||| j                  ||   d      <   x |S )
z
        fetch the trading fees for markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `trading fee structure <https://docs.ccxt.com/#/?id=trading-fee-structure>`
        r   r   r   r
  Tr   Fr   r   )r   r4  r@  rA  r   r   )r   r   fetchMarketResponser   rE  elements         r   fetch_trading_feeszupbit.fetch_trading_fees  s     	"008q#123 	SAG#//0CA0FPGG#//0CA0FPGG $ 0 01DQ1G RGH$(GL!#(GK 1!4GFOKRHT%%&9!&<hGH	S r   c           	          | j                  | j                  |d            | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Ncandle_date_time_utcrn  rg  ri  re  candle_acc_trade_volume)r  r   r   )r   ohlcvr  s      r   parse_ohlcvzupbit.parse_ohlcv  sy    " NN4++E3IJKUO4UL1UK0UM2U$=>
 	
r   rn   c                    | j                          | j                  |      }| j                  |      }| j                  | j                  ||      }|d}|d   ||d}	d}
|*| j                  | j                  |||z  dz              |	d<   |dk(  r>t        t        |dz              }||	d	<   | j                  | j                  |	|            }
n!| j                  | j                  |	|            }
| j                  |
||||      S )
u  

        https://docs.upbit.com/kr/reference/분minute-캔들-1
        https://global-docs.upbit.com/reference/minutes

        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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr   r)   )r  	timeframer  r   torh   <   unit)r   r  parse_timeframer   rf   r^  sumintroundpublicGetCandlesTimeframeUnitr   publicGetCandlesTimeframeparse_ohlcvs)r   r
  r  r  r   r   r  timeframePeriodtimeframeValuer   r   
numMinutess               r   fetch_ohlcvzupbit.fetch_ohlcv  s    	V$..y9))$//9iP=ETl'

  LL%59PSW9W)XYGDMY&U?R#789J(GFO99$++gv:VWH55dkk'66RSH>   69eUKKr   r  r   c                    d }| j                  | j                  d      }| j                  |d      }|| j                  ||      }|S |rh||t	        | j
                  dz         | j                  |      }| j                  |      }	t        j                  ||	      }
| j                  ||
      }|S |t        | j
                  dz         | j                  ||      }|S )Nr   r#  a   createOrder() requires the price and amount argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentzu When createMarketBuyOrderRequiresPrice is False, "amount" is required and should be the total quote amount to spend.)
r   r   r   cost_to_precisionr!   r)   number_to_stringr$   
string_mulr   )r   r
  r  r   r   quoteAmountr   r#  amountStringpriceStringcostRequests              r   calc_order_pricezupbit.calc_order_price[  s
   ,0OODLLJm,n)/00>K  /}"477  .D  $D  E  E008L//6K!,,\;GK00EK
  ~'  3j  )j  k  k00@Kr   r  r  c                    | j                          | j                  |      }d}|dk(  rd}n |dk(  rd}nt        | j                  dz         |d   |d}	|d	k(  rL||t	        | j                  d
z         d	|	d<   | j                  ||      |	d<   | j                  ||      |	d<   nv|dk(  rY|dk(  rd|	d<   | j                  ||||      }
|
|	d<   nM|t	        | j                  dz         d|	d<   | j                  ||      |	d<   nt        | j                  dz         | j                  |dd      }|dk(  rg| j                  |ddg      }d|	d<   |dk(  r| j                  ||||      }
|
|	d<   n/|t	        | j                  dz         | j                  ||      |	d<   | j                  |d      }|||	d<   |	d   dk7  rV|	d   dk7  rN| j                  |dd      }| j                  |dg      }|||	d<   n |	d   dk(  rt	        | j                  dz         | j                  |ddg      }| j                  | j                  |	|            }| j                  |      S )u  
        create a trade order

        https://docs.upbit.com/kr/reference/주문하기
        https://global-docs.upbit.com/reference/order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: supports 'market' and 'limit'. if params.ordType is set to best, a best-type order will be created regardless of the value of type.
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.cost]: for market buy and best buy orders, the quote quantity that can be used alternative for the amount
        :param str [params.ordType]: self field can be used to place a ‘best’ type order
        :param str [params.timeInForce]: 'IOC' or 'FOK'. only for limit or best type orders. self field is required when the order type is 'best'.
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r  r  r  z> createOrder() supports only buy or sell in the side argument.r)   )r  r  r   zD the limit type order in createOrder() is required price and amount.ord_typer   r  r  z@ the market sell type order in createOrder() is required amount.zH createOrder() supports only limit or market types in the type argument.ordTypebestz> the best sell type order in createOrder() is required amount.clientOrderId
identifierr   time_in_forcez> the best type order in createOrder() is required timeInForce.r#  )r   r  r!   r)   r   price_to_precisionamount_to_precisionr  r{  omitr   r  privatePostOrdersr   parse_order)r   r
  r  r  r  r   r   r  	orderSider   
orderPrice
customTyper  r   r   s                  r   create_orderzupbit.create_ordern  s   $ 	V$	5=IV^Itww)iijjTl
 7?}'2x(xyy")GJ#66vuEGG $ 8 8 HGHXu}&-
#!22665&Q
#- >+DGG6x,xyy&.
#$($<$<VV$L!tww)sstt''	:F
YYv	:'>?F"(GJu}!22665&Q
#- >+DGG6v,vww$($<$<VV$L!((A$$1GL!:(*wz/Bg/M226=/ZKYYv7F&+6(:&&0+DGG6v,vww6OV#<=))$++gv*FG* ))r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |      S )u  

        https://docs.upbit.com/kr/reference/주문-취소
        https://global-docs.upbit.com/reference/order-cancel

        cancels an open order
        :param str id: order id
        :param str symbol: not used by upbit cancelOrder()
        :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   privateDeleteOrderr   r  r   r)   r
  r   r   r   s         r   cancel_orderzupbit.cancel_order  sL     	B
 **4;;w+GH( ))r   c                 r   | j                          i }| j                  |d      }	| j                  |d      }|||d<   n |	|	|d<   nt        | j                  dz         |dk(  rL||t        | j                  dz         d|d<   | j                  ||      |d<   | j                  ||      |d	<   nv|d
k(  rY|dk(  rd|d<   | j                  ||||      }
|
|d<   nM|t        | j                  dz         d
|d<   | j                  ||      |d	<   nt        | j                  dz         | j                  |dd      }|dk(  rg| j                  |ddg      }d|d<   |dk(  r| j                  ||||      }
|
|d<   n/|t        | j                  dz         | j                  ||      |d	<   | j                  |d      }|||d<   |d   d
k7  rW|d   dk7  rO| j                  |dd      }| j                  |ddg      }|||d<   n |d   dk(  rt        | j                  dz         | j                  |ddg      }| j                  | j                  ||            }i }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d<   | j                  |d
      |d
<   | j                  |      S )u  

        https://docs.upbit.com/kr/reference/취소-후-재주문
        https://global-docs.upbit.com/reference/cancel-and-new

        canceled existing order and create new order. It's only generated same side and symbol canceled order. it returns the data of the canceled order, except for `new_order_uuid` and `new_identifier`. to get the details of the new order, use `fetchOrder(new_order_uuid)`.
        :param str id: the uuid of the previous order you want to edit.
        :param str symbol: the symbol of the new order. it must be the same symbol of the previous order.
        :param str type: the type of the new order. only limit or market is accepted. if params.newOrdType is set to best, a best-type order will be created regardless of the value of type.
        :param str side: the side of the new order. it must be the same side of the previous order.
        :param number amount: the amount of the asset you want to buy or sell. It could be overridden by specifying the new_volume parameter in params.
        :param number price: the price of the asset you want to buy or sell. It could be overridden by specifying the new_price parameter in params.
        :param dict [params]: extra parameters specific to the exchange API endpoint.
        :param str [params.clientOrderId]: to identify the previous order, either the id or self field is hasattr(self, required) method.
        :param float [params.cost]: for market buy and best buy orders, the quote quantity that can be used alternative for the amount.
        :param str [params.newTimeInForce]: 'IOC' or 'FOK'. only for limit or best type orders. self field is required when the order type is 'best'.
        :param str [params.newClientOrderId]: the order ID that the user can define.
        :param str [params.newOrdType]: self field only accepts limit, price, market, or best. You can refer to the Upbit developer documentation for details on how to use self field.
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  prev_order_uuidprev_order_identifierz- editOrder() is required id or clientOrderId.r   zE editOrder() is required price and amount to create limit type order.new_ord_type	new_price
new_volumer  r  r   zA editOrder() is required amount to create market sell type order.zF editOrder() supports only limit or market types in the type argument.
newOrdTyper  z: editOrder() is required amount to create best sell order.newClientOrderIdnew_identifiernewTimeInForcenew_time_in_forcez- the best type order is required timeInForce.r#  new_order_uuidr  new_order_identifierr  r  )r   r   r  r   r)   r  r  r  r!   r{  r  privatePostOrdersCancelAndNewr   r  )r   r)   r
  r  r  r  r   r   r   prevClientOrderIdr  r  r  r   r   rD  s                   r   
edit_orderzupbit.edit_order  s)   * 	 ,,V_E6?3>)+G%&*/@G+,#DGG.]$]^^7?}'2y(yzz&-GN##'#:#:65#IGK $($<$<VV$LGL!Xu}*1'!22665&Q
'1$>+DGG6y,yzz*2'(,(@(@(P%tww)qqrr''nM
YYvn'EFF&,GN#u}!22665&Q
'1$>+DGG6r,rss(,(@(@(P%((1CD$(5G$%>"h.7>3Jg3U226;KM`aKYYv(8:M'NOF&/:+,>*f4+DGG6e,eff6$6#?@55dkk'66RS* ))(4DEv#//:PQ|))(F;v++Hh?x''r   c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )uR  

        https://docs.upbit.com/kr/reference/입금-리스트-조회
        https://global-docs.upbit.com/reference/deposit-list-inquiry

        fetch all deposits made to an account
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr)   r   r   )r   r   privateGetDepositsr   parse_transactionsr   r   r  r   r   r   r   r   s           r   fetch_depositszupbit.fetch_depositsX  s     	
 }}T*H"*4.GJ$GG**4;;w+GH" &&x5%HHr   c                     | j                          d|i}d}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  ||      S )uZ  
        fetch information on a deposit

        https://docs.upbit.com/kr/reference/개별-입금-조회
        https://global-docs.upbit.com/reference/individual-deposit-inquiry

        :param str id: the unique id for the deposit
        :param str [code]: unified currency code of the currency deposited
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.txid]: withdrawal transaction id, the id argument is reserved for uuid
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  Nr)   r   )r   r   privateGetDepositr   parse_transactionr   r)   r   r   r   r   r   s          r   fetch_depositzupbit.fetch_deposit  su     	B
 }}T*H"*4.GJ))$++gv*FG  %%h99r   c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )u]  

        https://docs.upbit.com/kr/reference/전체-출금-조회
        https://global-docs.upbit.com/reference/withdrawal-list-inquiry

        fetch all withdrawals made from an account
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr)   r   r   )r   r   privateGetWithdrawsr   r  r  s           r   fetch_withdrawalszupbit.fetch_withdrawals  s     	
 }}T*H"*4.GJ$GG++DKK,HI$ &&x5%HHr   c                     | j                          d|i}d}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  ||      S )u{  
        fetch data on a currency withdrawal via the withdrawal id

        https://docs.upbit.com/kr/reference/개별-출금-조회
        https://global-docs.upbit.com/reference/individual-withdrawal-inquiry

        :param str id: the unique id for the withdrawal
        :param str [code]: unified currency code of the currency withdrawn
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.txid]: withdrawal transaction id, the id argument is reserved for uuid
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  Nr)   r   )r   r   privateGetWithdrawr   r  r  s          r   fetch_withdrawalzupbit.fetch_withdrawal  su     	B
 }}T*H"*4.GJ**4;;w+GH  %%h99r   statusc           	      >    ddddddddd}| j                  |||      S )Npendingfailedokcanceled)
submitting	submittedalmost_acceptedrejectedaccepted
processingdoner  r   r   r   statusess      r   parse_transaction_statuszupbit.parse_transaction_status  s8    #"( #"	
 &&99r   transactionr   c                 b   d }d }| j                  |d      }| j                  | j                  |d|            }| j                  |d      }|dk(  rd}| j                  |d      }| j                  ||      }	i d|d| j                  |d	      d|	d
| j                  |d
      dd d|dd dd d|dd dd d| j	                  | j                  |d            d|d| j                  |      d| j                  |d      d|d| j                  |      d d |	| j                  |d      ddS )Ndone_atr  r  re   
withdrawalr   r   r)   r  r  networkaddress	addressToaddressFromtagtagTotagFromr   r  updatedtxidr;  r<  r   r  )internalcommentr   )r   r  r   r   r  safe_string_lowerr^  )
r   r  r   r  r  
updatedRawr;  r  r	  r   s
             r   r  zupbit.parse_transaction	  s   > %%k9=
NN4#3#3Kz#Z[	V4:D%%k:>
&&z8<
K
$"";7
 
 d&&{H=	

 t
 w
 
 4
 3
 T
 t
 d33D4J4J;X_4`a
 D
 t~~j1
 D$$[&9
  !
" Y/#
$  ((e<)
 	
r   c                 4    dddd}| j                  |||      S )Nrm  closedr  )waitr  cancelr  r  s      r   parse_order_statuszupbit.parse_order_statusK  s)     

 &&99r   r   c           	      B   | j                  |d      }| j                  |d      }|dk(  rd}nd}| j                  |d      }| j                  |d      }| j                  | j                  |d            }| j                  | j                  |d	            }d }	| j                  |d
      }
| j                  |d      }| j                  |d      }| j                  |d      }d }|d
k(  rd}|
}d }
d }d }| j                  |d      }| j                  |d      }| j                  ||      }| j	                  |dg       }| j                  ||d d ||d      }t        |      }|dkD  r||dz
     d   }	d}|d}d}d}t        d|      D ]q  }||   }t        j                  || j                  |d            }|s1| j	                  ||   di       }| j                  |d      }|\t        j                  ||      }s t        j                  ||      }||d   |d}| j                  i d|d|d|d|d| j                  |      d |	d!|d!   d"|d#| j                  |d$      d%d d|d
|
d&d d| j                  |      d'| j                  |      d(|d)|||||d*      S )+Nr  r  r  r  r  r  r  r  r  r   r  remaining_volumeexecuted_volumer  paid_feetrades)r   r  r   r   r;  FTr   r#  r   r  r  r   r)   r  r<  lastTradeTimestampr
  r  r   r  postOnlyr   rv  r  filled)	remainingr   r   r+  )r   r  r&  r|  r   r  rA  r@  r$   
string_add
string_div
safe_orderr^  safe_string_upperr   )r   r   r  r)   r  r  r  r;  r   r,  r   r  r/  r.  r#  rv  r   r  r-  r+  	numTradesgetFeesFromTradesrE  r  tradeFeetradeFeeCosts                             r   r  zupbit.parse_orderS  s   l eV,v.5=DD%%e\:
z2NN4#3#3E<#HI	(()9)9%)IJ!  0!!%2$$U,>?	!!%):;7?DDE""5*5##E84!!(F3"5""664@
  K	q=!'	A!6{!C %$(!D1i( Lq	))$0@0@0OP$#vay%DH#'#3#3Hf#EL#/")"4"4Wl"KL ((v6G"7OC   
E 
" 
 Z 
 	 

 Y/ 
 !"4 
 fX& 
 D 
 411%I 
  
 D 
 U 
 D 
 D%%d+ 
 t((1 
  f! 
" f# 
$ #+ 
  	r   c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  ||||      S )u  
        fetch all unfilled currently open orders

        https://docs.upbit.com/kr/reference/대기-주문-조회
        https://global-docs.upbit.com/reference/open-order

        :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
        :param str [params.state]: default is 'wait', set to 'watch' for stop limit orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr)   r  r   )r   r  privateGetOrdersOpenr   parse_ordersr   r
  r  r   r   r   r  r   s           r   fetch_open_orderszupbit.fetch_open_orders  s     	[[(F &tGH$GG,,T[[&-IJ.   65%@@r   c                    | j                          ddi}d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  d||      \  }}| j                  | j	                  ||            }| j                  ||||      S )	u  
        fetches information on multiple closed orders made by the user

        https://docs.upbit.com/kr/reference/종료-주문-조회
        https://global-docs.upbit.com/reference/closed-order

        :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
        :param int [params.until]: timestamp in ms of the latest order
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  Nr)   r  
start_timer   end_timer   r  handle_until_optionprivateGetOrdersClosedr   r:  r;  s           r   fetch_closed_orderszupbit.fetch_closed_orders%  s     	V
 [[(F &tGH$)GL!$GG22:wO..t{{7F/KL0   65%@@r   c                    | j                          ddi}d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  d||      \  }}| j                  | j	                  ||            }| j                  ||||      S )	u  
        fetches information on multiple canceled orders made by the user

        https://docs.upbit.com/kr/reference/종료-주문-조회
        https://global-docs.upbit.com/reference/closed-order

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest order
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r%  Nr)   r  r>  r   r?  r@  r;  s           r   fetch_canceled_orderszupbit.fetch_canceled_ordersZ  s     	X
 [[(F &tGH$)GL!$GG22:wO..t{{7F/KL0   65%@@r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |      S )u  

        https://docs.upbit.com/kr/reference/개별-주문-조회
        https://global-docs.upbit.com/reference/individual-order-inquiry

        fetches information on an order made by the user
        :param str id: order id
        :param str symbol: not used by upbit fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  )r   privateGetOrderr   r  r  s         r   fetch_orderzupbit.fetch_order  sM     	B
 ''GV(DEX ))r   codesc                 h    | j                          | j                  |      }| j                  ||      S )u  

        https://docs.upbit.com/kr/reference/전체-입금-주소-조회
        https://global-docs.upbit.com/reference/general-deposit-address-inquiry

        fetch deposit addresses for multiple currencies and chain types
        :param str[]|None 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   privateGetDepositsCoinAddressesparse_deposit_addresses)r   rI  r   r   s       r   fetch_deposit_addresseszupbit.fetch_deposit_addresses  s5     	77?( ++He<<r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }| j                  |       ||| j                  |      ||dS )Ndeposit_addresssecondary_addressr   net_type)r   r   r  r  r  )r   r   check_addressnetwork_id_to_code)r   depositAddressr   r  r  r	  r   	networkIds           r   parse_deposit_addresszupbit.parse_deposit_address  s     "">3DE~/BC%%njA
&&z2$$^Z@	7#"..y9
 	
r   c           
      :   | j                          | j                  |      }d}| j                  |      \  }}|t        | j                  dz         | j                  | j                  |d   | j                  ||d         d|            }| j                  |      S )u  

        https://docs.upbit.com/kr/reference/개별-입금-주소-조회
        https://global-docs.upbit.com/reference/individual-deposit-address-inquiry

        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['network']: deposit chain, can view all chains via self.publicGetWalletAssets, default is eth, unless the currency has a default chain within self.options['networks']
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nz/ fetchDepositAddress requires params["network"]r)   r   )r   rQ  )	r   r   handle_network_code_and_paramsr   r)   privateGetDepositsCoinAddressr   network_code_to_idrV  )r   r   r   r   networkCoder   s         r   fetch_deposit_addresszupbit.fetch_deposit_address  s     	==&"AA&IV#DGG._$_``55dkk //Xf=MNC
 7  ))(33r   c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }|t        | j                  dz   |z   dz         | j                  |      S )u  

        https://docs.upbit.com/kr/reference/입금-주소-생성-요청
        https://global-docs.upbit.com/reference/deposit-address-generation

        create a currency deposit address
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r   r)   messagez is generating zx deposit address, call fetchDepositAddress or createDepositAddress one more time later to retrieve the generated address)r   r   &privatePostDepositsGenerateCoinAddressr   r   r    r)   rV  )r   r   r   r   r   r   r^  s          r   create_deposit_addresszupbit.create_deposit_address&  s     	==&
 >>t{{7TZ?[\  ""8Y7 +<!<t!C  GA  "A  B  B))(33r   r  c                 $   | j                  ||      \  }}| j                          | j                  |      }d|i}d}|dk7  r| j                  |       | j	                  |dd      }	|	t        | j                  dz         | j                  |dg      }|	|d<   |d   |d<   ||d	<   |||d
<   | j                  |d      }| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |      S )u$  

        https://docs.upbit.com/kr/reference/디지털자산-출금하기
        https://global-docs.upbit.com/reference/withdrawal-digital-assets

        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  Nr   r  rQ  z' withdraw() requires a network argumentr)   r   r  rP  )handle_withdraw_tag_and_paramsr   r   rR  safe_string_upper_2r   r)   r  privatePostWithdrawsCoinr   privatePostWithdrawsKrwr  )
r   r   r  r  r  r   r   r   r   r  s
             r   re   zupbit.withdrawL  s'    99#vFV==&f
 5=w'..vy*MG'2[([\\YYv	{3F")GJ"*4.GJ!(GI/2+,YYvy1F44T[[&5QRH33DKK4PQH %%h//r   c                 "    | j                         S N)milliseconds)r   s    r   rU  zupbit.nonce  s      ""r   r|   GETc                    | j                  | j                  d   |   d| j                  i      }|d| j                  z   dz   | j                  ||      z   z  }| j	                  || j                  |            }|dk7  r|r|d| j                  |      z   z  }|dk(  r| j                          i }| j                         }	| j                  |	d}
|}d }|dk7  r|d	k7  r| j                  |      }d
|d<   |r| j                  |      }|+| j                  | j                  |      d      }||
d<   d|
d<   | j                  |
| j                  | j                        d      }d|z   |d<   ||||dS )Nr   rz   r  POST?r}   )
access_keyrU  ri  DELETEzapplication/jsonzContent-Typesha512
query_hashSHA512query_hash_algsha256zBearer Authorization)urlmethodbodyheaders)implode_paramsr{   rz   r.   r  extract_params	urlencodecheck_required_credentialsr  apiKeyjson	rawencodehashencodejwtsecret)r   pathr   rv  r   rx  rw  ru  queryrU  r   hasQueryauthr  tokens                  r   signz
upbit.sign  s   !!$))E"23"7:
  	sT\\!C'$*=*=dF*KKK		&$"5"5d";<VsT^^E222)++-GIIKE"kkG HD%f&8yy(*<'~~e,yyT!2H=(,%,4()HHWdkk$++&>IE'05'8GO$fdwOOr   httpCodereasonru  rv  rx  rw  c
                    |y | j                  |d      }
|
| j                  |
d      }| j                  |
d      }| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d   ||       | j                  | j                  d   ||       | j                  | j                  d   ||       t        |      y )Nerrorr^  r*    r   r   )r   r   r)   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  r  ru  rv  rx  rw  r   requestHeadersrequestBodyr  r^  r*   feedbacks                 r   handle_errorszupbit.handle_errors  s     '2&&ui8G##E62Dww}t+H001I7T\]001I4QYZ001I7T\]001I4QYZ))r   rg  )J__name__
__module____qualname__r   r   strr   r   r  r  r   r
   r4  dictr9  r   rF  rI  r   r	   r   r_  r   rb  r   r~  r   r  r  r   r  r  r   r  r   r  listr  r  floatr   r  r   r   r  r   r  r   r  r   r  r  r  r  r  r   r  r&  r  r<  rC  rE  rH  r   rM  rV  r\  r`  re   rU  r  r  r  __classcell__)r   s   @r   r&   r&      s   E# EN 02 A3 A 46 U
s U
n 02 =3 = 24 dS dL $& ,$v, ,.74 7F 7r) )  $& ,( ,4 48dSU A A AZd AF :>b 3s 33 3Y 364 6 66 6p 04B 8GW 8G7 8Gt 02 03 0f 0B Bv B BH 6:UW ,A3 ,As ,A# ,A\`af\g ,A\ 57 @
 @
;N @
D )+ { (
 
4 
2 26DW[df AL# ALc ALQT ALkoptku ALF IMUW s E # \_ & gksu ]*3 ]*i ]*y ]*RW ]*`c ]*~ 37r $*s $*C $*L `drv  @B c(S c(# c(Y c(i c(Y\ c(lo c(  GL c(J *.Dt\^ )I3 )Ic )I )Icghsct )IV 26b %: %:3 %:N -1tRV_a )Ic )I )IC )Ifjkvfw )IV 59 %:3 %:c %:N:s :@
T @
X @
Q\ @
D: :a av a aF /3TXac -A -A3 -Ac -Ahlmrhs -A^ 154VZce 3A# 3AS 3APS 3Ajnotju 3Aj 37TX\eg 3AC 3As 3ARU 3Aj 26b <*c <*3 <*| 8<B  =W  =4P^K_  =D
h 
R` 
. 79 4# 4^ 4@ 8: $43 $4n $4L DHPR 30S 30% 30# 30Wb 30j# &eBSW P@c 3 S # X\ dg r   r&   N)*ccxt.base.exchanger   ccxt.abstract.upbitr   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r    r!   r"   ccxt.base.decimal_to_precisionr#   ccxt.base.preciser$   r&    r   r   <module>r     se    ( + _  _  _  _  _  _  * 0 - . ' . + ) * 4 %e"Hk e"r   