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
10 changes: 5 additions & 5 deletions strategy_platform_config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"accounts": {
"schwab": {
"account_scope": "default",
"execution_mode": "live",
"dry_run_only": false
"execution_mode": "paper",
"dry_run_only": true
}
}
},
Expand All @@ -27,9 +27,9 @@
},
"accounts": {
"ibkr": {
"account_ids": ["U15998061"],
"execution_mode": "live",
"dry_run_only": false
"account_ids": ["U00000000"],
"execution_mode": "paper",
"dry_run_only": true
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ibkr_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def test_submit_order_intent_sets_account_when_provided(self) -> None:
ib = FakeIB()
report = submit_order_intent(
ib,
OrderIntent(symbol="SPY", side="buy", quantity=5, account_id="U18308207"),
OrderIntent(symbol="SPY", side="buy", quantity=5, account_id="U00000001"),
wait_seconds=0,
stock_factory=FakeContract,
market_order_factory=FakeMarketOrder,
)

self.assertEqual(ib.orders[0][1].account, "U18308207")
self.assertEqual(report.raw_payload["account_id"], "U18308207")
self.assertEqual(ib.orders[0][1].account, "U00000001")
self.assertEqual(report.raw_payload["account_id"], "U00000001")

def test_submit_order_intent_rejects_notional_equity_order(self) -> None:
ib = FakeIB()
Expand All @@ -144,8 +144,8 @@ def test_submit_order_intent_rejects_conflicting_account_id(self) -> None:
with self.assertRaises(ValueError):
submit_order_intent(
ib,
OrderIntent(symbol="SPY", side="buy", quantity=5, account_id="U18308207"),
account_id="U15998061",
OrderIntent(symbol="SPY", side="buy", quantity=5, account_id="U00000001"),
account_id="U00000000",
wait_seconds=0,
stock_factory=FakeContract,
market_order_factory=FakeMarketOrder,
Expand Down
22 changes: 11 additions & 11 deletions tests/test_ibkr_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def reqPositions(self):
def positions(self):
return [
SimpleNamespace(
account="U18308207",
account="U00000001",
contract=SimpleNamespace(symbol="TQQQ"),
position=3,
avgCost=100.0,
),
SimpleNamespace(
account="U18308207",
account="U00000001",
contract=SimpleNamespace(
symbol="TQQQ",
secType="OPT",
Expand All @@ -35,7 +35,7 @@ def positions(self):
avgCost=3200.0,
),
SimpleNamespace(
account="U15998061",
account="U00000000",
contract=SimpleNamespace(symbol="AAPL"),
position=5,
avgCost=200.0,
Expand All @@ -44,33 +44,33 @@ def positions(self):

def accountValues(self):
return [
SimpleNamespace(account="U18308207", tag="NetLiquidation", currency="USD", value="1000"),
SimpleNamespace(account="U18308207", tag="AvailableFunds", currency="USD", value="250"),
SimpleNamespace(account="U15998061", tag="NetLiquidation", currency="USD", value="2000"),
SimpleNamespace(account="U15998061", tag="AvailableFunds", currency="USD", value="500"),
SimpleNamespace(account="U00000001", tag="NetLiquidation", currency="USD", value="1000"),
SimpleNamespace(account="U00000001", tag="AvailableFunds", currency="USD", value="250"),
SimpleNamespace(account="U00000000", tag="NetLiquidation", currency="USD", value="2000"),
SimpleNamespace(account="U00000000", tag="AvailableFunds", currency="USD", value="500"),
]


class IbkrPortfolioTests(unittest.TestCase):
def test_fetch_portfolio_snapshot_filters_by_account_id(self) -> None:
ib = FakeIB()

snapshot = fetch_portfolio_snapshot(ib, account_ids=("U18308207",), wait_seconds=0)
snapshot = fetch_portfolio_snapshot(ib, account_ids=("U00000001",), wait_seconds=0)

self.assertTrue(ib.req_positions_called)
self.assertEqual(snapshot.total_equity, 1000.0)
self.assertEqual(snapshot.buying_power, 250.0)
self.assertEqual(tuple(position.symbol for position in snapshot.positions), ("TQQQ",))
self.assertEqual(snapshot.positions[0].account_id, "U18308207")
self.assertEqual(snapshot.metadata["account_ids"], ("U18308207",))
self.assertEqual(snapshot.positions[0].account_id, "U00000001")
self.assertEqual(snapshot.metadata["account_ids"], ("U00000001",))
self.assertEqual(snapshot.metadata["option_positions"][0]["underlier"], "TQQQ")
self.assertEqual(snapshot.metadata["option_positions"][0]["right"], "C")
self.assertEqual(snapshot.metadata["option_positions"][0]["strike"], 70.0)

def test_fetch_portfolio_snapshot_sums_selected_accounts(self) -> None:
snapshot = fetch_portfolio_snapshot(
FakeIB(),
account_ids=("U18308207", "U15998061"),
account_ids=("U00000001", "U00000000"),
wait_seconds=0,
)

Expand Down