sshh12 / tradinhood Goto Github PK
View Code? Open in Web Editor NEWProgrammatically trading stocks, crypto, and options with Robinhood.
License: MIT License
Programmatically trading stocks, crypto, and options with Robinhood.
License: MIT License
Hey Shrivu. It is cool that your library provides an interface to OHCLV data from google and cryptocompare, but I would also like to be able to get it straight from Robinhood. I know it doesn't go back very far, but still - it's good to have access to price data straight from the exchange you're trading on. If you would be interested in implementing this, you could reference how wang-ye does it in robinhood-crypto.
Maybe I'm missing this feature, but I can't see either of those attributes on positions in the API.
My workaround for now is:
for position in rbh.positions:
print(rbh[rbh.session.get(position['instrument']).json()['symbol']].price)
If the API supports a simpler approach, please document it.
Otherwise, please consider adding this functionality.
Tradinhood rules. Thank you.
I'm new to this repo and am unable to get passed the login.
$ python3
Python 3.7.4 (default, Jul 11 2019, 10:43:21)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import config
from tradinhood import Robinhood
rbh = Robinhood()
rbh.login(username=config.robinhood_username, password=config.robinhood_password)
Traceback (most recent call last):
File "/tmp/rh/lib/python3.7/site-packages/tradinhood/robinhood.py", line 167, in login
res.raise_for_status()
File "/tmp/rh/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.robinhood.com/oauth2/token/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/rh/lib/python3.7/site-packages/tradinhood/robinhood.py", line 170, in login
raise APIError('Login failed')
tradinhood.robinhood.APIError: Login failed
Today I have gotten two different errors from urllib3 through Tradinhood.
The first is "Connection aborted, Remote end closed connection without response" while querying account_info on line 452 of Robinhood.py.
The second is "Connection aborted, OSError(22, 'Invalid argument'))" when querying current_quote from line 566 of Robinhood.py.
In both cases I would expect Tradinhood to gracefully handle the errors without unexpectedly terminating.
Please let me know if you would like me to open a second issue to separate the two errors, or in case there is any further information I can provide. Thank you.
I believe I was running on commit 708c68b when I got the following error:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 265, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3.7/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3.7/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 265, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/Tradinhood/Tradinhood/Robinhood.py", line 448, in account_info
res = self.session.get(ENDPOINTS['accounts'] + self.acc_num)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 525, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 495, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./tradinhood.py", line 235, in <module>
wealth_now = wealth()
File "./tradinhood.py", line 114, in wealth
return buy_power() + stock_value() + crypto_value(data) + dollars_pending()
File "./tradinhood.py", line 117, in buy_power
return Decimal(rbh.account_info['margin_balances']['overnight_buying_power'])
File "~/Tradinhood/Tradinhood/Robinhood.py", line 452, in account_info
raise APIError('Unable to access account')
Tradinhood.Robinhood.APIError: Unable to access account
After that I pulled the latest (0698a93) and got the following error:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.7/ssl.py", line 1049, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.7/ssl.py", line 908, in read
return self._sslobj.read(len, buffer)
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3.7/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3.7/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.7/ssl.py", line 1049, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.7/ssl.py", line 908, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(22, 'Invalid argument'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/Tradinhood/Tradinhood/Robinhood.py", line 562, in current_quote
res = self.session.get(ENDPOINTS['forex_market_quote'] + self.pair_id + '/')
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 525, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 495, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(22, 'Invalid argument'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./tradinhood.py", line 212, in <module>
symbol_stats['price'] = rbh[symbol].price.normalize()
File "~/Tradinhood/Tradinhood/Robinhood.py", line 571, in price
return Decimal(self.current_quote['mark_price'])
File "~/Tradinhood/Tradinhood/Robinhood.py", line 566, in current_quote
raise APIError('Unable to access currency data')
Tradinhood.Robinhood.APIError: Unable to access currency data
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.