Skip to content

Commit

Permalink
get_current_price API로 다수의 티커가 입력되는 경우 200개씩 분할해서
Browse files Browse the repository at this point in the history
요청함(#125)
  • Loading branch information
mr-yoo committed Jun 14, 2024
1 parent 9dae7d9 commit c5f80ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions pyupbit/quotation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def get_daily_ohlcv_from_base(ticker="KRW-BTC", base=0):
return None


def _get_current_price(ticker="KRW-BTC", limit_info=False, verbose=False):
url = "https://api.upbit.com/v1/ticker"
return _call_public_api(url, markets=ticker)

def get_current_price(ticker="KRW-BTC", limit_info=False, verbose=False):
"""현재가 정보 조회
Expand All @@ -245,27 +249,26 @@ def get_current_price(ticker="KRW-BTC", limit_info=False, verbose=False):
Returns:
[type]: [description]
"""
url = "https://api.upbit.com/v1/ticker"
data, req_limit_info = _call_public_api(url, markets=ticker)

if isinstance(ticker, str) or \
(isinstance(ticker, list) and len(ticker) == 1):
# 단일 티커
if isinstance(ticker, str) or (isinstance(ticker, list) and len(ticker) == 1):
price, req_limit_info = _get_current_price(ticker, limit_info, verbose)
if verbose is False:
price = data[0]['trade_price']
else:
price = data[0]
price = price[0]['trade_price']

else:
# 여러 티커로 조회한 경우
if verbose is False:
price = {x['market']: x['trade_price'] for x in data}
else:
price = data
slice_size = 200
price = []
for idx in range(0, len(ticker), slice_size):
ticker_sliced = ticker[idx: idx+slice_size]
price_sliced, req_limit_info = _get_current_price(ticker_sliced, limit_info, verbose)
price += price_sliced

if verbose is False:
price = {x['market']: x['trade_price'] for x in price}

if limit_info:
return price, req_limit_info
else:
return price
return price


def get_orderbook(ticker="KRW-BTC", limit_info=False):
Expand Down Expand Up @@ -363,9 +366,10 @@ def get_orderbook(ticker="KRW-BTC", limit_info=False):
# print(get_daily_ohlcv_from_base("KRW-BTC", base=9))
# print(get_ohlcv("KRW-BTC", interval="day", count=5))

# krw_tickers = get_tickers(fiat="KRW")
# print(len(krw_tickers))

tickers = get_tickers()
print(len(tickers))
prices1 = get_current_price(tickers)
print(prices1)
# krw_tickers1 = krw_tickers[:100]
# krw_tickers2 = krw_tickers[100:]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setuptools.setup(
name='pyupbit',
version='0.2.33',
version='0.2.34',
author='Jonghun Yoo, Brayden Jo',
author_email=author_email,
description='python wrapper for Upbit API',
Expand Down

0 comments on commit c5f80ea

Please sign in to comment.