The timing on this closing trade turned out to be spot on, close to the top of the day(I'm assuming times are UTC).
How did it execute at that time? I know at some point your execution algo was checking that the bid-ask spread is no bigger than X multiples of the minimum tick size. Does your execution try every X minutes and then finally it succeeds when there's enough liquidity that the spread is small enough, or something else?
No, as you can see below I submitted an offer at 112.97 which got filled very quickly (approximately 30 seconds later).
It was just luck - I don't start trading US Markets until 2pm, and this happened to be the first to go, and that just happened to be the top of the market.
Rob
Code:
emacs /media/LACIE-D2/Rob/run_stack_handler_20220310.arch
ctrl-s BRENT
sysproduction.run_stack_handler.run_stack_handler:
None
Arguments:
[]
2022-03-10:0030.06 {'type': 'stack_handler'} check_external_position_break will run every 0 minutes until process ends with heartbeats every 10 minutes
2022-03-10:0030.08 {'type': 'stack_handler'} spawn_children_from_new_instrument_orders will run every 0 minutes until process ends with heartbeats every 10 minutes
2022-03-10:0030.11 {'type': 'stack_handler'} generate_force_roll_orders will run every 60 minutes at most 10 times with heartbeats every 10 minutes
2022-03-10:0030.13 {'type': 'stack_handler'} create_broker_orders_from_contract_orders will run every 0 minutes until process ends with heartbeats every 10 minutes
2022-03-10:0030.15 {'type': 'stack_handler'} process_fills_stack will run every 0 minutes until process ends with heartbeats every 10 minutes
2022-03-10:0030.17 {'type': 'stack_handler'} handle_completed_orders will run every 0 minutes until process ends with heartbeats every 10 minutes
2022-03-10:0030.20 {'type': 'stack_handler'} safe_stack_removal will run once only on process completion
2022-03-10:0030.22 {'type': 'stack_handler'} refresh_additional_sampling_all_instruments will run every 60 minutes until process ends with heartbeats every 10 minutes
2022-03-10:0030.24 {'type': 'run_stack_handler'} Not starting process:because Not yet time to run
....
2022-03-10:0100.07 {'type': 'stack_handler', 'component': 'mongoIbBrokerClientIdData'} Locked IB client ID 688
2022-03-10:0100.21 {'type': 'run_stack_handler', 'broker': 'IB', 'clientid': 688} spawn_children_from_new_instrument_orders still alive, done 0 of unlimited executions every 0 minutes
2022-03-10:0100.23 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'instrument_order_id': 32086} Passive roll handling order (Order ID:32086) Type best for dynamic_TF_carry BRENT-LAST, qty [-1], fill [0]@ price, None Parent:no parent Children:no_children, reducing trade, entire trade in next contract 20220700
2022-03-10:0100.27 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': '', 'instrument_order_id': 32086} [Warning] Short of time, so allocating to algo_market
2022-03-10:0100.29 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'instrument_order_id': 32086} List of contract orders spawned [(Order ID:no order ID) Type best for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:32086 Children:no_children]
2022-03-10:0100.32 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'instrument_order_id': 32086, 'contract_order_id': ''} Put child order (Order ID:no order ID) Type best for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:32086 Children:no_children LOCKED on stack with ID 31881 from parent order (Order ID:32086) Type best for dynamic_TF_carry BRENT-LAST, qty [-1], fill [0]@ price, None Parent:no parent Children:no_children
2022-03-10:1400.06 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'instrument_order_id': 32086} Sending order (Order ID:31881) Type best for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:32086 Children:no_children to algo sysexecution.algos.algo_market.algoMarket
2022-03-10:1400.08 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'component': 'ibFuturesContractData'} Reqid -1: 2119 Market data farm is connecting:usfuture
....
2022-03-10:1400.32 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'instrument_order_id': 32086} Created a broker order (Order ID:no order ID) Type market for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:31881 Children:no_children (not yet submitted or written to local DB)
2022-03-10:1400.34 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'component': 'ibExecutionStackData', 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'broker_order_id': ''} Going to submit order (Order ID:no order ID) Type market for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:31881 Children:no_children to IB
2022-03-10:1400.37 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'component': 'ibExecutionStackData', 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'broker_order_id': ''} Order submitted to IB
2022-03-10:1400.39 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'component': ...
2022-03-10:1401.02 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'instrument_order_id': 32086, 'broker_order_id': ''} Submitted order to IB (Order ID:no order ID) Type market for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [-1]@ price, 112.97 Parent:31881 Children:no_children
2022-03-10:1401.04 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'broker_order_id': 32030} Managing trade (Order ID:32030) Type market for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [-1]@ price, 112.97 Parent:31881 Children:no_children with market order
2022-03-10:1401.07 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'broker_order_id': 32030} Trade completed
2022-03-10:1401.09 {'type': 'stack_handler', 'component': 'mongoContractOrderStackData', 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'instrument_order_id': 32086} Changed fill qty from [0] to [-1] for order (Order ID:31881) Type best for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:32086 Children:[32030]
2022-03-10:1401.12 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'instrument_code': 'BRENT-LAST', 'contract_date': '20220600'} Updated position of BRENT-LAST/20220600 from 1 to 0; new position in db is 0
2022-03-10:1401.14 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'instrument_order_id': 32086} Updated position of BRENT-LAST/20220600 because of trade (Order ID:31881) Type best for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [0]@ price, None Parent:32086 Children:[32030] ID:31881 with fills -1
2022-03-10:1401.16 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688, 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'instrument_order_id': 32086} Updated position of dynamic_TF_carry BRENT-LAST from 1 to 0 because of trade (Order ID:32086) Type best for dynamic_TF_carry BRENT-LAST, qty [-1], fill [0]@ price, None Parent:no parent Children:[31881] 32086 fill [-1]
2022-03-10:1401.19 {'type': 'stack_handler', 'component': 'mongoInstrumentOrderStackData', 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'instrument_order_id': 32086} Changed fill qty from [0] to [-1] for order (Order ID:32086) Type best for dynamic_TF_carry BRENT-LAST, qty [-1], fill [0]@ price, None Parent:no parent Children:[31881]
2022-03-10:1401.21 {'type': 'stack_handler', 'component': 'mongoContractOrderStackData', 'strategy_name': 'dynamic_TF_carry', 'instrument_code': 'BRENT-LAST', 'contract_order_id': 31881, 'instrument_order_id': 32086} [Warning] Can't change order (Order ID:31881) Type best for dynamic_TF_carry/BRENT-LAST/20220600, qty [-1], fill [-1]@ price, 112.97 Parent:32086 Children:[32030] INACTIVE as inactive
2022-03-10:1401.23 {'type': 'stack_handler', 'broker': 'IB', 'clientid': 688} Released contract order 31881 from algo control
(I'm assuming times are UTC).
). Regardless of the outcome of that trade, I'm uncomfortable with that. I think I might need an additional per-instrument risk control, that's risk adjusted, and perhaps should be *after* the DO. I'm not a fan of that method tho, for the same reason Rob mentioned in his post.