/// <summary> /// Handles the LiveData event /// </summary> /// <param name="args">Any event arguments that might be passed</param> public void LiveDataEventHandler(LiveDataEventArgs args) { // Ensure that the Live tool panel is enabled if (!IsEnabled) { IsEnabled = true; } Status = String.Format("{0} item{1}", args.Count, args.Count != 1 ? "s" : String.Empty); }
private void UpdateStockData(LiveDataEventArgs args) { if (this.InvokeRequired) { try { this.Invoke(new UpdateStockDataDelegate(UpdateStockData), new object[] { args }); } catch { } } else { try { //if(true) if (args.IsReal) { if (this.lb_stockprice.Text != args.CurrentPrice.ToString("0.00")) { this.lb_stockprice.Text = args.CurrentPrice.ToString("0.00"); double percent = (args.CurrentPrice - args.PreClose) / args.PreClose * 100; this.lb_stockpercent.Text = string.Format("{0}", percent.ToString("0.00")); if (args.CurrentPrice < args.PreClose) { //背景变绿色 this.lb_stockprice.ForeColor = Color.Green; this.lb_stockpercent.ForeColor = Color.Green; } else if (args.CurrentPrice == args.PreClose) { //背景变黑色 this.lb_stockpercent.ForeColor = Color.Black; this.lb_stockprice.ForeColor = Color.Black; } else { //背景变红色 this.lb_stockpercent.ForeColor = Color.Red; this.lb_stockprice.ForeColor = Color.Red; } //背景变蓝色 this.lb_stockprice.BackColor = Color.Blue; resetBackGroundTimer.Enabled = true; } } else { if (args.Stockcode == string.Empty) { this.lb_stockprice.Text = "结束"; } else { this.lb_stockprice.Text = "模拟中..."; } } } catch { } } }
void rp_LiveData_Arrival(object sender, LiveDataEventArgs args) { try { if (args.IsReal) { RunningPolicy rp = (RunningPolicy)sender; for (int i = 1; i < grid_realpolicy.Rows.Count; i++) { if (((RunningPolicy)grid_realpolicy.Rows[i].UserData).PolicyGuid == rp.PolicyGuid) { double lastprice; double lastbid = 0; double lastask = 0; try { lastprice = System.Convert.ToDouble(grid_realpolicy.Rows[i][3]); } catch { lastprice = 0; } try { lastbid = System.Convert.ToDouble(grid_realpolicy.Rows[i][5]); } catch { } try { lastask = System.Convert.ToDouble(grid_realpolicy.Rows[i][6]); } catch { } if (args.CurrentPrice != lastprice || args.Bid != lastbid || args.Ask != lastask) { CellStyle ncs; if (args.PreClose < args.CurrentPrice) { grid_realpolicy.SetCellStyle(i, 3, cs_change); ncs = cs_up; grid_realpolicy.SetCellStyle(i, 4, cs_up); } else if (args.PreClose > args.CurrentPrice) { grid_realpolicy.SetCellStyle(i, 3, cs_change); ncs = cs_down; grid_realpolicy.SetCellStyle(i, 4, cs_down); } else { grid_realpolicy.SetCellStyle(i, 3, cs_change); ncs = cs_even; grid_realpolicy.SetCellStyle(i, 4, cs_even); } if (args.Bid > args.PreClose) { grid_realpolicy.SetCellStyle(i, 5, cs_up); } else if (args.Bid < args.PreClose) { grid_realpolicy.SetCellStyle(i, 5, cs_down); } else { grid_realpolicy.SetCellStyle(i, 5, cs_even); } if (args.Ask > args.PreClose) { grid_realpolicy.SetCellStyle(i, 6, cs_up); } else if (args.Ask < args.PreClose) { grid_realpolicy.SetCellStyle(i, 6, cs_down); } else { grid_realpolicy.SetCellStyle(i, 6, cs_even); } //grid_realpolicy.SetCellStyle(i,3,new C1.Win.C1FlexGrid.CellStyle() grid_realpolicy.Rows[i][3] = Math.Round(args.CurrentPrice, 8, MidpointRounding.AwayFromZero); grid_realpolicy.Rows[i][5] = Math.Round(args.Bid, 8, MidpointRounding.AwayFromZero); grid_realpolicy.Rows[i][6] = Math.Round(args.Ask, 8, MidpointRounding.AwayFromZero); grid_realpolicy.Rows[i][4] = string.Format("{0}%", Math.Round((args.CurrentPrice - args.PreClose) / args.PreClose * 100, 2, MidpointRounding.AwayFromZero).ToString("0.00")); ParameterizedThreadStart pts = new ParameterizedThreadStart(reset_grid); Thread th = new Thread(pts); th.Start(new ResetObject(i, ncs)); } break; } } } } catch { } }
void runningPolicy_LiveData_Arrival(object sender, LiveDataEventArgs args) { UpdateStockData(args); }