[ts-gen] Order Cancel
Bill Pippin
pippin at owlriver.net
Fri Dec 7 12:07:51 EST 2007
Nils,
About the bug in order cancellation:
> The order command appearently accepts 'Cancel' as possible argument, but
> I did not get any effect from it and I couldn't find an example so far.
The short answer is that I've found the problem, fixed it, and pushed a new
release, and the cancel option for the order command works consistently now,
as opposed to the case before where it accidently worked when line item ids
and the internal order ids were synchronized.
About your comment about cancelling all positions:
> ... a brute force cancel all and everything would be actually sufficent.
The shim does not currently offer this functionality, and is unlikely to do
so any time soon. The IB tws provides an option to unwind all positions,
and we feel such a potentially drastic operation is best supervised via the
gui. There are many possible problems with panic exits, and automated
code for same has many risks which we prefer to avoid for now.
Now, returning to the order cancellation bug, and in more detail, for
developers who might be interested:
The patch is as follows:
--- old/send.c 2007-12-07 11:34:23.000000000 -0500
+++ send.c 2007-12-07 11:34:28.000000000 -0500
@@ -64,7 +64,7 @@
Sig(RequestIds) { s += rule, b << num.value; }
Sig(PlaceOrder) { o.router.bots.xact.sync_send(o, self); }
-Sig(CancelOrder) { s += rule, b << xid.item.id(); }
+Sig(CancelOrder) { s += rule, b << xid.id(); }
Sig(ReqScanParms) { s += rule; }
Sig(EndBulletin) { s += rule; }
Sig(OpenOrders) { s += rule; }
In the code above, the wire() rule for CancelOrder was changed to
print the transaction id, a short-lived monotonic transaction code
for use between the shim and the IB tws, rather than the transaction
line item id. Of course you probably want to pick up the new release
rather than just applying the patch yourself; the above is simply to
explain what was changed for this problem alone.
I tracked the problem down by looking at the trace output. The save
option captures the raw protocol strings to files, and there are
rough scripts to translate the binary to text:
wire protocol image binary to text filter script
------------------- ----------------------------
shim2tws.bin bin/req.filter < shim2tws.bin
tws2shim.bin bin/msg.filter < tws2shim.bin
After translation, and with a bit more formatting using vi, I have the
following request and message logs. They are similar to what is sent
to the output log, but without the processing; the ShimText log prints
event (command, request, and message) objects to a text file, which
serves to show where the shim works; the binary files are captured
without any translation by the shim, and so can be used to see where it
fails.
requests:
23|764|
3|15|1|AIG|STK||0.00||1|SMART||USD||BUY|2|LMT|50.0|0.0|GTC||||0||0||
0|0|0|1|1|0|||||||||
3|15|1|AIG|STK||0.00||1|SMART||USD||BUY|2|LMT|50.0|0.0|GTC||||0||1||
0|0|0|1|1|0|||||||||
5| 1|
4| 1|3|
messages:
34|20071207 10:25:45 EST|
9| 1|1|
4| 2|-1|2104|Market data farm connection is OK:usfuture|
4| 2|-1|2104|Market data farm connection is OK:usfarm|
4| 2|-1|2107|HMDS data farm connection is inactive but should be available
upon demand.:ushmds2a|
3| 6|1|Submitted|0|2|0.0|1344889771|0|0.0|764|
5|10|1|AIG|STK||0.0|?|SMART|USD|AIG|BUY|2|LMT|50.0|0.0|GTC||DUxxxx|O|0||764|
1344889771|1|0|0||1344889771.0/DU4181/100|||||||||0||0|||||||1|0|0|0|
|3|0|0||0|1|
3| 6|1|Submitted|0|2|0.0|1344889771|0|0.0|764|
4| 2|3|135|Can't find order with id =:3|
Clearly the place order request correctly translates from the line item id to
the transaction id, and the cancel order request does not:
good -v- good
3|15|1|AIG|STK||0.00||1|SMART||USD||BUY|2|LMT|50.0|0.0|GTC||||0||0|| ...
good -^- good
nope -v- nope
4| 1|3|
nope -^- nope
Once the patch is applied, the text log shows the cancel working properly.
Here command, request and message events are prefixed with an event code
of 1, 2, or 3, respectively:
4|100| 0|# |4|100|0|****************|
4|100| 0|# |4|100|0|0.51|070831|risk|
4|100| 0|# |4|100|0|****************|
3| 9| 1|1|
3| 4| 2| -1|2104|Market data farm connection is OK:usfuture|
3| 4| 2| -1|2104|Market data farm connection is OK:usfarm|
3| 4| 2| -1|2107|HMDS data farm connection is inactive but should be avail
1|26| 0|order(3,LMT,Create,2,50.0,0.0,0);|
2| 3|15|1| 3|LMT|BUY|STK.SMART.AIG.
1|26| 0|order(3,LMT,Submit,2,50.0,0.0,0);|
2| 3|15|1| 3|LMT|BUY|STK.SMART.AIG.
3| 3| 6|1|Submitted|0|2|0.0|1344889772|0|0.0|2818|
1|13| 0|open;|
2| 5| 1|
3| 5|10|1|AIG|STK||0.0|?|SMART|USD|AIG|BUY|2|LMT|50.0|0.0|GTC|| ...
3| 3| 6|1|Submitted|0|2|0.0|1344889772|0|0.0|2818|
1|26| 0|order(3,MKT,Cancel,2,00.0,0.0,0);|
2| 4| 1|1|
3| 3| 6|1|PendingCancel|0|2|0.0|1344889772|0|0.0|2818|
3| 4| 2| 1| 202|Order Canceled - reason:|
3| 3| 6|1|Cancelled|0|2|0.0|1344889772|0|0.0|2818|
1| 7| 0|quit;|
Thanks,
Bill
More information about the ts-general
mailing list