1.2.2 • Published 5 years ago
stock-data.js v1.2.2
:bulb: This library is new, so there might be issues. If you find any, please report them at the issues section.
Features
- Real time data (multiple stocks at a time)
- Historical data
- Historical data from one day (multiple stocks at a time)
- Intraday Data
- Search
- Forex data (realtime, historical)
- Manipulate your data using options
Installing
$ npm install stock-data.js
API-token
Go to WorldTradingData and obtain an API-token for free by creating an account.
(A free account you can make 250 API-calls per day and you can follow how many you have left from their dashboard)
Usage
Because the API-token is personal I would recommend using the token as an enviroment variable. Visit documentation for available options.
Each example uses:
const stockdata = require('stock-data.js');
Real time data
// Get the real time price and additional data from AAPL
stockdata.realtime({
symbols: 'AAPL',
API_TOKEN: process.env.TOKEN,
})
.then(response => {
...
})
.catch(error => {
...
});
// Get the real time price and additional data from AAPL, MSFT and TSLA
stockdata.realtime({
symbols: ['AAPL', 'MSFT', 'TSLA'],
API_TOKEN: process.env.TOKEN,
})
.then(response => {
...
})
.catch(error => {
...
});
Historical data
// Get historical data for AAPL using options to only get data from the year 2018
stockdata.historical({
symbol: 'AAPL',
API_TOKEN: process.env.TOKEN,
options: {
date_from: '2018-01-01',
date_to: '2018-12-31'
}
})
.then(response => {
...
})
.catch(error => {
...
});
Historical data: single day
// Get the historical data of AAPL and Microsoft from the date 2018-01-02
stockdata.historicalDay({
symbols: ['AAPL', 'MSFT'],
API_TOKEN: process.env.TOKEN,
options: {
date: '2018-01-02'
}
})
.then(response => {
...
})
.catch(error => {
...
});
Intraday
// Get the prices of AAPL with 1 min interval the last 5 days
stockdata.intraday({
symbol: 'AAPL',
API_TOKEN: process.env.TOKEN,
options: {
interval: '1',
range: '5'
}
})
.then(response => {
...
})
.catch(error => {
...
});
Search
// Searching for Apple
stockdata.search({
search_term: 'Apple',
API_TOKEN: process.env.TOKEN,
})
.then(response => {
...
})
.catch(error => {
...
});
Forex
Real time data
// Get the realtime values of USD
stockdata.forex.realtime({
base: 'USD',
API_TOKEN: process.env.TOKEN,
})
.then(response => {
...
})
.catch(error => {
...
});
Historical data
// Get the historical values between USD and GBP
stockdata.forex.historical({
base: 'USD',
convert_to: 'GBP',
API_TOKEN: process.env.TOKEN,
})
.then(response => {
...
})
.catch(error => {
...
});
Historical data: single day
// Get the historical values from 2018-01-01 of USD
stockdata.forex.historicalDay({
base: 'USD',
API_TOKEN: process.env.TOKEN,
options: {
date: '2018-01-01',
}
})
.then(response => {
...
})
.catch(error => {
...
});
Contributing
WIP
Disclaimer
All the data comes from WorldTradingData. They might shutdown their service or change their business model at any time. So please note that this library is only a wrapper and it might stop working at any time if WorldTradingData stop delivering data.
License
MIT