private void UpdateValues() { if (_perfEnabled) { PerfAnalyzer.startTime(_performanceLabel + "_UpdateValuesDuration"); } while (!_tradeQueue.IsEmpty) { TradeInfo t; if (_tradeQueue.TryDequeue(out t)) { _tradeList.Add(new TASTableObj(t, lastPrice)); lastPrice = t.Prc; UpdateTextFields(t); } } while (_tradeList.Count > MAXHISTORY) { _tradeList.RemoveAt(0); } PopulateGrid(); if (_perfEnabled) { PerfAnalyzer.endTime(_performanceLabel + "_UpdateValuesDuration"); } }
private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) { if (_perfEnabled) { PerfAnalyzer.startTime(_perfLabel + "_RowColoringTime"); } GridView view = sender as GridView; Lvl2TableObj cellObject = null; lock (_bindingList) { if (_bindingList.Count > gridView1.GetDataSourceRowIndex(e.RowHandle)) { cellObject = _bindingList[gridView1.GetDataSourceRowIndex(e.RowHandle)]; } } if (cellObject != null) { if (cellObject.IsOurOrder) { if (e.Column.Caption.Equals("Exch")) { e.Appearance.BackColor = Color.Red; e.Appearance.ForeColor = Color.White; } else { e.Appearance.BackColor = Color.Black; e.Appearance.ForeColor = Color.White; } } else { float px = cellObject.Price; for (int j = 0; j < _sortedPriceLvls.Length; j++) { if (_sortedPriceLvls.ElementAt(j) == px) { e.Appearance.BackColor = _priceLevelBGColors[j % 6]; } } } if (_perfEnabled) { PerfAnalyzer.endTime(_perfLabel + "_RowColoringTime"); } } }
private void UpdateTextFields(TradeInfo ti) { if (_perfEnabled) { PerfAnalyzer.startTime(_performanceLabel + "_UpdateTextFieldsDuration"); } textEditVol.Text = ti.TotVol.ToString("##########"); textEditOpen.Text = ti.Open.ToString("0.00"); textEditHigh.Text = ti.High.ToString("0.00"); textEditLow.Text = ti.Low.ToString("0.00"); double last; if (textEditLast.Text == "") { textEditLast.Text = lastPrice.ToString("0.00"); } else if ((last = Convert.ToDouble(textEditLast.Text)) != lastPrice) { textEditLast.Text = lastPrice.ToString("0.00"); textEditLast.BackColor = last > lastPrice ? Color.Red : Color.LightGreen; } else { textEditLast.BackColor = DefaultBackColor; } float change = lastPrice - ti.Open; Color dayColor = (change > 0) ? Color.LightGreen : Color.Red; textEditChng.Text = change.ToString("0.00"); textEditPercent.Text = (change / ti.Open).ToString("0.00"); textEditChng.BackColor = textEditPercent.BackColor = (change == 0 ? DefaultBackColor : dayColor); if (_perfEnabled) { PerfAnalyzer.endTime(_performanceLabel + "_UpdateTextFieldsDuration"); } }
private void RepopulateGrid() { QuoteBookStruct book = mergeQuoteBooks(); //if the book is empty, remove all exchange quotes (can't just clear list or our orders will be removes as well) if ((_buy && book.NumBid == 0 || (!_buy && book.NumAsk == 0))) { foreach (byte key in _exchBookDict.Keys) { Lvl2TableObj obj; _exchBookDict.TryRemove(key, out obj); lock (_bindingList) { _bindingList.Remove(obj); } } } else { //if any exchange has a quote in our dictionary, but not the latest quotebook, it doesn't exist anymore, so remove it foreach (byte key in _exchBookDict.Keys) { if ((_buy && !book.BidExch.Contains(key)) || (!_buy && !book.AskExch.Contains(key))) { Lvl2TableObj obj; _exchBookDict.TryRemove(key, out obj); lock (_bindingList) { _bindingList.Remove(obj); } } } } if (_perfEnabled) { PerfAnalyzer.startTime(_perfLabel + "_SetAllOrdersTime"); } _priceLevels.Clear(); List <OrderBook> books = ConvertQuoteBookToOrders(book); foreach (OrderBook b in books) { _priceLevels.Add(b._ordprc); if (_exchBookDict.ContainsKey(b._exch)) { _exchBookDict[b._exch].UpdateQuote(b); } else { Lvl2TableObj obj = new Lvl2TableObj(b); _exchBookDict.TryAdd(b._exch, obj); lock (_bindingList) { _bindingList.Add(obj); } } } _sortedPriceLvls = _buy ? _priceLevels.Reverse().ToArray() : _priceLevels.ToArray(); if (_perfEnabled) { PerfAnalyzer.endTime(_perfLabel + "_SetAllOrdersTime"); } }