rghuckins / robinhood-google-sheets

Robinhood Custom Functions for Google Sheets šŸ“ˆ
146 stars 47 forks source link
google-apps-script google-sheets options robinhood robinhood-api spreadsheet stocks

Robinhood for Google Sheets

Google Apps Script custom functions that retrieve stock and options data from the Robinhood API and return data in a tabular format for use in Google Sheets.

The Robinhood API is not publicly available but has been explored extensively and is accessible after authenticating.

Script "installation"

  1. Create or open a spreadsheet in Google Sheets.
  2. Select the menu item Tools > Script editor. If you are presented with a welcome screen, click Blank Project on the left to start a new project.
  3. Delete any code in the script editor.
  4. Copy and paste all code in robinhood.gs into the script editor.
  5. IMPORTANT: Replace robinhoodUsername and robinhoodPassword with your own Robinhood credentials. e.g.
    var robinhoodUsername = 'janedoe';
    var robinhoodPassword = 'passw0rd';
  6. (As of 1/19/20) Log into Robinhood on the Web to [https://stackoverflow.com/questions/55902967/is-there-any-way-to-get-a-bearer-token-now-since-robinhood-has-changed-the-api/56841942](obtain a device_id) and add it to your payload to get past RH's Oauth flow.
  7. Select the menu item File > Save. Give the script project a name and click OK.
  8. Refresh the spreadsheet. You will now be able to use custom functions to retrieve your Robinhood data!

Custom functions

ROBINHOOD_GET_ACH_TRANSFERS()

ROBINHOOD_GET_DIVIDENDS()

ROBINHOOD_GET_DOCUMENTS()

ROBINHOOD_GET_OPTIONS_ORDERS()

ROBINHOOD_GET_OPTIONS_POSITIONS()

ROBINHOOD_GET_ORDERS()

ROBINHOOD_GET_PORTFOLIOS()

ROBINHOOD_GET_POSITIONS()

ROBINHOOD_GET_WATCHLIST()

NOTE: Columns returned will change if Robinhood API responses change

Refresh Data menu item

TL;DR: Calling a ROBINHOOD_GET function without changing the argument passed to function will not return new data. A Refresh Data custom menu item is implemented so that data can be refreshed.

Apps Script custom functions are deterministic and will only recalculate if their arguments change. All ROBINHOOD_GET functions have an optional datetime parameter so that the current datetime can be passed to the function in order to force recalculation. A Google Sheets custom menu with a Refresh Data item is implemented so that a current datetime value can be set in cell Refresh!$A$1. ROBINHOOD_GET functions that reference this cell will return non-cached, fresh results when Refresh Data is clicked. Stolen from https://stackoverflow.com/a/17347290. Example:

ROBINHOOD_GET_POSITIONS(Refresh!$A$1)

Examples of usage in Google Sheets

functions_list functions_help positions_function_1 positions_function_2

NOTE: These are examples of a dashboard created using data returned by the functions. Data can be consumed in whatever way you see fit!

positions_dashboard_1 positions_dashboard_2

Gotchas

{
  "direction": "credit",
  "premium": "5.00000000",
  "time_in_force": "gfd",
  "processed_premium": "10.00000000000000000",
  "updated_at": "2018-04-18T17:11:38.981149Z",
  "created_at": "2018-04-18T17:11:38.315155Z",
  "pending_quantity": "0.00000",
  "ref_id": "CCBCE885-E41D-42A1-9EAE",
  "state": "filled",
  "processed_quantity": "2.00000",
  "id": "6822d0a2-737d-48de-8a24",
  "price": "0.05000000",
  "cancel_url": null,
  "trigger": "immediate",
  "chain_id": "57661a97-f7d4-470c-80c5",
  "response_category": "success",
  "chain_symbol": "ROB.N",
  "legs": [
    {
      "option": "https://api.robinhood.com/options/instruments/06717265-09c1-4e20-8f60/",
      "side": "sell",
      "position_effect": "open",
      "id": "66054ae1-5f30-4725-b203",
      "executions": [
        {
          "timestamp": "2018-04-18T17:11:38.581000Z",
          "price": "0.05000000",
          "settlement_date": "2018-04-19",
          "id": "8a49f0e9-52c9-4db3-ae2d",
          "quantity": "2.00000"
        }
      ],
      "ratio_quantity": 1
    }
  ],
  "type": "limit",
  "canceled_quantity": "0.00000",
  "quantity": "2.00000"
}

I have only been able to test this code with my own account; any PRs or issues created are welcome! šŸ˜ŽšŸ“ˆ