Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Portfolio HIstory Functionlaity like Broker api in Trading api … #439

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions alpaca/trading/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from alpaca.common.enums import BaseURL

from alpaca.trading.requests import (
GetPortfolioHistoryRequest,
GetCalendarRequest,
ClosePositionRequest,
GetAssetsRequest,
Expand All @@ -28,6 +29,7 @@
)

from alpaca.trading.models import (
PortfolioHistory,
OptionContract,
OptionContractsResponse,
Order,
Expand Down Expand Up @@ -743,3 +745,28 @@ def get_option_contract(
return response

return TypeAdapter(OptionContract).validate_python(response)

# ############################## PORTFOLIO HISTORY ################################# #
def get_portfolio_history(
self,
history_filter: Optional[GetPortfolioHistoryRequest] = None,
) -> Union[PortfolioHistory, RawData]:
"""
Gets the portfolio history statistics for an account.

Args:
history_filter: The various portfolio history request parameters.

Returns:
PortfolioHistory: The portfolio history statistics for the account.
"""

response = self.get(
f"/account/portfolio/history",
history_filter.to_request_fields() if history_filter else {},
)

if self._use_raw_data:
return response

return PortfolioHistory(**response)