Skip to content
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

Refactor strategy classes #642

Merged
merged 5 commits into from
Dec 3, 2024
Merged

Refactor strategy classes #642

merged 5 commits into from
Dec 3, 2024

Conversation

Al4ise
Copy link
Collaborator

@Al4ise Al4ise commented Dec 2, 2024

The implementations of submit_order and submit_orders methods have been refactored with uniformity between brokers and ease of use as a priority.

  1. In broker/tradier.py, broker/interactive_brokers_rest.py, etc. files, we have 2 functions: _submit_order and _submit_orders, handling single and multiple orders respectively.

  2. In broker.py, these methods get wrapped by the submit_order and submit_orders methods. (No changes from before)

  3. In strategy.py, these methods get combined into one submit_order method, which can handle both single and multiple orders. This was done as part of an effort to streamline the strategy class and make it more newcomer-friendly.

  4. As per a user suggestion, when submitting multiple options orders at once, is_multileg is now automatically set to True

  5. The submit_orders method in the strategy class remains for now, but is marked as deprecated in the docstring and internally relies on the new submit_order method. Might mark it as not deprecated later.

  6. A lot of backend logic has been moved from strategy.py to _strategy.py. strategy.py should contain mainly stuff that the users/strategy builders should interract with.

  7. Added the run_live() and backtest() methods to strategy.py as to make running and backtesting strategies simpler to newcomers.

Note: Everything is 100% backwards compatible

Also includes some general improvements for Interactive Brokers REST.

Description by Korbit AI

What change is being made?

Refactor order submission methods by encapsulating order processing logic, deprecating submit_orders method in favor of enhancing submit_order to handle both single and multiple orders, and extracting order validation into a separate function.

Why are these changes being made?

To improve code maintainability and clarity by consolidating order submission logic in a central method, making it easier to extend and manage, while also ensuring that orders are validated before submission, thus reducing potential errors during order processing. Additionally, streamlining the order-related methods paves the way for more flexible broker implementations and code reuse across different components.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

@Al4ise Al4ise requested a review from grzesir as a code owner December 2, 2024 13:46
Copy link
Contributor

korbit-ai bot commented Dec 2, 2024

Korbit doesn't automatically review large (500+ lines changed) pull requests such as this one. If you want me to review anyway, use /korbit-review.

@Al4ise Al4ise changed the title Refactor order submission methods Refactor strategy classes Dec 3, 2024
@grzesir grzesir merged commit bbf9d19 into dev Dec 3, 2024
1 check 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