1

The Connection is being established but no message is being printed to the terminal. Here is my code.

import websocket, json

cc = 'btcusd'

interval = '1m'

socket = f'wss://stream.binance.com:9443/ws/{cc}@kline_{interval}'

print('This part of the code has been executed')


def on_open(ws):
  print("Opened")

def on_message(ws, message):
    print(message)

def on_close(ws):
    print("Connection Closed")

ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()
Precious Chika
  • 119
  • 1
  • 2
  • 6
  • do you have link to documentation? Show it in question (not in comment) – furas Oct 25 '21 at 13:00
  • base on documentation on https://docs.binance.org/api-reference/dex-api/ws-streams.html and https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md it seems you have to `subscribe` after `opened` – furas Oct 25 '21 at 13:06
  • maybe you should use module like https://python-binance.readthedocs.io/en/latest/ or you should check in source code how it works. – furas Oct 25 '21 at 13:11
  • code works for me for `cc = 'bnbbtc'` or `cc = 'btcusdt'` (with `t` at the end) but not for `cc = 'btcusd'` – furas Oct 25 '21 at 13:19

0 Answers0