[ts-gen] create & modify orders
Bill Pippin
pippin at owlriver.net
Wed Apr 16 11:46:12 EDT 2008
Nils,
Thanks for the post. Please understand that the shim is currently in
a transitional state. The create and submit commands work, but modify
is broken. The bind command adds another layer of indirection for
order templates, and the command reader expects to cross that layer
when it typechecks order parameters. Paul hit the key points with
his post, about which more later.
> exs/wire ... I tried different combinations, all the same output.
> Database is freshly set up and has the required items in Templates
> and Position tables.
> Any hints?
With the changes, some of the regression tests in exs are broken. I
left exs/wire alone with old[er] code, so when you looked at exs/wire,
you were looking at an incomplete and non-working script. The
current approach is demonstrated by exs/bind, which shows the
use of the bind command to add that layer of indirection I mentioned
above. Here's a fragment from exs/bind:
# Buy two shares of AIG, thereby entering a position.
# Then sell the shares to exit the position and end up flat.
wait 2;
bind key(take-pos) to oid(1);
bind key(exit-pos) to oid(2);
create item take-pos LMT 2 35.00 0.0; wait 1;
modify item take-pos MKT 3 0.0 0.0; wait 1;
submit item take-pos; wait 1;
exit;
Paul's recasting, by using different variable names in the bind
commands, and commenting out the modify, is exactly to the point.
I've lost track of who said what in the immediately reference'd
post below; I think this is Paul speaking, and I might be pointing
out the obvious, but here goes:
>>> ... In the most recent 'bin/includes' are commands of the form:
>>> create item 12 3 LMT 2 50.0 0.0;
>>> ... previously the "12" ^^ was not present. My understanding is
>>> that this is a limit order to buy 2 lots of AIG at price 50.0; and
>>> that it's AIG because it references row "3" in the "Template" table,
>>> which in turn (pid=2) references row 2 in the "Position" table: this
>>> ultimately deriving its entries from risk.sql. ...
All true, and in addition, the 12 is the contract number for AIG. The
next release you see will be using that argument in that position,
if only because the template record will not provide access to the
contract index. For now it is a required dummy value.
> Seems to be clear. However, all I get is ... ext/wire
As mentioned above, and by Paul, bind commands are needed prior
to the create and submit commands. So, for the syntax errors below,
the reader typechecks all tokens while parsing, and for any token
used for table lookup, rejects that token if the table lookup fails.
In this case, for the template keys, with type TmpK, when the reader
looked in the Bindings, and there was no entry, that's just what
happened: the table lookup failed, and there's a syntax error:
> Scan: 14 17 0 <LMT>
> 2 Term: mod TmpK (nil)
> 3 Grammar rule: Terminal (TmpK)
> 4 Grammar rule: Compound (mod)
> 5 Syntax error:
> 6 Cursor state: match; text is:
> 7 create item 1 LMT 2 40.00 0.0;
> 8 -----------------^------------
Now, for Paul's post:
> Maybe you are not using the "bind" command before the "create"? The
> example below seems to work. I've used strings "one" and "two", but
> they could be anything. I think the "12" is currently a dummy
> parameter that just needs to be there. Probably somebody will give a
> better explanation later, but hopefully this will work:
> #!./shim -f
> #
> bind key(one) to oid(1);
> bind key(two) to oid(2);
> create item 12 one LMT 2 40.00 0.0; wait 1;
> #odify item 12 one MKT 3 0.0 0.0; wait 1;
> submit item one; wait 1;
> ...
All to the point. To reiterate, (1) modify is currently broken;
(2) the key index 12 is a required dummy value, and in the future
it will be a contract expression, with a number of possible forms
allowed; and (3) you may choose what names you wish as variable
names for the template key bindings. E.g., in function bracket of
bin/includes, I use identity mappings, from key uid to key uid, to
provide for the extra layer of indirection while still using the
same command text:
# ...
BuyOrder='create item 12 3 LMT 2 50.0 0.0;' # AIG
SellHigh='create item 12 4 LMT 2 60.0 0.0;'
StopLoss='create item 12 5 STP 2 0.0 49.0;'
# ...
cmd_shim 'bind key(3) to oid(3);'
cmd_shim 'bind key(4) to oid(4);'
cmd_shim 'bind key(5) to oid(5);'
cmd_shim 'open;' ; sleep 1 # open orders info
cmd_shim "$BuyOrder" ; sleep 1 # optimistic order
cmd_shim "$SellHigh" ; sleep 1 # limit exit order
cmd_shim "$StopLoss" ; sleep 1 # bail on disaster
# ...
Paul, thanks for the quick answer, and Nils, if you have more questions,
please feel free to ask them.
Thanks,
Bill
More information about the ts-general
mailing list