Giter VIP home page Giter VIP logo

Comments (5)

awweather avatar awweather commented on May 31, 2024 2

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

from alpaca-ts.

117 avatar 117 commented on May 31, 2024

If you try:

stream.on('message', (data) => console.log(data))

Do you receive the desired subscription messages?

from alpaca-ts.

117 avatar 117 commented on May 31, 2024

The following code is working for me locally:

import { AlpacaStream } from '@master-chief/alpaca'

const stream = new AlpacaStream({
  credentials: {
    key: 'mykey',
    secret: 'mysecret',
  },
  type: 'account',
  source: 'iex',
})

stream.once('authenticated', () => stream.subscribe('trade_updates'))
stream.on('trade_updates', (data) => console.log(data))

Results in:

{
  event: 'canceled',
  execution_id: '2a206db5-4e27-4e74-b5cf-61394e4c036c',
  ...
}

from alpaca-ts.

awweather avatar awweather commented on May 31, 2024

The code below produces these 3 messages in my console:

{ T: 'success', msg: 'connected' }
{ T: 'success', msg: 'authenticated' }
{ T: 'error', code: 400, msg: 'invalid syntax' }
const stream = new AlpacaStream({
        credentials: {
          key: process.env.ALPACA_API_KEY_PAPER,
          secret: process.env.ALPACA_SECRET_KEY_PAPER,
          paper: true,
        },
        type: "account",
        source: "iex"
      })
this.socketConnection.on("message", (data) => {
      console.log(data);
    });

    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);
    });

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

from alpaca-ts.

117 avatar 117 commented on May 31, 2024

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. 😃

from alpaca-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.