Skip to content

Commit

Permalink
Merge pull request #32 from zackurben/feature/add-apo-like-indicators
Browse files Browse the repository at this point in the history
Feature/add apo like indicators
  • Loading branch information
zackurben authored Nov 12, 2017
2 parents 7b4d28a + 61ebda6 commit eb86f1a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
11 changes: 11 additions & 0 deletions lib/technical.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ module.exports = config => {
signalmatype
});

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

return {
sma: SMA_LIKE('SMA'),
ema: SMA_LIKE('EMA'),
Expand All @@ -64,6 +73,8 @@ module.exports = config => {
willr: SMA_LIKE('WILLR'),
adx: SMA_LIKE('ADX'),
adxr: SMA_LIKE('ADXR'),
apo: APO_LIKE('APO'),
ppo: APO_LIKE('PPO'),
mom: SMA_LIKE('MOM'),
bop: SMA_LIKE('BOP'),
cci: SMA_LIKE('CCI'),
Expand Down
3 changes: 3 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const keys = {
'Technical Analysis: WILLR': 'data',
'Technical Analysis: ADX': 'data',
'Technical Analysis: ADXR': 'data',
'Technical Analysis: APO': 'data',
'Technical Analysis: PPO': 'data',
'Technical Analysis: MOM': 'data',
'Technical Analysis: BOP': 'data',
'Technical Analysis: CCI': 'data',
Expand Down Expand Up @@ -143,6 +145,7 @@ const keys = {
'5.3: Signal Period': 'signalperiod',
'5.3: SlowK MA Type': 'slowkmatype',
'5.3: FastD MA Type': 'fastdmatype',
'5.3: MA Type': 'matype',
'5.4: Fast MA Type': 'fastmatype',
'5.4: SlowD Period': 'slowdperiod',
'5.5: Slow MA Type': 'slowmatype',
Expand Down
2 changes: 1 addition & 1 deletion test/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
jest.unmock('request-promise-native');
const alpha = require('../')();
const delay = require('delay');
const TIME = 4000;
const TIME = 5000;

test(`intraday crypto works`, () => {
expect.assertions(2);
Expand Down
2 changes: 1 addition & 1 deletion test/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
jest.unmock('request-promise-native');
const alpha = require('../')();
const delay = require('delay');
const TIME = 4000;
const TIME = 5000;

test(`intraday data works`, () => {
expect.assertions(2);
Expand Down
2 changes: 1 addition & 1 deletion test/forex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
jest.unmock('request-promise-native');
const alpha = require('../')();
const delay = require('delay');
const TIME = 4000;
const TIME = 5000;

test(`forex data works`, () => {
expect.assertions(3);
Expand Down
2 changes: 1 addition & 1 deletion test/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
jest.unmock('request-promise-native');
const alpha = require('../')();
const delay = require('delay');
const TIME = 4000;
const TIME = 5000;

test(`sector performance data works`, () => {
expect.assertions(11);
Expand Down
40 changes: 39 additions & 1 deletion test/technical.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
jest.unmock('request-promise-native');
const alpha = require('../')();
const delay = require('delay');
const TIME = 4000;
const TIME = 5000;

test(`sma data works`, () => {
expect.assertions(9);
Expand Down Expand Up @@ -325,6 +325,44 @@ test(`adxr data works`, () => {
});
});

test(`apo data works`, () => {
expect.assertions(11);
return delay(TIME)
.then(() => alpha.technical.apo(`msft`, `daily`, `close`))
.then(data => {
expect(data['Meta Data']).toBeDefined();
expect(data['Meta Data']['1: Symbol']).toEqual('msft');
expect(data['Meta Data']['2: Indicator']).toEqual('Absolute Price Oscillator (APO)');
expect(data['Meta Data']['3: Last Refreshed']).toBeDefined();
expect(data['Meta Data']['4: Interval']).toEqual('daily');
expect(data['Meta Data']['5.1: Fast Period']).toEqual(12);
expect(data['Meta Data']['5.2: Slow Period']).toEqual(26);
expect(data['Meta Data']['5.3: MA Type']).toEqual(0);
expect(data['Meta Data']['6: Series Type']).toEqual('close');
expect(data['Meta Data']['7: Time Zone']).toBeDefined();
expect(data['Technical Analysis: APO']).toBeDefined();
});
});

test(`ppo data works`, () => {
expect.assertions(11);
return delay(TIME)
.then(() => alpha.technical.ppo(`msft`, `daily`, `close`))
.then(data => {
expect(data['Meta Data']).toBeDefined();
expect(data['Meta Data']['1: Symbol']).toEqual('msft');
expect(data['Meta Data']['2: Indicator']).toEqual('Percentage Price Oscillator (PPO)');
expect(data['Meta Data']['3: Last Refreshed']).toBeDefined();
expect(data['Meta Data']['4: Interval']).toEqual('daily');
expect(data['Meta Data']['5.1: Fast Period']).toEqual(12);
expect(data['Meta Data']['5.2: Slow Period']).toEqual(26);
expect(data['Meta Data']['5.3: MA Type']).toEqual(0);
expect(data['Meta Data']['6: Series Type']).toEqual('close');
expect(data['Meta Data']['7: Time Zone']).toBeDefined();
expect(data['Technical Analysis: PPO']).toBeDefined();
});
});

test(`mom data works`, () => {
expect.assertions(9);
return delay(TIME)
Expand Down

0 comments on commit eb86f1a

Please sign in to comment.