Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 10:46:10 +0000



Post From: ASCIL Different OrderIDs for Same Order

[2023-08-19 20:10:28]
Gradient - Posts: 89
Hi,

I'm doing a replay based backtest of a ASCIL strategy.

I've written logic to check for resting orders and to cancel them if after some time threshold. (See Below).

if (LongOrderId !=0){
      sc.AddMessageToLog("LongOrderID Cancellation Check Beginning",1);
      //get the status of order
      s_SCTradeOrder LongTradeOrder;
      sc.GetOrderByOrderID(LongOrderId, LongTradeOrder);
      
      //find order
      if(LongTradeOrder.InternalOrderID==LongOrderId){
        sc.AddMessageToLog("Looking Up Long Order for Cancellation",1);
        
        IsOrderFilled = LongTradeOrder.OrderStatusCode == SCT_OSC_FILLED;
        
        SCDateTime LongExecutionTime;
        
        LongExecutionTime=LongTradeOrder.LastActivityTime;
        
        int LongExecutionMinute=LongExecutionTime.GetMinute();
        
        //if not filled send cancel
        if(IsOrderFilled==0 && (CurrentMinute - LongExecutionMinute)>1){
          sc.SetAlert(1,"Trigger to Cancel Stale Order");
          sc.AddMessageToLog("Stale Order Cancellation Triggered",1);
        
          int LongCancellation=sc.CancelOrder(LongOrderId);
        }
      }
      
      
    }
    if(ShortOrderId !=0) {
      sc.AddMessageToLog("ShortOrderID Cancellation Check Beginning",1);

      //get the status of the order
      s_SCTradeOrder ShortTradeOrder;
      sc.GetOrderByOrderID(ShortOrderId,ShortTradeOrder);
      
      //find order
      if (ShortTradeOrder.InternalOrderID == ShortOrderId){
        sc.AddMessageToLog("Looking Up Short Order for Cancellation",1);
        
        SCDateTime ShortExecutionTime;
        
        IsOrderFilled=ShortTradeOrder.OrderStatusCode==SCT_OSC_FILLED;
        ShortExecutionTime=ShortTradeOrder.LastActivityTime;
        
        int ShortExecutionMinute=ShortExecutionTime.GetMinute();
        
        //if not filled send cancel
        if (IsOrderFilled==0 && (CurrentMinute-ShortExecutionMinute)>1){
          sc.SetAlert(1,"Trigger to Cancel Stale Order");
          sc.AddMessageToLog("Stale Order Cancellation Triggered",1);
          
          int ShortCancellation=sc.CancelOrder(ShortOrderId);

        }
      }
    }
        
    //end of cancel stale orders


I've noticed that, for example, the ShortOrderId is changing to a random number even though no new orders have been sent. In this case, the ShortOrderId is only set when a new sell order is created.

See Attached

From the Price Chart image, you can see that a buy order was stopped out. Thus there should be a LongOrderId which there is.

A sell order was then sent after being stopped out of the long but wasn't filled.

Looking at the Changing Error image, you can see that I'm logging the LongOrderId and ShortId, as well as the Bar Time and Execution Time when an order is submitted.

You can also see that even though there are no new orders submitted (see Price Chart image) both the LongOrderId and the ShortOrderId both change.

Referring back to the cancel order logic above, I log when checking if the OrderId matches the InternalOrderId of the retrieved order.

This log is displayed correctly for a couple iterations but then stops because the ShortOrderId changes even though no new order has been sent, thus preventing the stale order from being canceled.

How and why is this happening?

Please Advise.

Thanks.
Date Time Of Last Edit: 2023-08-19 20:11:24
imageShortOrderId Changing Price Chart.png / V - Attached On 2023-08-19 20:02:25 UTC - Size: 35.41 KB - 72 views
imageShortOrderId Changing Error.png / V - Attached On 2023-08-19 20:02:33 UTC - Size: 128.61 KB - 71 views