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

Invalid/Cancel Market-On-Open and Market-On-Close #8566

Open
4 tasks done
AlexCatarino opened this issue Jan 30, 2025 · 0 comments
Open
4 tasks done

Invalid/Cancel Market-On-Open and Market-On-Close #8566

AlexCatarino opened this issue Jan 30, 2025 · 0 comments
Labels

Comments

@AlexCatarino
Copy link
Member

Expected Behavior

If the MOO doesn't fill with the first bar of day, it should be invalid (IB cancels this order)
If the MOC doesn't fill with the last bar of the day, it should be invalid.

Actual Behavior

If the MOO fills with any bar after the opening.
If the MOC fills on the next open

Reproding the problem

class LogicalFluorescentPinkFox(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2023, 3, 1)
        self.set_start_date(2023, 3, 5)
        self.set_cash(100000)
        self.asset_symbol = self.add_equity("EEM", Resolution.MINUTE).symbol

        self.schedule.on(self.date_rules.every_day(self.asset_symbol), 
                            self.time_rules.after_market_open(self.asset_symbol, -60), 
                            self._place_market_on_open)
        self.schedule.on(self.date_rules.every_day(self.asset_symbol), 
                            self.time_rules.before_market_close(self.asset_symbol, 60), 
                            self._place_market_on_close
                            )


    def on_data(self, data: Slice):
        pass

    def _place_market_on_open(self):
        self.market_on_open_order(symbol=self.asset_symbol, quantity=-1)

    def _place_market_on_close(self):
        self.market_on_open_order(symbol=self.asset_symbol, quantity=1)

Potential Solution

Check the bar timestamp to set the status to OrderStatus.Canceled.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant