alpacahq / alpacahq/Alpaca-API

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

オープン
#285 コメント 2 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。