TradeBuilder drops commissions reported after the first execution of an order
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #10188 by @quantconnect-kronos — merged
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C#
- Stars
- 22.6k
- Forks
- 5.4k
- Avg merge
- 11h 39m
- Merged PRs (30d)
- 104
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QuantConnect/Lean
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
QuantConnect/Lean#10216 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
QuantConnect/Lean#10206 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
QuantConnect/Lean#10199 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
QuantConnect/Lean#10198 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
QuantConnect/Lean#10197 ·
Maintainers usually reply within 1 day
All issues in QuantConnect/Lean
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day