alpha_vantage_api_wrapper
Advanced tools
Comparing version 0.0.15 to 0.1.0
@@ -283,2 +283,163 @@ "use strict"; | ||
} | ||
rsi(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
let options_err = Validator_1.Validator.validateTechInd(options); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'RSI', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
ad(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
delete o['series_type']; | ||
delete o['time_period']; | ||
let options_err = Validator_1.Validator.validateTechInd(options, '_schma', ['series_type', 'time_period']); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'AD', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
adx(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
delete o['series_type']; | ||
let options_err = Validator_1.Validator.validateTechInd(options, '_schma', 'series_type'); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'ADX', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
cci(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
delete o['series_type']; | ||
let options_err = Validator_1.Validator.validateTechInd(options, '_schma', 'series_type'); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'CCI', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
aroon(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
delete o['series_type']; | ||
let options_err = Validator_1.Validator.validateTechInd(options, '_schma', 'series_type'); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'AROON', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
bbands(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
let options_err = Validator_1.Validator.validateTechInd(options, 'bands'); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'BBANDS', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
obv(ticker, options = {}) { | ||
return new Promise((reject, resolve) => { | ||
if (!this._alpha.hasApiKey()) | ||
reject(consts_1.NO_TOKEN); | ||
if (ticker == '') | ||
reject(consts_1.NO_TICKER); | ||
let o = this._options; | ||
delete o['series_type']; | ||
delete o['time_period']; | ||
let options_err = Validator_1.Validator.validateTechInd(options, '_schma', ['series_type', 'time_period']); | ||
if (options_err) { | ||
reject(ErrorSerializer_1.ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'OBV', ticker); | ||
axios_1.default.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch((err) => { | ||
reject(err.data); | ||
}); | ||
}); | ||
} | ||
setRequiredOptions(options, func, ticker) { | ||
@@ -285,0 +446,0 @@ Object.assign(options, { |
@@ -16,2 +16,7 @@ "use strict"; | ||
}); | ||
const _schemaBBands = _schemaTechInd.keys({ | ||
nbdevup: joi.number().positive(), | ||
nbdevdn: joi.number().positive(), | ||
matype: joi.number().min(0).max(8), | ||
}); | ||
const _schemaMAMA = _schemaTechInd.keys({ | ||
@@ -83,2 +88,5 @@ fastlimit: joi.number().positive().precision(2), | ||
} | ||
if (schema.toLowerCase() == 'bands') { | ||
return _schemaBBands; | ||
} | ||
if (schema.toLowerCase() == 'stoch') { | ||
@@ -85,0 +93,0 @@ return _schemaSTOCH; |
{ | ||
"name": "alpha_vantage_api_wrapper", | ||
"version": "0.0.15", | ||
"version": "0.1.0", | ||
"description": "Alpha Vintage API Wrapper for Node.Js", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -319,2 +319,184 @@ import {Alpha} from './index' | ||
public rsi(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o = this._options | ||
let options_err = Validator.validateTechInd(options); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'RSI', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
public ad(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o: any = this._options | ||
delete o['series_type'] | ||
delete o['time_period'] | ||
let options_err = Validator.validateTechInd(options, '_schma', ['series_type', 'time_period']); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'AD', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
public adx(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o :any = this._options | ||
delete o['series_type'] | ||
let options_err = Validator.validateTechInd(options, '_schma', 'series_type'); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'ADX', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
public cci(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o: any = this._options | ||
delete o['series_type'] | ||
let options_err = Validator.validateTechInd(options, '_schma', 'series_type'); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'CCI', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
public aroon(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o: any = this._options | ||
delete o['series_type'] | ||
let options_err = Validator.validateTechInd(options, '_schma', 'series_type'); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'AROON', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
public bbands(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o: any = this._options | ||
let options_err = Validator.validateTechInd(options, 'bands'); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'BBANDS', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
public obv(ticker: string, options: object = {}) { | ||
return new Promise((reject: Function, resolve: Function) => { | ||
if (!this._alpha.hasApiKey()) reject(NO_TOKEN) | ||
if (ticker == '') reject(NO_TICKER) | ||
let o: any = this._options | ||
delete o['series_type'] | ||
delete o['time_period'] | ||
let options_err = Validator.validateTechInd(options, '_schma', ['series_type', 'time_period']); | ||
if (options_err) { | ||
reject(ErrorSerializer.ValidationError(options_err)); | ||
} | ||
Object.assign(o, options); | ||
this.setRequiredOptions(o, 'OBV', ticker) | ||
axios.get(this._alpha._url, { | ||
params: o | ||
}).then((res) => { | ||
resolve(res.data) | ||
}).catch((err) => { | ||
reject(err.data) | ||
}) | ||
}) | ||
} | ||
protected setRequiredOptions(options: object, func: string, ticker: string) { | ||
@@ -321,0 +503,0 @@ Object.assign(options, { |
@@ -17,2 +17,8 @@ let joi = require('joi'); | ||
const _schemaBBands: any = _schemaTechInd.keys({ | ||
nbdevup: joi.number().positive(), | ||
nbdevdn: joi.number().positive(), | ||
matype: joi.number().min(0).max(8), | ||
}) | ||
const _schemaMAMA: any = _schemaTechInd.keys({ | ||
@@ -96,2 +102,6 @@ fastlimit: joi.number().positive().precision(2), | ||
if (schema.toLowerCase() == 'bands') { | ||
return _schemaBBands | ||
} | ||
if (schema.toLowerCase() == 'stoch') { | ||
@@ -98,0 +108,0 @@ return _schemaSTOCH |
131771
2115