diff --git a/README.md b/README.md index dfa064f..8258bf9 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ FYI [Robinhood's Terms and Conditions](https://brokerage-static.s3.amazonaws.com * [`tag(tag, callback)`](#tagtag-callback) * [`popularity(symbol, callback)`](#popularitysymbol-callback) * [`options_positions`](#options_positions) + * [`get_currency_pairs`](#get_currency_pairs) + * [`get_crypto`](#get_crypto) * [`options_orders`](#options_orders) * [Contributors](#contributors) @@ -979,6 +981,40 @@ var Robinhood = require('robinhood')(credentials, function() { Return news about a symbol. +### `get_currency_pairs` + +Get crypto - currency pairs + +```javascript +var credentials = require("../credentials.js")(); +var Robinhood = require('robinhood')(credentials, function() { + Robinhood.get_currency_pairs((err, response, body) => { + if (err) { + console.error(err); + } else { + console.log(body); + } + }); +}); +``` + +### `get_crypto` + +Get cryptocurrency quote information from symbol + +```javascript +var credentials = require("../credentials.js")(); +var Robinhood = require('robinhood')(credentials, function() { + Robinhood.get_crypto('DOGE', (err, response, body) => { + if (err) { + console.error(err); + } else { + console.log(body); + } + }); +}); +``` + `Documentation lacking sample response` **Feel like contributing? :)** # Contributors @@ -1000,6 +1036,7 @@ Alejandro U. Alvarez ([@aurbano](https://github.com/aurbano)) * Ryan Hendricks ([@ryanhendricks](https://github.com/ryanhendricks)) * Patrick Michaelsen ([@prmichaelsen](https://github.com/prmichaelsen)) * Joshua Wilborn ([@joshuajwilborn](https://github.com/joshuajwilborn)) +* Adrian Veliz ([@aveliz1999](https://github.com/aveliz1999)) ------------------ diff --git a/robinhood.d.ts b/robinhood.d.ts index 8f025a0..d9257e8 100644 --- a/robinhood.d.ts +++ b/robinhood.d.ts @@ -241,6 +241,20 @@ declare namespace robinhood { */ url (url: string, callback: request.RequestCallback): void + + /** + * Get the Robinhood crypto to currency pairs + * @param callback + */ + get_currency_pairs(callback: request.RequestCallback): void + + /** + * Get the quote data for a specified crypto symbol. + * @param symbol + * @param callback + */ + get_crypto(symbol: string, callback: request.RequestCallback): void + /** * * @param callback diff --git a/src/robinhood.js b/src/robinhood.js index d80dfe3..db8b703 100644 --- a/src/robinhood.js +++ b/src/robinhood.js @@ -20,6 +20,8 @@ function RobinhoodWebApi(opts, callback) { * +--------------------------------+ */ var _apiUrl = 'https://api.robinhood.com/'; + var _currencyPairsUrl = 'https://nummus.robinhood.com/currency_pairs/'; + var _options = opts || {}, // Private API Endpoints _endpoints = { @@ -64,7 +66,9 @@ function RobinhoodWebApi(opts, callback) { sp500_up: 'midlands/movers/sp500/?direction=up', sp500_down: 'midlands/movers/sp500/?direction=down', news: 'midlands/news/', - tag: 'midlands/tags/tag/' + tag: 'midlands/tags/tag/', + + crypto: 'marketdata/forex/quotes/' }, _clientId = 'c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS', _deviceToken = 'ea9fa5c6-01e0-46c9-8430-5b422c99bd16', @@ -680,6 +684,37 @@ function RobinhoodWebApi(opts, callback) { ); }; + api.get_currency_pairs = function(callback) { + return request.get( + { + uri: _currencyPairsUrl, + }, + callback + ) + } + + api.get_crypto = function(symbol, callback) { + return api.get_currency_pairs(function (error, response, body) { + if(error) { + return callback(error, response, body); + } + + var assets = JSON.parse(body).results; + var asset = assets.find(a => a.asset_currency.code.toLowerCase() === symbol.toLowerCase()); + if(!asset) { + var codes = assets.map(a => a.asset_currency.code); + return callback(new Error("Symbol not found. Only these codes are allowed: " + JSON.stringify(codes))); + } + + return _request.get( + { + uri: _apiUrl + _endpoints.crypto + asset.id + '/' + }, + callback + ); + }); + } + _init(_options); return api;