From 7ba0f2ffbaf835ab3ddcf940d3b06e38c07f3bf3 Mon Sep 17 00:00:00 2001 From: edtechre Date: Thu, 14 Dec 2023 17:32:09 -0800 Subject: [PATCH] Add symbol field to FeeInfo. --- src/pybroker/common.py | 2 ++ src/pybroker/portfolio.py | 4 +++- tests/test_portfolio.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pybroker/common.py b/src/pybroker/common.py index a16ce87..b2fa131 100644 --- a/src/pybroker/common.py +++ b/src/pybroker/common.py @@ -152,11 +152,13 @@ class FeeInfo(NamedTuple): """Contains info for custom fee calculations. Attributes: + symbol: Trading symbol. shares: Number of shares in order. fill_price: Fill price of order. order_type: Type of order, either "buy" or "sell". """ + symbol: str shares: Decimal fill_price: Decimal order_type: Literal["buy", "sell"] diff --git a/src/pybroker/portfolio.py b/src/pybroker/portfolio.py index c4bd61c..61541d4 100644 --- a/src/pybroker/portfolio.py +++ b/src/pybroker/portfolio.py @@ -353,6 +353,7 @@ def __init__( def _calculate_fees( self, + symbol: str, fill_price: Decimal, shares: Decimal, order_type: Literal["buy", "sell"], @@ -364,6 +365,7 @@ def _calculate_fees( fees = to_decimal( self._fee_mode( FeeInfo( + symbol=symbol, shares=shares, fill_price=fill_price, order_type=order_type, @@ -424,7 +426,7 @@ def _add_order( shares: Decimal, ) -> Order: self._order_id += 1 - fees = self._calculate_fees(fill_price, shares, type) + fees = self._calculate_fees(symbol, fill_price, shares, type) order = Order( id=self._order_id, date=date, diff --git a/tests/test_portfolio.py b/tests/test_portfolio.py index 2dc2774..aac017f 100644 --- a/tests/test_portfolio.py +++ b/tests/test_portfolio.py @@ -733,6 +733,7 @@ def test_sell_when_all_shares_and_fractional(): def calc_fees(fee_info): + assert fee_info.symbol == SYMBOL_1 assert fee_info.shares == SHARES_1 if fee_info.order_type == "buy": assert fee_info.fill_price == FILL_PRICE_1