alpha_vantage_api_wrapper
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -7,2 +7,3 @@ "use strict"; | ||
const Crypto_1 = require("./Crypto"); | ||
const TechInd_1 = require("./TechInd"); | ||
class Alpha { | ||
@@ -20,2 +21,3 @@ /** | ||
this.crypto = new Crypto_1.Crypto(this); | ||
this.techInd = new TechInd_1.TechInd(this); | ||
} | ||
@@ -22,0 +24,0 @@ hasApiKey() { |
@@ -10,2 +10,29 @@ "use strict"; | ||
}); | ||
const _schemaTechInd = joi.object().keys({ | ||
datatype: joi.any().valid('csv', 'json'), | ||
interval: joi.any().valid('1min', '5min', '15min', '30min', '60min', 'daily', 'weekly', 'monthly'), | ||
series_type: joi.any().valid('close', 'open', 'high', 'low'), | ||
time_period: joi.number().integer() | ||
}); | ||
const _schemaMAMA = _schemaTechInd.keys({ | ||
fastlimit: joi.number().positive().precision(2), | ||
slowlimit: joi.number().positive().precision(2), | ||
}); | ||
const _schemaMACD = _schemaTechInd.keys({ | ||
fastperiod: joi.number().positive(), | ||
slowperiod: joi.number().positive(), | ||
signalperiod: joi.number().positive(), | ||
}); | ||
const _schemaMACDEXT = _schemaMACD.keys({ | ||
fastmatype: joi.number().min(0).max(8), | ||
slowmatype: joi.number().min(0).max(8), | ||
signalmatype: joi.number().min(0).max(8), | ||
}); | ||
const _schemaSTOCH = _schemaTechInd.keys({ | ||
fastkperiod: joi.number().positive(), | ||
slowkperiod: joi.number().positive(), | ||
slowdperiod: joi.number().positive(), | ||
slowkmatype: joi.number().min(0).max(8), | ||
slowdmatype: joi.number().min(0).max(8), | ||
}); | ||
class Validator { | ||
@@ -27,3 +54,36 @@ static validateOptions(options, forbiddenKeys = '') { | ||
} | ||
static validateTechInd(options, schema = '_schema', forbiddenKeys = '') { | ||
if (options == {}) { | ||
return null; | ||
} | ||
let err = null; | ||
let _s = this.getSchema(schema); | ||
if (util_1.isNullOrUndefined(forbiddenKeys) || forbiddenKeys == '') { | ||
let { error } = joi.validate(options, _s); | ||
err = error; | ||
} | ||
else { | ||
let { error } = joi.validate(options, _s.forbiddenKeys(forbiddenKeys)); | ||
err = error; | ||
} | ||
return err; | ||
} | ||
static getSchema(schema) { | ||
if (schema == '_schema') { | ||
return _schemaTechInd; | ||
} | ||
if (schema.toLowerCase() == 'mama') { | ||
return _schemaMAMA; | ||
} | ||
if (schema.toLowerCase() == 'macd') { | ||
return _schemaMACD; | ||
} | ||
if (schema.toLowerCase() == 'macdext') { | ||
return _schemaMACDEXT; | ||
} | ||
if (schema.toLowerCase() == 'stoch') { | ||
return _schemaSTOCH; | ||
} | ||
} | ||
} | ||
exports.Validator = Validator; |
{ | ||
"name": "alpha_vantage_api_wrapper", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Alpha Vintage API Wrapper for Node.Js", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
268
README.md
@@ -32,2 +32,15 @@ # Alpha Vantage API - Node.js Wrapper [![Build Status](https://travis-ci.org/travis-ci/travis-web.svg?branch=master)](https://travis-ci.org/travis-ci/travis-web) | ||
* [Performance](#performance) | ||
* [Technical Indicators](#technical-indicators) | ||
* [SMA](#sma) | ||
* [EMA](#ema) | ||
* [WMA](#wma) | ||
* [DEMA](#dema) | ||
* [TEMA](#tema) | ||
* [TRIMA](#trima) | ||
* [KAMA](#kama) | ||
* [MAMA](#mama) | ||
* [T3](#t3) | ||
* [MACD](#macd) | ||
* [MACDEXT](#macdext) | ||
* [STOCH](#stoch) | ||
@@ -69,5 +82,5 @@ ## Instalation | ||
{ | ||
"datatype": "json" || "csv", | ||
"outputsize": "compact" || "full", | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" | ||
"datatype": "json" || "csv", // Default "json" | ||
"outputsize": "compact" || "full", // Default "compact" | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" // Default "5min" | ||
} | ||
@@ -87,4 +100,4 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"outputsize": "compact" || "full", | ||
"datatype": "json" || "csv", // Default "json" | ||
"outputsize": "compact" || "full", // Default "compact" | ||
} | ||
@@ -104,4 +117,4 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"outputsize": "compact" || "full", | ||
"datatype": "json" || "csv", // Default "json" | ||
"outputsize": "compact" || "full", // Default "compact" | ||
} | ||
@@ -121,3 +134,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -137,3 +150,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -153,3 +166,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -169,3 +182,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -184,3 +197,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -199,3 +212,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -220,5 +233,5 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"outputsize": "compact" || "full", | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" | ||
"datatype": "json" || "csv", // Default "json" | ||
"outputsize": "compact" || "full", // Default "compact" | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" // Default "5min" | ||
} | ||
@@ -237,4 +250,4 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"outputsize": "compact" || "full", | ||
"datatype": "json" || "csv", // Default "json" | ||
"outputsize": "compact" || "full", // Default "compact" | ||
} | ||
@@ -254,3 +267,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -270,3 +283,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -294,3 +307,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -309,3 +322,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -324,3 +337,3 @@ ``` | ||
{ | ||
"datatype": "json" || "csv", | ||
"datatype": "json" || "csv", // Default "json" | ||
} | ||
@@ -339,2 +352,211 @@ ``` | ||
alpha.sector.performance() | ||
``` | ||
# Technical Indicators | ||
## SMA | ||
This API returns the simple moving average (SMA) values. | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.sma(ticker, options) | ||
``` | ||
## EMA | ||
This API returns the exponential moving average (EMA) values. | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.ema(ticker, options) | ||
``` | ||
## WMA | ||
This API returns the weighted moving average (WMA) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.wma(ticker, options) | ||
``` | ||
## DEMA | ||
This API returns the double exponential moving average (DEMA) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.dema(ticker, options) | ||
``` | ||
## TEMA | ||
This API returns the triple exponential moving average (TEMA) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.tema(ticker, options) | ||
``` | ||
## TRIMA | ||
This API returns the triangular moving average (TRIMA) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.trima(ticker, options) | ||
``` | ||
## KAMA | ||
This API returns the Kaufman adaptive moving average (KAMA) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.kama(ticker, options) | ||
``` | ||
## MAMA | ||
This API returns the MESA adaptive moving average (MAMA) values. | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
"fastlimit" 0.01, // Float - Default 0.01 | ||
"slowlimit": 0.01 // Float - Default 0.01 | ||
} | ||
``` | ||
```js | ||
alpha.techInd.mama(ticker, options) | ||
``` | ||
## T3 | ||
This API returns the triple exponential moving average (T3) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
} | ||
``` | ||
```js | ||
alpha.techInd.t3(ticker, options) | ||
``` | ||
## MACD | ||
This API returns the moving average convergence / divergence (MACD) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
"fastperiod" 12, // Integer - Default 12 | ||
"slowperiod": 26, // Integer - Default 26 | ||
"signalperiod": 9, // Integer - Default 9 | ||
} | ||
``` | ||
```js | ||
alpha.techInd.mama(ticker, options) | ||
``` | ||
## MACDEXT | ||
This API returns the moving average convergence / divergence values with controllable moving average type | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
"fastperiod" 12, // Integer - Default 12 | ||
"slowperiod": 26, // Integer - Default 26 | ||
"signalperiod": 9, // Integer - Default 9 | ||
"fastmatype": 0, // Integer - Default 0-8 | ||
"slowmatype": 0, // Integer - Default 0-8 | ||
"signalmatype": 0, // Integer - Default 0-8 | ||
} | ||
``` | ||
```js | ||
alpha.techInd.mamaExt(ticker, options) | ||
``` | ||
## STOCH | ||
This API returns the stochastic oscillator (STOCH) values | ||
Available options = **object** | ||
```javascript | ||
{ | ||
"interval": "1min" || "5min" || "15min" || "30min" || "60min" || "daily weekly" || "monthly" // String - Default = "5min" | ||
"time_period": 60 || 200 // Integer - Default 60 | ||
"series_type": "close" || "open" || "high" || "low" // String - Default "close" | ||
"datatype": "json" || "csv", // String - Default "json" | ||
"fastkperiod" 5, // Integer - Default 5 | ||
"slowkperiod": 3, // Integer - Default 3 | ||
"slowdperiod": 3, // Integer - Default 3 | ||
"slowkmatype": 0, // Integer - Default 0-8 | ||
"slowdmatype": 0, // Integer - Default 0-8 | ||
} | ||
``` | ||
```js | ||
alpha.techInd.stoch(ticker, options) | ||
``` |
@@ -5,2 +5,3 @@ import { Stocks } from './Stocks' | ||
import { Crypto } from './Crypto' | ||
import { TechInd } from './TechInd'; | ||
@@ -14,2 +15,3 @@ export class Alpha { | ||
crypto: Crypto; | ||
techInd: TechInd; | ||
@@ -26,3 +28,4 @@ | ||
this.forex = new Forex(this); | ||
this.crypto = new Crypto(this) | ||
this.crypto = new Crypto(this); | ||
this.techInd = new TechInd(this); | ||
} | ||
@@ -29,0 +32,0 @@ |
@@ -10,2 +10,34 @@ let joi = require('joi'); | ||
const _schemaTechInd: any = joi.object().keys({ | ||
datatype: joi.any().valid('csv', 'json'), | ||
interval: joi.any().valid('1min', '5min', '15min', '30min', '60min', 'daily', 'weekly', 'monthly'), | ||
series_type: joi.any().valid('close', 'open', 'high', 'low'), | ||
time_period: joi.number().integer() | ||
}) | ||
const _schemaMAMA: any = _schemaTechInd.keys({ | ||
fastlimit: joi.number().positive().precision(2), | ||
slowlimit: joi.number().positive().precision(2), | ||
}) | ||
const _schemaMACD: any = _schemaTechInd.keys({ | ||
fastperiod: joi.number().positive(), | ||
slowperiod: joi.number().positive(), | ||
signalperiod: joi.number().positive(), | ||
}) | ||
const _schemaMACDEXT: any = _schemaMACD.keys({ | ||
fastmatype: joi.number().min(0).max(8), | ||
slowmatype: joi.number().min(0).max(8), | ||
signalmatype: joi.number().min(0).max(8), | ||
}) | ||
const _schemaSTOCH = _schemaTechInd.keys({ | ||
fastkperiod: joi.number().positive(), | ||
slowkperiod: joi.number().positive(), | ||
slowdperiod: joi.number().positive(), | ||
slowkmatype: joi.number().min(0).max(8), | ||
slowdmatype: joi.number().min(0).max(8), | ||
}) | ||
export class Validator { | ||
@@ -28,2 +60,42 @@ static validateOptions(options: Object, forbiddenKeys: String | Array<String> = '') { | ||
} | ||
static validateTechInd(options: Object, schema: string = '_schema', forbiddenKeys: String | Array<String> = '') { | ||
if (options == {}) { | ||
return null | ||
} | ||
let err = null; | ||
let _s = this.getSchema(schema) | ||
if (isNullOrUndefined(forbiddenKeys) || forbiddenKeys == '') { | ||
let { error } = joi.validate(options, _s) | ||
err = error; | ||
} else { | ||
let { error } = joi.validate(options, _s.forbiddenKeys(forbiddenKeys)) | ||
err = error; | ||
} | ||
return err | ||
} | ||
static getSchema(schema: string) { | ||
if(schema == '_schema'){ | ||
return _schemaTechInd | ||
} | ||
if (schema.toLowerCase() == 'mama') { | ||
return _schemaMAMA | ||
} | ||
if(schema.toLowerCase() == 'macd') { | ||
return _schemaMACD | ||
} | ||
if (schema.toLowerCase() == 'macdext') { | ||
return _schemaMACDEXT | ||
} | ||
if (schema.toLowerCase() == 'stoch') { | ||
return _schemaSTOCH | ||
} | ||
} | ||
} |
119161
22
1791
544