Try using the BitFlyer Ligntning API in Python

Background

Since I started trading with BitFlyer Lightning, I decided to touch the API.

API documentation

API specifications API Documentation

The test is API Playground

Try using

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

Try using the BitFlyer Ligntning API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try using the DropBox Core API in Python
Tweet using the Twitter API in Python
Try hitting the YouTube API in Python
Try using ChatWork API and Qiita API in Python
Try using the Twitter API
Try using the Twitter API
Try using the PeeringDB 2.0 API
Initial settings when using the foursquare API in python
Using the National Diet Library Search API in Python
Hit the Sesami API in Python
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Hit the web API in Python
Try using Python argparse's action API
Try using the Python Cmd module
Access the Twitter API in Python
Try using Leap Motion in Python
Mouse operation using Windows API in Python
Try using the HL band in order
Get Youtube data in Python using Youtube Data API
Quickly try Microsoft's Face API in Python
Try hitting the Spotify API in Django.
Regularly upload files to Google Drive using the Google Drive API in Python
Try using FireBase Cloud Firestore in Python for the time being
[Cloudian # 7] Try deleting the bucket in Python (boto3)
Python: Try using the UI on Pythonista 3 on iPad
Get image URL using Flickr API in Python
Evernote API in Python
Try using the Python web framework Tornado Part 1
Tips for hitting the ATND API in Python
Let's judge emotions using Emotion API in Python
Try gRPC in Python
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Try using the collections module (ChainMap) of python3
C API in Python 3
Try 9 slices in Python
Try using the Python web framework Tornado Part 2
Try implementing the Monte Carlo method in Python
Hit the Firebase Dynamic Links API in Python
Try using Tweepy [Python2.7]
Try accessing the YQL API directly from Python 3
To automatically send an email with an attachment using the Gmail API in Python
Continue to retrieve tweets containing specific keywords using the Streaming API in Python
Upload JPG file using Google Drive API in Python
[Unity (C #), Python] Try running Python code in Unity using IronPython
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Determine the threshold using the P tile method in python
Get LEAD data using Marketo's REST API in Python
Send and receive Gmail via the Gmail API using Python
Try to delete tweets in bulk using Twitter API
OpenVINO using Inference Engine Python API in PC environment
Using the LibreOffice app in Python (1) Where are the macros?
A little bit from Python using the Jenkins API
Hit Mastodon's API in Python
[Python] Try using Tkinter's canvas
Download the file in Python
Find the difference in Python
Try using Kubernetes Client -Python-