Order Events And Handlers


Class strategy features a number of event handlers for handling order events. These are declared as virtual functions  with a name that has an 'on_' prefix. They are:

 

virtual void on_transaction(const transaction&);

 

virtual void on_order_filled(const order_ref&, const transaction&);

virtual void on_order_sent(const order_ref&);

virtual void on_order_partially_filled(order_ref&, const transaction&);

virtual void on_order_status_changed(order_ref&);

virtual void on_order_cancel_rejected(order_ref&, const reject_info&);

virtual void on_order_replace_rejected(order_ref&, const reject_info&);

virtual void on_order_rejected(order_ref&, const reject_info&);

By default these members do nothing. Developers must define their own overrides to respond to the events that trigger such handlers.

 

Tutorial 303


Tutorial 303 randomly sends market and limit orders to buy and sell. For demonstration purposes the strategy defines implementations for all order and trade related event handlers. In this case they are used exclusively to print messages to the terminal as well as a few assertions.

 

Since this tutorial is a little longer, we will look at each section separately. Please refer to the tutorial project to get a complete source listing.

 

                 void on_bar_close(void)   override

                    {

                              std::cout << "***on_bar_close()***" << std::endl;

                              int action = rand.int32(0, 5);

 

                              // buy market

                              if (action == 0) {

                                        if (!mkt_order.is_active()) {

                                                  mkt_order = mkt.buy(1).tag("market-buy");

                                        }

                              }

 

                              // sell market

                              else if (action == 1) {

                                        if (!mkt_order.is_active()) {

                                                  mkt_order = mkt.sell(1).tag("market-sell");

                                        }

                              }

 

                              // buy limit

                              else if (action == 2) {

                                        if (!lmt_order.is_active()) {

                                                  lmt_order = mkt.buy_limit(1, mkt.low[0]).tag("limit-buy");

                                        }else {

                                                  if (lmt_order.age_in_bars() > 5)

                                                            lmt_order.cancel();

                                        }

                              }

 

                              //sell limit

                              else if (action == 3) {

                                        if (!lmt_order.is_active()) {

                                                  lmt_order = mkt.sell_limit(1, mkt.high[0]).tag("limit-sell");

                                        }else {

                                                  if (lmt_order.age_in_bars() > 5)

                                                            lmt_order.cancel();

                                        }

                              }

                              // . . .

                    }

 

This part is quite should be self explanatory. We generate a random number, and depending on the number we perform a particular action. Note that we retain an order reference for every order we generate. Before we assign to the order_ref object we ensure that the existing reference is not to an active order (that would cause an exception). Also recall that the order_ref::is_active() member also checks if the object is initialized at all (if not it returns false). Unless you are working with a trivial strategy the call to is_active() is essential before assigning to an order_ref object.

 

Event Handlers


See the last section for a full listing of program output. When going through program output pay attention to the order in which the event handler functions are called. For example on_order_status_changed() is called before on_order_sent()

 

WARNING - 'Live' vs 'Simulated' Environments:

There is an important difference between a strategy that is being deployed, or tested, on 'live' data versus one that runs in simulation on data from a database table!

In a 'live' environment (when the strategy is connected to the server software), the strategy responds to incoming messages. These messages are processed one message at a time. An incoming message will be ignored if the strategy is still responding to another message. For example, if an new price record message is received, the strategy's on_bar_close() member is invoked which may send new orders to the broker/platform. These orders may be filled or rejected immediately, but the strategy won't know about it until it processes the corresponding incoming messages. This means that your code can't get confused. If an order status is 'active' in one line of code, it can't magically change to 'cancelled' in a subsequent line, even if on the exchange the order was already cancelled. This is however a technicality since under normal circumstances event handler members will be evaluated magnitudes faster than the time it takes to send and receive messages.

In a 'simulated' environment, the strategy is optimized for speed. There is no message queue at all. Hence, when order::cancel() is called, the order is cancelled immediately, and an on_order_status_change() event will interrupt the event handler that is currently being evaluated. Another difference is that in simulation, orders are filled in their entirety and so partial fills won't occur. Orders are also never rejected.

This can cause subtle and not so subtle differences in how your strategy behaves. This is why walk-forward testing in a 'live' environment is very important to verify that the strategy acts as expected.

 

 

 

on_order_sent()


This member is called a soon as an order was sent by any order function like instrument::buy(), before the order function returns - hence the warning message below.

 

                    void on_order_sent(order_ref& o) override 

                    {

                              std::cout << "***on_order_sent()***" << std::endl;

                              o.print(std::cout);

 

                              // WARNING:

                              // Do not expect the following to work!!          

                              // if (o == mkt_order) {

                              //           std::cout << "sent market order" << std::endl;

                              // }

                              // 'mkt_order' is not yet initialized as member that sent the order has not returned yet.

 

                    }

 

on_order_status_changed()


