TradeBuilder drops commissions reported after the first execution of an order

Chiusa
#10,126 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #10188 di @quantconnect-kronos — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

The fee cache is in TradeBuilder.ProcessFill, keyed by order ID in _ordersWithFeesAssigned; the reproduction is a C# snippet that builds a SPY partial fill followed by a status-only Filled event with a $1 commission and checks ClosedTrades[0].TotalFees. Start by reading how ProcessFill decides whether an order's fee has already been assigned and separate commission handling from execution and price updates. Done means the snippet reports 1, duplicate commission reports are still ignored, and a regression test covers a status-only completion after a partial fill.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

priority:p2

Problem

TradeBuilder.ProcessFill records an order ID in _ordersWithFeesAssigned on its first execution, even when the reported fee is zero. Any commission reported by a later event for that order is then ignored by trade statistics.

For example, a partial buy execution can report no commission, followed by a final status-only event carrying the commission. After the position closes, ClosedTrades[].TotalFees is zero instead of the commission paid. This is independent of portfolio cash accounting: it concerns the fees attached to reconstructed trades.

Reproduction

var symbol = new Symbol(
    SecurityIdentifier.GenerateEquity("SPY", Market.USA, mapSymbol: false), "SPY");
var time = new DateTime(2024, 1, 2, 15, 0, 0, DateTimeKind.Utc);
var builder = new TradeBuilder(FillGroupingMethod.FillToFill, FillMatchingMethod.FIFO);
builder.SetSecurityManager(new SecurityManager(new TimeKeeper(time)));
var noFee = new OrderFee(new CashAmount(0m, "USD"));
var commission = new OrderFee(new CashAmount(1m, "USD"));

builder.ProcessFill(new OrderEvent(1, symbol, time,
    OrderStatus.PartiallyFilled, OrderDirection.Buy, 300m, 2m, noFee), 1m, 0m);
// The brokerage closes the order without another execution and reports its commission.
builder.ProcessFill(new OrderEvent(1, symbol, time.AddMinutes(1),
    OrderStatus.Filled, OrderDirection.Buy, 300m, 0m, commission), 1m, 1m);
builder.ProcessFill(new OrderEvent(2, symbol, time.AddMinutes(2),
    OrderStatus.Filled, OrderDirection.Sell, 301m, -2m, noFee), 1m, 0m);

Console.WriteLine(builder.ClosedTrades[0].TotalFees); // actual: 0; expected: 1

Verified with the QuantConnect.Common assembly built from master (0b5c3db88): the first closed trade has TotalFees = 0 for FillToFill, FlatToFlat, and FlatToReduced. The same missing commission remains with the zero-quantity statistics guards. It is not caused by those guards: the existing first-event fee cache already discarded it.

Expected result

Trade reconstruction must retain genuine commissions reported after an order's first execution, without inventing an execution or treating a status-only event's price as a market-price update. Existing protection against duplicate commission reporting must be preserved.

Suggestion: separate commission accounting from execution/price processing and define how incremental versus repeated order fees are handled. Add regression coverage for deferred commission, including a status-only completion after a partial fill.

Impact is limited to trade fee statistics; this reproduction does not imply missing portfolio cash charges.

Lingua principale
C#
Stelle
22.6k
Fork
5.4k
Merge medio
11h 39m
PR unite (30g)
104

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di QuantConnect/Lean

Tutte le issue di QuantConnect/Lean

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.