Trade logic slop generated by copilot x(
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
from trading_bot.models.trade import summarize_alpaca_portfolio
|
||||
|
||||
|
||||
def test_calculate_cash_to_spy_ratio() -> None:
|
||||
account = {"cash": "1000.00"}
|
||||
positions = [{"symbol": "SPY", "qty": "10", "market_value": "5000", "avg_entry_price": "500"}]
|
||||
orders = []
|
||||
|
||||
summary = summarize_alpaca_portfolio(account, positions, orders)
|
||||
|
||||
assert summary.cash == 1000.0
|
||||
assert summary.spy_quantity == 10.0
|
||||
assert summary.spy_market_value == 5000.0
|
||||
assert summary.current_cash_to_spy_ratio == 0.2
|
||||
assert summary.projected_cash_to_spy_ratio == 0.2
|
||||
assert summary.open_spy_order_count == 0
|
||||
|
||||
|
||||
def test_projected_ratio_includes_open_spy_buy_order() -> None:
|
||||
account = {"cash": "1000.00"}
|
||||
positions = [{"symbol": "SPY", "qty": "10", "market_value": "5000", "avg_entry_price": "500"}]
|
||||
orders = [
|
||||
{
|
||||
"symbol": "SPY",
|
||||
"side": "buy",
|
||||
"qty": "2",
|
||||
"filled_qty": "0",
|
||||
"limit_price": "500",
|
||||
"status": "open",
|
||||
"type": "limit",
|
||||
}
|
||||
]
|
||||
|
||||
summary = summarize_alpaca_portfolio(account, positions, orders)
|
||||
|
||||
assert summary.open_spy_order_count == 1
|
||||
assert summary.estimated_spy_price == 500.0
|
||||
assert summary.projected_cash_to_spy_ratio == 0.14285714285714285
|
||||
|
||||
|
||||
def test_projected_ratio_handles_no_spy_position_but_open_order() -> None:
|
||||
account = {"cash": "1500.00"}
|
||||
positions = []
|
||||
orders = [
|
||||
{
|
||||
"symbol": "SPY",
|
||||
"side": "buy",
|
||||
"qty": "3",
|
||||
"filled_qty": "0",
|
||||
"limit_price": "500",
|
||||
"status": "open",
|
||||
"type": "limit",
|
||||
}
|
||||
]
|
||||
|
||||
summary = summarize_alpaca_portfolio(account, positions, orders)
|
||||
|
||||
assert summary.spy_quantity == 0.0
|
||||
assert summary.spy_market_value == 0.0
|
||||
assert summary.current_cash_to_spy_ratio is None
|
||||
assert summary.projected_cash_to_spy_ratio == 1.0
|
||||
assert summary.open_spy_order_count == 1
|
||||
Reference in New Issue
Block a user