Comments (9)
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.
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.
@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.
@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.
@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.
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.
@caviles Can you post your code? What I had posted should still work
from robinhood-node.
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.
@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)
- [Question] Is bid_price required for place_buy_order?
- Error when trying to authenticate HOT 5
- reintroduce set_mfa_code
- How to use with crypto symbols?
- Security HOT 1
- How to list all the instruments HOT 2
- Account Isn't Sent - Fails HOT 2
- Unable to retrieve auth token through credentials HOT 2
- Unable to retrieve the refresh_token HOT 1
- how to persist auth?
- dynamic _deviceToken & _clientId ? HOT 1
- calculating returns
- SMS challenge
- Fractional Shares?
- updated_at[gte] for orders (question)
- Are there any plans to add a trailing-stop-loss order type to this code? Is there a more fundamental reason it has not been added yet? HOT 1
- wrong repo
- Unable to Login & Execute API calls using the established methods
- Possible API change HOT 1
- Looking for project maintainers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robinhood-node.