Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

AlpacaStream for type "account" is busted for paper accounts #71

Closed
xanoinc opened this issue May 18, 2021 · 8 comments
Closed

AlpacaStream for type "account" is busted for paper accounts #71

xanoinc opened this issue May 18, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@xanoinc
Copy link

xanoinc commented May 18, 2021

Description
When using type account for AlpacaStream it complains about malformed json.

I did some research and it looks like according to the documentation, the account stream uses binary frames for the paper api while the live stream uses text frames. I'm not sure why, but that seems to be causing an issue.

See note from - https://alpaca.markets/docs/api-documentation/api-v2/streaming/

Expected

Expecting paper support to work just like normal support.

Reproduction
Steps we can take to reproduce the bug:

Just create a stream using a paper account and trade_updates channel and it will complain about bad json

Logs
If applicable, add logs to help explain the bug.

Additional
Add any other context about the problem here.

@xanoinc xanoinc added the bug Something isn't working label May 18, 2021
@117
Copy link
Contributor

117 commented May 18, 2021

Good catch.

@117
Copy link
Contributor

117 commented May 20, 2021

I have been swamped with my current project lately but I will get to this by end of week!

@xanoinc
Copy link
Author

xanoinc commented May 20, 2021

I think I may have fixed this in stream.ts. So far this appears to work.

          this.connection.onmessage = async (event) => {
              let data = event.data
              if (data instanceof Blob) {
                data = await event.data.text()
              }

              let parsed = JSON.parse(data), messages = this.params.type == 'account' ? [parsed] : parsed;

@117
Copy link
Contributor

117 commented May 21, 2021

Will try your fix out.

117 added a commit that referenced this issue May 21, 2021
@117
Copy link
Contributor

117 commented May 21, 2021

Just tested your fix, works great! Thanks for the contribution, version 6.2.2 has this update implemented.

@117 117 closed this as completed May 21, 2021
@awweather
Copy link

@117 @seanmetrix The Blob type doesn't exist in Nodejs, only the browser. So this breaks any attempt to access the stream.

@FallingSnow
Copy link

@117 You need to add the following maybe?

import { Blob } from "node:buffer";

@117 117 reopened this Aug 17, 2021
117 added a commit that referenced this issue Aug 17, 2021
@117
Copy link
Contributor

117 commented Aug 17, 2021

@FallingSnow @awweather This should be resolved in 6.2.6.

@117 117 closed this as completed Aug 17, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants