alpacahq / alpacahq/Alpaca-API

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

未关闭
#285 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
没有语言数据
星标
174
派生
17
PR 合并指标
30 天内没有已合并 PR

描述

**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.

贡献指南

这个仓库没有索引到贡献指南

调研方向

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.

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, backend-api-design, fintech-quant
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。