AutoTrader Web Square-off Process

How AutoTrader Web squares off a position safely, and what to do when it fails.

Square-offPositionsSafety checks
In short

When you square off a position, AutoTrader Web pulls the latest positions and orders, confirms the position is open, locks it so two requests cannot run at once, then places a reverse order (or cancels child orders for BO/CO positions). It checks the result up to 10 times for about a minute. If the square-off fails, that position is paused for 15 minutes, which protects you from building an accidental reverse position. You can fix the cause and retry after the pause, square off manually, or switch the pause off in your settings. When you square off several positions at once, short positions are closed before long ones.

In this post, we explain how the square-off process of AutoTrader Web works. It helps to understand this so you can take the right action if something goes wrong.

The process is designed to protect you from building a reverse position when a square-off is requested or clicked many times by mistake. The sections below explain how.

Internal Working

The square-off process has several steps. Here is the full flow, step by step.

  1. AT Web gets a request to square off a position.
  2. AT Web pulls the latest positions and orders from your trading platform.
  3. It tries to find the position. If it cannot find it, the system throws an error: Position not found.
  4. It checks if the position is open. The system decides an open position like this:
    1. Normal positions are checked using net quantity non-zero.
    2. Complex positions (Bracket and Cover order positions) are checked using open legs (open child orders, also known as target or stoploss orders). This is needed because of the following scenario:
      1. User places a BUY bracket order with 1 quantity for SBIN.
      2. It gets executed and he has a BO position open with net quantity 1.
      3. User places a SELL bracket order with 1 quantity for SBIN.
      4. It gets executed and he has a BO position still open with net quantity 0.
      5. So we cannot use net quantity for BO and CO positions to decide whether they are open. In this case the user still has both the BUY and SELL BO positions open, because their target and stoploss orders are open.
  5. If the position is not open, AT Web stops.
  6. If the position is open, it proceeds to do the square-off:
    1. If the square-off for this position failed in the last 15 minutes, the system will not proceed, for safety. It tells you that the position is paused and how much of the pause is left.
      • A user or his program can square off many times when he sees the position is not squared off (in case of failures). In the worst case, this can lead to a reverse position being generated, which may keep increasing with every square-off request and lead to heavy losses. So the system pauses square-off-market requests for a position that has just failed.
      • The pause runs for 15 minutes from the last failure. After it ends, the position is accepted again. This gives you time to fix the cause, for example by adding margin or cancelling a forgotten order, and then retry on the same day.
      • During the pause you can still square off manually by placing a reverse order, or by using the Custom Square-off button.
      • If you are an experienced user and want to retry straight away, switch off Square-off Safety Pause in Settings > General > Trading. It is on by default. With it off, the system accepts your retry at once. The error message reminds you of this setting.
    2. The position is locked by AT Web to avoid parallel square-off, which would cause unexpected results.
      • Parallel square-off can happen if the square-off request is submitted many times by the user or by automated strategies.
    3. If it cannot acquire the lock, an error is generated: Square-off is already running. This happens when multiple square-off requests come for the same position while a square-off is in progress.
    4. Cancellation of open orders:
      • If this option is set to true (the default), it automatically cancels any open orders for the selected symbol and product type.
      • This helps prevent a common mistake where a trader forgets to cancel an existing open order. If not cancelled, the broker may reject the square-off order due to insufficient margin, because it treats it like a second exit order.
    5. The system decides the square-off action:
      • For simple positions, a reverse order is placed with quantity as the absolute net quantity.
      • For complex (BO and CO) positions, all of their open child (target and stoploss) orders are cancelled. This causes the position to square off, which is how BO and CO positions are squared off on your trading platform too. If the system cannot find any open child orders, it throws an error: No open child (target or stoploss) orders found.
    6. The system does the following checks 10 times (if the position remains open):
      • It fetches the latest orders and positions from your trading platform.
      • It verifies that the position is closed:
        • If the position is closed, the system stops with success.
        • If the position is not closed, the system waits for some time and verifies again. However, if it sees that the square-off order was rejected by the broker, it throws an error: Square-off order rejected by broker.
    7. If the position is still open after 10 checks, the system considers it a failure. You get an error: Waited long enough, but the position is still open.
      • A position that has failed is paused for the next 15 minutes. This protects you, because retrying at once could result in multiple square-off orders being generated.

