AutoTrader Web Square-off Process

In this post, we will understand how the square-off process of AutoTrader Web works. It is extremely important to understand this, so that you are prepared to make the correct decision if something goes wrong.

Internal Working

Square-off process is fairly complex, we have simplified it here so that it is easy to understand.

  1. AT Web gets a request to square-off a position
  2. AT-Web pulls latest positions and orders from your trading platform
  3. It checks if the position is OPEN. How does the system determine an OPEN position?
    1. Normal positions are checked with net quantity non-zero
    2. Complex positions (Bracket & Cover order positions) are checked with open legs (or open child orders also known as target or stoploss orders). Why? Consider following scenario:
      1. User places a BUY bracket order with 1 quantity for SBIN
      2. It gets executed & 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 & he has a BO position still open with net quantity 0
      5. Hence, we cannot use net quantity for BO & CO positions to determine whether they are open. Because in this case the user still has both BUY & SELL BO positions open as their target & s/l orders are open
  4. If the position is NOT OPEN, AT Web stops
  5. If the position is OPEN, then it proceeds to do the square-off
    1. Position is locked by AT Web to avoid parallel square-off as it will result in unexpected results.
      1. Parallel square-off can happen if sqaure-off request is submitted multiple times by user or automated strategies
    2. If it cannot acquire the lock, an error will be generated. This will happen if multiple square-off requests come for the same position & the position square-off is in-progress.
    3. The system will decide on square-off action
      1. For simple positions, a reverse order is placed with quantity as absolute net quantity
      2. For complex (BO & CO) positions, all of it’s open child (target & s/l) orders are cancelled. As this will cause the position to square-off, this is how BO & CO are square-off on your trading platform as well.
    4. The system will then fetch latest orders and positions from your trading platform
    5. It will verify that position is CLOSED
      1. If the position is not CLOSED, then the system waits for some time and verifies again
    6. If the position is CLOSED, the system stops with SUCCESS
    7. If the position is STILL OPEN, then system considers it as FAILURE
      1. A position that has failed once will never be accepted for square-off again. This is done to safeguard our users, as it can result in multiple square-off orders being generated.

What to do in case of a failure?

If there is a failure, then you must manually square off the position. A manual square-off can be done as follows:

  • For normal positions
    • Place a reverse order from AT Web’s Trade screen
  • For BO or CO positions
    • Cancel all of their target & s/l orders from AT Web’s Trade screen

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

After spending more than 12 years developing Financial Software, I took a break from my career to start my own algorithmic trading setup. This new journey started well and along with my own proprietary trading systems, I also started building automation systems for retail traders, fund managers and HNIs. I was employed with firms like Morgan Stanley, HSBC & SunGard. I work on various technologies, but my strengths are building server side cloud based algorithmic trading systems built primarily using Java programming language. Apart from all of this, I am a big fan of Formula 1 racing :-)

Leave A Comment