Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poloniex & websockets

===SIMPLE & SHORT===

Does anybody have working application that talks with Poloniex through WAMP in these days (January, 2018)?

===MORE SPECIFIC===

I used several info sources to make it work using combo: autobahn-cpp & C++. Windows 10 OS. I was able to connect to wss://api.poloniex.com, realm1. Plus I was able to subscribe and get subscription ID. But I never got any events even when everything established.

===RESEARCH===

During research in the web I saw a lot of controversial information:

1. Claims, that wss://api2.poloniex.com should be used, and channels names are actually numbers - How to connect to poloniex.com websocket api using a python library

2. This answer gave me base code, but I am getting anything more than just connections, also by following this answer - wss://api.poloniex.com is correct address - Connecting to Poloniex Push-API

3. I saw post (sorry, lost the link), there were comments made that websockets implementation are basically broken on poloniex. They were posted 6 months ago.

===SPECS===

1. Windows 10

2. Autobahn-Cpp

3. wss://api.poloniex.com:443 ; realm1

4. Different subscriptions: ticker, BTC_ETH, 148, 1002, etc..

5. Source code I got from here

===WILL HELP AS WELL===

  1. Is there any way to get all valid subscriptions or, probably, those, that have more than 0 subscribers? I mean, does WAMP have a way to do that?

  2. Is there any known issues with Autobahn-Cpp and poloniex combo?

  3. Is there any simpler way to test WAMP elsewhere to make sure Autobahn isn't a problem? Like any other well documented & supported online projects that accept WAMP websocket communication?

like image 323
Anton Kasabutski Avatar asked Jan 26 '26 12:01

Anton Kasabutski


2 Answers

I can receive the correct tick order book data from wss://api2.poloniex.com use python3 but sometime The channel 1002 may stop sending the new tick info.

like image 85
Ming Chu Avatar answered Jan 29 '26 03:01

Ming Chu


wss://api.poloniex.com:443 ; realm1

This may be the issue as I've been using api2 and here is the code that works, and has been working for the past 2 quarters non-stop. Its in python, but should be easy enough to port to C++.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import websocket
import json

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

def on_close(ws):
    print("### closed ###")
    connection.close()

def on_open(ws):
    print("ONOPEN")
    ws.send(json.dumps({'command':'subscribe','channel':'BTC_ETH'}))

def on_message(ws, message):
    message = json.loads(message)
    print(message)

websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://api2.poloniex.com/",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
ws.on_open = on_open
ws.run_forever()

the code is pretty much self-explanatory (You can check all channels/pairs on Poloniex API website), just save it and run in terminal

python3 fileName.py

should provide You with BTCETH raw stream of orders and trades on console output.

Playing with the message/subscriptions You can then do as You please with it.

like image 31
0x3W Avatar answered Jan 29 '26 02:01

0x3W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!