Skip to content

[Bug]: Lowercase close misses position, shadow order id collisions, Alpaca shorts stored as longs, zero-qty fills, 90-minute bars restart hourly #111

Closed

Description

@quantum-like

Affected package version

0.1.2 (main at 43fc66f4)

Environment

Linux, source checkout of main at 43fc66f4 with the repo's dev environment (uv sync); offline test suite.

Observed behavior

  1. close_position("aapl") on the safety facade leaves an AAPL position open.
  2. Two shadow orders accepted in the same millisecond get the same id.
  3. An Alpaca short snapshot is stored with a positive quantity, so a later close sells more.
  4. An Alpaca fill with filled_qty 0 is recorded as a full fill.
  5. A 90-minute aggregation restarts at each hour instead of keeping 10:30–12:00 intact.

Expected behavior

  1. The uppercase position is found and reduced. 2. Ids stay unique. 3. Shorts are negative. 4. The fill is rejected. 5. Windows align to midnight.

Minimal reproduction

Each case has a focused unit test on quantum-like/live branch review/fixes (one commit per fix, on top of 43fc66f4). Every test fails on main and passes with its fix:

  • tests/unit/test_safe_broker.py::test_position_lookup_and_close_ignore_symbol_case, ::test_external_position_lookup_ignores_symbol_case
  • tests/unit/test_safe_broker.py::test_shadow_order_ids_stay_unique_when_the_clock_does_not_advance
  • tests/unit/test_alpaca_broker.py::test_sync_positions_signs_short_holdings
  • tests/unit/test_alpaca_broker.py::test_fill_event_does_not_invent_a_quantity
  • tests/unit/test_bar_aggregator.py::test_bar_windows_do_not_restart_at_the_hour

Compatibility impact

Public behavior or results

Acceptance criteria

Each case has a unit test that fails on main and passes with the fix; the existing suite stays green.

I have a PR ready with these fixes and will link it here.

Amir

Activity

  1. added
    type: bugConfirmed or reported incorrect behavior
    compatibility: affectedHas Python, platform, dependency, or cross-library compatibility impact
    on Oct 7, 2026
  2. stefan-jansen commented on Oct 17, 2026

    @stefan-jansen
    Contributor

    I reproduced the reported defects and split the repairs into focused owning issues and PRs, preserving the original contribution:

    The same new public-workflow tests were run against complete original producing source from base 2ad36a8 and against each fix. That base contains only the dependency-security prerequisite relative to main 43fc66f. No copied implementation or patched faulty method was used to manufacture the failure.

    The focused PRs are now running the full stable and ecosystem checks. This bundled report and PR #112 remain open until the five fixes are merged and their evidence is recorded. No release or credentialed provider qualification is claimed.

    AI assistance: Codex reviewed and verified the original Cursor-assisted contribution and prepared the additional regressions.

  3. added a commit that references this issue on Oct 20, 2026
    f2ee7e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibility: affectedHas Python, platform, dependency, or cross-library compatibility impactpriority: normalNormal planned workstatus: acceptedAccepted for implementationtype: bugConfirmed or reported incorrect behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions