diff --git a/docs/ROBINHOOD.md b/docs/ROBINHOOD.md index 2e13cbf..fe56a4e 100755 --- a/docs/ROBINHOOD.md +++ b/docs/ROBINHOOD.md @@ -924,10 +924,10 @@ Represents all of the user's holdings on Robinhood and allows for various querie Creates a new Portfolio object. -| Param | Type | -| --- | --- | -| user | [User](#User) | -| array | Array | +| Param | Type | Description | +| --- | --- | --- | +| user | [User](#User) | | +| array | Array | Created via User.getPortfolio() | @@ -1166,6 +1166,7 @@ Represents the user that is logged in while accessing the Robinhood API. * [.cancelOpenOrders()](#User+cancelOpenOrders) ⇒ Promise * [.getRecentOptionOrders()](#User+getRecentOptionOrders) ⇒ Promise.<Array> * [.getPortfolio()](#User+getPortfolio) ⇒ Promise.<Object> + * [.getHistoricals()](#User+getHistoricals) ⇒ Promise.<Object> * [.getLinkedBanks()](#User+getLinkedBanks) ⇒ Promise.<Object> * [.addDeposit(bankID, amount, frequency)](#User+addDeposit) ⇒ Promise.<Object> * [.getDocuments()](#User+getDocuments) ⇒ Promise.<Array> @@ -1277,6 +1278,12 @@ Returns an array of recent option orders. ### user.getPortfolio() ⇒ Promise.<Object> Returns a Portfolio object containing all open positions in a user's portfolio. +**Kind**: instance method of [User](#User) + + +### user.getHistoricals() ⇒ Promise.<Object> +Returns an object that can be used to create a chart, show total return, etc. + **Kind**: instance method of [User](#User) diff --git a/objects/broker/robinhood/Portfolio.js b/objects/broker/robinhood/Portfolio.js index 6ae7ddb..2e185bb 100755 --- a/objects/broker/robinhood/Portfolio.js +++ b/objects/broker/robinhood/Portfolio.js @@ -12,7 +12,7 @@ class Portfolio extends Robinhood { /** * Creates a new Portfolio object. * @param {User} user - * @param {Array} array + * @param {Array} array - Created via User.getPortfolio() */ constructor(user, array) { if (!array instanceof Array) throw new Error("Parameter 'array' must be an array."); diff --git a/objects/broker/robinhood/Robinhood.js b/objects/broker/robinhood/Robinhood.js index 172cf30..ab718bc 100755 --- a/objects/broker/robinhood/Robinhood.js +++ b/objects/broker/robinhood/Robinhood.js @@ -17,12 +17,8 @@ class Robinhood { if (error) reject(error); else if (response.statusCode > 299 || response.statusCode < 200) { if (body.indexOf("{") === 0) { - let json = JSON.parse(body); - let keys = Object.keys(json); - if (keys.length === 1) body = " | " + json[keys[0]]; - else body = ".\n\n" + JSON.stringify(json, null, 2); - + body = ".\n\n" + JSON.stringify(json, null, 2); } else body = " | " + body; reject(new LibraryError("Robinhood responded with code " + response.statusCode + body)); } else { diff --git a/objects/broker/robinhood/User.js b/objects/broker/robinhood/User.js index 4cbb1de..62d9e65 100755 --- a/objects/broker/robinhood/User.js +++ b/objects/broker/robinhood/User.js @@ -392,6 +392,30 @@ class User extends Robinhood { }) } + /** + * Returns an object that can be used to create a chart, show total return, etc. + * @returns {Promise} + */ + getHistoricals(span, interval) { + const _this = this; + return new Promise((resolve, reject) => { + request({ + uri: _this.url + "/portfolios/historicals/" + _this.account, + headers: { + 'Authorization': 'Bearer ' + _this.token + }, + qs: { + span: span, + interval: interval + } + }, (error, response, body) => { + Robinhood.handleResponse(error, response, body, _this.token, res => { + resolve(res); + }, reject); + }) + }) + } + // Invalid token? // // getNotifications() { diff --git a/package.json b/package.json index 7404681..beba262 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "algotrader", - "version": "1.4.0", + "version": "1.4.1", "description": "Algorithmically trade stocks and options using Robinhood, Yahoo Finance, and more.", "main": "index.js", "scripts": {