This member  is called every time an order's status changes. Note that you can access the previous status with order_ref::prev_status().

 

          void on_order_status_changed(order_ref& o) override 

          {

                    std::cout << "***on_order_status_changed()***" << std::endl;

                    std::cout << fmt::format("order status change; order-id:{}; symbol:{}",

                                                                                o.id(),o.symbol()) << std::endl;

                    std::cout << "  order tag:  " << o.tag() << std::endl;

                    std::cout << "  new status: " << order::to_string(o.status()) << std::endl;

                    std::cout << "  old status: " << order::to_string(o.prev_status()) << std::endl;

          }

 

on_transaction()


This member is called when a transaction is confirmed. In practice you will more likely respond to on_order_filled() and on_order_partially_filled() since that saves you from having to explicitly determine whether the order was completely filled. Use the transaction::order() and transaction::instrument() members to access related objects.

 

          void on_transaction(const transaction& t) override 

          {

                    std::cout << "***on_transaction()***" << std::endl;

                    //t.print(std::cout);

                    if (t.order() == mkt_order) {

                              std::cout << "transaction at market for : " << t.symbol() << std::endl;

                    }

                    if (t.order() == lmt_order) {

                              std::cout << "transaction at limit for : " << t.symbol() << std::endl;

                    }

                    std::cout << "new position is : " << t.instrument().position() << std::endl;

          }

 

on_order_filled()


This event handler is called when an order is filled in its entirety. Note that the order_ref argument is const. The order is no longer intended to be modified.

 

          void on_order_filled(const order_ref& o, const transaction& t) override

          {

                    std::cout << "***on_order_filled()***" << std::endl;

                    //Note: In simulation all orders are filled in their entirety - no partial fills!

                    if (o == lmt_order) {

                              std::cout << "limit order filled for: " + o.symbol() << std::endl;

                    }

                    if (o == mkt_order) {

                              std::cout << "market order filled for: " + o.symbol() << std::endl;

                    }

          }

 

on_order_partially_filled()


This event handler is called when an order is partially filled. The order_ref argument is not constant, so that you can modify or cancel the order.

 

          void on_order_partially_filled(order_ref& o, const transaction& t)

          {

                    std::cout << "***on_order_partially_filled()***" << std::endl;

                    //Note: In simulation all orders are filled in their entirety - no partial fills!

                    if (o == lmt_order) {

                              std::cout << "limit order partially filled" << std::endl;

                              std::cout << "filled quantity: " << o.filled_quantity() << std::endl;

                              std::cout << "remaining quantity: " << o.remaining() << std::endl;

                    }

          }

 

on_trade_open()


Recall the definition of a trade as explained in a previous section. A trade constitutes all the buying and selling between when the trade is first opened until it is closed. A trade can thus have any number of add-on legs and partial-exit legs.

The on_trade_open() even handler is invoked when a new trade is opened. Use the instrument argument to determine if the trade is long or short.

 

          void on_trade_open(instrument& i) override

          {                    

                    std::cout << "***on_trade_open()***" << std::endl;

                    //tsa_assert(i == mkt);

                    std::cout << "A new trade has been opened for symbol: " << i.symbol() << std::endl;

                    if (i.is_long()) {

                              std::cout << "The trade is long." << std::endl;

                    }else{          

                              tsa_assert(!i.is_flat());

                              std::cout << "The trade is short." << std::endl;

                    }

                    tsa_assert(i.position() != 0);

                    std::cout << "Current position: " << i.position() << std::endl;

          }

 

on_trade_close()


The on_trade_close() member is called when a trade is closed out, either by the position going flat or via reversal. The trade_info structure holds various trade metrics describing the trade.

 

          void on_trade_close(instrument& i, const trade_info& t) override

          {

                    std::cout << "***on_trade_close()***" << std::endl;

                    std::cout << "A trade has been closed for symbol: " << i.symbol() << std::endl;

                    std::cout << "Trade net-profit is: " << t.net_profit << std::endl;

                    /*          Transaction Info members

                              t.close_timestamp; t.commission; t.direction; t.entry_timestamp;

                              t.gross_profit; t.max_position; t.negative_excursion; t.net_profit;

                              t.num_bars; t.num_transactions ;t.positive_excursion; t.slippage; t.trade_ID;

                              etc.

                    */

          }

 

on_order_rejected


This member is called when an order is rejected. If information is available it can be retrieved via order_ref::reject_info() which returns a string. Rejects do not occur with standard simulations!

 

          void on_order_rejected(order_ref& o)

          {

                    std::cout << "***on_order_rejected()***" << std::endl;

                    std::cout << "order rejected; order-id: " << o.id() << std::endl;

                    std::cout << "reject info: " << o.reject_info() << std::endl;

          }

 

on_order_cancel_rejected


This handler is called when a cancel request is rejected; presumably because the order was already filled.  Rejects do not occur with standard simulations!

 

          void on_order_cancel_rejected(order_ref& o)

          {

                    std::cout << "***on_order_cancel_rejected()***" << std::endl;

                    std::cout << "cancel rejected; order-id: " << o.id() << std::endl;

                    std::cout << "reject info: " << o.reject_info() << std::endl;

          }

 

on_order_replace_rejected


