Пример #1
0
        public virtual void OnBroadcastCallback(BroadcastEventArgs e)
        {
            EventHandler <BroadcastEventArgs> hdlr = OnBroadcast;

            if (hdlr != null)
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new BroadcastEventDelegate(OnBroadcastCallback), e);
                }
                else
                {
                    hdlr(this, e);
                }
            }
        }
Пример #2
0
        private void FireBroadcast(object o, BroadcastEventArgs e)
        {
            DateTime dateValue;
            InvestmentSystemBroadcast investment_system_broadcast = e.Data;

            if (investment_system_broadcast.Type ==
                InvestmentSystemBroadcast.Types.BroadcastType.DATA)
            {
                InvestmentSystemOneData invsys_one_data =
                    InvestmentSystemOneData.ParseFrom(
                        investment_system_broadcast.Delegate);

                if (invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.SYSTEM)
                {
                    DateTime.TryParseExact(
                        invsys_one_data.UpdateTm, "HH:mm.ss", enUS,
                        DateTimeStyles.AssumeUniversal, out dateValue);

                    statusLabel.Text = invsys_one_data.Status;

                    double ask = Convert.ToDouble(invsys_one_data.BestAsk);
                    double bid = Convert.ToDouble(invsys_one_data.BestBid);

                    openPLLabel.Text   = invsys_one_data.OpenPl.ToString("0.00");
                    closedPLLabel.Text = invsys_one_data.ClosedPl.ToString("0.00");

                    if (invsys_one_data.OpenPl > 0)
                    {
                        openPLLabel.ForeColor = Color.Green;
                    }
                    else if (invsys_one_data.OpenPl < 0)
                    {
                        openPLLabel.ForeColor = Color.Red;
                    }
                    else
                    {
                        openPLLabel.ForeColor = Color.Black;
                    }

                    if (invsys_one_data.ClosedPl > 0)
                    {
                        closedPLLabel.ForeColor = Color.Green;
                    }
                    else if (invsys_one_data.ClosedPl < 0)
                    {
                        closedPLLabel.ForeColor = Color.Red;
                    }
                    else
                    {
                        closedPLLabel.ForeColor = Color.Black;
                    }

                    chartPanel.UpdateBidAsk(bid, ask);

                    bidaskLabel.Text = ask.ToString(controller.PriceFormat) +
                                       " , " + bid.ToString(controller.PriceFormat);

                    this.ParentForm.Text = controller.ConnectionElement.Name +
                                           " " + invsys_one_data.Status + " " + dateValue.ToLongTimeString();

                    if (invsys_one_data.TimebarList.Count == 1)
                    {
                        chartPanel.UpdateTimebarData(invsys_one_data.TimebarList[0], false);
                    }
                }
                else if (loginFlag == true &&
                         invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.TIMEBAR)
                {
                    foreach (Timebar timebar in invsys_one_data.TimebarList)
                    {
                        chartPanel.UpdateTimebarData(timebar, true);
                    }
                }
                else if (loginFlag == true &&
                         invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.TREND)
                {
                    foreach (Trend trend in invsys_one_data.TrendList)
                    {
                        chartPanel.AddTrendData(trend);
                    }
                }
                else if (loginFlag == true &&
                         invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.EXECUTION)
                {
                    foreach (OrderExecution execution in invsys_one_data.OrderExecutionList)
                    {
                        chartPanel.AddOrderExecutionData(execution, true);

                        GTLTreeNode node = new GTLTreeNode(
                            EPOCH.AddSeconds(execution.Timestamp)
                            .ToLocalTime().ToString());

                        if (execution.Type == OrderExecution.Types.ExecutionType.BUY)
                        {
                            node.SubItems.AddRange(new GTLSubItem [] {
                                new GTLSubItem(EPOCH.AddSeconds(execution.Timebar).ToLocalTime().ToString()),
                                new GTLSubItem("BUY"),
                                new GTLSubItem("" + execution.Quantity),
                                new GTLSubItem("" + execution.Price)
                            });
                        }
                        else
                        {
                            node.SubItems.AddRange(new GTLSubItem [] {
                                new GTLSubItem(EPOCH.AddSeconds(execution.Timebar).ToLocalTime().ToString()),
                                new GTLSubItem("SELL"),
                                new GTLSubItem("" + execution.Quantity),
                                new GTLSubItem("" + execution.Price)
                            });
                        }

                        data.Nodes.Insert(0, node);
                    }
                }

                chartPanel.Redraw();
            }
        }