Code Monkey home page Code Monkey logo

Comments (9)

brycelund avatar brycelund commented on May 30, 2024 1

I had to use the callback function in the initializer to make sure it was all the way authenticated before attempting any other functions.

var rh = Robinhood({username:'username', password:'password'}, function(){

    rh.positions( function(error, response, body){
        console.log(body);
    });

});

I haven't tried it the way you posted, but that works for me at least to authenticate and get the current positions. For some reason I have trouble when trying to place an order.

from robinhood-node.

busse avatar busse commented on May 30, 2024

I've used this project as an example implementation as I work on building my own script: https://github.com/markalfred/robinhood-to-csv

Using the prompt package, it shows:

function login () {
  return new Promise((resolve, reject) => {
    prompt.message = prompt.delimeter = ''
    prompt.start()
    prompt.get({
      properties: {
        username: { default: process.env.ROBINHOOD_USERNAME, required: true },
        password: { default: process.env.ROBINHOOD_PASSWORD, required: true, hidden: true }
      }
    }, (err, res) => {
      if (err) {
        reject(err)
      } else {
        R = robinhood({ username: res.username, password: res.password }, resolve)
      }
    })
  })
}

I haven't previously used Promises in node, so that project has taught me a few things.

from robinhood-node.

aurbano avatar aurbano commented on May 30, 2024

@busse using promises would make this a lot cleaner, so I've been thinking of adding them to this for a while. The only "downside" is that native support was fairly recent so I stayed away from it for now.

Also the docs need to be updated with authenticated examples, I'll try to spend some time on this soon. thanks!

from robinhood-node.

andreipopovici avatar andreipopovici commented on May 30, 2024

@aurbano I was just about to add Promises in my fork of robinhood-node. Did you, by any chance, get around to doing this? It would be a waste to duplicate the effort.

Otherwise, I'd be glad to try it and start a PR.

I was looking at https://github.com/request/request-promise for a quick & dirty way to replace request and be done with it.

from robinhood-node.

aurbano avatar aurbano commented on May 30, 2024

@andreipopovici I haven't had the time to get started on it, but if you go for it I'll be happy to merge it into the proyect

from robinhood-node.

caviles avatar caviles commented on May 30, 2024

The API seems to work great for me on unauthenticated calls. I see the login fn setting the token. However, when I call the API I get an error that says the token is invalid. Can anyone offer any guidance on this? I've tried sniffing the traffic using a proxy but the app detects I am doing so and blocks me. I've tried the example from brycelund and could not successfully get back my positions even though login got a token. Any help would be greatly appreciated. Thanks in advance!

from robinhood-node.

brycelund avatar brycelund commented on May 30, 2024

@caviles Can you post your code? What I had posted should still work

from robinhood-node.

caviles avatar caviles commented on May 30, 2024

Hey brycelund,

I must have somehow munged something up. I copied a second time and tried again, it's working great. Thanks for the lightning fast reply.

from robinhood-node.

jspenc72 avatar jspenc72 commented on May 30, 2024

@brycelund
@caviles
For development you can do something like this and add the credentials.js to your .gitignore. For production, set an environment variable.

var credentials = require("credentials.js")()
var Robinhood = require('robinhood')
    colors  = require('colors');

var Robinhood = require('robinhood')(credentials, function(){
    console.log("Connected!".green);
    Robinhood.create_watch_list('Technology', function(err, response, body){
        if(err){
            console.error(err);
        }else{
            console.log("created watchlist");
            console.log(body);
        }
    })
});

where credentials.js is a file containing something of the form:

module.exports = function () {
    'use strict';
    var credentials = {
        username: '', 
        password: ''
    };
    return credentials
}

This is useful if you are using multiple accounts but has some major security concerns. :-)

from robinhood-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.