Skip to content

Commit

Permalink
Add symbol field to FeeInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
edtechre committed Dec 15, 2023
1 parent 359667a commit 7ba0f2f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/pybroker/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 3 additions & 1 deletion src/pybroker/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def __init__(

def _calculate_fees(
self,
symbol: str,
fill_price: Decimal,
shares: Decimal,
order_type: Literal["buy", "sell"],
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/test_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ba0f2f

Please sign in to comment.