question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does the streaming API still work?

See original GitHub issue

I’ve followed the docs on your main github page, but my subscriptions to quotes/updates/etc doesn’t work. I receive a successful authentication message, but when I try to subscribe for quotes, I never get any notifications.

The docs on alpaca’s site it shows something like this, but I don’t see anything related to subscribing for updates.

{
    "action": "listen",
    "data": {
        "streams": ["trade_updates"]
    }
}

But in your example, the action is “subscribe” and the data doesn’t appear to be formatted in a similar format. I’m not sure what I’m missing…

Here is my code for connecting to the socket

this.socketConnection.once("authenticated", () => {
      this.socketConnection.subscribe("quotes", ["AAPL, FB, SPY"]);

      this.socketConnection.on("quote", (quote) => {
        console.log(quote);
      });

      this.socketConnection.on("bar", (bar) => {
        console.log(bar);
      });

      this.socketConnection.on("trade", (trade) => {
        console.log(trade);
      });

      this.socketConnection.on("trade_updates", (update) => {
        console.log(update);
      });
});`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
awweathercommented, Jun 26, 2021

Wow, I’m not sure how I missed the quotes needing to be individual strings. That seemed to be the issue. I did have market_data, just showed you the wrong one in the example. Thanks for taking the time to help with this! This library has been really helpful

0reactions
117commented, Jun 26, 2021

In your socket connection you pass the array of quotes as one string:

["AAPL, FB, SPY"]

This is incorrect they should be individual strings:

["AAPL", "FB", "SPY"]

It is also important that you switch the type to market_data in the AlpacaStream constructor. If quotes is what you wish to receive, the example below works for me:

const stream = new AlpacaStream({
  credentials: {
    key: 'myKey',
    secret: 'mySecret',
  },
  type: 'market_data',
})

stream.once('authenticated', () =>
  stream.subscribe('quotes', ['AAPL', 'FB', 'SPY']),
)

stream.on('subscription', ({ quotes }) =>
  console.log(`subscribed to ${quotes.join(',')}`),
)

stream.on('quote', (quote) => console.log(quote))

I get the following output when running the above code:

subscribed to SPY,AAPL,FB

Hope this ends up working for you. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Streaming API vs REST API – what is the difference?
Streaming APIs are stateful, and REST APIs are stateless (which means that the API itself saves no client context, except for the initial ......
Read more >
The Key Differences Between Streaming APIs and REST APIs
When it comes to the differences between streaming APIs and REST APIs, real-time apps don't REST. Find out how they compare and contrast....
Read more >
Stream api v1 deprecation - Twitter Developers
We recently graduated filtered stream into Twitter API v2: Early Access and announced a 60-day deprecation window. We will retire this endpoint in...
Read more >
Consuming streaming data | Docs | Twitter Developer Platform
To open the data stream to have Tweets delivered, you need to send a connection request to the API. In the streaming model,...
Read more >
REST vs Streaming APIs: How They Differ - Nordic APIs
Streaming still operates over the same HTTP methods as REST, but because of its event-driven interactions, the relationship shifts power from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found