Skip to content

Conversation

@Antifrajz
Copy link

@Antifrajz Antifrajz commented Oct 11, 2025

Pull Request

NautilusTrader prioritizes correctness and reliability, please follow existing patterns for validation and testing.

  • [ x] I have reviewed the CONTRIBUTING.md and followed the established practices

Summary

In this PR, the concept of Market and Stop Market orders with protection is introduced. It basically converts any Market or Stop Market order, once triggered, into a Limit xor Stop Limit order using the protection points from the market configuration and the best opposite limit on the order book.

Related Issues/PRs

Resolves #1082

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (impacts existing behavior)
  • Documentation update
  • Maintenance / chore

Testing

Ensure new or changed logic is covered by tests.

  • Affected code paths are already covered by the test suite
  • I added/updated tests to cover new or changed logic

I added Unit tests for calucation and all affected code paths

@CLAassistant
Copy link

CLAassistant commented Oct 11, 2025

CLA assistant check
All committers have signed the CLA.

@cjdsellers
Copy link
Member

Hi @Antifrajz

Thanks for the contribution!

Looks like the pre-commit failed, but this is easy to fix. Just run the following and push any changes to the same PR:

make pre-commit

or (if you're on Windows):

pre-commit run --all-files

Also consider running the following to install the git hook which will run the pre-commit automatically on commit:

pre-commit install

@Antifrajz
Copy link
Author

Antifrajz commented Oct 14, 2025

Hi @Antifrajz

Thanks for the contribution!

Looks like the pre-commit failed, but this is easy to fix. Just run the following and push any changes to the same PR:

make pre-commit

or (if you're on Windows):

pre-commit run --all-files

Also consider running the following to install the git hook which will run the pre-commit automatically on commit:

pre-commit install

Done, thank you @cjdsellers

Edit: I will resolve confilcts asap, I'm on a vacation now

Jasmin Imamović added 2 commits October 15, 2025 08:59
@cjdsellers
Copy link
Member

Hi @Antifrajz

I think a price_protection_points field needs to be added into the nautilus_trader/backtest/engine.pxd Cython declaration file. Hope that helps!

@cjdsellers cjdsellers changed the title Enhancement/price protection for market Add price protection support for market orders Oct 22, 2025
@cjdsellers
Copy link
Member

Hi @Antifrajz

Thank you for your work on this 🙏.

Since it's quite a large change, I'll start reviewing properly after the next release (which is imminent 1-2 days). We'd also need the CLA signing prior to merge as well.

@Antifrajz
Copy link
Author

Hi @Antifrajz

Thank you for your work on this 🙏.

Since it's quite a large change, I'll start reviewing properly after the next release (which is imminent 1-2 days). We'd also need the CLA signing prior to merge as well.

Hi @cjdsellers ,

Thank you for your help. I made the last changes just before I went to sleep, hoping the pipelines would pass in the meantime.

No problem at all on the review timing; please take your time. We can do the CLA signing when we're both available.

Best

@faysou
Copy link
Collaborator

faysou commented Oct 27, 2025

Hi, the CLA is an online form, you just need to sign it (if you want), there's no need to wait for @cjdsellers on this.

@Antifrajz
Copy link
Author

Hi, the CLA is an online form, you just need to sign it (if you want), there's no need to wait for @cjdsellers on this.

Hello @faysou
Chirs conctacted me and I have already signed it

@faysou
Copy link
Collaborator

faysou commented Oct 28, 2025

The pull request still shows the CLA as not signed, maybe you can try again.

cjdsellers and others added 27 commits October 29, 2025 06:33
Update CI wheel counts after dropping Python 3.11.
Use isort for import sorting instead of ruff's built-in import sorting
(rule "I"). This allows separate line_length configurations: code uses
100 chars (ruff) while imports use 150 chars (isort) to prevent unwanted
multi-line hanging indent formatting.

isort provides more granular control over import formatting for now.
- Add interactive Plotly tearsheets with performance metrics and charts
- Add CAGR, CalmarRatio, MaxDrawdown portfolio statistics
- Standardize uv pip commands
- Pin cargo-deny/nextest/llvm-cov/audit versions
- Enable license checks in CI
- Clarify implied-vol MIT license with hash verification
- Update workspace license from deprecated LGPL-3.0 to LGPL-3.0-or-later
- Add `_sorted` flag and `sort=False` parameter to defer sorting
- Add presorted parameter to data iterator to skip redundant sorts
- Optimize `BacktestNode` to sort once after loading all data configs
- Add test coverage and documentation for deferred sorting
- Implement Rust reconciliation engine for continuous position sync
- Add lifecycle tracking with zero-crossing detection for avg price
- Add backwards-solving to reconstruct missing opening fills
- Add test coverage (28 Python + 51 Rust tests)
- Replace all f64 parsing with Decimal to reduce rounding errors
- Fix MARGIN position parsing to handle quote-to-base conversion
Remove dead code causing warnings.
@Antifrajz Antifrajz force-pushed the enhancement/price_protection_for_market branch from 65838a6 to 5e52e49 Compare October 29, 2025 05:34
@Antifrajz
Copy link
Author

The pull request still shows the CLA as not signed, maybe you can try again.

There is a problem with my email. I fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Price protection for market and stop-market type orders

7 participants