anilshanbhag / robinhoodshell Goto Github PK
View Code? Open in Web Editor NEWA command line shell for trading stocks using Robinhood
License: MIT License
A command line shell for trading stocks using Robinhood
License: MIT License
Currently the list table includes symbol, current price, quantity, and total equity. It would be very useful if you could also include things like % change, today's return, and total return, as this helps me better gauge how well every pick is going. I'm not sure how difficult this would be, depending on if the data is included in the request you make, but I think it's worth putting it in.
I might be able to help with this if you'd like. I'd just need to know where I could find the data I'm looking for within the API.
Thanks!
Can I have the shell script look for buy/sell stocks in a csv, then process automatically?
Thanks.
When I use "l," the program returns errors after listing my portfolio value and closes the application.
Buy stock b
b amd 10 62.00
Done
Robinhood accounts shows "market buy at 62.00"
Is this expected?
hello. getting Bad Order when placing a sell order. I've tried limit, and market. any ideas?
Buy orders go throug perfectly, both limit and market.
Thanks
My authentication is successful and l is listing the portfolio value but it doesn't show the individual positions. Moreover when I tried to get the quote using q command, it also errors out.
Please help.
> l
┌Account───────────────┐
│ Portfolio Value │ Change │ Buying Power │
├────────┼────────┤
│ 2217.66 │ -8.0 (-2.38%) │ 9.6600 │
└────┴──────────────┘
Traceback (most recent call last):
File "shell.py", line 613, in
RobinhoodShell().cmdloop()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 217, in onecmd
return func(arg)
File "shell.py", line 136, in do_l
market_data = self.trader.get_stock_marketdata(instruments)
File "/Users/skumar/Project/OptionChanakya/RobinhoodShell/Robinhood/Robinhood.py", line 465, in get_stock_marketdata
return info['results']
KeyError: 'results'
> q spy
Traceback (most recent call last):
File "shell.py", line 613, in
RobinhoodShell().cmdloop()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 217, in onecmd
return func(arg)
File "shell.py", line 481, in do_q
raw_data = self.trader.get_stock_marketdata(instruments)
File "/Users/skumar/Project/OptionChanakya/RobinhoodShell/Robinhood/Robinhood.py", line 465, in get_stock_marketdata
return info['results']
KeyError: 'results'
raise NameError('Invalid Symbols: ' + ",".join(stocks)).upper() #TODO: custom exception
AttributeError: 'exceptions.NameError' object has no attribute 'upper'
Saw where this was an issue previously. Am still running into it though any suggestions? Occurs when I try to view my portfolio
yes same here pls fix
q goog
Traceback (most recent call last):
File "./shell.py", line 613, in
RobinhoodShell().cmdloop()
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 217, in onecmd
return func(arg)
File "./shell.py", line 481, in do_q
raw_data = self.trader.get_stock_marketdata(instruments)
File "/Users/sk/RobinhoodShell/Robinhood/Robinhood.py", line 465, in get_stock_marketdata
return info['results']
KeyError: 'results'
(RobinhoodShell) mark@marks-Air RobinhoodShell (master)*$ ./shell.py
Welcome to the Robinhood shell. Type help or ? to list commands.
Welcome to the Robinhood shell. Type help or ? to list commands.
l
┌Account──────────┬─────────────────┬──────────────┐
│ Portfolio Value │ Change │ Buying Power │
├─────────────────┼─────────────────┼──────────────┤
│ redacted │ redacted │ redacted │
└─────────────────┴─────────────────┴──────────────┘
Traceback (most recent call last):
File "./shell.py", line 627, in
RobinhoodShell().cmdloop()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cmd.py", line 217, in onecmd
return func(arg)
File "./shell.py", line 150, in do_l
price = market_data[i]['last_trade_price']
TypeError: 'NoneType' object is not subscriptable
Cannot list my portfolio.
version: Python 3.7.7
$ ./shell.py
Traceback (most recent call last):
File "./shell.py", line 383, in
RobinhoodShell().cmdloop()
File "./shell.py", line 33, in init
self.trader.login(username=USERNAME, password=PASSWORD)
File "/Users/jason/Documents/repo/RobinhoodShell/Robinhood.py", line 136, in login
raise RH_exception.LoginFailed()
AttributeError: 'module' object has no attribute 'LoginFailed'
It works fine when my account has stocks, but when I have options in my account it crashes and burns:
(I get that options aren't 'supported', but it shouldn't die should it? )
Traceback (most recent call last):
File "shell.py", line 627, in
RobinhoodShell().cmdloop()
File "/usr/lib64/python3.8/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/lib64/python3.8/cmd.py", line 217, in onecmd
return func(arg)
File "shell.py", line 141, in do_l
market_data = self.trader.get_stock_marketdata(instruments)
File "/home/bcrockett/Downloads/RobinhoodShell/Robinhood/Robinhood.py", line 474, in get_stock_marketdata
return info['results']
KeyError: 'results'
I get the following error when using the W and L command.
w
Traceback (most recent call last):
File "./shell.py", line 300, in
RobinhoodShell().cmdloop()
File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
return func(arg)
File "./shell.py", line 99, in do_w
table.column_headers = ["symbol", "current price"]
File "/usr/local/lib/python2.7/dist-packages/beautifultable/beautifultable.py", line 167, in setattr
super(BeautifulTable, self).setattr(name, value)
File "/usr/local/lib/python2.7/dist-packages/beautifultable/beautifultable.py", line 299, in column_headers
header = self._validate_row(value)
File "/usr/local/lib/python2.7/dist-packages/beautifultable/beautifultable.py", line 378, in _validate_row
self._initialize_table(len(row))
File "/usr/local/lib/python2.7/dist-packages/beautifultable/beautifultable.py", line 364, in _initialize_table
self._column_alignments = AlignmentMetaData(self, [self.default_alignment] * column_count)
File "/usr/local/lib/python2.7/dist-packages/beautifultable/meta.py", line 8, in init
self.validate(i)
File "/usr/local/lib/python2.7/dist-packages/beautifultable/meta.py", line 24, in validate
+ ', was {}'.format(value))
TypeError: 'type' object is not iterable
Buy command returns stock not found but the price is accessible through q command and stock is purchasible via app interface.
Buy command examples:
b AUTO 1 15.00
Stock not found
q AUTO
AUTO: $15.00
=======
EDIT: Symbol not visible through app interface, please delete this issue. Sorry about that.
I might have missed something, but when trying to list existing open orders it only prints out max 100 for the same ticker. Even though I have 5 times more..
Login works as intended, but unable to trade or get portfolio data since Robinhood maintenance cycle last night.
$./shell.py
Welcome to the Robinhood shell. Type help or ? to list commands.
> l
Traceback (most recent call last):
File "./shell.py", line 564, in <module>
RobinhoodShell().cmdloop()
File "/usr/lib64/python2.7/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib64/python2.7/cmd.py", line 221, in onecmd
return func(arg)
File "./shell.py", line 60, in do_l
portfolio = self.trader.portfolios()
File "/home/Z8/ETF/Shell/Robinhood.py", line 826, in portfolios
req.raise_for_status()
File "/usr/lib/python2.7/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.robinhood.com/portfolios/
$ ./shell.py
Welcome to the Robinhood shell. Type help or ? to list commands.
> b SPY 1 300.00
Traceback (most recent call last):
File "./shell.py", line 564, in <module>
RobinhoodShell().cmdloop()
File "/usr/lib64/python2.7/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib64/python2.7/cmd.py", line 221, in onecmd
return func(arg)
File "./shell.py", line 227, in do_b
res = self.trader.place_buy_order(stock_instrument, quantity, price)
File "/home/Z8/ETF/Shell/Robinhood.py", line 1586, in place_buy_order
return self.place_order(instrument, quantity, ask_price, transaction)
File "/home/Z8/ETF/Shell/Robinhood.py", line 1538, in place_order
'account': self.get_account()['url'],
File "/home/Z8/ETF/Shell/Robinhood.py", line 701, in get_account
res.raise_for_status() # auth required
File "/usr/lib/python2.7/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.robinhood.com/accounts/
Hi! Ultimately I'd like to use this to set up a $5 buy of a stock every day, but didn't see anywhere in the documentation mentioning fractional shares.
Is it possible or are there plans for future support?
Thanks!
My name is Luis, I'm a big-data machine-learning developer, I'm a fan of your work, and I usually check your updates.
I was afraid that my savings would be eaten by inflation. I have created a powerful tool that based on past technical patterns (volatility, moving averages, statistics, trends, candlesticks, support and resistance, stock index indicators).
All the ones you know (RSI, MACD, STOCH, Bolinger Bands, SMA, DEMARK, Japanese candlesticks, ichimoku, fibonacci, williansR, balance of power, murrey math, etc) and more than 200 others.
The tool creates prediction models of correct trading points (buy signal and sell signal, every stock is good traded in time and direction).
For this I have used big data tools like pandas python, stock market libraries like: tablib, TAcharts ,pandas_ta... For data collection and calculation.
And powerful machine-learning libraries such as: Sklearn.RandomForest , Sklearn.GradientBoosting, XGBoost, Google TensorFlow and Google TensorFlow LSTM.
With the models trained with the selection of the best technical indicators, the tool is able to predict trading points (where to buy, where to sell) and send real-time alerts to Telegram or Mail. The points are calculated based on the learning of the correct trading points of the last 2 years (including the change to bear market after the rate hike).
I think it could be useful to you, to improve, I would like to share it with you, and if you are interested in improving and collaborating I am also willing, and if not file it in the box.
If tou want, Please read the readme , and in case of any problem you can contact me ,
If you are convinced try to install it with the documentation.
https://github.com/Leci37/LecTrade/tree/develop I appreciate the feedback
Are parameters currently supported in any fashion? (Aside from simply changing the shell code)
Would be really nice to call this from another script and work in my own automation from there
Ex:
./shell.py -l
Am I missing something, or are Option Orders not yet displayed with the 'o' command?
('l' shows both stocks and options positions, great!)
like $SPX
Is there any way to download all the ETFs symbols in robinhood?
Following our discussions in #22 and
b9ec538#commitcomment-33584861
we have a functioning solution for automation again. However, it generates tons of email. For every single invocation of shell.py, even to do no more than lookup my account balances--which I might do many times per day--it goes through time-delaying stages of generating yet another verification code, followed by a second mail "We’re emailing to confirm your recent login to Robinhood."
I was thinking, again in Robinhood/Robinhood.py, maybe around the lines
#gets access token for final response to stay logged in
res3 = self.session.post(endpoints.login(), data=payload, timeout=15)
res3.raise_for_status()
data = res3.json()
if 'access_token' in data.keys() and 'refresh_token' in data.keys():
self.auth_token = data['access_token']
self.refresh_token = data['refresh_token']
self.headers['Authorization'] = 'Bearer ' + self.auth_token
# How about export this into a file, and reuse later?
# Serialize this access_token, and deserialize it next run, instead of going thru login hack
return True
What parts of the data
structure are essential to keep the login session alive (for the ~24hrs at least)?
How about saving/exporting that into a .json or xml file,
Finally, attempting to read and import that file if exists next time RobinhoodShell is run, failing over to the regular existing login routine which regenerates a valid session?
I might try to hack it up, but it won't be pretty; I tend to resort to subshells and languages I'm more familiar with.
Hello was wondering if this works with cryptocurrency trading in RH? RH doesnt offer stop loss or stop buys for cryptocurrencies
Reset a few devices I had this afternoon and all at once they were unable to log back in... several accounts... credentials are all correct.
$ ./Shell/shell.py
Traceback (most recent call last):
File "./Shell/shell.py", line 564, in
RobinhoodShell().cmdloop()
File "./Shell/shell.py", line 37, in init
self.trader.login(username=USERNAME, password=PASSWORD)
File "/home/Z8/ETF/Shell/Robinhood.py", line 136, in login
raise RH_exception.LoginFailed()
AttributeError: 'module' object has no attribute 'LoginFailed'
this error has begun occurring when using the 'l' list all option:
Traceback (most recent call last):
File "./shell.py", line 565, in
RobinhoodShell().cmdloop()
File "/usr/lib64/python2.7/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib64/python2.7/cmd.py", line 221, in onecmd
return func(arg)
File "./shell.py", line 86, in do_l
raw_data = self.trader.quotes_data(symbols)
File "/home/HMSS013/.dropbox-shared/Dropbox/Public/Market Service/Shell/Robinhood.py", line 257, in quotes_data
raise NameError('Invalid Symbols: ' + ",".join(stocks)).upper() #TODO: custom exception
AttributeError: 'exceptions.NameError' object has no attribute 'upper'
I do not understand the Challenge-Type in the config.py. If I do not have 2FA, what do I put there? Or, if I have 2FA for sms, I have sms in the field, and it still gives email as the challenge type when I run shell.py. I do not get a sms code and so I do not know what to input. Thanks for any help.
hello. getting Bad Order when placing a sell order. I've tried limit, and market. any ideas?
Buy orders go throug perfectly, both limit and market.
Thanks
Buy command orders the wrong stock symbol.
Buy command examples:
b NX 1 17.10
b LIVE 1 12.85
Resulting orders:
NXPI
LYV
The first example results in ordering of stocks with a different symbol that contains letters from the first symbol, but the second example is a stock that has a completely different symbol but the company has the same name. The RH API URLs in instrument.data appear to be correct. Interestingly, the resulting orders are the first search results on the list of stocks that appear when using the original app interface.
I get this when I try to execute ./shell.py
:~/RobinhoodShell$ ./shell.py
File "./shell.py", line 123
change = f"{change:.3f}"
^
SyntaxError: invalid syntax
please kindly look at this please
am using python 3
At least when running under my own account, stop-loss orders do not appear to be working:
ex:
sl stock-symbol #ofshares price
Error executing order
Does RobinhoodShell provide support for cryptocurrency trading?
When I use the parameter sl to place a stop loss it actually gets executed as a stop-limit.
So, "sl MSFT 1 50" translates to a stop-limit order of MSFT at $50.
I've tried adding in: "order = 'market'" into where "place_stop_loss_order" is defined in Robinhood.py but still get the same result. Seems to me like this should have overriden the default value of "limit" order with "market" order and thus be translated to a stop-loss order. Maybe this is why stop-loss is not currently supported with RobinhoodShell yet? Not sure
This would be really helpful to get worked out
I can use "q SPY", but how can I do "q SPY call 270 6/29".
thanks.
I've previously installed everything without issue. My machine got a clean wipe and now as I try to reinstall this I get this error.
`squinton-ml:RobinhoodShell shaunquinton$ sudo pip install -r requirements.txt
Password:
The directory '/Users/shaunquinton/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/shaunquinton/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting beautifultable==0.3.0 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/74/a8/1b183b85dfe7434f4a99477b8c8a6b2bf6f2cdd6b4b113267d25a4ba036e/beautifultable-0.3.0.tar.gz
Collecting enum==0.4.6 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/0c/4e/1ea357e7783c756bb579333c1e4a026fb331371ee771f616ffedc781e531/enum-0.4.6.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/init.py", line 6, in
import distutils.core
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 16, in
from distutils.dist import Distribution
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 9, in
import re
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 143, in
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-ox7486a5/enum/`
I've tried the suggestions in the error messaging, but have not been able to resolve the issue. Is anyone else getting this error?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.