Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions application/account_facts_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def build_firstrade_account_snapshot(
if not isinstance(balances, Mapping):
raise AccountFactsPublishError("snapshot_invalid")
currency = balances.get("currency")
# Firstrade US equity balance payloads often omit an ISO currency field; the
# rest of this platform already treats Firstrade cash as USD.
if currency is None:
currency = "USD"
if not isinstance(currency, str) or not _CURRENCY_RE.fullmatch(currency):
raise AccountFactsPublishError("provider_currency_unavailable")
provider_equity = balances.get("provider_equity")
Expand Down
13 changes: 11 additions & 2 deletions tests/test_account_facts_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ def test_builds_fixed_snapshot_with_only_provider_equity_and_cash():
assert "buying_power" not in repr(payload)


@pytest.mark.parametrize("value", [None, "", "usd", "US", "USDX", "USD " ])
def test_rejects_missing_or_invalid_provider_currency(value):
def test_defaults_missing_provider_currency_to_usd():
data = observation()
data["balances"]["currency"] = None
payload = build_firstrade_account_snapshot(
data, load_account_facts_publish_config(config()), account_scope="us"
)
assert payload["broker_reported_balances"][0]["currency"] == "USD"


@pytest.mark.parametrize("value", ["", "usd", "US", "USDX", "USD "])
def test_rejects_invalid_provider_currency(value):
data = observation()
data["balances"]["currency"] = value

Expand Down