Skip to content

Commit f161b07

Browse files
committed
don't warn for BP usage on stocks/ETFs
1 parent befc93e commit f161b07

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

ttcli/portfolio.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from collections import defaultdict
22
from datetime import date, datetime
33
from decimal import Decimal
4-
from typing import Annotated, cast
4+
from typing import Annotated
55

66
from rich.console import Console
77
from rich.table import Table
88
from tastytrade import DXLinkStreamer
9-
from tastytrade.account import MarginReportEntry
9+
from tastytrade.account import EmptyDict
1010
from tastytrade.dxfeed import Greeks
1111
from tastytrade.instruments import (
1212
Cryptocurrency,
@@ -545,17 +545,16 @@ def margin():
545545
"portfolio", "bp-max-percent-per-position", fallback=5.0
546546
)
547547
for i, entry in enumerate(margin.groups):
548-
if not entry:
548+
if isinstance(entry, EmptyDict):
549549
continue
550-
entry = cast(MarginReportEntry, entry)
551550
bp = -entry.buying_power
552551
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":
554553
warnings.append(
555554
f"Per-position BP usage is too high for {entry.description}, max is {max_percent}%!"
556555
)
557556
table.add_row(
558-
*[entry.description, conditional_color(bp), f"{bp_percent:.1f}%"],
557+
*[entry.code, conditional_color(bp), f"{bp_percent:.1f}%"],
559558
end_section=(i == last_entry),
560559
)
561560
bp_percent = abs(round(margin.margin_requirement / margin.margin_equity * 100, 1))

ttcli/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ def __init__(self):
138138
def _get_credentials(self):
139139
username = os.getenv("TT_USERNAME")
140140
password = os.getenv("TT_PASSWORD")
141-
if self.config.has_section("general"):
142-
username = username or self.config["general"].get("username")
143-
password = password or self.config["general"].get("password")
141+
username = username or self.config.get("general", "username", fallback=None)
142+
password = password or self.config.get("general", "password", fallback=None)
144143

145144
if not username:
146145
username = getpass.getpass("Username: ")
@@ -150,15 +149,16 @@ def _get_credentials(self):
150149
return username, password
151150

152151
def get_account(self) -> Account:
153-
account = self.config["general"].get("default-account", None)
152+
if len(self.accounts) == 1: # auto-select if there's only 1 option
153+
return self.accounts[0]
154+
account = self.config.get("general", "default-account", fallback=None)
154155
if account:
155156
try:
156157
return next(a for a in self.accounts if a.account_number == account)
157158
except StopIteration:
158159
print_warning(
159160
"Default account is set, but the account doesn't appear to exist!"
160161
)
161-
162162
for i in range(len(self.accounts)):
163163
if i == 0:
164164
print(

0 commit comments

Comments
 (0)