alpacahq / alpacahq/Alpaca-API
[Paper][Crypto] BTCUSD returns impossible avg_entry_price and understated cost_basis
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 174
- Fork
- 17
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
**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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api, backend-api-design, fintech-quant
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100