Back

Market order fill response timeout too short?

I noticed when running a live algo using market orders for options that the timeout of 5s to get a fill response seems too short ?
The algo got the fill responses after about 13s but in the meantime the algo had called the Quit statement to exit as the market order API call responded with an error because of the timeout being too short.
Is this a known issue? Perhaps the timeout needs to be configurable?

ERROR] FATAL UNHANDLED EXCEPTION: at RestSharp.RestClient.DoExecuteAsPost (RestSharp.IHttp http, System.String method) [0x00000] in <a413af11872d4786add172686a6728e8>:0 , at RestSharp.RestClient.Execute (RestSharp.IRestRequest request, System.String httpMethod, System.Func`3[T1,T2,TResult] getResponse) [0x00022] in <a413af11872d4786add172686a6728e8>:0 ,ApiConnection.TryRequest(): System.Net.WebException: The request timed out, at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00052] in <59be416de143456b88b9988284f43350>:0 , at System.Net.HttpWebRequest.GetResponse () [0x0000e] in <59be416de143456b88b9988284f43350>:0 , at RestSharp.Http.GetRawResponse (System.Net.HttpWebRequest request) [0x00000] in <a413af11872d4786add172686a6728e8>:0 ,ApiConnection.TryRequest(): System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---> System.Exception: at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00000] in <59be416de143456b88b9988284f43350>:0 , at System.Net.WebConnection.ReadDone (System.IAsyncResult result) [0x00000] in <59be416de143456b88b9988284f43350>:0 , at System.Runtime.Remoting.Messaging.AsyncResult.Invoke (System.Runtime.Remoting.Messaging.AsyncResult ) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 , at System.Runtime.Remoting.Messaging.AsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 , at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 , at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 , at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00044] in <59be416de143456b88b9988284f43350>:0 , --- End of inner exception stack trace ---, at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in <59be416de143456b88b9988284f43350>:0 , at System.Net.HttpWebRequest.GetResponse () [0x0000e] in <59be416de143456b88b9988284f43350>:0 , at RestSharp.Http.GetRawResponse (System.Net.HttpWebRequest request) [0x00000] in <a413af11872d4786add172686a6728e8>:0 ,SecurityTransactionManager.WaitForOrder(): Order did not fill within 5 seconds.,AlgorithmManager.Run(): Algorithm state changed to Stopped at 1/7/2019 8:56:10 PM,Cloud.Api.SetAlgorithmStatus(): Request Resource: live/status/update Error(s): Invalid value for status: 'Completed'. Valid values are: Running,Stopped,RuntimeError,Liquidated

Update Backtest







0

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.


After reviewing Lean I found the configuration property for the timeout: SecurityTransacitonManager MarketOrderFillTimeout, but the better solution is to handle asynchronously.

0

Thank you for sharing Ernest! The documentation section on Order Types has now been updated.

As you have pointed out, there are two possible ways to fix the issue:

  1. Increase the timeout response by adjusting MarketOrderFillTimeout:

Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(15);2. Send a market order asynchronously by using the boolean flag on the market order argument:MarketOrder("SPY", 100, asynchronous: true);

 

 

0

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.


Hi Halldor,
when using a very long timeout such as 2 minutes (as per updated doc) or 15 minutes as per your comment, wouldn't this be a problem for algos that rely on 1 minute or less data update resolution? i.e. wouldn't the algo be blocked for the timeout period if the order isn't filled and so any data events would be missed?
-ES


 
0

>wouldn't this be a problem for algos that rely on 1 minute or less data update resolution

Absolutely Ernest, the "right" answer is to use asynchronous market orders and update anything in the algorithm which depends on synchronous behavior but it's a harder fix for most people to make.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed