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 @@ -207,6 +207,10 @@ def build_firstrade_account_snapshot(
raise AccountFactsPublishError("snapshot_time_invalid")

cash_balance = balances.get("cash_balance")
# Use exact available_cash only when cash_balance is absent — still a real
# provider cash figure, never synthesized from equity or buying power.
if cash_balance is None:
cash_balance = balances.get("available_cash")
cash: list[dict[str, str]] = []
if cash_balance is not None:
cash.append({
Expand Down
17 changes: 17 additions & 0 deletions tests/test_account_facts_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_rejects_qrs_amounts_outside_exact_decimal_contract(value):
def test_allows_cash_to_be_absent_without_synthesizing_it():
data = observation()
data["balances"]["cash_balance"] = None
data["balances"]["available_cash"] = None

payload = build_firstrade_account_snapshot(
data, load_account_facts_publish_config(config()), account_scope="us"
Expand All @@ -124,6 +125,22 @@ def test_allows_cash_to_be_absent_without_synthesizing_it():
assert payload["cash"] == []


def test_falls_back_to_available_cash_when_cash_balance_absent():
data = observation()
data["balances"]["cash_balance"] = None
data["balances"]["available_cash"] = "240.00"

payload = build_firstrade_account_snapshot(
data, load_account_facts_publish_config(config()), account_scope="us"
)

assert payload["cash"] == [{
"currency": "USD",
"cash_balance": "240.00",
"source_tag": "provider.cash_balance",
}]


@pytest.mark.parametrize(
("overrides", "reason"),
[
Expand Down
Loading