python

BTC積立Bot

import ccxt
import math
import schedule
import time

API_KEY = 'your_api_key'
API_SECRET = 'your_api_secret'
FUND_JPY = 1000.0 # 積立額(円)

def main():

    ex = ccxt.liquid()
    ex.apiKey = API_KEY
    ex.secret = API_SECRET
    
    # 残高取得
    balance = ex.fetch_balance()
    balance_jpy = float(balance['JPY']['total'])
    
    # BTC価格取得
    ticker = ex.fetch_ticker(symbol='BTC/JPY')
    btc_price = float(ticker['ask'])

    # 購入量計算(Liquidは最低取引量0.0001)
    amount = math.floor((FUND_JPY / btc_price) * 10 ** 4) / (10 ** 4)
    
    # 成行で購入
    try:
        order = ex.create_market_buy_order(symbol='BTC/JPY', amount=amount)
    except Exception as e:
       print(e)
    else:
       print(order)

# 積立スケジュール (https://schedule.readthedocs.io/en/stable/ )
schedule.every().day.at("10:00").do(main)

while True:
    schedule.run_pending()
    time.sleep(1)
Was this helpful?