Trade Cancel

Imported from previous forum

[ original email was from Antonio Meireles - aaugmeir@uol.com.br ]
I’m developing a fix engine that translates messages between a fix (4.1) channel and a stock exchange central system.

The stock exchange’s rule allows Trade Cancel, so when this occurs, I send an Execution Report (ExecTransType=Cancel) canceling the previous Execution Report (ExecTransType=New), and everything seems to be OK.

But, the stock exchange’s rule also says that when one trade is cancelled, the quantity of that trade is cancelled too, so this quantity doesn’t come back to the order. And this goes against the fix general rule (OrderQty=CumQty+LeavesQty).

Let me try to explain better:

Remark: in the next examples I’ll use Exec Rpt(ExecTransType, OrderStatus) to represent the Execution Report Message and its key fields.

1 – By the Stock Exchange’s rule, this should happens

| New Order (QTY=500) | |
|------------------------->| Order Request (QTY=500) |
| |------------------------->|
| | Order Ack (QTY=500) |
| |<-------------------------|
| Exec Rpt(New,New) | |
| OrderQ = CumQ + LeavesQ | |
| 500 = 0 + 500 | |
|<-------------------------| |
| | Trade Occurred (QTY=500) |
| |<-------------------------|
| Exec Rpt(New,Filled) | |
| OrderQ = CumQ + LeavesQ | |
| 500 = 500 + 0 | |
|<-------------------------| |
| | Trade Cancelled (QTY=500)|
| |<-------------------------|
|Exec Rpt(Cancel,Cancelled)| |
| OrderQ != CumQ + LeavesQ | |
| (*)500 != 0 + 0 | |
|<-------------------------| |
| | |

(*) – The order was cancelled with the trade, sending ExecTransType = Cancel and OrderStatus = Cancelled, so there is no remaining quantity (LeavesQty=0) in the order. And when OrderStatus = Cancelled there is an exception to the general rule
(OrderQ = CumQ + LeavesQ).

2 – But Fix (4.1) Channel’s Developers said that I should not cancel the trade and the order at the same time. So, they think that I should send the trade cancel and after this, the order cancel, so this should happens:

Fix My Engine Stock Exchange
| New Order (QTY=500) | |
|------------------------->| Order Request (QTY=500) |
| |------------------------->|
| | Order Ack (QTY=500) |
| |<-------------------------|
| Exec Rpt(New,New) | |
| OrderQ = CumQ + LeavesQ | |
| 500 = 0 + 500 | |
|<-------------------------| |
| | Trade Occurred (QTY=500) |
| |<-------------------------|
| Exec Rpt(New,Filled) | |
| OrderQ = CumQ + LeavesQ | |
| 500 = 500 + 0 | |
|<-------------------------| |
| | Trade Cancelled (QTY=500)|
| |<-------------------------|
| Exec Rpt(Cancel,New) | |
| OrderQ = CumQ + LeavesQ | |
| 500 = 0 + 500 | |
|<-------------------------| |
| Exec Rpt(New,Cancel) | |
| OrderQ != CumQ + LeavesQ | |
| 500 != 0 + 0 | |
|<-------------------------| |
| | |

This works fine with Total Filled Orders, but there are some problems with Partially Filled Orders:

1st – If the order still has opened quantity and I send the cancel, all the order will be cancelled and not only the cancelled trade quantity.

2nd – If the order was filled by several Partial Fills, each of these Partial Fills can be cancelled at different times.

So I`ve decided not to cancel the order after receiving an trade cancel. I think that if I wait the order becomes totally filled and then I test if it has received any trade cancel messages, so in this case I send the order cancel, taking care to avoid duplicate order cancel messages, it may works.

If the order never becomes totally filled it will expire and the open quantity will be also cancelled.

The problem in this approach is that there will be a period of time between the Trade Cancel and the Order Cancel when the Client will think that he has an open quantity different of the open quantity that he really has in the Stock Exchange.

Does anybody know if that approach is fine or what should I do to solve this problem?

Thanks in Advance,

Antonio Meireles
MACSYS Informatica
Brazil