Skip to content

Commit

Permalink
Merge pull request westonplatter#27 from westonplatter/portfolio-hist…
Browse files Browse the repository at this point in the history
…oricals

related to westonplatter#26. fetch portfolio historical data.
  • Loading branch information
westonplatter authored Sep 3, 2018
2 parents e198f90 + 65dde3a commit aea0d80
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/portfolio_historicals.py
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))
4 changes: 4 additions & 0 deletions fast_arrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
# user
from fast_arrow.resources.user import User

# portfolio
from fast_arrow.resources.portfolio import Portfolio

# search
from fast_arrow.resources.collection import Collection
18 changes: 18 additions & 0 deletions fast_arrow/resources/portfolio.py
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

0 comments on commit aea0d80

Please sign in to comment.