Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with the OnAccountItemUpdate event

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problems with the OnAccountItemUpdate event

    HI,

    I have an addon where I subscribe to account events to monitor the OnAccountItemUpdate event.
    I create a position with an ATM strategy (with an SL and TP OCO order) and everything works OK, I see the OnAccountItemUpdate event being executed correctly.

    The problem is when I cancel the SL or TP order. The system deletes the 2 orders and I see that the OnOrderUpdate event of the SL and TP orders is executed with the status "Cancelled".

    From then on, the OnAccountItemUpdate event is never executed again.

    Is this a platform error or am I doing something wrong?

    NOTE: What I really need is to control that the SL orders are not deleted. So, is there any way to cancel deleting an order? Can I intercept a "beforedelete" type order event to not allow the user to delete it? What I'm trying to do is detect in the OnAccountItemUpdate event that there is an open item without SL and give an alert message.

    This is the code I am using

    Code:
    //subscribe events
    
            protected override void OnStateChange()
            {
                israUtils.outputLog("OnStateChange -> " + State.ToString());
                
                if (State == State.SetDefaults)
                {
                    Description                                    = @"TEST";
                    Name                                        = "MyAddon";
    
                    Account.AccountStatusUpdate += OnAccountStatusUpdate;
                }
                else if (State == State.Terminated)
                {
                    // Unsubscribe to events
                    Account.AccountStatusUpdate -= OnAccountStatusUpdate;
    
                    // Iterar sobre todas las cuentas disponibles
                    foreach (var account in Account.All)
                    {
                        if (account != null)
                        {
                            // Suscribirse a los eventos específicos de cada cuenta
                            account.AccountItemUpdate -= OnAccountItemUpdate;
                            account.ExecutionUpdate -= OnExecutionUpdate;
                            account.OrderUpdate -= OnOrderUpdate;
                            account.PositionUpdate -= OnPositionUpdate;
                        }
                    }
    
    
    //events
    
           private void OnOrderUpdate(object sender, OrderEventArgs e)
            {
                Order order = e.Order;
                
                israUtils.outputLog($"Order {order.ToString()}");
            }
            
            private void OnAccountStatusUpdate(object sender, AccountStatusEventArgs e)
            {
                israUtils.outputLog(string.Format("OnAccountStatusUpdate, Account: {0} Status: {1}", e.Account.Name, e.Status));
    
                if (e.Status == ConnectionStatus.Connected)
                {
                    e.Account.AccountItemUpdate += OnAccountItemUpdate;
                    e.Account.ExecutionUpdate += OnExecutionUpdate;
                    e.Account.OrderUpdate += OnOrderUpdate;
                    e.Account.PositionUpdate += OnPositionUpdate;                }        
            }
            
            private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
            {
                // Do something with the account item update
                 israUtils.outputLog(string.Format("OnAccountItemUpdate Account: {0} AccountItem: {1} Value: {2}",
                      e.Account.Name, e.AccountItem, e.Value));
                
                if (openPositions())
                {
                    Order stopOrder = e.Account.Orders
                        .FirstOrDefault(o =>
                            o.OrderType == OrderType.StopMarket &&        
                            (o.OrderState == OrderState.Working ||                
                             o.OrderState == OrderState.Accepted) &&                  
                            o.Oco != "");    
                
                    if (stopOrder == null)
                    {
                        //alguien se ha cargado la orden SL
                        israUtils.outputLog("ALERT: order SL not found");
                    }
                }
            }
    
    ​
    Thanks​

    #2
    HI,

    I saw the problem was an indicator of mine is handling the OnAccountItemUpdate too.

    Now the events are working OK, but

    Is possible cancel the SL Order deletion? So I can avoid to have create them again.


    Thanks​

    Comment


      #3
      Hello Powerbucker,

      That would be expected. If you cancel an order, that event goes to OnOrderUpdate. There's no way to prevent a user from canceling an order. Once a cancel is submitted, the order will be canceled. In general, we cannot advise trying to interfere with order events as that may cause issues with a user trying to manage their account.







      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      553 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      100 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      543 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      546 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X