|
1 | 1 | from collections import defaultdict |
2 | 2 | from datetime import date, datetime |
3 | 3 | from decimal import Decimal |
4 | | -from typing import Annotated, cast |
| 4 | +from typing import Annotated |
5 | 5 |
|
6 | 6 | from rich.console import Console |
7 | 7 | from rich.table import Table |
8 | 8 | from tastytrade import DXLinkStreamer |
9 | | -from tastytrade.account import MarginReportEntry |
| 9 | +from tastytrade.account import EmptyDict |
10 | 10 | from tastytrade.dxfeed import Greeks |
11 | 11 | from tastytrade.instruments import ( |
12 | 12 | Cryptocurrency, |
@@ -545,17 +545,16 @@ def margin(): |
545 | 545 | "portfolio", "bp-max-percent-per-position", fallback=5.0 |
546 | 546 | ) |
547 | 547 | for i, entry in enumerate(margin.groups): |
548 | | - if not entry: |
| 548 | + if isinstance(entry, EmptyDict): |
549 | 549 | continue |
550 | | - entry = cast(MarginReportEntry, entry) |
551 | 550 | bp = -entry.buying_power |
552 | 551 | bp_percent = abs(float(bp / margin.margin_equity * 100)) |
553 | | - if abs(bp_percent) > max_percent: |
| 552 | + if abs(bp_percent) > max_percent and entry.underlying_type != "Equity": |
554 | 553 | warnings.append( |
555 | 554 | f"Per-position BP usage is too high for {entry.description}, max is {max_percent}%!" |
556 | 555 | ) |
557 | 556 | table.add_row( |
558 | | - *[entry.description, conditional_color(bp), f"{bp_percent:.1f}%"], |
| 557 | + *[entry.code, conditional_color(bp), f"{bp_percent:.1f}%"], |
559 | 558 | end_section=(i == last_entry), |
560 | 559 | ) |
561 | 560 | bp_percent = abs(round(margin.margin_requirement / margin.margin_equity * 100, 1)) |
|
0 commit comments