Failed to connect binance WebSocket api

Viewed 1519

I am trying to connect to binance websocket API using python. But it fails with this error: [Errno 8] nodename nor servname provided, or not known

import websocket
import sys
import pkg_resources

SOCKET = 'wss://stream.binance.com:9443/ws/ethusdt@kline_1m'

def on_open(ws):
    print('opened connection')

def on_close(ws):
    print('close connection')

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

def on_error(ws, error):
    print(error)


websocket.enableTrace(True)
ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message, on_error=on_error)
ws.run_forever()

Anyone has an idea how should I resolve the issue. Are their APIs reliable? Thanks in advance

1 Answers

Binanic api change consistently with each upgrade to the API. There a few ways of approaching the problem .

firstly check that the WSS socket is live ...

SOCKET = 'wss://stream.binance.com:9443/ws/ethusdt@kline_1m'

Then

A: check that you can log on manually through their documentation site as there live testing facility on there

If that is not successful.

B: Check that you API keys are still valid for account interaction

C: check the api version they currently using

E: on the API documentation there is live examples you can test the get requests

D: Their service sometimes has limits on how often you can call their API Make sure you within range

Over an above that if you have tested their api live examples for get requests there no reason that is should not work . As a rule of thumb I always use postman or insomnia to check the requests before I implement it in my own code as sometimes your header in the post requests do not match their header requirements

Insomnia or Postman

I personally always use the insomnia first to make sure the requests work then implement it in my code to match the format .

Related