finnhubio / Finnhub-API

Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals and alternative data. https://finnhub.io/docs/api
98 stars 6 forks source link

websocket hangs #38

Closed pycoder2020 closed 4 years ago

pycoder2020 commented 4 years ago

Still getting websocket hanged from time to time. Here is log with times:

2020-03-19 21:42:13,026 DEBUG    --- request header ---
2020-03-19 21:42:13,026 DEBUG    GET /?token=******* HTTP/1.1

Upgrade: websocket
Host: ws.finnhub.io
Origin: http://ws.finnhub.io
Sec-WebSocket-Key: dH1TtIi/fv/2y2krxO8LFQ==
Sec-WebSocket-Version: 13
Connection: upgrade

2020-03-19 21:42:13,026 DEBUG    -----------------------
2020-03-19 21:42:13,027 DEBUG    --- response header ---
2020-03-19 21:43:18,517 DEBUG    HTTP/1.1 101 Switching Protocols
2020-03-19 21:43:18,517 DEBUG    Server: nginx/1.10.3
2020-03-19 21:43:18,517 DEBUG    Date: Thu, 19 Mar 2020 19:43:18 GMT
2020-03-19 21:43:18,517 DEBUG    Connection: upgrade
2020-03-19 21:43:18,518 DEBUG    Upgrade: websocket
2020-03-19 21:43:18,518 DEBUG    Sec-WebSocket-Accept: HPA4Fq1EUSF3nokqIzFXlMUVDfw=
2020-03-19 21:43:18,519 DEBUG    -----------------------
2020-03-19 21:43:18,519 DEBUG    send: b'\x81\xa3\x18Q\x90\x01cs\xe4xh4\xb2;:"\xe5ck2\xe2hz4\xb2-:"\xe9lz>\xfc#"s\xc2BTs\xed'

Check time between:

2020-03-19 21:42:13,027 DEBUG    --- response header ---
2020-03-19 21:43:18,517 DEBUG    HTTP/1.1 101 Switching Protocols

Passed more then 1 minute to get protocol switching header.

After:

2020-03-19 21:43:18,519 DEBUG    send: b'\x81\xa3\x18Q\x90\x01cs\xe4xh4\xb2;:"\xe5ck2\xe2hz4\xb2-:"\xe9lz>\xfc#"s\xc2BTs\xed'

Do not get any response for more 13 minutes. Still waiting...

Maybe I can help debug this issue somehow?

pycoder2020 commented 4 years ago

More details

netstat -abtn | findstr 35.232
  TCP    192.168.2.1:58882      35.232.124.3:443       ESTABLISHED
pycoder2020 commented 4 years ago

Stream stopped again...

2020-03-20 14:41:31,698 DEBUG    -----------------------
2020-03-20 14:41:31,698 DEBUG    --- response header ---
2020-03-20 14:41:31,840 DEBUG    HTTP/1.1 101 Switching Protocols
2020-03-20 14:41:31,840 DEBUG    Server: nginx/1.10.3
2020-03-20 14:41:31,840 DEBUG    Date: Fri, 20 Mar 2020 12:41:32 GMT
2020-03-20 14:41:31,840 DEBUG    Connection: upgrade
2020-03-20 14:41:31,840 DEBUG    Upgrade: websocket
2020-03-20 14:41:31,840 DEBUG    Sec-WebSocket-Accept: 80woxDhWUZnvdGoxr7FwOOUsDik=
2020-03-20 14:41:31,842 DEBUG    -----------------------
2020-03-20 14:41:31,842 DEBUG    send: b'\x81\xa3d\x8f\xf0\x02\x1f\xad\x84{\x14\xea\xd28F\xfc\x85`\x17\xec\x82k\x06\xea\xd2.F\xfc\x89o\x06\xe0\x9c ^\xad\xa2A(\xad\x8d'
2020-03-20 14:41:36,811 INFO     {'data': [{'p': 25.03, 's': 'RCL', 't': 1584708096947, 'v': 4}], 'type': 'trade'} Delay -136ms = 1584708096811 - 1584708096947
2020-03-20 14:41:36,812 INFO     {'data': [{'p': 25.03, 's': 'RCL', 't': 1584708096947, 'v': 4}], 'type': 'trade'} Delay -135ms = 1584708096812 - 1584708096947
2020-03-20 14:41:36,812 INFO     {'data': [{'p': 25, 's': 'RCL', 't': 1584708096946, 'v': 557}], 'type': 'trade'} Delay -134ms = 1584708096812 - 1584708096946
2020-03-20 14:41:36,812 INFO     {'data': [{'p': 25, 's': 'RCL', 't': 1584708096946, 'v': 557}], 'type': 'trade'} Delay -134ms = 1584708096812 - 1584708096946

-------------------REMOVED SOME LINES--------------------------

2020-03-20 15:32:40,338 INFO     {'data': [{'p': 23.75, 's': 'RCL', 't': 1584711159774, 'v': 25}], 'type': 'trade'} Delay 564ms = 1584711160338 - 1584711159774
2020-03-20 15:32:40,338 INFO     {'data': [{'p': 23.75, 's': 'RCL', 't': 1584711159774, 'v': 25}], 'type': 'trade'} Delay 564ms = 1584711160338 - 1584711159774
2020-03-20 15:32:40,338 INFO     {'data': [{'p': 23.73, 's': 'RCL', 't': 1584711160063, 'v': 900}], 'type': 'trade'} Delay 275ms = 1584711160338 - 1584711160063
2020-03-20 15:32:40,339 INFO     {'data': [{'p': 23.73, 's': 'RCL', 't': 1584711160063, 'v': 900}], 'type': 'trade'} Delay 276ms = 1584711160339 - 1584711160063
2020-03-20 15:32:40,339 INFO     {'data': [{'p': 23.8125, 's': 'RCL', 't': 1584711160184, 'v': 5}], 'type': 'trade'} Delay 155ms = 1584711160339 - 1584711160184
2020-03-20 15:32:40,339 INFO     {'data': [{'p': 23.8125, 's': 'RCL', 't': 1584711160184, 'v': 5}], 'type': 'trade'} Delay 155ms = 1584711160339 - 1584711160184

After last update 15:32:40,339 no more data until now... @finnhubio is there any difference in payed API key in streaming? (for example different stream priority, different server). Seems WS stream do not work reliable...

pycoder2020 commented 4 years ago

Tried to rerun scrip and for this time stream restored, but we still have issue with stream stopping and leaving open connection.