This is a command line tool and small Node.js API for retreiving data from Alpha Vantage.
You can use this from the command line to download stock data from Alpha Vantage to a CSV file.
You can use it from your Node.js app as a reusable code module.
Data is returned as is from Alpha Vantage with no modification.
For more information please see my blog post on the Data Wrangler.
If you like this project, please star this repo and support my work
Alpha Vantage is free, but to use it you must sign up for an API key. Please follow this link to sign up:
https://www.alphavantage.co/support/#api-key
For general guidance on working with financial market data, please refer to this finance API guide
The examples that follow use the 'demo' API key, please be aware that this has very limited usage.
To use this tool you need to have Node.js installed. This is quite straight forward, please see the Node.js web site for more details:
alpha-vantage-cli's main purpose is to be used from the command line to download stock data to a CSV file.
Once you have Node.js installed you can install the command line tool via npm by running the following command:
npm install -g alpha-vantage-cli
This installs the tool globally so that you can run it from any directory.
Minimal usage looks like this:
alpha-vantage-cli --type=<data-type> --symbol=<code-for-the-instrument> --api-key=<your-api-key>
Options:
For example to download daily data for Microsoft:
alpha-vantage-cli --type=daily --symbol=MSFT --api-key=demo --out=MSFT-daily.csv
Or to download intraday data:
alpha-vantage-cli --type=intraday --symbol=MSFT --api-key=demo --out=MSFT-intraday.csv
Optional options:
alpha-vantage-cli can also be imported into a Node.js script to be used from code.
To use please install locally in your Node.js project using npm as follows:
npm install --save alpha-vantage-cli
Here are examples of use from a JavaScript code file. Don't forget to replace the API key with your own!
S
var AlphaVantageAPI = require('alpha-vantage-cli').AlphaVantageAPI;
var yourApiKey = 'demo';
var alphaVantageAPI = new AlphaVantageAPI(yourApiKey, 'compact', true);
alphaVantageAPI.getIntradayData('MSFT', '15min')
.then(intradayData => {
console.log("Intraday data:");
console.log(intradayData);
})
.catch(err => {
console.error(err);
});
Usage from TypeScript is very similar to JavaScript, but with the added advantage of static types and better intellisense in Visual Studio Code!
import { AlphaVantageAPI } from 'alpha-vantage-cli';
var yourApiKey = 'demo';
var alphaVantageAPI = new AlphaVantageAPI(yourApiKey, 'compact', true);
alphaVantageAPI.getDailyData('MSFT')
.then(dailyData => {
console.log("Daily data:");
console.log(dailyData);
})
.catch(err => {
console.error(err);
});
import { AlphaVantageAPI } from 'alpha-vantage-cli';
var yourApiKey = 'demo';
var alphaVantageAPI = new AlphaVantageAPI(yourApiKey, 'compact', true);
alphaVantageAPI.getIntradayData('MSFT', '15min')
.then(intradayData => {
console.log("Intraday data:");
console.log(intradayData);
})
.catch(err => {
console.error(err);
});
A blog post is coming soon that describes how this works!
ts-node cli.ts --type=daily --symbol=STW.AX --api-key=<put-your-api-key-here> --out=./test.csv
or
npm run test:daily
npm run test:intraday
If you are interested to get into TypeScript please take a look at my no-frills minimal Node.js typescript starter project.