npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

alpha-vantage-cli

v1.0.8

Published

A command line app and Node.js api for retreiving data from Alpha Vantage.

Downloads

116

Readme

alpha-vantage-cli

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.

Getting an Alpha Vantage API key

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

The examples that follow use the 'demo' API key, please be aware that this has very limited usage.

Node.js installation

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:

http://nodejs.org/

Usage from the command line

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:

  • --type -> The type of data to download (daily or intraday).
  • --symbol -> The symbol for the company or instrument you are interested in (eg MSFT)
  • --api-key -> Your Alpha Vantage API key.
  • --out -> Sets the name of the output file. CSV data is written to this file.

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:

  • --output-data-size -> Sets the output data size (full or compact).
  • --interval -> Sets the interval for intraday data (1min, 5min, 15min, 30min or 60min)
  • --verbose -> Display verbose information while the tool is running.
  • --version -> Display the version of the tool.
  • --help -> Display help.

Usage from a Node.js script

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

Usage from JavaScript

Here are examples of use from a JavaScript code file. Don't forget to replace the API key with your own!

Daily data

S

Intraday data

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

Usage from TypeScript is very similar to JavaScript, but with the added advantage of static types and better intellisense in Visual Studio Code!

Daily data

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

Intraday data

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

How it works

A blog post is coming soon that describes how this works!

Testing the code from the repository

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

TypeScript template

If you are interested to get into TypeScript please take a look at my no-frills minimal Node.js typescript starter project.