twelvedata / twelvedata-python

Twelve Data Python Client - Financial data API & WebSocket
https://twelvedata.com
MIT License
392 stars 57 forks source link

[Bug] Unable to get Websockets to work #41

Closed anshulmittal712 closed 3 years ago

anshulmittal712 commented 3 years ago

Description I'm trying to follow the example as mentioned here to subscribe to a few tickers but I don't get any events. I understand that WS are only for paid plans and I am still evaluating it on the Basic plan, but as per the documentation and this support link, there are a few instruments for which the trial for WS is enabled even for the base users, with certain limitations. I have tried with multiple tickers from this list, and also from the ones in the example, but to no avail.

My code

from twelvedata import TDClient
import os
td = TDClient(apikey=os.getenv("TD_API_KEY"))

ts = td.time_series(
    symbol="BTC/USD",
    interval="1min",
    outputsize=1
).as_json()
print(ts)

def on_event(e):
    print(e)

ws = td.websocket(symbols=['BTC/USD'], on_event=on_event, log_level="debug")
ws.subscribe(['ETH/BTC', 'AAPL','BTC/USD'])
ws.connect()
ws.keep_alive()

Expected Output and Problem Description To establish that the API key works, I am printing the Time Series for BTC/USD. That works as expected. However, the second part of the code does not add any tickers to the list of subscribed instruments.

I am expecting at least an output like so, (and then the subsequent events for change in ticker price):

{"event":"subscribe-status","status":"ok","success":[{"symbol":"BTC/USD","exchange":"Binance","country":"","type":"Digital Currency"}],"fails":null}

Screenshots of actual output The output just stays at this and I need to interrupt to exit from this. Screenshot 2021-07-04 at 2 14 35 AM

Environment

certifi==2020.12.5
chardet==4.0.0
cycler==0.10.0
gevent==21.1.2
greenlet==1.1.0
idna==2.10
kiwisolver==1.3.1
matplotlib==3.4.2
mplfinance==0.12.7a17
numpy==1.21.0
pandas==1.2.5
Pillow==8.2.0
pyparsing==2.4.7
pyTelegramBotAPI==3.7.9
python-dateutil==2.8.1
pytimeparse==1.1.8
pytz==2021.1
requests==2.25.1
six==1.16.0
twelvedata==1.2.1
urllib3==1.26.4
websocket-client==1.1.0
zope.event==4.5.0
zope.interface==5.4.0
midasSSS commented 3 years ago

Try to reinstall: websocket-client==0.55.0

anshulmittal712 commented 3 years ago

Thanks a lot, @midasSSS. Spent hours pouring over source code trying to see what's going wrong, and this simple dependency change fixes it. 🥳 🎊

Might be useful to include this in the Readme here. Can raise a PR for the same.