Comments (10)
I am getting a strange error using a custom written wrapper class:
'use strict';
const Log = require('./Log.js');
module.exports = class {
constructor(alpaca, subscriptions) {
this.client = alpaca.websocket;
this.client.onStateChange((newState) => {
Log.debug(`websocket state changed to ${newState}`);
});
this.client.onConnect(() => {
Log.info('connected to websocket');
this.client.subscribe([
'trade_updates',
'account_updates',
'T.FB',
'Q.AAPL',
'A.FB',
'AM.AAPL'
]);
});
this.client.onOrderUpdate(data => {
Log.info(`order updates: ${JSON.stringify(data)}`);
});
this.client.onAccountUpdate(data => {
Log.info(`account updates: ${JSON.stringify(data)}`);
});
this.client.onStockTrades((subject, data) => {
Log.info(`stock trades: ${subject}, ${data}`);
});
this.client.onStockQuotes((subject, data) => {
Log.info(`stock quotes: ${subject}, ${data}`);
});
this.client.onStockAggSec((subject, data) => {
Log.info(`stock aggregate seconds: ${subject}, ${data}`);
});
this.client.onStockAggMin((subject, data) => {
Log.info(`stock aggregate minutes: ${subject}, ${data}`);
});
this.client.onError((error) => {
Log.error(error);
});
this.client.onDisconnect(() => {
Log.info('disconnected from websocket');
});
}
connect() {
this.client.connect();
}
};
MacBook-Pro ➜ alpaca-trade node index.js
2018-12-06T04:36:50.649Z [debug] websocket state changed to connecting
2018-12-06T04:36:50.649Z [debug] websocket state changed to authenticating
2018-12-06T04:36:50.649Z [debug] websocket state changed to connected
2018-12-06T04:36:50.649Z [info] connected to websocket
{ NatsError: 'Authorization Violation'
at Client.processErr (/Users/justin/Sites/alpaca-trade/node_modules/nats/lib/nats.js:1114:28)
at Client.processInbound (/Users/justin/Sites/alpaca-trade/node_modules/nats/lib/nats.js:859:28)
at Socket.<anonymous> (/Users/justin/Sites/alpaca-trade/node_modules/nats/lib/nats.js:529:16)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'NatsError',
message: '\'Authorization Violation\'',
code: 'NATS_PROTOCOL_ERR',
chainedError: undefined }
I verified that I am passing a correct AlpacakeyId
and secretKey
.
from alpaca-trade-api-js.
Ran into the exact same error yesterday. It worked a couple minutes before, then without me changing my code it just started returning those errors.
from alpaca-trade-api-js.
Currently to access polygon data it is required that you have opened a brokerage account. I ran the code above with my own credentials and it worked. If you have a brokerage account and are seeing this issue then it is indeed a problem.
@faridelnasire that is very strange that it was working at all... It could also be an issue with Polygon.
We are working on adding trade and quote streaming to the Alpaca data api, so you should be able to stream that data soon without requiring a brokerage account.
The streaming endpoints are definitely not well documented right now (not documented at all really) and we are planning on improving this.
from alpaca-trade-api-js.
@ChemicalRocketeer thanks for the reply. So, is there anyway without streaming, to get real-time quote prices/volume?
from alpaca-trade-api-js.
Unfortunately not, until more data api features are available. Creating a brokerage account with Alpaca should be a pretty easy fix in the meantime though, and should make the above code start working.
from alpaca-trade-api-js.
You might be able to get what you want using the getBars()
function also.
from alpaca-trade-api-js.
Hey @suddjian , does this still not work? I tested this before, and I do not see it working so I wanted to ask:
I'm trying to get some kind of streaming data.
I've been getting it with this, and hit the limits often when I fetch any more rapidly than ~1000ms:
If this does not work, definitely no worries - but I just wanted to check that I'm not missing something else that is also available.
from alpaca-trade-api-js.
I'm afraid I can't answer that, I'm not involved with this project anymore. @umitanuki?
from alpaca-trade-api-js.
For those using node, you simply have to call client.connect()
. I had the same issue, then after calling this function, the socket is working as expected.
from alpaca-trade-api-js.
This seems to be working now. I'm using a paper account and polygon: false
and I am getting minuet bar data. I tried with aggregate second data and it does not work which matches what the docs say about being Polygon only.
websocket.onStockAggSec(function(data)): Register callback function for the channel 'A.<SYMBOL>'. (Polygon only)
this._dataSocket.subscribe(['alpacadatav1/AM.FB', 'alpacadatav1/AM.AAPL', 'alpacadatav1/AM.GOOG']);
[10:38:57 AM] [6/10/2020] [log] State changed to connecting
[10:38:57 AM] [6/10/2020] [log] Server started on port: 4000
[10:38:57 AM] [6/10/2020] [log] State changed to authenticating
[10:38:57 AM] [6/10/2020] [log] State changed to connected
[10:38:57 AM] [6/10/2020] [log] Connected to data socket
[10:39:05 AM] [6/10/2020] [log] Stock agg min: AM.AAPL {"ev":"AM","symbol":"AAPL","volume":77794,"accumulatedVolume":803668,"officialOpenPrice":347.98,"vwap":349.5151,"openPrice":349.93,"closePrice":350.03,"highPrice":350.03,"lowPrice":349.85,"averagePrice":349.4641,"startEpochTime":1591799880000,"endEpochTime":1591799940000}
[10:39:05 AM] [6/10/2020] [log] Stock agg min: AM.FB {"ev":"AM","symbol":"FB","volume":46717,"accumulatedVolume":314452,"officialOpenPrice":240.92,"vwap":236.1886,"openPrice":237.27,"closePrice":237.16,"highPrice":237.28,"lowPrice":237.14,"averagePrice":237.5336,"startEpochTime":1591799880000,"endEpochTime":1591799940000}
from alpaca-trade-api-js.
Related Issues (20)
- [Question]: Max number of bars returned from getBarsV2 HOT 1
- [Bug]: getBarsV2 returns AlpacaBar objects without symbols HOT 1
- getSnapshot previous close price discrepancy[Bug]:
- [Question]: page_token is null instead of empty string HOT 2
- [Bug]: throw new Error('WebSocket is not open: readyState 0 (CONNECTING)'); HOT 3
- [Question]: What replaced Alpaca.getAggregates()? HOT 1
- [Question]: Is there a way to call the Announcement functions? HOT 1
- [Bug]: importing alpaca-trade-api in react HOT 2
- [Bug]: WebSocket is not open: readyState 0 (CONNECTING)'
- [Bug]: Update Node deps / NodeJS14 -> 18
- [Bug]: getLatestCryptoQuote is not a function HOT 1
- [Question]: Why does order.getAll not take all params? HOT 1
- [Bug]: DataV2 `pageLimit` not respected when `limit` is not specified HOT 1
- [Question]: How to Take Profit and set Stop Loss HOT 1
- [Bug]: Cannot open bracket order starting with sell stop
- [Bug]: GetNewsParams->includeContent should be include_content HOT 2
- [Bug]: Date precision
- Support intraday_reporting on getPortfolioHistory
- [Question]: Has getCryptoBars() been replaced by getLatestCryptoBars() ? HOT 1
- [Bug]: Status Code 422 for createOrder
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-trade-api-js.