wagenaartje / stocks.js Goto Github PK
View Code? Open in Web Editor NEW:moneybag: stocks.js is an easy-to-use stock market API for Javascript
Home Page: https://github.com/wagenaartje/stocks.js
License: MIT License
:moneybag: stocks.js is an easy-to-use stock market API for Javascript
Home Page: https://github.com/wagenaartje/stocks.js
License: MIT License
Your readme claims that the js isn't currently hosted however users should eb able to use this url in a script tag:
https://raw.githubusercontent.com/wagenaartje/stocks.js/master/dist/stocks.js
Could be useful to advertise that to others.
Thanks for the library!
Any time I enter an incorrect stock symbol, I get this error:
TypeError: this._throw is not a function
Yet it still works when I give a correct stock symbol. Do you know how I can resolve this issue?
Please see
https://docs.npmjs.com/files/package.json#description
under Some tips:
To avoid errors like: Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
.
I'm using a very tight project setup for a minimal project, therefore I don't want to bloat up the project with a transpilation just for this library.
Checked through the code and did some tests but want to make sure im not totally missing something. Can I get the current price with any of the calls, or can Alpha Vantage return that at all? I only want to pull the current price like once an hour so it doesn't have to be down to the second or anything.
{
"Error Message": "The intraday time series encountered an internal or external error - we apologize for the inconvenience. If you would like to obtain the realtime stock quote for the current trading day, please refer to the latest data point of our DAILY and DAILY ADJUSTED functions (e.g., https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo | https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo)."
}
I think its really bad approach to use stocks.API_KEY
directly without using a constructor. What about const stock = new Stocks({API_KEY: 'xxxx'})
?
I am confused. I use stocks.js like
var Stocks = require("stocks.js");
var stocks = new Stocks('XXXX');
stocks.timeSeries({
symbol: 'TSLA',
interval: '1min',
amount: 10
}, function (err, res) {
console.log(res);
});
Also, I installed stocks.js with npm.
However, I got an error "ReferenceError: Stocks is not defined"
Is there any suggestion?
Thanks in advance.
I am running the jsfiddle example here https://jsfiddle.net/wagenaartje/2pph8rax/6/
I changed the API key but it is not retrieving any data.
Does it not work anymore? Is it being blocked?
Once URL.searchParams
has compability with more browsers, we can use this to simplify the _createURL
function. At this moment, the function is supported by:
The usage is pretty simple, example:
var url = new URL('https://www.alphavantage.co/query?');
var params = {
function: 'TIME_SERIES_INTRADAY',
symbol: 'MSFT',
interval: '1min',
apikey: 'demo'
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
For Node, all you need to do is add:
var URL = require('url').URL;
is not necessary as dependency.
I guess the commit of the global variable broke nodejs [https://github.com/wagenaartje/stocks.js/commit/8548d96010f2f48dbf7bc649bf27883dd07fbc01].
program:
var stocks = require("stocks.js");
stocks.API_KEY = 'XXXX';
stocks.timeSeries({
symbol: 'TSLA',
interval: '1min',
amount: 10
}, function (err, res) {
console.log(res);
});
result:
stocks.timeSeries({
^
TypeError: stocks.timeSeries is not a function
at Object.<anonymous> (/app/app3.js:3:8)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
date
is always set to Invalid Date
in Firefox.
Issue is that newSample['date'] = new Date(key + ' EDT');
isn't proper ES[56]. Date's ctor expects a RFC 2822 or ISO8601 dateString
but YYYY-MM-DD EDT
isn't. Chrome seems more lenient than FF.
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
Any time is ask for a month of data, it will give around 21 days, and a year will give around 200 days of data. Is there anyway to fix this?
I need to add target: 'node'
to my webpack config otherwise I've got this error
ERROR in ./~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'child_process'
I would suggest to use https://www.npmjs.com/package/whatwg-fetch. I can create a pull request
Should we use an error hashtable to throw errors? Or is there any other cleaner way we could handle errors? At this moment, the _checkOptions
function is very ugly and unreadable. We need to find a way to fix this.
Something I thought of was:
Stocks.prototype.ERRORS = {
0: 'Some error message'
1: 'Some other error message'
2: ...
}
So you could easily call errors like:
throw new Error(this.ERRORS[0])
But I think there is a better solution out there...
"use strict";
exports.__esModule = true;
var stocks = require("stocks.js");
stocks.API_KEY = 'XXXX';
stocks.timeSeries({
symbol: 'TSLA',
interval: '1min',
amount: 10
}, function (err, res) {
console.log(res);
});
Debugged a little bit and the URL created is messed up, the interval is rewritten
Processing Key:function = TIME_SERIES_intraday
Processing Key:symbol = TSLA
Processing Key:outputsize = full
Processing Key:1min = undefined1min
This is the URL: [https://www.alphavantage.co/query?apikey=Q7U8TQA8Q5ZBYYTY&function=TIME_SERIES_intraday&symbol=TSLA&outputsize=full&1min=undefined1min&]
Stacktrace if useful:
Error: An error occured. Please create an issue at https://github.com/wagenaartje/stocks/issues with your code, and provide the following message: Invalid API call, please visit doc
umentation (https://www.alphavantage.co/documentation/) for function: TIME_SERIES_INTRADAY
at exports.XMLHttpRequest.request.onload (/app/node_modules/stocks.js/src/stocks.js:56:21)
at exports.XMLHttpRequest.dispatchEvent (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
at setState (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:614:14)
at IncomingMessage.<anonymous> (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
Hi @wagenaartje !
I like your idea ๐ , and I started a little refactoring on my fork with your code style.
But I propose a contribution guide to help other people to contribute.
And it would be great if everything is written in ES6.
What do you think about it ?
Have a nice day ๐ฎ
Is there a way to include more intervals for day trading, for example 2h/4h?
var Stocks = require("stocks.js");
const stocks = new Stocks("J4AUAHBUZ1DQDSA0");
export default function Form() {
const [stock, setStock] = useState("");
const callApi = async () => {
var result = await stocks.timeSeries(options);
var options = {
symbol: "AAPL",
interval: "daily",
start: new Date("2020-07-01"),
end: new Date("2020-09-09"),
};
console.log(result);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.