Skip to content

Commit

Permalink
Merge pull request #33 from zackurben/feature/add-remaining-indicators
Browse files Browse the repository at this point in the history
Feature/add remaining indicators
  • Loading branch information
zackurben authored Nov 12, 2017
2 parents eb86f1a + 3c2a376 commit d115eb3
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 145 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@
- Adding CHANGELOG.md and backfilling releases
- Adding utils to the core export
- Adding missing tests

0.0.6
- Increasing jest timeout
- Updating deps

0.0.7
- Adding env support for the api key
- Updating deps

1.0.0
- Adding forex support
- Adding crypto support
- Adding technical indicator support
- Adding weekly and monthly adjusted time series data support
- Updating deps
- Fixed issue where failing requests were not going to a catch handler.

BREAKING
- Changing the daily adjusted data to be under the daily_adjusted namespace from
adjusted
256 changes: 116 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,179 +8,155 @@ This is a simple wrapper around the [Alpha Vantage API](https://www.alphavantage

All contributions are welcome! This is an open source project under the MIT license, see [LICENSE.md](LICENSE.md) for additional information.

### Roadmap

- [x] View basic symbol data
- [x] Add code linting
- [x] Add code coverage
- [x] Add documentation
- [x] Add more test coverage
- [x] Add CI/CD support
- [x] Add Sector Performance data
- [ ] Add Technical indicators data
- [x] Add Forex data
- [x] Add Crypto currency data
- [x] Add utils to clean up response data
- [ ] Add better documentation for the sdk functions

### Installation
`All available functions with this SDK have the same parameters as listed in the the Alpha Vantage Docs, without the "function" or "apikey". Do not include the "function" or "apikey" parameters when using this library. All functions return promises with the response data.`

## Installation
```bash
npm i alphavantage
```

### Usage


##### Setup
## Usage

```javascript
/**
* Init alphavantage with your API key.
* Init Alpha Vantage with your API key.
*
* @param {String} key
* Your AlphaVantage API key.
* Your Alpha Vantage API key.
*/
const alpha = require('alphavantage')({ key: 'qweqweqwe' });
```

##### Data

```javascript
/**
* Data functions: Short Term
*
* Types available: intraday
*
* All of the data functions have the same signature:
* alpha.data.intraday(symbol [, size [, type [, interval]]])
*
* @param {String} symbol
* The stock ticker symbol to get data for.
* @param [String] size
* The result size to fetch. Available: compact (last 100pts) and full (all, very large).
* @param [String] type
* The datatype to getch. Available: json and csv
* @param [Number] interval
* The time interval (mins) inbetween data points. Available: 1, 5, 15, 30, and 60
*
* @returns {Promise}
* The request promise.
*/
// Simple examples
alpha.data.intraday(`msft`).then(data => {
console.log(data);
});

/**
* Data functions: Long Term
*
* Types available: daily, adjusted, weekly, and monthly
*
* All of the data functions have the same signature:
* alpha.data.<type>(symbol [, size [, type]])
*
* @param {String} symbol
* The stock ticker symbol to get data for.
* @param [String] size
* The result size to fetch. Available: compact (last 100pts) and full (all, very large).
* @param [String] type
* The datatype to getch. Available: json and csv
*
* @returns {Promise}
* The request promise.
*/
alpha.data.<type>(`msft`).then(data => {
alpha.forex.rate('btc', 'usd').then(data => {
console.log(data);
});
```
})

##### Technicals
alpha.crypto.intraday('btc', 'usd').then(data => {
console.log(data);
})

```javascript
/**
* Technical functions: SMA-Like
*
* Types available: sma, wma, dema, tema, trima, kama, t3, rsi, mom, cmo, roc, rocr, trix, and midpoint.
*
* All of the previous technical functions have the same signature:
* alpha.technical.<type>(symbol [, interval [, time_period [, series_type]]])
*
* @param {String} symbol
* The stock ticker symbol to get data for.
* @param {String} interval
* Time interval between two consecutive data points in the time series.
* The following values are supported: 1min, 5min, 15min, 30min, 60min, daily, weekly, monthly
* @param {Number} time_period
* Number of data points used to calculate each moving average value.
* Positive integers are accepted (e.g., time_period=60, time_period=200)
* @param {String} series_type
* The desired price type in the time series.
* Four types are supported: close, open, high, low
*
* @returns {Promise}
* The request promise.
*/
alpha.technical.<type>(`msft`, `daily`, `close`).then(data => {
alpha.technical.sma(`msft`, `daily`, 60, `close`).then(data => {
console.log(data);
});
})

/**
* Technical functions: MAMA-Like
*
* Types available: mama
*
* All of the previous technical functions have the same signature:
* alpha.technical.<type>(symbol [, interval [, series_type [, fastlimit [, slowlimit]]]])
*
* @param {String} symbol
* The stock ticker symbol to get data for.
* @param {String} interval
* Time interval between two consecutive data points in the time series.
* The following values are supported: 1min, 5min, 15min, 30min, 60min, daily, weekly, monthly
* @param {String} series_type
* The desired price type in the time series.
* Four types are supported: close, open, high, low
* @param [Number] fastlimit
* Positive floats are accepted. By default, fastlimit=0.01
* @param [Number] slowlimit
* Positive floats are accepted. By default, slowlimit=0.01
*
* @returns {Promise}
* The request promise.
*/
alpha.technical.mama(`msft`, `daily`, `close`).then(data => {
alpha.performance.sector().then(data => {
console.log(data);
});
```

