Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Add crypto functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
avelizmu committed Feb 11, 2021
1 parent 2df92d7 commit be0727e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* [Contributors](#contributors)

<!-- toc stop -->
Expand Down Expand Up @@ -957,6 +959,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
Expand All @@ -978,6 +1014,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))

------------------

Expand Down
14 changes: 14 additions & 0 deletions robinhood.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 36 additions & 1 deletion src/robinhood.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -63,7 +65,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',
Expand Down Expand Up @@ -670,6 +674,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;
Expand Down

0 comments on commit be0727e

Please sign in to comment.