Hi I am testing pre market order in Live Deployment with Interactive Broker.
Initially i just used market order and the order was placed as Market On Open order..
So I used isMarketOpen(symbol) to check if the market is open. and if market is open, use marketOrder, if not, use limit Order.
if self.IsMarketOpen(testSymbol):
self.Debug(f"onData {self.Time} {testSymbol.Value} market is open")
tag = str(self.Securities[testSymbol].Price)
ticket = self.MarketOrder(testSymbol, 1000,False,tag)
else:
self.Debug(f"onData {self.Time} {testSymbol.Value} market is NOT open")
limitPrice = self.Securities[testSymbol].Price * 1.03 # use a higher price to get entry
tag = str(self.Securities[testSymbol].Price)
ticket = self.LimitOrder(testSymbol,1000,limitPrice,tag)
self.Debug(f"test doing limit order for {testSymbol.Value} price: {self.Securities[testSymbol].Price} limitPrice: {limitPrice}")
However the limit order remained unfilled, even though the limit price was set much higher than the last executed pre-market price.
To confirm that a limit order at that price will result in an entry, i manually did a limit order at the same price in my IB account and the order went thru.
Is there anything I missed out? Thanks a lot!
Shile Wen
Hi Pranava,
By default, OnData is only called during market hours. We would need to enable extended market hours by adjusting the the AddEquity method to look like the following:
self.AddEquity(ticker, Resolution.Minute, Market.USA, False, 1, True)
If this doesn't fix the issue, please attach a backtest.
Best,
Shile Wen
Pranava
Hi Shile,
I am able to access the data in premarket hours. Should not be the problem.
I am using both a) universe filtering and b) custom symbols.
For universe filtering, i think self.UniverseSettings.ExtendedMarketHours = True does the trick. I did not have AddEquity for universe filtered symbols
For custom symbols, i did this: self.AddEquity(symbol.Value, Resolution.Minute, Market.USA, True, 0, True). The only difference is the data fillforward which i set as True.
The issue is with the placing of order. Market Order become market to open order. Limit order does not execute.
Is there any sample codes for live trading with IB I can reference to?
Pranava
Hi Shile,
I just wrote this piece of code for testing the order. Essentially what i did for adding the Equity and doing the orders.
Can only test on monday when the market open :D I am using Interactive Broker
Pranava
Hi Shile,
I have tested the execution of the code, including extra test cases
In InteractiveBrokers,
1) the limit buy order with a higher price is placed, and not executed (should be executed)
2) the limit buy order with a lower price is placed, (not executed immediately)
3) market order is placed as market is open order (not executed immediately)
However I tried the QuantConnect paper account,
1) the limit buy order with a higher price is placed, and executed
2) the limit buy order with a lower price is placed, (not executed immediately) [same behavior]
3) market order is placed as market is open order (not executed immediately) [same behavior]
Is there any settings I need to do in IB or QC? my strategy requires me to enter in premarket hour... Thanks a lot!
#-- this limit order gets executed self.Debug(f"onData {self.Time} {testSymbol.Value} market is NOT open") limitPrice = round((self.Securities[testSymbol].Price * 1.03),2) # use a higher price to get entry tag = "limit order 1.03 " + str(self.Securities[testSymbol].Price) ticket = self.LimitOrder(testSymbol,10,limitPrice,tag) self.Debug(f"test doing limit order 1.03 for {testSymbol.Value} price: {self.Securities[testSymbol].Price} limitPrice: {limitPrice}") #-- limit order placed limitPrice = round((self.Securities[testSymbol].Price * 0.97),2) # use a higher price to get entry tag = "limit order 0.97 " + str(self.Securities[testSymbol].Price) ticket = self.LimitOrder(testSymbol,15,limitPrice,tag) self.Debug(f"test doing limit order 0.97 for {testSymbol.Value} price: {self.Securities[testSymbol].Price} limitPrice: {limitPrice}") #-- market order placed as market as open tag = "market Order " + str(self.Securities[testSymbol].Price) ticket = self.MarketOrder(testSymbol, 20,False,tag) self.Debug(f"test doing market order for {testSymbol.Value} price: {self.Securities[testSymbol].Price}")
Pranava
Hi Shile,
The orders in premarket for Interactive Brokers need to be limit order and set with "allow pre-open" option for it to go through. I did this manually in trader workstation and the order went through. The orders submitted from Quantconnect over were sitting as normal orders but not executed.
Pranava
Hi Shile,
Managed to solve this by changing IB global settings using TWS.
Li Cheng
@Pranava I'm having the same issue, may I know how you managed to enable your limit orders to fill during extended hours with your algorithm?
I've enabled Trader Workstation's “Allow order to be activated, triggered, or filled outside of regular trading hours (if available).” setting.
Varad Kabade
Hi Li Cheng,
Did you send the pre-market orders as limit orders mentioned above after enabling settings in the TWS ?
We recommend using the following for all orders:
and for specific orders:
Please contact support@quantconnect.com if the problem is not resolved.
Best,
Varad Kabade
Li Cheng
Hi Varad,
Thanks for the information, I've solved the problem already.
Best
Cheng
Pranava
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!