Pass self._streams as a list to subscribe()#363
Pass self._streams as a list to subscribe()#363Shakespeare0 wants to merge 1 commit intoalpacahq:masterfrom
Conversation
Pass self._streams as a list (rather than a set) to _StreamConn.subscribe() because JSON can not encode a set
|
This PR was closed last week: #352 |
|
@shlomikushchi / @Shakespeare0 - My implementation was a bit different. I was casting to |
|
I'm not sure why @medusa-trade 's fix did not work, but |
|
I agree with @Shakespeare0. This seems like a better solution. I just haven't been able to test it. If it works across Python versions, I think it would be best to merge it. I honestly did dig into why my connections were hanging with my solution. I just know that when I removed those changes, it was still broke on my Ubuntu system with version 3.8.7, but it worked for my local 3.8.5. So I moved on. |
|
I think the connection hanging may be a different issue. Without this fix, rather than the connection hanging, I get the error |
|
I get 1006 errors ALLLLLLL THE TIME. Same thing Object of type set is not JSON serializable. Would love to see this fix merged in ASAP |
|
Merge? This is because Alpaca API gets disconnected midway. So the API tries to reconnect. But when it does so, the channels are not reinitialized, hence it remains a set that is not JSON serializable. Hence, in alpaca_trade_api > stream2.py change 'streams': channels to 'streams': list(channels) in line 132. |
If the connection drops and it tries to reconnect, it fails because the channels are saved in self._streams, which is a set, which is not serializable in JSON, so convert it back to a list when passing the channels to _StreamConn.subscribe().