Getting Your Portfolio History From Alpaca using Python
Check and chart your Portfolio History programmatically
I was playing with the Node JS Alpaca API Library and discovered that actually you can get the history of your portfolio very suitable for being use in a chart, and I suspect is the way Alpaca graph the daily, monthly, yearly and all the value of your equity.
I turned to the Python library to retrieve and plot the Portfolio History, but after digging for a while I found that the Python library have not yet implemented that function.
Extending the TradingClient class
The solution I found suit best my needs was extending the TradingClient
class.
from alpaca.trading.requests import GetPortfolioHistoryRequest
from alpaca.trading.client import TradingClient
from alpaca.common.enums import BaseURL
from typing import Optional, List, Union
from alpaca.trading.models import PortfolioHistory
from alpaca.common import RawData
import config
class TradingClientPortfolioAble(TradingClient):
def __init__(
self,
api_key: Optional[str] = None,
secret_key: Optional[str] = None,
paper…