void processOrder(TTOrderStatus status, ReadOnlyCollection <Order> orders) { foreach (Order order in orders) { processOrder(status, order); Thread.Sleep(5); } processSystemMessage(SystemMessage.ORDER_BOOK_DOWNLOAD); }
void processOrder(TTOrderStatus status, Order order, params Order[] orders) { TTOrder oldOrder = null; // If this order's instrument is not yet in our dictionary, then add the instrument // to our list and subscribe to the instrument updates if AutoSubscribeInstruments // is true. if (!_ttInstruments.ContainsKey(order.InstrumentKey)) { if (AutoSubscribeInstruments) { //TODO: figure out how to subscribe to instruments here //SubscribeToInstrument(order.InstrumentKey); /*InstrumentLookupSubscription ils = new InstrumentLookupSubscription(apiSession, Dispatcher.Current, order.InstrumentKey); * ils.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(ils_Update); * ils.Start();*/ } TTInstrument tti = new TTInstrument(order.InstrumentKey); _ttInstruments.Add(order.InstrumentKey, tti); } TTOrder tto; if (_workingTTOrders.ContainsKey(order.SiteOrderKey)) { tto = _workingTTOrders[order.SiteOrderKey]; } else { tto = NewTTOrder(order); } tto.Status = status; string orderKey = tto.Key; // Maintain our working orders switch (status) { case TTOrderStatus.Added: _workingTTOrders[orderKey] = tto; break; case TTOrderStatus.Deleted: case TTOrderStatus.Filled: case TTOrderStatus.Rejected: _workingTTOrders.Remove(orderKey); break; case TTOrderStatus.Updated: oldOrder = tto.Clone(); tto.TTAPI_Order = orders[0]; //newOrder = NewTTOrder(orders[0]); string newOrderKey = orders[0].SiteOrderKey; _workingTTOrders.Remove(orderKey); _workingTTOrders.Add(newOrderKey, tto); System.Diagnostics.Debug.Assert(orderKey.Equals(newOrderKey)); break; } // When we send an order using the SendOrder method, the method creates a // unique OrderTag and then blocks waiting for that order to be "created". // It waits for it to appear in the sentOrders dictionary with the OrderTag // that was generated as the key. This is the only way I could deduce to // be able to return a TTOrder object to the caller of SendOrder since all // the order sending methods appear to be asynchronous. if (!order.OrderTag.Equals("")) { _sentOrders[order.OrderTag] = tto; } //Console.WriteLine("Working orders size: {0}", workingTTOrders.Count); if (OnOrder != null) { OnOrder(status, _ttInstruments[order.InstrumentKey], tto, oldOrder); } }