Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 230 #238

Closed
wants to merge 3 commits into from
Closed

Fix 230 #238

wants to merge 3 commits into from

Conversation

jmichiel
Copy link
Contributor

@jmichiel jmichiel commented Jan 19, 2018

Fix for #230

This script exposed the issue:

from ws4py.client.threadedclient import WebSocketClient
import json, time, logging, threading

class DummyClient(WebSocketClient):
    def __init__(self, url):
        super().__init__(url)

    def opened(self):
        print("Websocket opened")
        self.send(json.dumps({'event': u'subscribe', 'channel': u'candles', 'key':'trade:5m:tBCHUSD'}))
        self.send(json.dumps({'event': u'subscribe', 'channel': u'ticker', 'symbol': u'tBTCUSD'}))
        self.send(json.dumps({'event': u'subscribe', 'channel': u'ticker', 'symbol': u'tBTGUSD'}))
        self.send(json.dumps({'event': u'subscribe', 'channel': u'ticker', 'symbol': u'tBCHUSD'}))

    def closed(self, code, reason=None):
        print("Websocket Closed", code, reason)

    def received_message(self, m):
        print(m)
        data = json.loads(str(m))
        if isinstance(data, dict):
            if data.get('event', None) == 'subscribed':
                print('Subscribed with id ', data['chanId'])

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    try:
        ws = DummyClient('wss://api.bitfinex.com/ws/2')
        ws.connect()
        ws.run_forever()
    except KeyboardInterrupt:
        ws.close()

It should produce this kind of output:
for each 'suscribe', you should have a 'susbcribed' with a chanId
then you should see data for each subscription as arrays with the chanId as first element.

{"event":"info","version":2}
{"event":"subscribed","channel":"ticker","chanId":1,"symbol":"tBTCUSD","pair":"BTCUSD"}
Subscribed with id  1
[1,[11669,50.19305176,11670,27.40211685,19,0.0016,11669,64602.90194275,11904,10647]]
{"event":"subscribed","channel":"ticker","chanId":49,"symbol":"tBTGUSD","pair":"BTGUSD"}
Subscribed with id  49
[49,[230.47,446.02458036,230.82,527.27514541,24,0.1168,229.5,71645.18196272,241.5,185]]
{"event":"subscribed","channel":"ticker","chanId":31,"symbol":"tBCHUSD","pair":"BCHUSD"}
Subscribed with id  31
[31,[1816,80.75025412,1816.2,185.6989998,-23.5,-0.0128,1818.5,28538.79857777,1863.1,1656]]
{"event":"subscribed","channel":"candles","chanId":76524,"key":"trade:5m:tBCHUSD"}
Subscribed with id  76524
[76524,[[1516304100000,1817.9,1829.8,1830,1810.9,80.06575253],[1516303800000,1798,1813.5,1820,1798,53.29618585],[1516303500000,1824.6,1798.1,1825,1798,170.83190693],[1516303200000,1824.4,1825,1832.1,1821.4,85.01132438],[1516302900000,1824.9,1824.4,1825,1823.1,77.16357855],[1516302600000,1827.9,1825,1834.9,1823.7,78.9139323],[1516302300000,1828.5,1825.4,1833.2,1823.3,38.58896115],[1516302000000,1830.6,1828.4,1836.5,1826.7,99.0569226],[1516301700000,1818.5,1830.5,1830.6,1818.5,39.46627181],[1516301400000,1816.8,1822.1,1830.4,1813,74.11415388],[1516301100000,1822.5,1816.7,1822.9,1805,97.3917624],[1516300800000,1819.3,1819.7,1822.9,1819.3,92.72934884],[1516300500000,1819,1819.3,1820,1814.2,57.18609166],[1516300200000,1810.8,1819,1820,1809.9,71.81453538],[1516299900000,1811.8,1811.4,1814.8,1795,125.18208723],[1516299600000,1815.2,1809.1,1819.4,1804.8,143.36985543],[1516299300000,1810.8,1815.5,1820,1800.4,69.44463075],[1516299000000,1806.8,1812.8,1820,1800.2,159.41801108],[1516298700000,1783.1,1809.3,1814,1775.4,389.83692787],[1516298400000,1771.3,1782.9,1787.2,1770,165.87814414],[1516298100000,1781.1,1774.4,1786.8,1770,107.03924811],[1516297800000,1780.6,1778.5,1795.4,1775.1,159.89096939],[1516297500000,1783.8,1780.5,1786.6,1776.2,83.35048525]]]
[76524,[1516368900000,1817.2,1817.5,1822.6,1810.5,8.3972583]]
[76524,[1516369200000,1817.3,1818.5,1818.5,1817,0.24530253]]
[49,[230.47,446.02458036,230.48,468.5786241,24,0.1168,229.5,71645.18196272,241.5,185]]
[76524,"hb"]
[1,"hb"]
[31,"hb"]

@jmichiel jmichiel closed this Jan 19, 2018
@jmichiel
Copy link
Contributor Author

This wasn't the proper way to do it

@jmichiel jmichiel deleted the fix_230 branch January 19, 2018 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant