8
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python - bitflyer ビットコイン売買

Posted at

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)
8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?