Skip to content

Improve validations for StopLimitOrder #2593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2025
Merged

Improve validations for StopLimitOrder #2593

merged 3 commits into from
May 3, 2025

Conversation

nicolad
Copy link
Collaborator

@nicolad nicolad commented May 3, 2025

  • Implemented new_checked for StopLimitOrder, bringing it in line with MarketOrder, LimitOrder, LimitIfTouchedOrder, and MarketToLimitOrder.

  • Dropped the side-specific trigger/limit inequality
    BUY orders may now use either trigger ≥ limit or trigger ≤ limit; the mirror applies to SELL.
    This unblocks “limit-if-touched” and similar strategies that were previously rejected.

  • Added complete domain-level validations:

    • quantity > 0
    • price > 0
    • trigger_price > 0
    • optional display_qty ≤ quantity
    • TimeInForce::Gtd ⇒ non-zero expire_time required
  • Legacy new now wraps new_checked, preserving the historical panic-on-error behaviour for external callers.

  • Extended rust-doc explaining the two legal stop-limit styles (break-out vs. mean-reversion).

  • Added a concise Display implementation for easier debugging/logging.

  • Unit-tests (4) live in the same module and cover the happy path plus each validation branch.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Fixes #2529


Note: this PR takes into consideration changes introduced in this commit c44604c

@nicolad nicolad requested a review from cjdsellers May 3, 2025 06:01
};

#[rstest]
fn buy_breakout_ok(_audusd_sim: CurrencyPair) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjdsellers let me know what do you think about this type of test, should I leave, remove or add more like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason I am asking is because I haven't seen smth like this here

https://github.com/nautechsystems/nautilus_trader/blob/develop/crates/model/src/orders/market.rs#L539

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its good to have one test which asserts all of the order properties we'd expect.

Comment on lines +68 to +70
/// # Errors
///
/// Returns an error if the order is invalid.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this because got this error here
image

@cjdsellers cjdsellers merged commit 07e5165 into develop May 3, 2025
16 checks passed
@cjdsellers cjdsellers deleted the 2529-stop_limit branch May 3, 2025 21:09
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.

Standardize validations for orders
2 participants