Fee models get the order, not the fill, so fees based on trade value use an estimate

Open
#10,140 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp, python
Domain
backend

Research direction

Start with OrderFeeParameters and the fee model call in BacktestingBrokerage, where fill.OrderFee is set after the fill but the fee model still receives the original order. The fix changes the fee-model interface across all fee models, including Python and brokerage plugins, so it needs design agreement first. Done means fee models see the fill's price and quantity while pre-trade buying power checks still use the order, with the reproduction case charging $1.00.

Written by the indexing model from the issue text.

Description

Expected Behavior

A fee model that charges on trade value, such as InteractiveBrokersFeeModel's 1% maximum per order, charges a fill on that fill's price and quantity.

Actual Behavior

OrderFeeParameters only carries the Security and the Order. BacktestingBrokerage sets fill.OrderFee after the fill, but it passes the fee model the original order and not the fill. So fee models estimate the trade value from the order's prices or the security's current price.

Once #10129 is merged, US equity orders under $100 pay 1% of trade value, so the estimate shows in the fee. For example, take a one-share buy stop at $100 when the next minute bar is 90/110/90/90 (open/high/low/close). It fills at $100 and should cost $1.00, but it's charged $0.90.

Potential Solution

Pass the fill (price and quantity) to the fee model when charging a fill, for example as an optional fill on OrderFeeParameters. Pre-trade fee estimates, such as buying power checks, keep using the order. This affects every fee model, including Python models and models in the brokerage plugins.

Reproducing the Problem

With #10129: EquityFillModel fills the stop above at $100, and InteractiveBrokersFeeModel charges $0.90.

System Information

master, .NET 10.

Dominant language
C#
Stars
22.6k
Forks
5.4k
Avg merge
11h 39m
Merged PRs (30d)
104

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantConnect/Lean

All issues in QuantConnect/Lean

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.