1.1.0 • Published 5 years ago

rbapi v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

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: 'username@email.com',
        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: 'username@email.com',
        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: 'username@email.com',
        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: 'username@email.com',
        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 git@github.com: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
1.1.0

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago