超簡単PythonでbitFlyer(ビットフライヤー)約定(取引)履歴取得(Lightning Realtime API利用)JSON-RPC 2.0版
超簡単にPythonでbitFlyer(ビットフライヤー)約定(取引)履歴取得(Lightning Realtime API利用)JSON-RPC 2.0版
Socket.IO版はこちらをどうぞ
1. ツールインストール
$ pip install websocket-client
2. ファイル作成
client.py
import websocket
import json
def on_message(ws, message):
print(json.loads(message)["params"]["message"])
def on_error(ws, error):
print(error)
def on_close(ws, close_status_code, close_msg):
print("### closed ###")
def on_open(ws):
message = {
"method": "subscribe",
"params": {"channel": "lightning_executions_BTC_JPY"},
}
ws.send(json.dumps(message))
print("### opened ###")
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
on_open = on_open,
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.run_forever()
3. 実行
$ client.py
[{'id': 2257621627, 'side': 'SELL', 'price': 5495547.0, 'size': 0.02, 'exec_date': '2021-09-05T15:40:44.9025668Z', 'buy_child_order_acceptance_id': 'JRF20210905-154044-438526', 'sell_child_order_acceptance_id': 'JRF20210905-154044-095904'}, {'id': 2257621628, 'side': 'SELL', 'price': 5495544.0, 'size': 0.0108942, 'exec_date': '2021-09-05T15:40:44.9025668Z', 'buy_child_order_acceptance_id': 'JRF20210905-154043-083886', 'sell_child_order_acceptance_id': 'JRF20210905-154044-095904'}]
以上、超簡単!