-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f3a4b4
commit 8f89444
Showing
22 changed files
with
301 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.note{ | ||
background-color: #FFF59C !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p> | ||
Robin Stocks is the easy to use python wrapper for interacting with the Robinhood API. | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE html> | ||
|
||
<iframe src="https://ghbtns.com/github-btn.html?user=jmfernandes&repo=robin_stocks&type=star&count=true&size=large" | ||
frameborder="0" scrolling="0" width="160px" height="30px"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
Advanced Usage | ||
============== | ||
|
||
---- | ||
|
||
.. image:: _static/pics/veyron.jpg | ||
|
||
Making Custom Get and Post Requests | ||
----------------------------------- | ||
|
||
Robin Stocks depends on Requests which you are free to call and use yourself, or you could | ||
use it within the Robin Stocks framework by using :func:`robin_stocks.helper.request_get`, :func:`robin_stocks.helper.request_post`, | ||
:func:`robin_stocks.helper.request_document`, and :func:`robin_stocks.helper.request_delete`. For example, if you wanted to make your own | ||
get request to the option instruments API endpoint in order to get all calls you would type: | ||
|
||
>>> url = 'https://api.robinhood.com/options/instruments/' | ||
>>> payload = { 'type' : 'call'} | ||
>>> robin_stocks.request_get(url,'regular',payload) | ||
|
||
Robinhood returns most data in the form:: | ||
|
||
{ 'previous' : None, 'results' : [], 'next' : None} | ||
|
||
where 'results' is either a dictionary or a list of dictionaries. However, sometimes | ||
Robinhood returns the results dictionary directly. To compensate for this, I added | ||
the **dataType** parameter which defaults to 'regular'. There are four possible values and there uses are: | ||
|
||
>>> robin_stocks.request_get(url,'regular') # For when the results are | ||
>>> # returned directly or you | ||
>>> # want to view 'next' or | ||
>>> # 'previous' values. | ||
>>> | ||
>>> robin_stocks.request_get(url,'results') # For when results contains a | ||
>>> # list or dictionary. | ||
>>> | ||
>>> robin_stocks.request_get(url,'pagination') # For when results contains a | ||
>>> # list, but you also want to | ||
>>> # append any information in | ||
>>> # 'next' to the list. | ||
>>> | ||
>>> robin_stocks.request_get(url,'indexzero') # For when results is a list | ||
>>> # of only one dictionary. | ||
|
||
Also keep in mind that the results from the Robinhood API have been decoded using ``.json()``. | ||
There are instances where the user does not want to decode the results (such as retrieving documents), so | ||
I added the :func:`robin_stocks.helper.request_document` function, which will always return the raw data, | ||
so there is no **dataType** parameter. :func:`robin_stocks.helper.request_post` is similar in that it only | ||
takes a url and payload parameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
List of All Functions | ||
===================== | ||
|
||
---- | ||
|
||
.. note:: | ||
|
||
Even though the functions are written as ``robin_stocks.module.function``, the module | ||
name is unimportant when calling a function. Simply use ``robin_stocks.function`` for all functions. | ||
|
||
Sending Requests to API | ||
----------------------- | ||
|
||
.. automodule:: robin_stocks.helper | ||
:members: request_get,request_post,request_delete,request_document | ||
|
||
Logging In and Out | ||
------------------ | ||
|
||
.. automodule:: robin_stocks.authentication | ||
:members: | ||
|
||
Loading Profiles | ||
------------------ | ||
|
||
.. automodule:: robin_stocks.profiles | ||
:members: | ||
|
||
Getting Stock Information | ||
------------------------- | ||
|
||
.. automodule:: robin_stocks.stocks | ||
:members: | ||
|
||
Getting Option Information | ||
-------------------------- | ||
|
||
.. automodule:: robin_stocks.options | ||
:members: | ||
|
||
Getting Market Information | ||
-------------------------- | ||
|
||
.. automodule:: robin_stocks.markets | ||
:members: | ||
|
||
Getting Positions and Account Information | ||
----------------------------------------- | ||
|
||
.. automodule:: robin_stocks.account | ||
:members: | ||
|
||
Placing and Cancelling Orders | ||
----------------------------- | ||
|
||
.. automodule:: robin_stocks.orders | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
Installing | ||
========== | ||
|
||
---- | ||
|
||
.. image:: _static/pics/yacht.jpg | ||
|
||
Using Pip | ||
--------- | ||
|
||
This is the simplest method. To install Robin Stocks globally or inside a virtual environment, | ||
open terminal and run the command:: | ||
|
||
$ pip install robin-stocks | ||
|
||
Get The Source Code | ||
------------------- | ||
|
||
If you prefer to install the source code directly, it can be found `here <https://github.com/jmfernandes/robin_stocks>`_, | ||
or you can clone the repository using:: | ||
|
||
$ git clone https://github.com/jmfernandes/robin_stocks.git | ||
|
||
Once the file has been downloaded or cloned, cd into the directory that contains the ``setup.py`` file and install using:: | ||
|
||
$ pip install . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
Introduction | ||
============ | ||
|
||
---- | ||
|
||
.. image:: _static/pics/wolf.jpg | ||
|
||
Philosophy | ||
---------- | ||
|
||
I've written the code in accordance with what I consider the best coding practices. | ||
Some of these are part of `PEP 20 <https://www.python.org/dev/pep-0020>`_ standards and some are my own. They are as follows: | ||
|
||
* Explicit is better than implicit | ||
|
||
This is the reason why my code uses ``import robin_stocks.module as module`` instead of ``from module import *``. | ||
This means that calls to a function from the module must be written as ``module.function`` instead of the simply | ||
``function``. When viewing the code, it's easy to see which functions come from which modules. | ||
|
||
* Flat is better than nested | ||
|
||
The __init__.py file contains an import of all the functions I want to be made public to the user. This allows | ||
the user to call ``robin_stocks.function`` for all functions. Without the imports, the user would have to call | ||
``robin_stocks.module.function`` and be sure to use the correct module name every single time. This may seem contradictory | ||
to the first standard, but the difference is that whereas I the developer must make explicit calls, for the end user it is | ||
unnecessary. | ||
|
||
* Three strikes and you refactor | ||
|
||
If you find yourself copying and pasting the same code 3 or more times, then it means you should put that code in | ||
its own function. Thus, I created the ``request_get`` and ``filter`` functions, and then provided input parameters to | ||
handle different use cases. | ||
|
||
* Type is in the name | ||
|
||
A person should be able to look at the code and know the purpose of all the names they see. For this reason | ||
I have written names of functions as ``snake_case``, names of input parameters and local function variables as | ||
``camelCase``, and names of global variables, class names, and enum names as ``PascalCase`` | ||
|
||
License | ||
------- | ||
|
||
Copyright (c) 2018 Joshua M. Fernandes | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
Quick Start | ||
============ | ||
|
||
---- | ||
|
||
.. image:: _static/pics/robinyell.jpg | ||
|
||
Importing and Logging In | ||
------------------------ | ||
|
||
The first thing you will need to do is to import Robin Stocks by typing: | ||
|
||
>>> import robin_stocks | ||
|
||
robin_stocks will need to added as a preface to every function call in the form of ``robin_stocks.function``. | ||
If you don't want to have to type robin_stocks at the beginning of every call, | ||
then import Robin Stocks by typing | ||
|
||
>>> from robin_stocks import * | ||
|
||
Keep in mind that this method is not considered good practice as it obfuscates the distinction between Robin Stocks' | ||
functions and other functions. For the rest of the documentation, I will assume that Robin Stocks was imported as ``import robin_stocks``. | ||
|
||
Once you have imported Robin Stocks, you will need to login in order to store an authentication token using | ||
|
||
>>> robin_stocks.login(<username>,<password>) | ||
|
||
Not all functions require authentication, but its good practice to log in to Robinhood at the beginning of your script. | ||
|
||
|
||
Building Profile and User Data | ||
------------------------------ | ||
|
||
The two most useful functions are ``build_holdings`` and ``build_user_profile``. These condense information from several | ||
functions into a single dictionary. If you wanted to view all your holdings then type: | ||
|
||
>>> my_stocks = robin_stocks.build_holdings() | ||
>>> for key,value in my_stocks.items(): | ||
>>> print(key,value) |
Oops, something went wrong.