##### Sector
## Util

Data polishing
- Rewrite weird data keys to be consistent across all api calls. This is an optional utility you can use with the result of any api call.

```javascript
/**
* Sector Performance
*
* Get realtime and historical sector performances calculated from S&P500 incumbents.
*
* @returns {Promise}
* The request promise.
*/
alpha.performance.sector().then(data => {
console.log(data);
});
const polished = alpha.util.polish(data);
```

##### Util
## Data

See [Alpha Vantage](https://www.alphavantage.co/documentation/#time-series-data) for the parameters.
```javascript
/**
* Data polishing
*
* Rewrite weird data keys to be consistent across all api calls. This is an optional
* utility you can use with the result of any api call.
*/
const polished = alpha.util.polish(data);
alpha.data.intraday(symbol, interval)
alpha.data.daily(symbol, interval)
alpha.data.daily_adjusted(symbol, interval)
alpha.data.weekly(symbol, interval)
alpha.data.weekly_adjusted(symbol, interval)
alpha.data.monthly(symbol, interval)
alpha.data.monthly_adjusted(symbol, interval)
```

## Forex

See [Alpha Vantage](https://www.alphavantage.co/documentation/#fx) for the parameters.
```javascript
alpha.forex.rate(from_currency, to_currency)
```

## Crypto

See [Alpha Vantage](https://www.alphavantage.co/documentation/#digital-currency) for the parameters.
```javascript
alpha.crypto.intraday(symbol, market)
alpha.crypto.daily(symbol, market)
alpha.crypto.weekly(symbol, market)
alpha.crypto.monthly(symbol, market)
```

## Technicals

See [Alpha Vantage](https://www.alphavantage.co/documentation/#technical-indicators) for the parameters.
```javascript
alpha.technical.sma(symbol, market)
alpha.technical.ema(symbol, interval, time_period, series_type)
alpha.technical.wma(symbol, interval, time_period, series_type)
alpha.technical.dema(symbol, interval, time_period, series_type)
alpha.technical.tema(symbol, interval, time_period, series_type)
alpha.technical.trima(symbol, interval, time_period, series_type)
alpha.technical.kama(symbol, interval, time_period, series_type)
alpha.technical.mama(symbol, interval, series_type, fastlimit, slowlimit)
alpha.technical.t3(symbol, interval, time_period, series_type)
alpha.technical.macd(symbol, interval, series_type, fastperiod, slowperiod, signalperiod)
alpha.technical.macdext(symbol, interval, series_type, fastperiod, slowperiod, signalperiod, fastmatype, slowmatype, signalmatype)
alpha.technical.stoch(symbol, interval, fastkperiod, slowkperiod, slowdperiod, slowkmatype, slowdmatype)
alpha.technical.stochf(symbol, interval, fastkperiod, fastdperiod, fastdmatype)
alpha.technical.rsi(symbol, interval, time_period, series_type)
alpha.technical.stochrsi(symbol, interval, time_period, series_type, fastkperiod, slowdperiod, fastdmatype)
alpha.technical.willr(symbol, interval, time_period)
alpha.technical.adx(symbol, interval, time_period)
alpha.technical.adxr(symbol, interval, time_period)
alpha.technical.apo(symbol, interval, series_type, fastperiod, slowperiod, matype)
alpha.technical.ppo(symbol, interval, series_type, fastperiod, slowperiod, matype)
alpha.technical.mom(symbol, interval, time_period, series_type)
alpha.technical.bop(symbol, interval)
alpha.technical.cci(symbol, interval, time_period)
alpha.technical.cmo(symbol, interval, time_period, series_type)
alpha.technical.roc(symbol, interval, time_period, series_type)
alpha.technical.rocr(symbol, interval, time_period, series_type)
alpha.technical.aroon(symbol, interval, time_period)
alpha.technical.aroonosc(symbol, interval, time_period)
alpha.technical.mfi(symbol, interval, time_period)
alpha.technical.trix(symbol, interval, time_period, series_type)
alpha.technical.ultosc(symbol, interval, timeperiod1, timeperiod2, timeperiod3)
alpha.technical.dx(symbol, interval, time_period)
alpha.technical.minus_di(symbol, interval, time_period)
alpha.technical.plus_di(symbol, interval, time_period)
alpha.technical.minus_dm(symbol, interval, time_period)
alpha.technical.plus_dm(symbol, interval, time_period)
alpha.technical.bbands(symbol, interval, time_period, series_type, nbdevup, nbdevdn)
alpha.technical.midpoint(symbol, interval, time_period, series_type)
alpha.technical.midprice(symbol, interval, time_period)
alpha.technical.sar(symbol, interval, acceleration, maximum)
alpha.technical.trange(symbol, interval)
alpha.technical.atr(symbol, interval, time_period)
alpha.technical.natr(symbol, interval, time_period)
alpha.technical.ad(symbol, interval)
alpha.technical.adosc(symbol, interval, fastperiod, slowperiod)
alpha.technical.obv(symbol, interval)
alpha.technical.ht_trendline(symbol, interval, series_type)
alpha.technical.ht_sine(symbol, interval, series_type)
alpha.technical.ht_trendmode(symbol, interval, series_type)
alpha.technical.ht_dcperiod(symbol, interval, series_type)
alpha.technical.ht_dcphase(symbol, interval, series_type)
alpha.technical.ht_dcphasor(symbol, interval, series_type)
```

## Performance

See [Alpha Vantage](https://www.alphavantage.co/documentation/#sector-information) for the parameters.
```javascript
alpha.performance.sector()
```

#### Contact
## Contributing

All contributions are welcome! The purpose of this library is to keep function parity with the Alpha Vantage API, while keeping a slim and intuitive programming interface. Before any pull requests are made, please run `npm run lint` to fix style issues and ensure that all test are passing `npm test`. The codebase should always remain at 100% test coverage.

## Contact
- Author: Zack Urben
- Twitter: https://twitter.com/zackurben (better)
- Contact: [email protected]
6 changes: 4 additions & 2 deletions lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ module.exports = config => {
return {
intraday: series('TIME_SERIES_INTRADAY'),
daily: series('TIME_SERIES_DAILY'),
adjusted: series('TIME_SERIES_DAILY_ADJUSTED'),
daily_adjusted: series('TIME_SERIES_DAILY_ADJUSTED'),
weekly: series('TIME_SERIES_WEEKLY'),
monthly: series('TIME_SERIES_MONTHLY')
weekly_adjusted: series('TIME_SERIES_WEEKLY_ADJUSTED'),
monthly: series('TIME_SERIES_MONTHLY'),
monthly_adjusted: series('TIME_SERIES_MONTHLY_ADJUSTED')
};
};
23 changes: 22 additions & 1 deletion lib/technical.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ module.exports = config => {
const APO_LIKE = fn => (symbol, interval, series_type, fastperiod, slowperiod, matype) =>
util.fn(fn)({ symbol, interval, series_type, fastperiod, slowperiod, matype });

/**
* A generic function generator for ht-like technicals.
*
* @param {String} fn
* The ht-like function to use
*/
const HT_LIKE = fn => (symbol, interval, series_type) => util.fn(fn)({ symbol, interval, series_type });

return {
sma: SMA_LIKE('SMA'),
ema: SMA_LIKE('EMA'),
Expand All @@ -72,6 +80,7 @@ module.exports = config => {
util.fn('STOCHRSI')({ symbol, interval, time_period, series_type, fastkperiod, fastdperiod, fastdmatype }),
willr: SMA_LIKE('WILLR'),
adx: SMA_LIKE('ADX'),
adx: SMA_LIKE('ADX'),
adxr: SMA_LIKE('ADXR'),
apo: APO_LIKE('APO'),
ppo: APO_LIKE('PPO'),
Expand All @@ -85,17 +94,29 @@ module.exports = config => {
aroonosc: SMA_LIKE('AROONOSC'),
mfi: SMA_LIKE('MFI'),
trix: SMA_LIKE('TRIX'),
ultosc: (symbol, interval, timeperiod1, timeperiod2, timeperiod3) =>
util.fn('ULTOSC')({ symbol, interval, timeperiod1, timeperiod2, timeperiod3 }),
dx: SMA_LIKE('DX'),
minus_di: SMA_LIKE('MINUS_DI'),
plus_di: SMA_LIKE('PLUS_DI'),
minus_dm: SMA_LIKE('MINUS_DM'),
plus_dm: SMA_LIKE('PLUS_DM'),
bbands: (symbol, interval, time_period, series_type, nbdevup, nbdevdn, matype) =>
util.fn('BBANDS')({ symbol, interval, time_period, series_type, nbdevup, nbdevdn, matype }),
midpoint: SMA_LIKE('MIDPOINT'),
midprice: SMA_LIKE('MIDPRICE'),
sar: (symbol, interval, acceleration, maximum) => util.fn('SAR')({ symbol, interval, acceleration, maximum }),
trange: SMA_LIKE('TRANGE'),
atr: SMA_LIKE('ATR'),
natr: SMA_LIKE('NATR'),
ad: SMA_LIKE('AD'),
obv: SMA_LIKE('OBV')
adosc: (symbol, interval, fastperiod, slowperiod) => util.fn('ADOSC')({ symbol, interval, fastperiod, slowperiod }),
obv: SMA_LIKE('OBV'),
ht_trendline: HT_LIKE('HT_TRENDLINE'),
ht_sine: HT_LIKE('HT_SINE'),
ht_trendmode: HT_LIKE('HT_TRENDMODE'),
ht_dcperiod: HT_LIKE('HT_DCPERIOD'),
ht_dcphase: HT_LIKE('HT_DCPHASE'),
ht_dcphasor: HT_LIKE('HT_PHASOR')
};
};
Loading

0 comments on commit d115eb3

Please sign in to comment.