Hi Louis,
Thanks for the insights. The algo itself is no important. I used hourly data to reduce resource and help me see through the timing of all these events easier. From my questions I do see a good framework would be extremely valuable.. Everything looks much clear except for three:
- Adding log after liquidation, I found liquidation orders being placed throughout a whole hour from day to day like following. Adding self.stat in front of liquidation solved it but I still wondered how it could happen. Similar problem on Jan 28 where orders are placed at 9:31 and 15:01. As OnData is only triggered by hourly data, I only expected all actions happen at hourly edges. Where do these 1min addtions come from?
2020-04-06 10:17:00 :LIQUIDATION ORDER PLACED2020-04-06 10:18:00 :LIQUIDATION ORDER PLACED2020-04-06 10:19:00 :LIQUIDATION ORDER PLACED+2020-01-28 09:31:00AAPLBuy Limit
Limit: $76.33226877625 USD
1333CanceledLiquidated+2020-01-28 09:31:00AAPLSell Stop Market
Stop: $75.57 USD
-1333CanceledLiquidated+2020-01-28 15:01:00AAPLBuy Limit
Fill: $78.647314442 USD
Limit: $78.647314442 USD
1294FilledLimit Price: ¤78.65+2020-01-28 15:01:00AAPLSell Stop Market
Fill: $77.86 USD
Stop: $77.86 USD
-1294FilledStop Price: ¤77.86
2. I added logs in OnOrderEvent trying to see timing of all order events (New, Submitted, Filled & Cancelled). I can only go through after commenting out the Submitted section in the end otherwise it keeps giving following error, although same code were used lines above with no issue.
Runtime Error: AttributeError : 'GeekyYellowGreenArmadillo' object has no attribute 'stopOrder' at OnOrderEvent elif orderEvent.OrderId == self.stopOrder.OrderId: === at Python.Runtime.PyObject.Invoke(PyTuple args in main.py:line 95 AttributeError : 'GeekyYellowGreenArmadillo' object has no attribute 'stopOrder'
Even if I comment out the last section, the New and Submitted order events do not seem to be logged:
2020-01-02 11:00:00 :LONG ORDER FILLED @ 73.616969751 STOP UPDATED @ 72.88 TARGET UPDATED @ 75.832020-01-06 10:00:00 :STOP ORDER FILLED @ 72.88 NEXT ENTRY TIME 2020-01-06 11:00:002020-01-06 12:00:00 :LONG ORDER FILLED @ 73.636735349 STOP UPDATED @ 72.9 TARGET UPDATED @ 75.852020-01-09 10:00:00 :STOP ORDER CANCELLED2020-01-09 10:00:00 :LIQUIDATION ORDER FILLED @ 76.176614692 STOP ORDER CANCELLED NEXT ENTRY TIME 2020-01-09 11:00:002020-01-09 12:00:00 :LONG ORDER FILLED @ 76.3693292725 STOP UPDATED @ 75.61 TARGET UPDATED @ 78.662020-01-17 16:00:00 :STOP ORDER CANCELLED
3. There is one error in the log says zero quantity
2020-01-17 16:00:00 :STOP ORDER CANCELLED2020-01-21 09:31:00 :Unable to submit order with id -10 that has zero quantity.2020-01-21 10:00:00 :LIQUIDATION ORDER FILLED @ 78.38294956875 STOP ORDER CANCELLED NEXT ENTRY TIME 2020-01-21 11:00:00
Thanks