alphavantage
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -21,2 +21,14 @@ 'use strict'; | ||
test(`intraday_extended data works`, () => { | ||
const fields = ['time', 'open', 'high', 'low', 'close', 'volume']; | ||
expect.assertions(3); | ||
return delay(TIME) | ||
.then(() => alpha.data.intraday_extended(`msft`, undefined, undefined, undefined, 'year1month1')) | ||
.then((data) => { | ||
expect(data instanceof Array).toBeDefined(); | ||
expect(data.length).toBeDefined(); | ||
expect(Object.keys(data[0])).toEqual(fields); | ||
}); | ||
}); | ||
test(`daily data works`, () => { | ||
@@ -23,0 +35,0 @@ expect.assertions(2); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
test(`company overview works`, () => { | ||
expect.assertions(58); | ||
expect.assertions(45); | ||
return delay(TIME) | ||
@@ -60,17 +60,4 @@ .then(() => alpha.fundamental.company_overview(`ibm`)) | ||
expect(data['SharesOutstanding']).toBeDefined(); | ||
expect(data['SharesShort']).toBeDefined(); | ||
expect(data['SharesFloat']).toBeDefined(); | ||
expect(data['SharesShortPriorMonth']).toBeDefined(); | ||
expect(data['ShortRatio']).toBeDefined(); | ||
expect(data['ShortPercentOutstanding']).toBeDefined(); | ||
expect(data['ShortPercentFloat']).toBeDefined(); | ||
expect(data['PercentInsiders']).toBeDefined(); | ||
expect(data['PercentInstitutions']).toBeDefined(); | ||
expect(data['ForwardAnnualDividendRate']).toBeDefined(); | ||
expect(data['ForwardAnnualDividendYield']).toBeDefined(); | ||
expect(data['PayoutRatio']).toBeDefined(); | ||
expect(data['DividendDate']).toBeDefined(); | ||
expect(data['ExDividendDate']).toBeDefined(); | ||
expect(data['LastSplitFactor']).toBeDefined(); | ||
expect(data['LastSplitDate']).toBeDefined(); | ||
}); | ||
@@ -77,0 +64,0 @@ }); |
@@ -798,6 +798,16 @@ 'use strict'; | ||
test(`200 request responses without meta data are thrown to a catch`, () => { | ||
test(`(json) 200 request responses without meta data are thrown to a catch`, () => { | ||
expect.assertions(1); | ||
return alpha.util | ||
.fn('200')({ datatype: 'json' }) | ||
.catch((error) => { | ||
expect(error).toEqual('An AlphaVantage error occurred. {}'); | ||
}); | ||
}); | ||
test(`util.fn defaults to datatype:json and throws an error due to missing meta data`, () => { | ||
expect.assertions(1); | ||
return alpha.util | ||
.fn('200')() | ||
@@ -808,1 +818,66 @@ .catch((error) => { | ||
}); | ||
describe('stripEol', () => { | ||
test('empty input', () => { | ||
expect(alpha.util.stripEol('')).toEqual(''); | ||
}); | ||
test('newline first', () => { | ||
expect(alpha.util.stripEol('\ntest')).toEqual('test'); | ||
}); | ||
test('newline last', () => { | ||
expect(alpha.util.stripEol('test\n')).toEqual('test'); | ||
}); | ||
test('multiple newline', () => { | ||
expect(alpha.util.stripEol('\ntest\n')).toEqual('test'); | ||
}); | ||
test('return first', () => { | ||
expect(alpha.util.stripEol('\rtest')).toEqual('test'); | ||
}); | ||
test('return last', () => { | ||
expect(alpha.util.stripEol('test\r')).toEqual('test'); | ||
}); | ||
test('multiple returns', () => { | ||
expect(alpha.util.stripEol('\rtest\r')).toEqual('test'); | ||
}); | ||
test('mixed newline and returns', () => { | ||
expect(alpha.util.stripEol('test\r\n')).toEqual('test'); | ||
}); | ||
test('invalid win newline', () => { | ||
expect(alpha.util.stripEol('test\n\r')).toEqual('test'); | ||
}); | ||
test('mixed win newline', () => { | ||
expect(alpha.util.stripEol('\r\ntest\n\r')).toEqual('test'); | ||
}); | ||
test('strips spaces at both ends', () => { | ||
expect(alpha.util.stripEol('\r\n test \n\r')).toEqual('test'); | ||
}); | ||
test('dosnt strip spaces in the middle of keys', () => { | ||
expect(alpha.util.stripEol('\r\n test value \n\r')).toEqual('test value'); | ||
}); | ||
}); | ||
describe('csvToJSON', () => { | ||
test('uses the first row for headers', () => { | ||
const text = `a,b,c,d | ||
1,2,3,4 | ||
9,8,7,6`; | ||
const output = alpha.util.csvToJSON(text); | ||
expect(output).toBeInstanceOf(Array); | ||
expect(output.length).toEqual(2); | ||
expect(Object.keys(output[0])).toEqual(['a', 'b', 'c', 'd']); | ||
expect(output[0]).toEqual({ a: `1`, b: `2`, c: `3`, d: `4` }); | ||
expect(output[1]).toEqual({ a: `9`, b: `8`, c: `7`, d: `6` }); | ||
}); | ||
}); |
243
CHANGELOG.md
@@ -1,38 +0,162 @@ | ||
# 0.0.1 | ||
# Changelog | ||
- Initial release | ||
All notable changes to this project will be documented in this file. | ||
# 0.0.2 | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
- Adding initial tests | ||
## [2.4.0] - 10/15/2022 | ||
# 0.0.3 | ||
### Added | ||
- Updating documentation | ||
- Fixing code linting | ||
- Added support for new symbol `TIME_SERIES_INTRADAY_EXTENDED` | ||
- Added generic support for new endpoints that return csv | ||
- Added new util `stripEol` to strip win and \*nix line endings | ||
- Added new util `csvToJSON` to convert raw csv into json | ||
# 0.0.4 | ||
## [2.3.1] - 10/9/2022 | ||
- Adding sector performance api | ||
### Changed | ||
# 0.0.5 | ||
- Updated the changelog to use [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format | ||
- Updated deps | ||
- Adding env variable support | ||
- Adding output restructuring utils with tests | ||
- Adding CHANGELOG.md and backfilling releases | ||
- Adding utils to the core export | ||
- Adding missing tests | ||
## [2.3.0] - 10/23/2021 | ||
# 0.0.6 | ||
### Fixed | ||
- Increasing jest timeout | ||
- Updating deps | ||
- Updated dependencies | ||
- Fixed broken tests | ||
# 0.0.7 | ||
### Changed | ||
- Adding env support for the api key | ||
- Modified jest config and folder name to follow a more standard configuration | ||
### Added | ||
- Adding new alpha.experimental function to support any API endpoint | ||
## [2.2.1] - 10/4/2020 | ||
### Fixed | ||
- Updated dependencies | ||
## [2.2.0] - 9/3/2020 | ||
### Added | ||
- Adding fundamental api support: OVERVIEW, INCOME_STATEMENT, BALANCE_SHEET, and CASH_FLOW | ||
## [2.1.0] - 7/26/2020 | ||
### Added | ||
- Adding forex intraday, daily, monthly, and weekly endpoint support. | ||
- Adding initial typescript types. | ||
### Fixed | ||
- Fixing malformed bundle file | ||
### Removed | ||
- Removed the data interval parameter for all except intraday | ||
## [2.0.1] - 2/26/2020 | ||
### Fixed | ||
- Fixed UMD support for browser and Node.js environments. | ||
## [2.0.0] - 10/8/2019 _DEPRECATED_ | ||
### Added | ||
- Adding browser support via UMD bundle. | ||
## [1.2.6] - 10/7/2019 | ||
### Changed | ||
- Updating dependencies. | ||
### Removed | ||
- Removing sector performance test until the API works again. | ||
## [1.2.5] - 4/15/2019 | ||
### Removed | ||
- Removing crypto intraday support (removed from API) | ||
## [1.2.4] - 4/5/2019 | ||
### Added | ||
- Adding symbol search endpoint support | ||
## [1.2.3] - 3/31/2019 | ||
### Changed | ||
- Updating dependencies to remove audit and outdated warnings | ||
## [1.2.2] - 3/31/2019 | ||
### Added | ||
- Adding Time Series FX (Daily) to the polish function | ||
## [1.2.1] - 3/31/2019 | ||
### Fixed | ||
- Fixing documentation for SMA usage | ||
### Removed | ||
- Removing test for intraday crypto data (removed from API) | ||
## [1.2.0] - 10/16/2018 | ||
### Added | ||
- Adding global quote endpoint support | ||
## [1.1.2] - 10/16/2018 | ||
### Changed | ||
- Updating deps | ||
# 1.0.0 | ||
### Fixed | ||
- Fixing broken forex test | ||
## [1.1.1] - 2/14/2018 | ||
### Changed | ||
- Updating dotenv dependency | ||
### Fixed | ||
- Fixing documentation for data endpoints | ||
## [1.1.0] - 1/1/2018 | ||
### Added | ||
- Adding batch quote support | ||
### Changed | ||
- Updating jest to 22.0.4 | ||
## [1.0.0] - 10/2/2017 | ||
### Added | ||
- Adding forex support | ||
@@ -42,3 +166,9 @@ - Adding crypto support | ||
- Adding weekly and monthly adjusted time series data support | ||
### Changed | ||
- Updating deps | ||
### Fixed | ||
- Fixed issue where failing requests were not going to a catch handler. | ||
@@ -51,68 +181,53 @@ | ||
# 1.1.0 | ||
## [0.0.7] - 9/19/2017 | ||
- Adding batch quote support | ||
- Updating jest to 22.0.4 | ||
### Added | ||
# 1.1.1 | ||
- Adding env support for the api key | ||
- Updating dotenv dependency | ||
- Fixing documentation for data endpoints | ||
### Changed | ||
# 1.1.2 | ||
- Updating deps | ||
- Fixing broken forex test | ||
# 1.2.0 | ||
## [0.0.6] - 8/30/2017 | ||
- Adding global quote endpoint support | ||
### Changed | ||
# 1.2.1 | ||
- Increasing jest timeout | ||
- Updating deps | ||
- Fixing documentation for SMA usage | ||
- Removing test for intraday crypto data (removed from API) | ||
## [0.0.5] - 8/13/2017 | ||
# 1.2.2 | ||
### Added | ||
- Adding Time Series FX (Daily) to the polish function | ||
- Adding env variable support | ||
- Adding output restructuring utils with tests | ||
- Adding CHANGELOG.md and backfilling releases | ||
- Adding utils to the core export | ||
- Adding missing tests | ||
# 1.2.3 | ||
## [0.0.4] - 8/8/2017 | ||
- Updating dependencies to remove audit and outdated warnings | ||
### Added | ||
# 1.2.4 | ||
- Adding sector performance api | ||
- Adding symbol search endpoint support | ||
## [0.0.3] - 8/2/2017 | ||
# 1.2.5 | ||
### Changed | ||
- Removing crypto intraday support (removed from API) | ||
- Updating documentation | ||
# 1.2.6 | ||
### Fixed | ||
- Updating dependencies. | ||
- Removing sector performance test until the API works again. | ||
- Fixing code linting | ||
# 2.0.0 - _DEPRECATED_ | ||
## [0.0.2] - 8/2/2017 | ||
- Adding browser support via UMD bundle. | ||
### Added | ||
# 2.0.1 | ||
- Adding initial tests | ||
- Fixed UMD support for browser and Node.js environments. | ||
## [0.0.1] - 8/2/2017 | ||
# 2.1.0 | ||
- Adding forex intraday, daily, monthly, and weekly endpoint support. | ||
- Adding initial typescript types. | ||
- Fixing malformed bundle file | ||
- Removed the data interval parameter for all except intraday | ||
# 2.2.0 | ||
- Adding fundamental api support: OVERVIEW, INCOME_STATEMENT, BALANCE_SHEET, and CASH_FLOW | ||
# 2.3.0 | ||
- Adding new alpha.experimental function to support any API endpoint | ||
- Initial release |
@@ -316,2 +316,31 @@ (function (global, factory) { | ||
/** | ||
* Strip \n and \r from values | ||
* | ||
* @param {String} value | ||
* The value to clean | ||
*/ | ||
const stripEol = (value = '') => value.replace(/\r/g, '').replace(/\n/g, '').trim(); | ||
/** | ||
* Convert raw csv input data into json. | ||
* | ||
* @param {String} raw | ||
* The json data | ||
*/ | ||
const csvToJSON = (raw = '') => { | ||
const lines = raw.split('\n'); | ||
const headers = lines.shift().split(','); | ||
return lines.map((row) => { | ||
const cols = row.split(','); | ||
let out = {}; | ||
headers.forEach((header, index) => { | ||
out[stripEol(header)] = stripEol(cols[index]); | ||
}); | ||
return out; | ||
}); | ||
}; | ||
/** | ||
* Wrapper function generator for any endpoint. | ||
@@ -325,34 +354,49 @@ * | ||
*/ | ||
const fn = (type) => (params) => | ||
fetch__default["default"](url(Object.assign({}, params, { function: type }))) | ||
.then((res) => { | ||
if (res.status !== 200) { | ||
throw `An AlphaVantage error occurred. ${res.status}: ${res.text()}`; | ||
} | ||
const fn = | ||
(type) => | ||
( | ||
params = { | ||
datatype: 'json' | ||
} | ||
) => | ||
fetch__default["default"](url(Object.assign({}, params, { function: type }))) | ||
.then((res) => { | ||
if (!res.status.toString().match(/2\d{2}/)) { | ||
throw `An AlphaVantage error occurred. ${res.status}: ${res.text()}`; | ||
} | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
if ( | ||
data['Meta Data'] === undefined && | ||
data['Realtime Currency Exchange Rate'] === undefined && | ||
data['Global Quote'] === undefined && | ||
data['bestMatches'] === undefined && | ||
data['Symbol'] === undefined && | ||
data['symbol'] === undefined && | ||
data['name'] === undefined && | ||
data['interval'] === undefined && | ||
data['unit'] === undefined && | ||
data['data'] === undefined | ||
) { | ||
throw `An AlphaVantage error occurred. ${data['Information'] || JSON.stringify(data)}`; | ||
} | ||
// Handle csv returns. | ||
if (params.datatype && params.datatype.toString().toLowerCase() !== 'json') | ||
return res.text().then((data) => csvToJSON(data)); | ||
return data; | ||
}); | ||
// Default to json return if the util doesnt specify otherwise | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
if ( | ||
params.datatype && | ||
params.datatype.toString().toLowerCase() === 'json' && | ||
data['Meta Data'] === undefined && | ||
data['Realtime Currency Exchange Rate'] === undefined && | ||
data['Global Quote'] === undefined && | ||
data['bestMatches'] === undefined && | ||
data['Symbol'] === undefined && | ||
data['symbol'] === undefined && | ||
data['name'] === undefined && | ||
data['interval'] === undefined && | ||
data['unit'] === undefined && | ||
data['data'] === undefined | ||
) { | ||
throw `An AlphaVantage error occurred. ${data['Information'] || JSON.stringify(data)}`; | ||
} | ||
return data; | ||
}); | ||
return { | ||
url, | ||
polish, | ||
fn | ||
fn, | ||
stripEol, | ||
csvToJSON | ||
}; | ||
@@ -400,13 +444,21 @@ }; | ||
*/ | ||
const series = (fn) => (symbol, outputsize = 'compact', datatype = 'json', interval = '1min') => { | ||
let params = { | ||
symbol, | ||
outputsize, | ||
datatype | ||
const series = | ||
(fn) => | ||
(symbol, outputsize = 'compact', datatype = 'json', interval = '1min', slice = 'year1month1') => { | ||
let params = { | ||
symbol, | ||
outputsize, | ||
datatype | ||
}; | ||
if (['TIME_SERIES_INTRADAY', 'TIME_SERIES_INTRADAY_EXTENDED'].includes(fn)) { | ||
params.interval = interval; | ||
} | ||
if (['TIME_SERIES_INTRADAY_EXTENDED'].includes(fn)) { | ||
params.datatype = 'csv'; | ||
params.slice = slice; | ||
} | ||
return util.fn(fn)(params); | ||
}; | ||
if (fn === 'TIME_SERIES_INTRADAY') params.interval = interval; | ||
return util.fn(fn)(params); | ||
}; | ||
/** | ||
@@ -430,2 +482,3 @@ * Util function to get the symbol search data. | ||
intraday: series('TIME_SERIES_INTRADAY'), | ||
intraday_extended: series('TIME_SERIES_INTRADAY_EXTENDED'), | ||
daily: series('TIME_SERIES_DAILY'), | ||
@@ -432,0 +485,0 @@ daily_adjusted: series('TIME_SERIES_DAILY_ADJUSTED'), |
@@ -19,13 +19,21 @@ 'use strict'; | ||
*/ | ||
const series = (fn) => (symbol, outputsize = 'compact', datatype = 'json', interval = '1min') => { | ||
let params = { | ||
symbol, | ||
outputsize, | ||
datatype | ||
const series = | ||
(fn) => | ||
(symbol, outputsize = 'compact', datatype = 'json', interval = '1min', slice = 'year1month1') => { | ||
let params = { | ||
symbol, | ||
outputsize, | ||
datatype | ||
}; | ||
if (['TIME_SERIES_INTRADAY', 'TIME_SERIES_INTRADAY_EXTENDED'].includes(fn)) { | ||
params.interval = interval; | ||
} | ||
if (['TIME_SERIES_INTRADAY_EXTENDED'].includes(fn)) { | ||
params.datatype = 'csv'; | ||
params.slice = slice; | ||
} | ||
return util.fn(fn)(params); | ||
}; | ||
if (fn === 'TIME_SERIES_INTRADAY') params.interval = interval; | ||
return util.fn(fn)(params); | ||
}; | ||
/** | ||
@@ -49,2 +57,3 @@ * Util function to get the symbol search data. | ||
intraday: series('TIME_SERIES_INTRADAY'), | ||
intraday_extended: series('TIME_SERIES_INTRADAY_EXTENDED'), | ||
daily: series('TIME_SERIES_DAILY'), | ||
@@ -51,0 +60,0 @@ daily_adjusted: series('TIME_SERIES_DAILY_ADJUSTED'), |
@@ -315,2 +315,31 @@ 'use strict'; | ||
/** | ||
* Strip \n and \r from values | ||
* | ||
* @param {String} value | ||
* The value to clean | ||
*/ | ||
const stripEol = (value = '') => value.replace(/\r/g, '').replace(/\n/g, '').trim(); | ||
/** | ||
* Convert raw csv input data into json. | ||
* | ||
* @param {String} raw | ||
* The json data | ||
*/ | ||
const csvToJSON = (raw = '') => { | ||
const lines = raw.split('\n'); | ||
const headers = lines.shift().split(','); | ||
return lines.map((row) => { | ||
const cols = row.split(','); | ||
let out = {}; | ||
headers.forEach((header, index) => { | ||
out[stripEol(header)] = stripEol(cols[index]); | ||
}); | ||
return out; | ||
}); | ||
}; | ||
/** | ||
* Wrapper function generator for any endpoint. | ||
@@ -324,35 +353,50 @@ * | ||
*/ | ||
const fn = (type) => (params) => | ||
fetch(url(Object.assign({}, params, { function: type }))) | ||
.then((res) => { | ||
if (res.status !== 200) { | ||
throw `An AlphaVantage error occurred. ${res.status}: ${res.text()}`; | ||
} | ||
const fn = | ||
(type) => | ||
( | ||
params = { | ||
datatype: 'json' | ||
} | ||
) => | ||
fetch(url(Object.assign({}, params, { function: type }))) | ||
.then((res) => { | ||
if (!res.status.toString().match(/2\d{2}/)) { | ||
throw `An AlphaVantage error occurred. ${res.status}: ${res.text()}`; | ||
} | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
if ( | ||
data['Meta Data'] === undefined && | ||
data['Realtime Currency Exchange Rate'] === undefined && | ||
data['Global Quote'] === undefined && | ||
data['bestMatches'] === undefined && | ||
data['Symbol'] === undefined && | ||
data['symbol'] === undefined && | ||
data['name'] === undefined && | ||
data['interval'] === undefined && | ||
data['unit'] === undefined && | ||
data['data'] === undefined | ||
) { | ||
throw `An AlphaVantage error occurred. ${data['Information'] || JSON.stringify(data)}`; | ||
} | ||
// Handle csv returns. | ||
if (params.datatype && params.datatype.toString().toLowerCase() !== 'json') | ||
return res.text().then((data) => csvToJSON(data)); | ||
return data; | ||
}); | ||
// Default to json return if the util doesnt specify otherwise | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
if ( | ||
params.datatype && | ||
params.datatype.toString().toLowerCase() === 'json' && | ||
data['Meta Data'] === undefined && | ||
data['Realtime Currency Exchange Rate'] === undefined && | ||
data['Global Quote'] === undefined && | ||
data['bestMatches'] === undefined && | ||
data['Symbol'] === undefined && | ||
data['symbol'] === undefined && | ||
data['name'] === undefined && | ||
data['interval'] === undefined && | ||
data['unit'] === undefined && | ||
data['data'] === undefined | ||
) { | ||
throw `An AlphaVantage error occurred. ${data['Information'] || JSON.stringify(data)}`; | ||
} | ||
return data; | ||
}); | ||
return { | ||
url, | ||
polish, | ||
fn | ||
fn, | ||
stripEol, | ||
csvToJSON | ||
}; | ||
}; |
{ | ||
"name": "alphavantage", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A simple interface to the Alpha Vantage API.", | ||
@@ -31,14 +31,14 @@ "main": "dist/bundle.js", | ||
"dependencies": { | ||
"cross-fetch": "^3.0.6" | ||
"cross-fetch": "^3.1.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.15.8", | ||
"@babel/preset-env": "^7.15.8", | ||
"babel-jest": "^27.3.1", | ||
"@babel/core": "^7.19.3", | ||
"@babel/preset-env": "^7.19.3", | ||
"babel-jest": "^29.1.2", | ||
"coveralls": "^3.1.1", | ||
"delay": "^5.0.0", | ||
"dotenv": "^10.0.0", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
"rollup": "^2.58.0" | ||
"dotenv": "^16.0.3", | ||
"jest": "^29.1.2", | ||
"prettier": "^2.7.1", | ||
"rollup": "^3.1.0" | ||
}, | ||
@@ -45,0 +45,0 @@ "jest": { |
@@ -207,2 +207,3 @@ # AlphaVantage | ||
alpha.experimental(fn, params); | ||
alpha.experimental('TIME_SERIES_DAILY', { symbol: 'XYZ', ...}); | ||
``` | ||
@@ -209,0 +210,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
191665
4274
215
2
Updatedcross-fetch@^3.1.5