npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rbapi

v1.1.0

Published

A nodejs library for communicating with Robinhood's API

Downloads

8

Readme

rbapi

A nodejs library for trading stocks on Robinhood.

This library strives for ease of use. The calls to Robinhood's api have been abstracted so you only need to care about the stock symbol, the price and the quantity.

Features

  • Get user and account information
  • Get stock quote
  • Place a buy order
  • Place a sell order
  • Automatically renew the access token so you only have to login once

Installing

Using Npm:

$ npm install rbapi --save

Example

Initialize


const rbapi = require('rbapi');

(async function() {

    /*
        You will need to provide the username and password.
        The deviceToken is a bit difficult to get but here's how you do that:
            1. Open the chrome browser
            2. Go to robinhood.com
            3. Log out if you are already logged in to robinhood
            4. Open up the developer tool
            5. Navigate to the Network tab
            6. Click on the clear icon to clear the network history
            7. Log in to your robinhood account
            8. In the filter box type in oauth
            9. Look for the POST method in the list for /oauth2/
            10. You will find the deviceToken in the request payload
     */
    let robinhood =  await rbapi.create({
        username: '[email protected]',
        password: 'mypassword',
        deviceToken: 'my-unique-device-token'
    });

    console.log(robinhood);
})();

Getting A Stock Quote


const rbapi = require('rbapi');

(async function() {

    let robinhood =  await rbapi.create({
        username: '[email protected]',
        password: 'mypassword',
        deviceToken: 'my-unique-device-token'
    });

    let stockSymbol = 'AAPL';

    let quote = await robinhood.quote(stockSymbol);

    console.log(quote);
})();

Buying Stock


const rbapi = require('rbapi');

(async function() {

    let robinhood =  await rbapi.create({
        username: '[email protected]',
        password: 'mypassword',
        deviceToken: 'my-unique-device-token'
    });

    // Place a limit order
    let limitBuy = await robinhood.buy({
        orderType: rbapi.OrderType.LIMIT,
        stockSymbol: 'AAPL',
        quantity: 1,
        price: 1.00
    });

    console.log(limitBuy);
    
    // Place a market order
    let marketBuy = await robinhood.buy({
        orderType: rbapi.OrderType.MARKET,
        stockSymbol: 'AAPL',
        quantity: 1
    });

    console.log(marketBuy);
    
})();

Selling Stock


const rbapi = require('rbapi');

(async function() {

    let robinhood =  await rbapi.create({
        username: '[email protected]',
        password: 'mypassword',
        deviceToken: 'my-unique-device-token'
    });

    // Place a limit order to sell a stock
    let limitSell = await robinhood.sell({
        orderType: rbapi.OrderType.LIMIT,
        stockSymbol: 'AAPL',
        quantity: 1,
        price: 1.00
    });

    console.log(limitSell);
    
     // Place a market order to sell a stock
    let marketSell = await robinhood.sell({
        orderType: rbapi.OrderType.MARKET,
        stockSymbol: 'AAPL',
        quantity: 1
    });
   
    console.log(marketSell);
    
})();

Orders


(async () => {
     // Get a list of orders
    let orders = await robinhood.api.orders.recent();
    console.log(orders);
    
    // Get specific information about an order given an id
    let orderId = orders[0].id; 
    let order = await robinhood.api.orders.get({
        id: orderId
    });
    console.log(order);
    
    // Cancel an order
    let result = await robinhood.api.orders.cancel({
        id: orderId
    })
    console.log(result);
    
})();

License

MIT

Development

If you are going to do fork this library and add to it you can do so by following these steps

git clone [email protected]:pyriter/rbapi.git
cd rbapi
npm install
touch test-credentials.config.json
vim test-credentials.config.json #Add your robinhood credentials
npm run test

#Once you are done and are ready to publish
npm version [major|minor|patch]
npm publish