Python
Bitcoin
ビットコイン
bitflyer

Python - bitflyer ビットコイン売買

More than 1 year has passed since last update.

bitflyer APIでビットコイン売買

pybitflyerのインストール

pip install pybitflyer

API Key

登録後以下から取得可能
https://lightning.bitflyer.jp/developer

ソース

import pandas as pd
import pybitflyer
import time
from datetime import datetime

# size : 注文数量、price : 価格(省略可)
def buy(api, size, product_code = "BTC_JPY", child_order_type = "MARKET", price = None, minute_to_expire = 10000, time_in_force = "GTC"):
    if price is None:
        buy_btc = api.sendchildorder(product_code=product_code, child_order_type=child_order_type, side="BUY",size=size, minute_to_expire=minute_to_expire, time_in_force=time_in_force)
    else:
        buy_btc = api.sendchildorder(product_code=product_code, child_order_type=child_order_type, side="BUY",size=size, minute_to_expire=minute_to_expire, time_in_force=time_in_force, price=price)

# size : 注文数量、price : 価格(省略可)
def sell(api, size, product_code = "BTC_JPY", child_order_type = "MARKET", price = None, minute_to_expire = 10000, time_in_force = "GTC"):
    if price is None:
        sell_btc = api.sendchildorder(product_code=product_code, child_order_type=child_order_type, side="SELL",size=size, minute_to_expire=minute_to_expire, time_in_force=time_in_force)
    else:
        sell_btc = api.sendchildorder(product_code=product_code, child_order_type=child_order_type, side="SELL",size=size, minute_to_expire=minute_to_expire, time_in_force=time_in_force, price=price)

API_KEY = "XXXXXXXXXXXXXX"
API_SECRET = "XXXXXXXXXXXXXXXXXXXXXX"

if __name__ == '__main__':
    api = pybitflyer.API(api_key = API_KEY, api_secret = API_SECRET)

    # 0.001BTC買い
    buy(api=api, size=0.001)

    # 0.001BTC売り
    sell(api=api, size=0.001)