alpacahq / alpacahq/Alpaca-API

[Paper][Crypto] BTCUSD returns impossible avg_entry_price and understated cost_basis

Open
#285 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
174
Forks
17
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

The Alpaca paper position endpoint reports an impossible BTCUSD average entry price and an understated cost basis.

The position response reports:

- `qty`: `1.251126057`
- `avg_entry_price`: `25267.0735`
- `cost_basis`: `31612.294`

However, all 21 observed BTC buy orders filled between `$61,405.9273` and `$65,203.1329`. An average entry of `$25,267.0735` is therefore outside the feasible purchase-price range.

The same incorrect values are returned by the REST API and the official `alpaca-py` SDK. The dashboard calculates its displayed unrealized P/L from this incorrect basis, so this does not appear to be only a frontend formatting issue.

**To Reproduce**

1. Retrieve the BTCUSD paper position using `GET /v2/positions/BTCUSD`.
2. Retrieve the complete filled-order history using `GET /v2/orders`.
3. Normalize `BTCUSD` and `BTC/USD` symbols.
4. Sort the BTC fills chronologically.
5. Reconstruct the remaining position using FIFO or weighted-average accounting.
6. Compare the result with `avg_entry_price` and `cost_basis` from the position endpoint.

Sanitized reproducible project:

https://github.com/AjayKasu1/alpaca-basis-proof

Detailed evidence report:

https://github.com/AjayKasu1/alpaca-basis-proof/blob/main/docs/alpaca-support-report.md

The reproduction analyzes 27 filled orders: 21 buys and 6 sells.

Results:

| Metric | Alpaca reported | Reconstructed |
|---|---:|---:|
| Average entry | $25,267.0735 | ~$63,967.7171 FIFO |
| Open cost basis | $31,612.2940 | ~$80,031.6776 |
| Unrealized P/L at captured market value | +$51,477.16 | ~$3,057.78 |

Core invariant:

`minimum buy price <= valid average entry <= maximum buy price`

In this case:

`$61,405.9273 <= $25,267.0735 <= $65,203.1329`

This condition is false.

**Expected behavior**

`avg_entry_price` and `cost_basis` should be calculated from the authoritative order and crypto-fee ledger. The reported average entry should remain within the observed fill-price range.

**Screenshots**

The linked repository contains a sanitized dashboard and deterministic reproduction. Account identifiers and raw broker order UUIDs have intentionally been excluded.

**Desktop**

- Account environment: Paper
- Asset: BTCUSD crypto
- API: Alpaca Trading API v2
- SDK: `alpaca-py 0.43.5`
- OS: macOS
- Browser: Not applicable; reproduced directly through the API and SDK

**Additional context**

The order-to-position quantity difference caused by asset-denominated crypto fees is disclosed by the reproduction. It cannot explain an average entry approximately `$36,139` below the minimum observed buy price.

This report concerns a functional paper-account position-ledger/data-integrity discrepancy. Affected account details and raw identifiers can be supplied privately through Alpaca Support.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the deterministic reproduction in the linked alpaca-basis-proof project and read docs/alpaca-support-report.md. Compare GET /v2/positions/BTCUSD with the complete GET /v2/orders history, including normalized symbols and crypto-denominated fees. Done means the position endpoint's average entry and cost basis reconcile with the authoritative fills and ledger.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design, fintech-quant
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.