Closed Alan-Solitar closed 4 years ago
I also ran into a whole lot of problems trying to connect using python. Having tested various libraries I assume that there's something wrong with the way server treats the requests.
I either get the error that the websocket is closed or that the connection has been forcefully closed by host.
@Alan-Solitar Please let me know if you manage to advance on this one.
the websocket is not working
This is a weird issue. I found this on that topic: https://stackoverflow.com/questions/45192699/python-socketio-client-not-working
I have the same problem. This snapshot works like a charm:
var socket = require('socket.io-client')('https://streamer.cryptocompare.com/')
var subscription = ['5~CCCAGG~BTC~USD', '5~CCCAGG~ETH~USD']
socket.emit('SubAdd', {subs: subscription})
socket.on("m", function (message) {
console.log(message)
})
But connection from python seems impossible.
socketIO = SocketIO('https://streamer.cryptocompare.com')
socketIO.on('connect', lambda: print("Connected to server!!!"))
socketIO.wait(seconds=1)
socketIO.emit({'subs': ['5~CCCAGG~BTC~USD', '5~CCCAGG~ETH~USD']})
socketIO.on('m', lambda m: print(m))
Also cannot get the streaming api to work from python... have tried all kinds of websocket apis. An example would be great!
Can anyone please find a solution. This is really needed
You need to specify transport protocol like so:
wss://streamer.cryptocompare.com/socket.io/?transport=websocket
@Jeiwan I can now connect to the WebSocket by using your address but there are some issues
import websocket as ws
subs = ['5~CCCAGG~BTC~USD','5~CCCAGG~ETH~USD']
socket = ws.create_connection('wss://streamer.cryptocompare.com/socket.io/?transport=websocket')
socket.send('SubAdd',{'subs': subs})
This gives the following error
socket.send('SubAdd',{'subs': subs})
Traceback (most recent call last):
File "<ipython-input-54-26867dcffc38>", line 1, in <module>
socket.send('SubAdd',{'subs': subs})
File "/home/dhaval/anaconda3/lib/python3.6/site-packages/websocket/_core.py", line 234, in send
return self.send_frame(frame)
File "/home/dhaval/anaconda3/lib/python3.6/site-packages/websocket/_core.py", line 253, in send_frame
data = frame.format()
File "/home/dhaval/anaconda3/lib/python3.6/site-packages/websocket/_abnf.py", line 209, in format
raise ValueError("Invalid OPCODE")
ValueError: Invalid OPCODE
Am I doing something wrong?
@DhavalThkkar Socket.io uses WebSocket as a transport layer and implements its own protocol on top of it. So the best solution is to find a Socket.io implementation in your language, because otherwise you would have to implement the protocol yourself. General WebSocket clients and libraries won't work.
Is there any working python example? Can't figure out how to deal with cryptocompare WS api.
@Achse Have you solved the problem?I had the same problem.I can't connect the socket.io server through socketIO_client library in python.
Tried to connect from Android,
mSocket = IO.socket("https://streamer.cryptocompare.com/");
mSocket.emit("SubAdd", "5~CCCAGG~BTC~USD");
returns 401~BADFORMAT
What am I doing wrong?
@jobinbasani Have you solved the problem? I had the same problem.
@joongwon Nope, haven't solved it yet
any updates on this yet?
not able to connect with socket-io-java-client on Android! results in objects returned as "401-BADFORMAT"
Found the right way for Java client. The following should work:
JSONObject object = new JSONObject(); JSONArray arr = new JSONArray(); try { arr.put("11~BTC'"); object.put("subs", arr); socket.emit("SubAdd", object); } catch (JSONException e) { e.printStackTrace(); }
Hi there, just wanted to let you know that this version of the streaming API is being sunset in the next couple of weeks as we are moving to version 2, that has a lot more features and better support. Please visit our documentation page which provides code examples in javascript, node, python and golang: https://min-api.cryptocompare.com/documentation/websockets.
Hello. I am trying to connect to the websocket using python.
I am using the python websocket-client module the following way.
socket = websocket.WebSocket() socket.connect('wss://streamer.cryptocompare.com')
However, when i try to connect, i get an error that the websocket is already closed.
Am I doing something wrong or is there an issue with the web socket?