This handler is called when a cancel-replace operation is rejected; presumably because the order was already filled. Rejects do not occur with standard simulations!

 

          void on_order_replace_rejected(order_ref& o)

          {

                    std::cout << "***on_order_replace_rejected()***" << std::endl;

                    std::cout << "order replace rejected; order-id: " << o.id() << std::endl;

                    std::cout << "reject info: " << o.reject_info() << std::endl;

          }

 

Program Output:


When inspecting the program's output, you will notice the long order-ids like 1000000003. Recall that order-ids are composed of the instrument-id (front) and order sequence(back). Since this strategy only has one instrument member, all order-ids start with 1.

 

=========================================

Tutorial:    303

=================================

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000001; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000001; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000001

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-01T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 1

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000001; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -1

***on_trade_open()***

A new trade has been opened for symbol: XYZ

The trade is short.

Current position: -1

***on_bar_close()***

***order counts***

number of orders: 1

number of active orders: 0

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000002; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000002; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000002

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                limit

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               99.18

aux price:           0

exec interval:       during_bar

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-03T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000002; symbol:XYZ

  order tag:  limit-buy

  new status: filled

  old status: submitted

***on_order_filled()***

limit order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : 0

***on_trade_close()***

A trade has been closed for symbol: XYZ

Trade net-profit is: 0.89

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000003; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000003; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000003

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-07T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000003; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : 1

***on_trade_open()***

A new trade has been opened for symbol: XYZ

The trade is long.

Current position: 1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000004; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000004; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000004

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                limit

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               102.16

aux price:           0

exec interval:       during_bar

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-08T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000004; symbol:XYZ

  order tag:  limit-sell

  new status: filled

  old status: submitted

***on_order_filled()***

limit order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : 0

***on_trade_close()***

A trade has been closed for symbol: XYZ

Trade net-profit is: 2.11

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000005; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000005; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000005

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-09T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000005; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -1

***on_trade_open()***

A new trade has been opened for symbol: XYZ

The trade is short.

Current position: -1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 0

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000006; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000006; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000006

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-11T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000006; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : 0

***on_trade_close()***

A trade has been closed for symbol: XYZ

Trade net-profit is: 2.3

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000007; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000007; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000007

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                limit

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               101.2

aux price:           0

exec interval:       during_bar

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-12T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000007; symbol:XYZ

  order tag:  limit-sell

  new status: filled

  old status: submitted

***on_order_filled()***

limit order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -1

***on_trade_open()***

A new trade has been opened for symbol: XYZ

The trade is short.

Current position: -1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000008; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000008; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000008

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-13T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_order_status_changed()***

order status change; order-id:1000000008; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : 0

***on_trade_close()***

A trade has been closed for symbol: XYZ

Trade net-profit is: -0.34

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000009; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000009; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000009

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                limit

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               101.13

aux price:           0

exec interval:       during_bar

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-14T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000010; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000010; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000010

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-16T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000010; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -1

***on_trade_open()***

A new trade has been opened for symbol: XYZ

The trade is short.

Current position: -1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000011; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000011; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000011

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-18T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000011; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -2

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000012; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000012; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000012

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-21T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000012; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -3

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000013; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000013; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000013

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-22T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000013; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -2

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000014; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000014; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000014

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-24T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000014; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -3

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000015; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000015; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000015

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-25T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000015; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -2

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000016; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000016; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000016

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              sell

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-26T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000016; symbol:XYZ

  order tag:  market-sell

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -3

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 1

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000017; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000017; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000017

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-28T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000017; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -2

***on_bar_close()***

***on_order_status_changed()***

order status change; order-id:1000000018; symbol:XYZ

  order tag:

  new status: pending_submit

  old status: created

***on_order_status_changed()***

order status change; order-id:1000000018; symbol:XYZ

  order tag:

  new status: submitted

  old status: pending_submit

***on_order_sent()***

order:

----------------------------------------------

id:                  1000000018

external id:         [id undefined]

tag:                 [tag undefined]

status:              submitted

prev status:         pending_submit

action:              buy

type:                market

symbol:              XYZ

exchange:

remaining quantity:  1

filled quantity:     0

price:               0

aux price:           0

exec interval:       at_open

time in force type:  gtc

min fill quant:      1

is_active:           true

is cancelled:        false

is stop limit:       false

is filled:           false

last fill timestamp: [date_time undefined]

is partially filled: false

create timestamp:    2015-01-29T00:00:00.0

instrument id:       1

----------------------------------------------

***order counts***

number of orders: 3

number of active orders: 2

***on_order_status_changed()***

order status change; order-id:1000000018; symbol:XYZ

  order tag:  market-buy

  new status: filled

  old status: submitted

***on_order_filled()***

market order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : -1

***on_order_status_changed()***

order status change; order-id:1000000009; symbol:XYZ

  order tag:  limit-buy

  new status: filled

  old status: submitted

***on_order_filled()***

limit order filled for: XYZ

***on_transaction()***

transaction at market for : XYZ

new position is : 0

***on_trade_close()***

A trade has been closed for symbol: XYZ

Trade net-profit is: 1.78

***on_bar_close()***

***order counts***

number of orders: 2

number of active orders: 0

press 'return' key to exit...