Commit de2d1e6c by wangfa

合约价格同步

parent 7e45bdef
/.idea
\ No newline at end of file
import websocket
import json
from db.redis_db import RedisClientLocal
SOCKET = "wss://fstream.binance.com/ws"
SUBSCRIBE_MESSAGE = "{\"method\": \"SUBSCRIBE\",\"params\":[\"!markPrice@arr\"]}"
MARK_PRICES = {}
def on_open(ws):
print("Connection established.")
ws.send(SUBSCRIBE_MESSAGE)
def on_close(ws):
print("Connection closed.")
def on_message(ws, message):
message = json.loads(message)
for item in message:
print(item)
MARK_PRICES[item["s"]] = item["p"]
redis_con.con().set(f"laravel_cache:premium-price:binance:{item['s']}", item['p'])
if __name__ == "__main__":
redis_con = RedisClientLocal()
ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
ws.run_forever()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment