Skip to content

Conversation

hope2see
Copy link
Contributor

Pull Request

This PR resolves the issue, which is to add trailing stop orders for OrderFactory bracket order.

Summary

  • Added/modified factories.pxd/pyx to support trailing stops in bracket
  • Modified emulator.pyx to solve the problem with trigger_price being None.
  • Added test_exchange_bracket_trailing_stop_orders.py
  • Modified trailing_stop_limit.pyx/pyx to refine small redundancies.

Related Issues/PRs

Issue#2523

Type of change

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

Release notes

  • I added a concise entry to RELEASES.md that follows the existing conventions (when applicable)

Testing

Ensure new or changed logic is covered by tests.

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

test_exchange_bracket_trailing_stop_orders.py

Copy link
Member

@cjdsellers cjdsellers left a comment

Choose a reason for hiding this comment

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

Hi @hope2see,

Thanks so much for the work here!

I think the grouping of params by order type turned out well, it's quite intuitive to align with the leading prefixes tp_* and sl_* like you've done.

# Update trailing stop
if order.order_type == OrderType.TRAILING_STOP_MARKET or order.order_type == OrderType.TRAILING_STOP_LIMIT:
self._trail_stop_order(matching_core, order)
if order.trigger_price is None:
Copy link
Member

@cjdsellers cjdsellers May 23, 2025

Choose a reason for hiding this comment

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

Are you able to share your thinking behind this decision?

Is this because with an activation_price we don't expect there to be a trigger_price until the activation price is hit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Unless trigger_price can be given by users, it remains unset until the order is activated. Thus, it can't be guaranteed to be not None without checking the order's status.

Actually, the modification in emulator.pyx should have been made when the initial PR for adding activation_price was submitted. At that time, I hadn't tested emulation_trigger, so it was overlooked.
Now, emulation_trigger is covered in the newly added tests for bracket order.

@cjdsellers cjdsellers merged commit 04675b5 into nautechsystems:develop May 24, 2025
17 checks passed
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.

2 participants