Rejected Order Event
Called whenever a previously placed order is rejected.
Interface: def on_reject(self,
event,
md,
order,
service,
account):
pass
Name | Type | Information |
---|---|---|
account_id | integer | The account id of the order event. Will be the same as account id of the script. |
clordid | string | Client Order Id in FIX. Is generated when the order is sent. Will be the same on executions. |
expected_direction | enum | Either increase, reduce, or reverse. This will be set when the order is first placed, and is a prediction of whether your order will increase, reduce, or reverse your current posistion. Note a short on a symbol that you do not currently hold would be considered an increase of that position. This can obviously change as it's possible you have orders in flight, that haven't filled yet. Can be usefull in debugging order behavior |
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 | The intent attribute you set in the order that generated this event. |
kind | integer | Event enum (10) representing the kind of event. *LIVE AND FORWARD ONLY*, represents the type of event (trade, quote, news, imbalance etc) |
line_number | string | line_number is the line in your strategy script where the order was placed that generated this event. Can be used to help debug order behavior |
order_algorithm | string | The order_algorithm GUID you set in the order that generated this event. This can be useful in debugging order behavior. |
order_id | string | Unique GUID of the order being rejected (very similar clordid). Will be None if the initial order wasn't started from same machine (e.g. from trading client) |
reason | string | Reason order was rejected. |
script_class_name | string | script_class_name represents the name of your Strategy class that placed the order that generated this event. Can be used to help debug order behavior |
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) |
state | string | Order Message's States |
symbol | string | Event Symbol. In most cases symbol is obvious (self.symbol, md.symbol). If the script has subscribed to multiple symbols events, then event.symbol should be used to identify the symbol. |
timestamp | muts | Timestamp of the event. |
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 |
from cloudquant.interfaces import Strategy
class OnRejectExample(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == "AAL"
def on_start(self, md, order, service, account):
# print the symbol and timestamp
print(self.symbol + "\n" + service.time_to_string(service.system_time) + "\tin on_start()\n\n")
# instance variable
self.do_once = True
def on_trade(self, event, md, order, service, account):
print( service.time_to_string(service.system_time) + "\tin on_trade()\n\n")
if self.do_once:
# sell shares you don't have with intent "exit" to trigger a reject
order.algo_sell(self.symbol, "market", intent="exit")
# set instance variable False
self.do_once = False
def on_reject(self, event, md, order, service, account):
# print timestamp
print( service.time_to_string(service.system_time) + "\tin on_reject()\n\n")
print("an order has been rejected\n")
# print reject event
print(event)
# receive an alert when an order is rejected
# you must create your alert id
_alertList = [('Reason', event.reason)]
service.alert(md.symbol, '734rd790-83e0-42sc-926a-722er3102eq3', _alertList, -1)
service.terminate()
Console
AAL 2016-08-15 09:30:00.000000 in on_start() 2016-08-15 09:30:00.152000 in on_trade() 2016-08-15 09:30:00.152000 in on_reject() an order has been rejected RejectEvent(instruction_id='49277842-de8d-4b13-8db6-1c90a124432b', script_id=u'2f7abe8c-f5bb-492d-99c6-8d8eb2ecb1cd', user_key=None, order_id='0000000000000001', state='L', reason='when intent is exit, current_position cannot be 0', timestamp=1471267800152000, symbol='AAL', account_number=0, clordid=None, intent='exit', order_algorithm='market', expected_direction=None, script_class_name='on_reject', line_number=22, kind=10)