달나라 노트

Python Upbit : get_current_price (암호화폐 현재가 조회) 본문

Python/Python ETC

Python Upbit : get_current_price (암호화폐 현재가 조회)

CosmosProject 2022. 2. 24. 00:44
728x90
반응형

 

 

 

pyupbit에서 어떤 암호화폐의 현재가를 조회하려면 get_current_price method를 이용합니다.

 

Syntax

pyupbit.get_current_price(ticker_list)

get_current_price method는 ticker들을 모아둔 list를 인자로 받습니다.

그리고 그 리스트에 담긴 ticker들의 현재가를 return합니다.

 

(ticker_list에 전달할 ticker가 1개라면 list가 아닌 그냥 ticker 하나만 전달해도 됩니다.)

 

Ticker관련 내용을 모른다면 아래 링크를 참고하면 됩니다.

https://cosmosproject.tistory.com/494

 

 

import pyupbit as ub

coin_price = ub.get_current_price('KRW-BTC')
print(coin_price)

coin_price = ub.get_current_price(['KRW-BTC'])
print(coin_price)


-- Result
46656000.0
46656000.0

KRW-BTC의 현재가를 return합니다.

위처럼 ticker를 한개만 전달할 때에는 list의 형태로 전달해도 되고 그냥 ticker 하나만 전달해도 됩니다.

 

 

 

 

 

 

import pyupbit as ub

coin_price = ub.get_current_price(['KRW-BTC', 'KRW-ETH', 'BTC-ETH'])
print(coin_price)


-- Result
{'KRW-BTC': 46656000.0, 'KRW-ETH': 3255000.0, 'BTC-ETH': 0.06984049}

위처럼 ticker를 여러 개 전달할 경우 각 ticker들의 현재가를 dictionary의 형태로 return합니다.

 

 

 

 

 

 

728x90
반응형
Comments