Skip to content

fix: preserve Alpaca short direction when closing positions - #123

Closed
stefan-jansen wants to merge 6 commits into
mainfrom
fix/alpaca-short-direction
Closed

stefan-jansen wants to merge 6 commits into
mainfrom
fix/alpaca-short-direction

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

An Alpaca short snapshot carries a separate side and an unsigned quantity. Treating that quantity as positive makes the portable broker see a long position and can sell more when asked to close it. Preserve the provider side when building portable positions so closing a short buys to cover.

Closes #118. Resolves the short-position part of #111, retaining the original #112 contribution by quantum-like/Cursor Agent.

Regression: uv run pytest -q tests/unit/test_alpaca_broker.py::TestAlpacaBrokerSetup::test_connected_short_is_closed_with_a_buy_to_cover.

  • Producing base 2ad36a8: the workflow fails because the public connected position is +50 instead of -50.
  • Fix deee1f1: the unchanged workflow passes, closes the -50 position, and submits an SDK market request to buy 50.
  • The fixture is an actual validated Alpaca Position model passed through connect, snapshot synchronization, public lookup and public close; only external transports are replaced. The base run loads the complete original producing source from git archive.
  • Two focused short-position tests, Ruff check/format and commit hooks passed. Hosted CI must pass the full supported-runtime, ecosystem, dependency, installed-artifact and other stable gates before merge.

Depends on security baseline #109. Alpaca provider evidence must be refreshed for a release because adapter behavior changes. No release or credentialed provider claim is included.

AI assistance: Cursor prepared the original repair; Codex reviewed it, added the SDK-to-public-close regression and ran failing-base/passing-fix verification.

dependabot Bot and others added 4 commits October 7, 2026 02:36
Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.7.0 to 2.8.0.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](urllib3/urllib3@2.7.0...2.8.0)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-version: 2.8.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Alpaca position snapshots report an unsigned share count and a separate
long/short side. Treating qty as a signed quantity stored shorts as longs,
so a later close sold more instead of buying to cover.

Co-authored-by: quantum-like <quantum-like@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@stefan-jansen stefan-jansen added type: bug Confirmed or reported incorrect behavior priority: normal Normal planned work status: accepted Accepted for implementation compatibility: affected Has Python, platform, dependency, or cross-library compatibility impact labels Oct 17, 2026
@stefan-jansen

Copy link
Copy Markdown
Contributor Author

Superseded by the combined maintainer-directed maintenance PR #121 to avoid qualifying and merging this queue separately. This PR head and its regression/documentation evidence are preserved in #121 and in a verified recovery archive. The accepted issue remains open until the combined fix lands; this closure does not claim the fix is merged. Follow-up work continues in #121.

@stefan-jansen
stefan-jansen deleted the fix/alpaca-short-direction branch October 18, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility: affected Has Python, platform, dependency, or cross-library compatibility impact priority: normal Normal planned work status: accepted Accepted for implementation type: bug Confirmed or reported incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve Alpaca short direction through connection and position closure

3 participants