![見出し画像](https://assets.st-note.com/production/uploads/images/77129024/rectangle_large_type_2_1d9910210cb0ae5a5e6e92cec37aa404.png?width=1200)
超簡単PythonでLiquid by FTX約定情報取得(WebSocket利用)
超簡単にPythonでLiquid by FTX約定情報取得(WebSocket利用)
1. ツールインストール
$ pip install websocket-client
2. ファイル作成
client.py
import websocket
import json
def on_message(ws, message):
print(json.loads(message)["data"])
def on_error(ws, error):
print(error)
def on_close(ws, close_status_code, close_msg):
print("### closed ###")
def on_open(ws):
message = {
"event": "pusher:subscribe",
"data": {"channel": "executions_cash_btcjpy"},
}
ws.send(json.dumps(message))
print("### opened ###")
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://tap.liquid.com/app/LiquidTapClient",
on_open = on_open,
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.run_forever(ping_interval = 60)
3. 実行
$ python client.py
{"created_at":1650806514,"id":480696407,"price":5083404.0,"quantity":0.0002,"taker_side":"sell","timestamp":"1650806514.472853"}
以上、超簡単!
4. 参考
この記事が気に入ったらサポートをしてみませんか?