[ts-gen] order placement

Bill Pippin pippin at owlriver.net
Thu Apr 23 14:41:19 EDT 2009


Mike,

About placing orders:

> I have a few questions regarding order placement.

You may not realize that the officially most-upto-date text to
describe the order commands is in the scripts exs/risk.rb and
exs/kill.rb .  I mention this in part because the parenthesized
tuples below are obsolete syntax:

> ... shim command ... to purchase 20,000 EUR.USD:

>    order(30545,MKT,Submit,20000,0,0,0)

> results in a ... drop message.

If the above is literally the syntax you used, then indeed, the parser
would drop the command due to syntax errors, which is what appears to
have happened.  The order regression scripts I mention above echo the
command text to the standard error, and are reasonably transparent,
so you should feel free to modify them for use with your paper account.

About order key bindings:

> If I type "bind key(abc) to oid(30545);", then I see the following
> [syntax | semantic | parse action] error message:
> ...

Your bind command should use the new syntax, and have as order template
identifier a valid Template table uid.  The sql/risk.sql script inserts
a few into the testing database to show you what's involved, and you'll
need to insert your own into the trading database before you can use it
for trades. 

An example bind command, one that you could use for a single session,
since order keys in the journal must be unique, might be:

    bind key:abc-090423-1339 to oid:1;

In the ruby risk.rb script, the order key variable name is filled in
via string interpolation.  You'll probably want to do something similar
in your own downstream scripts:

    bind key:#{take_pos} to oid:1;

> Do both of the order placement methods in the above links still work?

The post from 2007 is completely obsolete; the post from a year ago is
close enought to correct to be thoroughly confusing.  Again, see the
example scripts in the directory exs, and in particular, risk.rb and
kill.rb .  I update those as needed with each release.

> 2.  As I understand, the order id comes from the Product.uid field.
> How do I specify the exchange?

In brief, you'll be using some kind of contract expression in your
order creation command.  Contract expressions by their nature include
the route, and you can use any valid contract expression type, see
exs/tick for details.

I believe by "order id" you mean the contract expression, in the
form you've given, a Product uid.  This record key may be part of a
valid contract expression, in which you would follow the product uid
with an exchange name, e.g., pid:30545 at IDEALPRO.  There are other
valid contract expression forms, again, see exs/tick for details.

The string assignment to the variable src3 in the ruby code fragment
below, taken from risk.rb, gives an example of how to build the text
for a order creation command:

    sequence = "-aa-"
    identity =  sequence  + Time.new.strftime("%y%m%d-%H-%M-%S")
    take_pos = 'take-pos' + identity
    exit_pos = 'exit-pos' + identity
    brand    = 'test-pos'

    src0 = "wait 2;\n"
    src1 = "bind key:#{take_pos} to oid:1;\n"
    src2 = "bind key:#{exit_pos} to oid:2;\n"

    src3 = "create item #{brand} ibc:266093 at SMART #{take_pos} LMT 2  5.0  0.0;
    src4 = "modify item                           #{take_pos} MKT 1  0.0  0.0;
    src5 = "submit item                           #{take_pos};

The bind command [currently] glues together an order variable key
with an order template record; the create command glues the key,
and so that template, with: a mark or brand, which becomes the order
reference; a contract expression; and a quad consisting of the order
type, quantity, limit price, and aux price --- this quad gives the
initial value for the mutable arguments of an order, which you may
attempt to modify via the command of the same name.

The ruby code above produces in part the trace output below:

    create item test-pos ibc:266093 at SMART take-pos-aa-090423-13-51-05 LMT 2  5.0  0.0;
    modify item                           take-pos-aa-090423-13-51-05 MKT 1  0.0  0.0;
    submit item                           take-pos-aa-090423-13-51-05;

Analogous commands, given the appropriate binding of an order template to
the variable name abc-090423-13-51-05 , might be:

    create item test-pos ibc:12087792 at IDEALPRO abc-090423-13-51-05 MKT 20000 0.0 0.0;
    submit item                                abc-090423-13-51-05;

When fed to a risk mode shim from 090327, the above two commands
work as expected, giving the following log entries:

    1| 8| 0|bind key:abc-090423-13-51-05         to oid:1;|
    1|18| 0|risk create item test-pos :30545 at IDEALPRO abc-090423-13-51-05 MKT 20000 0.0 0.0;|
    2| 3|15|3|15|50|EUR|CASH||0.00||1|IDEALPRO||USD||BUY|20000|MKT|0.00|0.00|GTC||||0|test-pos|0||0|0|0|2|1|0|||||||||CASH::EUR:USD:
    3| 4| 2|        50|2109|Order Event Warning:Attribute 'Outside Regular Trading Hours' is ignored based on the order type and destination. PlaceOrder is now being processed.|
    1|21| 0|risk submit item                                abc-090423-13-51-05;|
    2| 3|15|3|15|50|EUR|CASH||0.00||1|IDEALPRO||USD||BUY|20000|MKT|0.00|0.00|GTC||||0|test-pos|1||0|0|0|2|1|0|||||||||CASH::EUR:USD:
    3|11| 7|50|EUR|CASH||0.0||IDEALPRO|USD|EUR.USD|0001f4e8.43a0445c.01.01|20090423  13:10:23|DU4181|IDEALPRO|BOT|20000|1.3095|1235252937|8|false|
    3| 5|10|50|EUR|CASH||0.0||IDEALPRO|USD|EUR.USD|BUY|20000|MKT|0.0|0.0|GTC||DU4181|C|0|test-pos|8|1235252937|false|false|0||1235252937.0/DU4181/100|||||||||0||0|||||||false|false|false|false||reduce on fill without block|false|false||0|LastPrice|
    3| 3| 6|50|Filled|20000|0|1.3095|1235252937|0|1.3095|8|
    3| 5|10|50|EUR|CASH||0.0||IDEALPRO|USD|EUR.USD|BUY|20000|MKT|0.0|0.0|GTC||DU4181|C|0|test-pos|8|1235252937|false|false|0||1235252937.0/DU4181/100|||||||||0||0|||||||false|false|false|false||reduce on fill without block|false|false||0|LastPrice|
    3| 3| 6|50|Filled|20000|0|1.3095|1235252937|0|1.3095|8|
    3| 5|10|50|EUR|CASH||0.0||IDEALPRO|USD|EUR.USD|BUY|20000|MKT|0.0|0.0|GTC||DU4181|C|0|test-pos|8|1235252937|false|false|0||1235252937.0/DU4181/100|||||||||0||0|||||||false|false|false|false||reduce on fill without block|false|false||0|LastPrice|
    3| 3| 6|50|Filled|20000|0|1.3095|1235252937|0|1.3095|8|

As you can see from the error warning, the 1st order template may well
not be very well suited to currency trades; certainly the value for the
rth flag is suspect.  Again, you'll want to set up your own order
templates in the database.

Thanks,

Bill



More information about the ts-general mailing list