Python --bitflyer Bitcoin trading

Buy and sell Bitcoin with bitflyer API

Install pybitflyer

pip install pybitflyer

API Key

Can be obtained from the following after registration https://lightning.bitflyer.jp/developer

Source

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

# size :Order quantity, price:price(Optional)
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 :Order quantity, price:price(Optional)
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.Buy 001 BTC
    buy(api=api, size=0.001)
    
    # 0.001 BTC sale
    sell(api=api, size=0.001)

Recommended Posts

Python --bitflyer Bitcoin trading
python algorithmic trading library
I tried using TradeWave (BitCoin system trading in Python)
Python --bitflyer Get asset balance
Bitcoin price monitor python script
Python --bitflyer Get chat content
Python
System trading starting with Python3: long-term investment