Safety Features

Locking to safeguard from parallel requests

Imagine you, or your automated trading program, send back-to-back square-off requests by mistake for the same position. If the requests reach the server within milliseconds of each other, both will see the position as open. This would result in multiple square-offs for the same position, and you would most likely end with a reverse position.

The system protects you here by locking the position before proceeding with the square-off. In such cases, only one request is allowed to proceed and the others are rejected.

Broker server slowness safety

Imagine you send a request to square off a position. The system places a reverse order to square it off, but the broker’s server is slow. The order takes longer than normal to execute. You, or your automated trading system, see the position as still open and decide to square off again. This places another reverse order, and you would most likely end with a reverse position.

The system protects you against this. It waits for up to a minute and keeps checking the status of the reverse order placed during square-off. It will not accept any new square-off request for the same position. If the position still remains open, the system marks it as a failure, and this position is paused for the next 15 minutes.

Safety from broker server errors

As explained above, a square-off order is sometimes rejected by a broker. There can be many causes, but the most common one is that market orders are restricted by brokers for certain illiquid stocks or derivatives, and a square-off order is a market order. In such cases, a user’s automated trading system would just keep retrying forever.

To protect you, the system marks the position as a square-off failure and notifies you. Most such cases need manual user intervention. The position is paused for 15 minutes, so a retrying program cannot keep sending the same rejected order to your broker.

Short positions are closed first

When you square off several positions together, or square off a whole account, the system closes your short positions before your long ones.

This matters when your positions hedge each other, because it is the pair that earns you the margin benefit. If a long position is closed first, the short position left behind is no longer hedged. Its margin requirement jumps, your account can fall short of margin, and your broker may then reject the square-off of that short position. You would be left holding the very position you most wanted to close.

Closing the shorts first releases margin instead of using it, so the long positions that follow can always go out. Each long position waits a short while for the shorts on the same account to close. If a short position gets stuck, the system does not wait forever. The long positions are released anyway, so nothing is left hanging.

This applies to the Sq-off (Market) button when you have selected more than one position, and to the Sq-off Acc button.

Common causes of failure

  1. Error from the broker while placing the square-off order.
  2. Broker’s server rejecting the square-off order. This happens for various reasons, such as market orders not being allowed for illiquid options, or a margin shortfall. A margin shortfall should ideally not happen during square-off, but we have mostly seen it when users have placed another target or stoploss order that they forgot about, and that order is blocking the margin.
  3. Another order was placed by the user or his algo during the square-off operation in the same symbol, affecting net quantity. So the system sees net quantity as non-zero after square-off (meaning the position is open) and gives a failure message.
  4. Broker’s server sending stale position data. The position is squared off, but the broker’s server is not sending the updated net quantity (which should now be zero). As a result, the system thinks the position is still open even after square-off and gives a failure message.

How to handle failures

After a failure the position is paused for 15 minutes. You have three options:

  • Fix the cause and wait for the pause to end, then square off at market again. This is usually the right choice when you know what went wrong, for example a margin shortfall or a forgotten open order.
  • Switch off the pause in Settings > General > Trading if you want to retry immediately. Only do this if you understand why the first attempt failed.
  • Square off manually, as below. This always works, even during the pause.

A manual square-off can be done as follows:

  • For BO or CO positions: Cancel all of their target and stoploss orders from AT Web’s Trade screen.
  • For Normal positions: Place a reverse order from AT Web’s Trade screen. A quick way to do this is to use the Custom Square-off Button on the positions screen (see screenshot below).

In the worst case, you can log in to your trading platform and do a manual square-off.

Square-off position custom button

Square-off position custom

Investigation

Failures are rare. Whenever they happen, something did not work as expected. You must find the cause and take the necessary action. Our systems are fully transparent and give you the insights to investigate any issue.

Use activity logs to figure out what went wrong.

Note: Once a square-off fails for a position, it is designed (to protect you) to error for that position on further square-off attempts. In such cases, you must investigate the activity logs to find the failure cause. Check the logs of the very first square-off request.

Next steps

Was this page helpful?

Last updated 2 September 2026