Rejected Orders
You can return a dictionary of {symbol: list of all OrderedDict objects made on the symbol}
Attributes:Sample - Access data attribute
account.executions
OrderedDict object - tuple
Name | Type | Information |
---|---|---|
account_number | integer | This should be a unique number assigned to this account. If this parameter is not given, a unique number will be assigned. |
clordid | string | Client Order Id in FIX. Is generated when the order is sent. Will be the same on executions. |
collect | dictionary | `json` dictionary of information collected at the time of the order. `None` means nothing collected. |
exit_options | dictionary | `json` dictionary of system parameters for setting up the exit. `None` means no system parameters. |
exit_parameters | dictionary | `json` dictionary of parameters for the exit script. `None` means no parameters. |
exit_script | string | Guid of the exit script. `None` means no exit script. |
explanation | string | ???Defaults to `None` |
filled_shares | integer | If any shares were executed. Seems very unlikely. Defaults to 0. |
flags | integer | ???Defaults to 0. |
instruction_id | string | Unique GUID for the instance of the script that generated the initial order. Will be `None` if the initial order wasn't started from same machine (e.g. from trading client) |
intent | string | Intended position change. One of "none", "init", "increase", "decrease", "exit", "reverse".
|
kind | integer | Event enum (10) representing the kind of event. |
order_algorithm | string | Name of algorithm to process order with. |
order_id | `None` | Unique GUID of order being filled (very similar clordid). Will be `None` if the initial order wasn't started from same machine (e.g. from trading client) |
price | float | Execution price |
reason | string | Reason order was rejected. |
script_id | string | GUID of the script. Will be `None` if the initial order wasn't started from same machine (e.g. from trading client) |
shares | integer | Shares executed on the trade. Always positive number, whether buy or sell execution |
???side | integer | Side of the trade
|
state | string | Symbol of trade |
symbol | string | Symbol of trade |
timestamp | muts | Timestamp of trade |
user_key | string | `user_key` set on the order. Can be used to identify trades that go together (pairs/batch/strategy). `account` object can be filtered on `user_key` |
Remarks:
- The returned dictionary will have a list of ALL symbols that have orders, even if there are no executions for that symbol.
Working Example:
Backtest for AAPL on 4/22/16 from 9:31-9:32. Extra Symbols: [SPY, TQQQ, QQQ]
from cloudquant.interfaces import Strategy
class AccountObjectRejectedOrders(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == 'TQQQ'
def on_start(self, md, order, service, account):
# generate rejected orders
order.algo_buy(self.symbol, "market", intent="exit")
order.algo_sell(self.symbol, "market", intent="exit")
# another symbol
order.algo_buy('SPY', "market", intent="exit")
order.algo_sell('SPY', "market", intent="exit")
# test pending with no execution
order.algo_buy('QQQ', "limit", intent="init", price=0.01, order_quantity=100)
def on_minute_bar(self, event, md, order, service, account, bar):
if event.timestamp > service.time(9, 31):
print '\n\n.............................\non_minute_bar\n\t%s\n' % service.time_to_string(
service.system_time,
'%H:%M:%S.%f')
print account
print '\n\naccount.rejected_orders'
print account.rejected_orders
print '\n\nBy Symbol'
for symbol in account.rejected_orders:
print symbol
for execution in account.rejected_orders[symbol]:
print execution, '\n'
service.terminate()
Console
............................. on_minute_bar 09:31:05.005000 account_id: 0 entry_pl: 0.00 mtm_pl: 0.00 buying_power: None open_capital_long: 0.00 open_capital_short: 0.00 pending_capital_long: 0.00 pending_capital_short: 0.00 max_capital_used: 0.00 max_capital_used_timestamp: 0 open_symbols: [] pending_symbols: ['QQQ'] SPY: Execution count : 0 realized_pl : entry_pl : 0.00 mtm_pl : 0.00 matched_trades : 0 unrealized_pl : entry_pl : 0.00 mtm_pl : 0.00 position : shares : 0 entry_price : 0.00 mtm_price : 0.00 capital_long : 0.00 capital_short : 0.00 pending : count_long : 0 shares_long : 0 capital_long : 0.00 count_short : 0 shares_short : 0 capital_short : 0.00 QQQ: Execution count : 0 realized_pl : entry_pl : 0.00 mtm_pl : 0.00 matched_trades : 0 unrealized_pl : entry_pl : 0.00 mtm_pl : 0.00 position : shares : 0 entry_price : 0.00 mtm_price : 0.00 capital_long : 0.00 capital_short : 0.00 pending : count_long : 1 shares_long : 100 capital_long : 11901.00 count_short : 0 shares_short : 0 capital_short : 0.00 TQQQ: Execution count : 0 realized_pl : entry_pl : 0.00 mtm_pl : 0.00 matched_trades : 0 unrealized_pl : entry_pl : 0.00 mtm_pl : 0.00 position : shares : 0 entry_price : 0.00 mtm_price : 0.00 capital_long : 0.00 capital_short : 0.00 pending : count_long : 0 shares_long : 0 capital_long : 0.00 count_short : 0 shares_short : 0 capital_short : 0.00 account.rejected_orders {'SPY': [OrderedDict([('intent', 'exit'), ('symbol', 'SPY'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000003'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 16), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)]), OrderedDict([('intent', 'exit'), ('symbol', 'SPY'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000004'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 17), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)])], 'TQQQ': [OrderedDict([('intent', 'exit'), ('symbol', 'TQQQ'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000001'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 12), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)]), OrderedDict([('intent', 'exit'), ('symbol', 'TQQQ'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000002'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 13), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)])]} By Symbol SPY OrderedDict([('intent', 'exit'), ('symbol', 'SPY'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000003'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 16), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)]) OrderedDict([('intent', 'exit'), ('symbol', 'SPY'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000004'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 17), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)]) TQQQ OrderedDict([('intent', 'exit'), ('symbol', 'TQQQ'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000001'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 12), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)]) OrderedDict([('intent', 'exit'), ('symbol', 'TQQQ'), ('price', 0.0), ('shares', 0), ('explanation', None), ('flags', 0), ('exit_script', None), ('exit_parameters', None), ('exit_options', None), ('collect', None), ('order_id', '0000000000000002'), ('order_algorithm', 'market'), ('clordid', None), ('instruction_id', 'cf14968b-2d73-5847-a4eb-8f355d111246'), ('script_id', u'd2d14d10-7515-4e3c-bc1b-0cc97403b2db'), ('user_key', None), ('filled_shares', 0), ('timestamp', 1481553000000000), ('state', 'L'), ('line_number', 13), ('script_class_name', 'AccountObjectRejectedOrders'), ('reason', 'when intent is exit, current_position cannot be 0'), ('account_id', 0), ('expected_direction', None), ('kind', 10)])