public void AddStateChangedHook(OrderPostProcessorStateHook orderWithState) { lock (this.hooksLock) { if (hooks.Contains(orderWithState)) { string msg = "TRIGGER_ALREADY_ADDED: " + orderWithState; throw new Exception(msg); } hooks.Add(orderWithState); } }
public override bool Equals(Object o) { OrderPostProcessorStateHook anotherTriggerCondition = (OrderPostProcessorStateHook)o; bool ret = this.Order == anotherTriggerCondition.Order && this.OrderState == anotherTriggerCondition.OrderState; return(ret); }
public void MoveTakeProfit(PositionPrototype proto, double newTakeProfitPositiveOffset) { if (proto.TakeProfitAlertForAnnihilation == null) { string msg = "I refuse to move TakeProfit order because proto.TakeProfitAlertForAnnihilation=null"; throw new Exception(msg); } if (proto.TakeProfitAlertForAnnihilation.OrderFollowed == null) { string msg = "I refuse to move TakeProfit order because proto.TakeProfitAlertForAnnihilation.OrderFollowed=null"; throw new Exception(msg); } Order order2killAndReplace = proto.TakeProfitAlertForAnnihilation.OrderFollowed; OrderState stateBeforeActiveAssummingSubmitting = order2killAndReplace.State; OrderState stateBeforeKilledAssumingActive = OrderState.Unknown; string msig = "MoveTakeProfit(" + proto.TakeProfitPositiveOffset + "=>" + newTakeProfitPositiveOffset + "): "; // 1. hook onKilled=>submitNew OrderPostProcessorStateHook takeProfitGotKilledHook = new OrderPostProcessorStateHook("TakeProfitGotKilledHook", order2killAndReplace, OrderState.Killed, delegate(Order takeProfitKilled, ReporterPokeUnit pokeUnit) { string msg = msig + "takeProfitGotKilledHook(): invoking OnTakeProfitKilledCreateNewTakeProfitAndAddToPokeUnit() " + " [" + stateBeforeKilledAssumingActive + "] => " + "[" + takeProfitKilled.State + "]"; takeProfitKilled.AppendMessage(msg); this.OnTakeProfitKilledCreateNewTakeProfitAndAddToPokeUnit(takeProfitKilled, newTakeProfitPositiveOffset, pokeUnit); } ); // 2. hook onActive=>kill OrderPostProcessorStateHook takeProfitReceivedActiveCallback = new OrderPostProcessorStateHook("TakeProfitReceivedActiveCallback", order2killAndReplace, OrderState.Active, delegate(Order takeProfitToBeKilled, ReporterPokeUnit pokeUnit) { string msg = msig + "takeProfitReceivedActiveCallback(): invoking KillOrderUsingKillerOrder() " + " [" + stateBeforeActiveAssummingSubmitting + "] => " + "[" + takeProfitToBeKilled.State + "]"; takeProfitToBeKilled.AppendMessage(msg); stateBeforeKilledAssumingActive = takeProfitToBeKilled.State; this.KillOrderUsingKillerOrder(order2killAndReplace); } ); this.OPPstatusCallbacks.AddStateChangedHook(takeProfitReceivedActiveCallback); this.OPPstatusCallbacks.AddStateChangedHook(takeProfitGotKilledHook); this.AppendOrderMessageAndPropagateCheckThrowOrderNull(proto.TakeProfitAlertForAnnihilation.OrderFollowed, msig + ": hooked takeProfitReceivedActiveCallback() and takeProfitGotKilledHook()"); }