private void ProcessNewTickResponse(NewTickResponse tickMessage) { foreach (var tick in tickMessage.Tick) { AppendToLog(string.Format("{0}:{1} - Price:{2} Volume:{3}", tick.Symbol.DataFeed, tick.Symbol.Symbol, tick.Price, tick.Volume)); } }
void IWCFServiceCallback.MessageOut(ResponseMessage message) { if (message is LoginResponse) { } else if (message is DataFeedListResponse) { _DataFeeds = ((DataFeedListResponse)message).DataFeeds; InitDataFeedControl(); } else if (message is NewTickResponse) { NewTickResponse tickMessage = (NewTickResponse)message; foreach (var tick in tickMessage.Tick) { txtLog.AppendText(string.Format("{0}:{1} - Price:{2} Volume:{3}", tick.Symbol.DataFeed, tick.Symbol.Symbol, tick.Price, tick.Volume) + Environment.NewLine); } ScrollToEnd(); } else if (message is HistoryResponse) { HistoryResponse histMessage = (HistoryResponse)message; txtLog.Text += "History Message" + Environment.NewLine; foreach (var bar in histMessage.Bars) { txtLog.AppendText(string.Format("{0} O:{1} H:{2} L:{3} C:{4} V:{5}", bar.Date.ToString(), bar.Open, bar.High, bar.Low, bar.Close, bar.Volume) + Environment.NewLine); } ScrollToEnd(); } else if (message is HeartbeatResponse) { } else if (message is ErrorInfo) { } else { } }
private void TickResponseCallback(NewTickResponse message) { //// tracer.ProcessTicks("NewTickResponse", message.Tick); //if (Ticks != null) // Ticks(this, new EventArgs<Tick[]>(message.Tick)); NewTickResponse tickMessage = (NewTickResponse)message; List <Quote> QuoteList = new List <Quote>(); foreach (var tick in tickMessage.Tick) { Console.WriteLine(string.Format("{0}:{1} - Price:{2} Volume:{3}", tick.Symbol.DataFeed, tick.Symbol.Symbol, tick.Price, tick.Volume)); Quote quote = new Quote(); quote.Symbol.Name = tick.Symbol.Symbol; quote.Timestamp = DataProvider.GetCurrentTimestamp(tick.Date); quote.Price = tick.Price; lock (lastQuotes) { Quote tempquote; if (!lastQuotes.TryGetValue(tick.Symbol.Symbol, out tempquote)) { lastQuotes.Add(tick.Symbol.Symbol, quote); } else { if (tempquote.Timestamp < quote.Timestamp) { lastQuotes[tick.Symbol.Symbol] = quote; } } } QuoteList.Add(quote); } if (OnNewQuoteResponse != null && QuoteList != null) { OnNewQuoteResponse(QuoteList); } }
private void TickMessageOutWorker(string aSessionID, Queue <Tick> aTicks) { IUserInfo aUserInfo; const int aMaxPackSize = 20; aUserInfo = DataServer.MessageRouter.gMessageRouter.GetUserInfo(aSessionID); if (aUserInfo == null) { lock (aTicks) { aTicks.Clear(); return; } } try { while (true) { NewTickResponse aResponse = new NewTickResponse(); bool bEmptyQueue = false; aResponse.Tick = new List <Tick>(); aResponse.User = aUserInfo; lock (aTicks) { while (aResponse.Tick.Count < aMaxPackSize) { if (aTicks.Count > 1) { aResponse.Tick.Add(aTicks.Dequeue()); } else if (aTicks.Count == 1) { bEmptyQueue = true; aResponse.Tick.Add(aTicks.Peek()); break; } else { bEmptyQueue = true; break; } } } if (aResponse.Tick.Count > 0) { aResponse.User.Send(aResponse); } if (bEmptyQueue) { lock (aTicks) { if (aTicks.Count > 0) { aTicks.Dequeue(); } if (aTicks.Count == 0) { break; } } } } } catch { lock (aTicks) { aTicks.Clear(); } } }
void IWCFServiceCallback.MessageOut(ResponseMessage message) { if (message is LoginResponse) { } else if (message is DataFeedListResponse) { _DataFeeds = ((DataFeedListResponse)message).DataFeeds; //InitDataFeedControl(); } else if (message is NewTickResponse) { NewTickResponse tickMessage = (NewTickResponse)message; List <Quote> QuoteList = new List <Quote>(); foreach (var tick in tickMessage.Tick) { Console.WriteLine(string.Format("{0}:{1} - Price:{2} Volume:{3}", tick.Symbol.DataFeed, tick.Symbol.Symbol, tick.Price, tick.Volume)); Quote quote = new Quote(); quote.Symbol.Name = tick.Symbol.Symbol; quote.Timestamp = DataProvider.GetCurrentTimestamp(tick.Date); quote.Price = tick.Price; //lock (newQuote) //{ // //newTicks.Add(tick); // newQuote.Add(quote); //} lock (lastQuotes) { Quote tempquote; if (!lastQuotes.TryGetValue(tick.Symbol.Symbol, out tempquote)) { lastQuotes.Add(tick.Symbol.Symbol, quote); } else { if (tempquote.Timestamp < quote.Timestamp) { lastQuotes[tick.Symbol.Symbol] = quote; } } } QuoteList.Add(quote); } if (OnNewQuoteResponse != null && QuoteList != null) { OnNewQuoteResponse(QuoteList); } } else if (message is HistoryResponse) { HistoryResponse histMessage = (HistoryResponse)message; Console.WriteLine("History Message" + Environment.NewLine); foreach (var bar in histMessage.Bars) { Console.WriteLine(string.Format("{0} O:{1} H:{2} L:{3} C:{4} V:{5}", bar.Date.ToString(), bar.Open, bar.High, bar.Low, bar.Close, bar.Volume) + Environment.NewLine); } //if (OnHistoryResponse != null && histMessage != null) //{ // OnHistoryResponse(histMessage); //} //ScrollToEnd(); } else if (message is HeartbeatResponse) { } else if (message is ErrorInfo) { } else { } }