Skip to content

fix(borrow): support Alpaca live API endpoints and clear borrow cache on mode/key changes #74

Done

Description

@mlgitdev

Description

  1. test_alpaca() (app/api.py:139), _sync_bulk_assets() (app/borrow.py:134), and _query_alpaca() (app/borrow.py:230) hardcode https://paper-api.alpaca.markets/v2/..., causing live Alpaca API keys (AK...) to fail with HTTP 401.
  2. BorrowService.update_credentials() (app/borrow.py:81-95) does not clear self._cache when switching mode to "heuristic" or updating keys, leaving stale Alpaca statuses cached.
  3. When mode == "alpaca" and Alpaca returns 404/error, _worker() still falls back to heuristic estimation instead of returning N/A.

References: app/api.py:139, app/borrow.py:81-95, 134, 230, 255-261

Steps to Reproduce

  1. Enter live Alpaca keys (AK...) and click Test Alpaca Connection -> fails with HTTP 401 against paper-api.
  2. Switch Borrow source mode from auto/alpaca to heuristic and save -> cached source: "alpaca" entries remain returned by get_status().

Expected Behavior

Automatically select https://paper-api.alpaca.markets for paper keys (PK...) and https://api.alpaca.markets for live keys (AK...), clear self._cache/self._details on mode or credential updates, and return N/A rather than heuristic when mode == "alpaca".

Operating System & Version

  • OS: Windows 11 x64 / macOS arm64 / Linux x86_64
  • Version: v2.12.0
  • Display / Scale: Verified via live Chrome CDP (1600x960) & local unit/backend suite

Logs & Additional Context

Backend reproduction confirmed paper-api hardcoded and stale alpaca cache after switching to heuristic = True.

Activity

  1. added
    bug
    on Dec 2, 2026
  2. self-assigned this
    on Dec 2, 2026
  3. github-actions commented on Dec 2, 2026

    @github-actions

    ✅ Issue Validation Passed

    • Conventional Commit title syntax (fix(borrow))
    • Verified issue type: BUG
    • Required template sections present and filled out

    This issue is well-structured and ready for work according to the Issue-First Protocol.

  4. mlgitdev commented on Dec 2, 2026

    @mlgitdev
    OwnerAuthor

    🚀 Resolution In Progress

    A fix for this issue has been implemented and submitted in Pull Request #82 (v2.12.1).

    • Branch: fix/audit-remediation-67
    • PR URL: fix(core): resolve 15 verified audit issues across UI, API, concurrency, audio, and packaging (v2.12.1) #82
    • Summary of Changes: Added alpaca_trading_base() in app/borrow.py to auto-select paper-api.alpaca.markets (PK...) vs api.alpaca.markets (AK...) with 401/403 fallback, cleared borrow caches on credential/mode changes, and respected strict mode='alpaca'. Verified via unit tests.
    • Verification: compileall clean, 84/84 unit tests passing (including tests/test_audit_fixes.py), and live Chrome CDP verification passed.

    This issue will automatically close upon PR #82 review and merge into main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions