9bbc8c05f1
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from cerbero_mcp.exchanges.ibkr.orders_complex import (
|
|
OrderSpec,
|
|
build_bracket_payload,
|
|
build_oco_payload,
|
|
)
|
|
|
|
|
|
def test_bracket_three_legs_with_oca():
|
|
payload = build_bracket_payload(
|
|
conid=42, sec_type="STK", side="BUY", qty=10,
|
|
entry_price=150.0, stop_loss=145.0, take_profit=160.0,
|
|
tif="GTC", exchange="SMART",
|
|
)
|
|
assert "orders" in payload
|
|
legs = payload["orders"]
|
|
assert len(legs) == 3
|
|
oca = legs[0].get("ocaGroup")
|
|
assert oca and all(l.get("ocaGroup") == oca for l in legs[1:])
|
|
assert legs[0]["orderType"] == "LMT"
|
|
assert legs[0]["price"] == 150.0
|
|
assert legs[0]["side"] == "BUY"
|
|
assert legs[1]["side"] == "SELL"
|
|
assert legs[2]["side"] == "SELL"
|
|
assert legs[1]["orderType"] == "STP"
|
|
assert legs[1]["auxPrice"] == 145.0
|
|
assert legs[2]["orderType"] == "LMT"
|
|
assert legs[2]["price"] == 160.0
|
|
|
|
|
|
def test_oco_oca_group_and_type():
|
|
legs = [
|
|
OrderSpec(conid=1, sec_type="STK", side="BUY", qty=1,
|
|
order_type="LMT", price=100),
|
|
OrderSpec(conid=1, sec_type="STK", side="BUY", qty=1,
|
|
order_type="LMT", price=110),
|
|
]
|
|
payload = build_oco_payload(legs)
|
|
assert len(payload["orders"]) == 2
|
|
oca = payload["orders"][0]["ocaGroup"]
|
|
for o in payload["orders"]:
|
|
assert o["ocaGroup"] == oca
|
|
assert o["ocaType"] == 1
|