Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 리뷰
- File
- Callback
- package
- Sync
- Golang
- bitcoin
- go언어
- Close
- range
- GO 언어
- c++
- write
- C
- go
- mutex
- API
- http
- 영화
- tcp
- FOR
- JavaScript
- window
- windows
- Python
- channel
- Linux
- 책
- install
- json
Archives
- Today
- Total
Code Habit
[python] requests 이용하여 upbit api 호출하기 본문
python의 requests 모듈을 이용하여 upbit에서 제공하는 api를 통해 비트코인 가격등의 정보를 가져올 수 있다.
import requests
import pprint
url = "https://api.upbit.com/v1/candles/minutes/15"
querystring = {"market" : "KRW-BTC", "count" : "200"}
response = requests.request("GET", url, params=querystring)
data = response.json()
pprint.pprint(data)
"KRW-BTC" 마켓의 15분 캔들 정보를 최근 것부터 200개 가져오는 예제다. 호출은 "GET" 방식을 사용하고 api 관련 https 주소와 필요한 정보를 파라미터를 넘겨주면 json형태로 결과값을 리턴해준다. 받은 값을 출력해보면 줄 정리가 되어 있지 않아 보기 힘든데 이를 pprint를 이용하여 보기좋게 출력할 수 있다.
>> 출력 결과
[{'candle_acc_trade_price': 1515347036.10004,
'candle_acc_trade_volume': 30.87598556,
'candle_date_time_kst': '2021-08-07T06:30:00',
'candle_date_time_utc': '2021-08-06T21:30:00',
'high_price': 49167000.0,
'low_price': 49020000.0,
'market': 'KRW-BTC',
'opening_price': 49044000.0,
'timestamp': 1628286299775,
'trade_price': 49113000.0,
'unit': 15},
{'candle_acc_trade_price': 2835614415.20379,
'candle_acc_trade_volume': 57.8686429,
'candle_date_time_kst': '2021-08-07T06:15:00',
'candle_date_time_utc': '2021-08-06T21:15:00',
'high_price': 49079000.0,
'low_price': 48921000.0,
'market': 'KRW-BTC',
'opening_price': 49034000.0,
'timestamp': 1628285396100,
'trade_price': 49044000.0,
'unit': 15},.
...
{'candle_acc_trade_price': 3602018706.83194,
'candle_acc_trade_volume': 76.37550908,
'candle_date_time_kst': '2021-08-06T21:45:00',
'candle_date_time_utc': '2021-08-06T12:45:00',
'high_price': 47264000.0,
'low_price': 47001000.0,
'market': 'KRW-BTC',
'opening_price': 47094000.0,
'timestamp': 1628254799526,
'trade_price': 47193000.0,
'unit': 15},
{'candle_acc_trade_price': 3914796712.99895,
'candle_acc_trade_volume': 82.97121576,
'candle_date_time_kst': '2021-08-06T21:30:00',
'candle_date_time_utc': '2021-08-06T12:30:00',
'high_price': 47386000.0,
'low_price': 47000000.0,
'market': 'KRW-BTC',
'opening_price': 47365000.0,
'timestamp': 1628253899281,
'trade_price': 47148000.0,
'unit': 15},
{'candle_acc_trade_price': 8285960648.12827,
'candle_acc_trade_volume': 174.8576549,
'candle_date_time_kst': '2021-08-06T21:15:00',
'low_price': 47146000.0,
'market': 'KRW-BTC',
'opening_price': 47192000.0,
'timestamp': 1628252999682,
'trade_price': 47388000.0,
'unit': 15}]