pip install pybitflyer
API Key
Can be obtained from the following after registration https://lightning.bitflyer.jp/developer
bitFlyer Lightning API
・ Restrictions https://lightning.bitflyer.jp/docs?lang=ja&_ga=2.103916546.34290189.1503318908-1417182779.1500704462
API restrictions
The HTTP API limits the number of calls as follows.
The Private API is limited to about 200 times per minute.
The maximum number of times per IP address is about 500 times per minute.
Average daily contract price is 0.Users less than 01 may be limited to approximately 10 Private API calls per minute the next day.
Manual ordering is not restricted.
・ Acquisition of Ticker
https://lightning.bitflyer.jp/docs?lang=ja&_ga=2.103916546.34290189.1503318908-1417182779.1500704462#ticker
Get every 5 seconds
import pybitflyer
import time
from datetime import datetime
from pytz import timezone
from dateutil import parser
import pytz
TICKER_KEYS = ["product_code",
"timestamp",
"tick_id",
"best_bid",
"best_ask",
"best_bid_size",
"best_ask_size",
"total_bid_depth",
"total_ask_depth",
"ltp",
"volume",
"volume_by_product"]
API_KEY = "XXXXXXXXXXXXXXXXXXXXXX" #Obtained from My Page after logging in to Bitflyer
API_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXX" #Obtained from My Page after logging in to Bitflyer
def to_jst(datestr):
return pytz.timezone('UTC').localize(parser.parse(datestr)).astimezone(timezone('Asia/Tokyo'))
if __name__ == '__main__':
api = pybitflyer.API(api_key = API_KEY, api_secret = API_SECRET)
now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
ticker_data = open(now + "_ticker_data.tsv", "w")
for ticker_key in TICKER_KEYS:
ticker_data.write(ticker_key + "\t")
ticker_data.write("\n")
while True:
ticker = api.ticker(product_code="BTC_JPY")
for ticker_key in TICKER_KEYS:
if ticker_key == "timestamp":
data = to_jst(str(ticker[ticker_key]).replace("T", " ")).strftime("%Y/%m/%d %H:%M:%S")
else:
data = str(ticker[ticker_key])
ticker_data.write(data + "\t")
ticker_data.write("\n")
ticker_data.flush()
time.sleep(5)
ticker_data.close()
It will fail due to a connection error, so if you do it properly, you need to take measures against the error.
Recommended Posts