コード例 #1
0
        private void fClient_Load(object sender, EventArgs e)
        {
            if (File.Exists("_lastguid"))
            {
                _LastUserID = File.ReadAllText("_lastguid");
            }

            TMainModel.OBInit();
            TMainModel.TRHInit();


            TMainModel.SetOrderBook(_GlobalOrderBook);
            TMainModel.SetOrderTradeHistory(_TradeHistory);

            _GlobalOrderBook = TMainModel.GetOrderBook();
            _TradeHistory    = TMainModel.GetTradeHistory();



            dgvOB.AutoGenerateColumns           = false;
            dgvTradeHistory.AutoGenerateColumns = false;
            dgvMyOrders.AutoGenerateColumns     = false;
        }
コード例 #2
0
        private async void UPDateData(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    Invoke((MethodInvoker) delegate
                    {
                        if (_UserID.Length == 0)
                        {
                            _UserID = TMainModel.GetCurrentUserID();
                        }
                        this.Text = _ActiveConnection ? $"{_CapStr}({_UserID}) ob.CNT:{_GlobalOrderBook?.Orders?.Count}" : "noConnection";
                    });


                    _GlobalOrderBook = TMainModel.GetOrderBook();
                    _TradeHistory    = TMainModel.GetTradeHistory();

                    if (_LastOrderCNTInOB != _GlobalOrderBook.Orders?.Count() && _GlobalOrderBook.Orders != null)
                    {
                        try
                        {
                            var qmyorders = _GlobalOrderBook.Orders
                                            .Where(w => (w.Symbol == _CurrSymb && w.UserID == _UserID))
                                            .Select(cl => new
                            {
                                cl.Symbol,
                                cl.Side,
                                cl.Quantity,
                                cl.Price
                            }).ToList();

                            var grOB = _GlobalOrderBook.Orders
                                       .OrderBy(o => o.Price)
                                       .Where(w => w.Symbol == _CurrSymb)
                                       .GroupBy(l => new { l.Side, l.Price })
                                       .Select(cl => new
                            {
                                Symbol    = cl.First().Symbol,
                                MYBIDQTY  = cl.First().Side == TOrderSide.Buy & cl.First().UserID == _UserID ? cl.Sum(s => s.Quantity) : 0,
                                MYASKQTY  = cl.First().Side == TOrderSide.Sell & cl.First().UserID == _UserID ? cl.Sum(s => s.Quantity) : 0,
                                MKTBIDQTY = cl.First().Side == TOrderSide.Buy & cl.First().UserID != _UserID ? cl.Sum(s => s.Quantity) : 0,
                                MKTASKQTY = cl.First().Side == TOrderSide.Sell & cl.First().UserID != _UserID ? cl.Sum(s => s.Quantity) : 0,
                                Price     = cl.First().Price
                            }).ToList();



                            if (InvokeRequired)
                            {
                                Invoke((MethodInvoker) delegate
                                {
                                    dgvOB.DataSource = grOB;
                                    dgvOB.Update();
                                    dgvMyOrders.DataSource = qmyorders;
                                    dgvMyOrders.Update();
                                });
                            }
                            else
                            {
                                dgvOB.DataSource = grOB;
                                dgvOB.Update();
                                dgvMyOrders.DataSource = qmyorders;
                                dgvMyOrders.Update();
                            }

                            _LastOrderCNTInOB = _GlobalOrderBook.Orders.Count();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"UPDateData.dtMyActiveOrders.{ex.Message }", "Network connection problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    if (_LastTradeCNTInTRH != _TradeHistory.TradesList?.Count() && _TradeHistory.TradesList != null)
                    {
                        try
                        {
                            if (InvokeRequired)
                            {
                                Invoke((MethodInvoker) delegate
                                {
                                    dgvTradeHistory.DataSource = _TradeHistory.TradesList.ToList();
                                    dgvTradeHistory.Update();
                                });
                            }
                            else
                            {
                                dgvTradeHistory.DataSource = _TradeHistory.TradesList.ToList();
                                dgvTradeHistory.Update();
                            }
                            _LastTradeCNTInTRH = _TradeHistory.TradesList.Count();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"UPDateData.dtTradeHistory.{ex.Message }", "Network connection problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
                catch (Exception ex)
                { MessageBox.Show($"UPDateData.{ex.Message }", "UPDateData", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
                Thread.Sleep(100);
            }
        }