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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
- uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec # v5.0.1

lint:
name: Lint
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -280,7 +280,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv and Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"
python-version: ${{ matrix.python-version }}
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv and Python 3.15
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"
python-version: "3.15"
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv and Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"
python-version: ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/private-comparisons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jobs:
with:
ref: ${{ github.sha }}

- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"
python-version: "3.12"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv and Python
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
version: "latest"
python-version: ${{ env.PYTHON_VERSION }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/successor-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
python-version: ${{ matrix.python }}
- name: Build the actual consumer wheel
Expand Down
24 changes: 12 additions & 12 deletions tests/property/test_order_type_invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def _make_broker(cash: float = 200_000.0) -> Broker:
return Broker(cash, NoCommission(), NoSlippage())
return Broker(cash, NoCommission(), NoSlippage(), allow_short_selling=True)


def _set_bar(
Expand Down Expand Up @@ -46,7 +46,7 @@ def _set_bar(
# ---------------------------------------------------------------------------


@settings(max_examples=200)
@settings(max_examples=200, deadline=None)
@given(
limit=st.floats(min_value=50.0, max_value=150.0, allow_nan=False, allow_infinity=False),
bar_high=st.floats(min_value=50.0, max_value=200.0, allow_nan=False, allow_infinity=False),
Expand All @@ -66,11 +66,12 @@ def test_limit_buy_never_fills_above_limit(limit: float, bar_high: float, bar_lo
broker._process_orders()

limit_fills = [f for f in broker.fills if f.order_type == "limit"]
assert len(limit_fills) == int(bar_low <= limit)
for fill in limit_fills:
assert fill.price <= limit + 1e-8, f"Limit BUY filled at {fill.price} > limit {limit}"


@settings(max_examples=200)
@settings(max_examples=200, deadline=None)
@given(
limit=st.floats(min_value=50.0, max_value=150.0, allow_nan=False, allow_infinity=False),
bar_high=st.floats(min_value=50.0, max_value=200.0, allow_nan=False, allow_infinity=False),
Expand All @@ -90,6 +91,7 @@ def test_limit_sell_never_fills_below_limit(limit: float, bar_high: float, bar_l
broker._process_orders()

limit_fills = [f for f in broker.fills if f.order_type == "limit"]
assert len(limit_fills) == int(bar_high >= limit)
for fill in limit_fills:
assert fill.price >= limit - 1e-8, f"Limit SELL filled at {fill.price} < limit {limit}"

Expand All @@ -99,7 +101,7 @@ def test_limit_sell_never_fills_below_limit(limit: float, bar_high: float, bar_l
# ---------------------------------------------------------------------------


@settings(max_examples=200)
@settings(max_examples=200, deadline=None)
@given(
stop=st.floats(min_value=50.0, max_value=200.0, allow_nan=False, allow_infinity=False),
bar_open=st.floats(min_value=50.0, max_value=200.0, allow_nan=False, allow_infinity=False),
Expand All @@ -121,11 +123,12 @@ def test_stop_buy_never_fills_below_stop(
broker._process_orders()

stop_fills = [f for f in broker.fills if f.order_type == "stop"]
assert len(stop_fills) == int(bar_high >= stop)
for fill in stop_fills:
assert fill.price >= stop - 1e-8, f"Stop BUY filled at {fill.price} < stop {stop}"


@settings(max_examples=200)
@settings(max_examples=200, deadline=None)
@given(
stop=st.floats(min_value=10.0, max_value=150.0, allow_nan=False, allow_infinity=False),
bar_open=st.floats(min_value=10.0, max_value=200.0, allow_nan=False, allow_infinity=False),
Expand All @@ -147,6 +150,7 @@ def test_stop_sell_never_fills_above_stop(
broker._process_orders()

stop_fills = [f for f in broker.fills if f.order_type == "stop"]
assert len(stop_fills) == int(bar_low <= stop)
for fill in stop_fills:
assert fill.price <= stop + 1e-8, f"Stop SELL filled at {fill.price} > stop {stop}"

Expand All @@ -156,7 +160,7 @@ def test_stop_sell_never_fills_above_stop(
# ---------------------------------------------------------------------------


@settings(max_examples=100)
@settings(max_examples=100, deadline=None)
@given(
entry_price=st.floats(min_value=50.0, max_value=150.0, allow_nan=False, allow_infinity=False),
tp_offset=st.floats(min_value=1.0, max_value=20.0, allow_nan=False, allow_infinity=False),
Expand Down Expand Up @@ -189,12 +193,7 @@ def test_bracket_exactly_one_exit(
entry, tp, sl = orders
broker._process_orders()

if entry.status != broker.__class__.__dict__.get("_x", None):
# Entry should have filled (market order at current price)
pass

if entry.filled_price is None:
return # Entry didn't fill (shouldn't happen with market)
assert entry.filled_price is not None

# Bar 1: exit bar with random high/low
exit_close = (exit_high + exit_low) / 2
Expand All @@ -206,6 +205,7 @@ def test_bracket_exactly_one_exit(
tp_filled = tp.status.value == "filled"
sl_filled = sl.status.value == "filled"

assert (tp_filled or sl_filled) == (exit_high >= tp_price or exit_low <= sl_price)
if tp_filled or sl_filled:
# Exactly one should have filled, not both
assert not (tp_filled and sl_filled), (
Expand Down
Loading