Since I started trading with BitFlyer Lightning, I decided to touch the API.
API specifications API Documentation
The test is API Playground
You can get the key and secret from the BitFlyer Lightning API menu. Try using requests.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
import requests
import time
import hmac
import hashlib
api_key = 'key'
api_secret = 'secret'
api_endpoint = 'https://api.bitflyer.jp'
def get_api_call(path):
method = 'GET'
timestamp = str(time.time())
text = timestamp + method + path
sign = hmac.new(api_secret, text, hashlib.sha256).hexdigest()
request_data=requests.get(
api_endpoint+path
,headers = {
'ACCESS-KEY': api_key,
'ACCESS-TIMESTAMP': timestamp,
'ACCESS-SIGN': sign,
'Content-Type': 'application/json'
})
return request_data
def post_api_call(path,body):
body = json.dumps(body)
method = 'POST'
timestamp = str(time.time())
text = timestamp + method + path + body
sign = hmac.new(api_secret, text, hashlib.sha256).hexdigest()
request_data=requests.post(
api_endpoint+path
,data= body
,headers = {
'ACCESS-KEY': api_key,
'ACCESS-TIMESTAMP': timestamp,
'ACCESS-SIGN': sign,
'Content-Type': 'application/json'
})
return request_data
path = '/v1/gethealth'
status = get_api_call(path).json()['status']
print status
Please concatenate the GET query to the path or add it to the argument. Please use a dictionary object for the POST body. When you execute it, you can get the status of BitFlyer Lightning. About NORMAL is returned. The API response is returned in JSON, but some APIs return only the status. It seems that Streaming using PubNub is also possible.
Recommended Posts