Comments (5)
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.
If you try:
stream.on('message', (data) => console.log(data))
Do you receive the desired subscription messages?
from alpaca-ts.
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.
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.
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)
- News Support HOT 3
- CORS Paper mode issue? HOT 5
- Streaming using Paper Credentials HOT 3
- V2 Market Data Additions HOT 7
- Support for overriding baseUrls HOT 6
- Does not compile with TypeScript 4.7 module = nodenext HOT 26
- BarsTimeframe not supporting arbitrary values HOT 4
- Cannot run npm run build with node v17 & npm v8 HOT 1
- Bar interface does not match Alpaca Bar HOT 10
- Package does not export typing information
- Add `non_marginable_buying_power` to the `getAccount` response.
- Create Account Endpoint
- What would be the best way to get previous trading history for an account?
- Uncaught (in promise) Error: PageOfTrades parsing failed "Cannot read property 'map' of null" HOT 2
- Error: export 'AlpacaClient' (imported as 'AlpacaClient') was not found in '@master-chief/alpaca' (possible exports: default) HOT 2
- /v2/positions/{symbol} supports qty and percentage params HOT 1
- Expand timeframe options for getBars HOT 2
- Crypto Support HOT 10
- Add Functionality to Close AlpacaStream? HOT 2
- Build Output Not Reflecting Recent PR HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alpaca-ts.