Univ./Trading Program Project
Binance rest-api 이용해보기
scio
2018. 3. 13. 17:15
Binance API를 이용하여 Market Data를 가져와보자
Binance official api docs 를 참조!
우선 Binance API는 크게 아래와 같이 나뉘어져 있다.
Name | Description |
---|---|
rest-api.md | Details on the Rest API (/api) |
errors.md | Descriptions of possible error messages from the Rest API |
web-socket-streams.md | Details on available streams and payloads |
user-data-stream.md | Details on the dedicated account stream |
wapi-api.md | Details on the Withdrawal API (/wapi) |
가져올 수 있는 데이터가 public type인지 private type로 나눌 수 있다.
예로 public type는 현재 비트코인이 얼마인지, private type는 내 지갑을 조회하는 것. 등이다.
private type를 이용하기 위해서는 api key를 발급받아야 한다. 어려운게 아니니 따로 서술하지 않겠다.
저 중에서 rest api를 먼저 이용해 볼텐데 api는 get, post 방식으로 나눌 수 있다.
우선 아래의 코드만 본다면 get 방식의 api는 모두 이용할 수 있을 것이다.
1 2 3 4 5 6 7 8 9 10 11 12 | import requests import pprint ep='https://api.binance.com' ping='/api/v1/ping' ticker24h='/api/v1/ticker/24hr' params = {'symbol': 'BTCUSDT'} r1=requests.get(ep+ping) r2 = requests.get(ep+ticker24h, params=params) #use parameter pprint.pprint(r1.json()) pprint.pprint(r2.json()) | cs |