private void SendStoplossOrderWorkItem(object state) { StoplossOrder order = (StoplossOrder)state; OrderRequest request = new OrderRequest(order) { Category = OrderCategory.Sell, Price = order.StoplossPrice, PricingType = OrderPricingType.MakertPriceMakeDealInFiveGradesThenCancel, Volume = order.ExistingVolume, SecurityCode = order.SecurityCode, }; string error; DispatchedOrder dispatchedOrder = CtpSimulator.GetInstance().DispatchOrder(request, out error); if (dispatchedOrder == null) { ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (logger != null) { logger.ErrorFormat( "Exception in dispatching stop loss order: id {0} code {1} stoploss price {2}, volume {3}. Error: {4}", order.OrderId, order.SecurityCode, order.StoplossPrice, order.ExistingVolume, error); } } else { ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); if (logger != null) { logger.InfoFormat( "Dispatched stop loss order: id {0} code {1} stoploss price {2}, volume {3}.", order.OrderId, order.SecurityCode, order.StoplossPrice, order.ExistingVolume); } lock (_orderLockObj) { RemoveActiveStoplossOrder(order); AddSentOrder(order); } // force query order status. CtpSimulator.GetInstance().QueryOrderStatusForcibly(); } }
public void RegisterStoplossOrder(StoplossOrder order) { if (order == null) { throw new ArgumentNullException(); } lock (_orderLockObj) { AddActiveStoplossOrder(order); } CtpSimulator.GetInstance().SubscribeQuote(order.SecurityCode); }
public static CtpSimulator GetInstance() { if (_instance == null) { lock (typeof(CtpSimulator)) { if (_instance == null) { _instance = new CtpSimulator(); } } } return(_instance); }
private StoplossOrderManager() { CtpSimulator.GetInstance().RegisterQuoteReadyCallback(OnQuoteReady); CtpSimulator.GetInstance().RegisterOrderStatusChangedCallback(OnOrderStatusChanged); }