Exemple #1
0
        private void FireLogin(object sender, EventArgs e)
        {
            string request_id = Guid.NewGuid().ToString();
            string timestamp  = com.quantmodel.common.network.message.ClientMessage.getTimestamp();

            InvestmentSystemOneRequest hades_request =
                InvestmentSystemOneRequest.CreateBuilder()
                .SetRequestId(request_id)
                .SetTimestamp(timestamp)
                .SetType(InvestmentSystemOneRequest.Types.RequestType.LOGIN)
                .Build();

            InvestmentSystemResponse response = sendRPC(
                InvestmentSystemRequest.CreateBuilder()
                .SetRequestId(request_id)
                .SetSessionId(request_id)
                .SetTimestamp(timestamp)
                .SetType(InvestmentSystemRequest.Types.RequestType.COMMAND)
                .SetDelegate(System.Text.Encoding.UTF8.GetString(hades_request.ToByteArray()))
                .Build());

            InvestmentSystemOneData invsys_one_data =
                InvestmentSystemOneData.ParseFrom(response.Delegate);

            foreach (Timebar timebar in invsys_one_data.TimebarList)
            {
                chartPanel.UpdateTimebarData(timebar, true);
            }

            foreach (Trend trend in invsys_one_data.TrendList)
            {
                chartPanel.AddTrendData(trend);
            }

            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();
            loginFlag = true;
        }
Exemple #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();
            }
        }