forked from westonplatter/fast_arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request westonplatter#27 from westonplatter/portfolio-hist…
…oricals related to westonplatter#26. fetch portfolio historical data.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import configparser | ||
from fast_arrow import Client | ||
from fast_arrow import Portfolio | ||
|
||
# | ||
# get the authentication configs | ||
# | ||
config_file = "config.debug.ini" | ||
config = configparser.ConfigParser() | ||
config.read(config_file) | ||
username = config['account']['username'] | ||
password = config['account']['password'] | ||
account = config['account']['account'] | ||
|
||
client = Client(username=username, password=password) | ||
result = client.authenticate() | ||
|
||
span="year" | ||
bounds="regular" | ||
portfolio_historicals = Portfolio.historical(client, account, span, bounds) | ||
|
||
ehs = portfolio_historicals["equity_historicals"] | ||
begins_at = ehs[-1]["begins_at"] | ||
ends_at = ehs[0]["begins_at"] | ||
|
||
print(ehs[0].keys()) | ||
|
||
print("Fetched portfolio data between {} and {}".format(begins_at, ends_at)) |
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,18 @@ | ||
class Portfolio(object): | ||
|
||
@classmethod | ||
def historical(cls, client, account="", span="year", bounds="regular"): | ||
possible_intervals = { | ||
"day": "5minute", | ||
"week": "10minute", | ||
"year": "day", | ||
"5year": "week" } | ||
assert span in possible_intervals.keys() | ||
interval = possible_intervals[span] | ||
assert bounds in ["regular", "trading"] | ||
|
||
base_request_url = "https://api.robinhood.com/portfolios/historicals/" | ||
request_url = "{}{}/".format(base_request_url, account) | ||
params = { "span": span, "interval": interval, "bounds": bounds } | ||
data = client.get(request_url, params=params) | ||
return data |