示例#1
0
        public ServerMasterUi()
        {
            InitializeComponent();

            List <IServer> servers = ServerMaster.GetServers();

            if (servers == null &&
                ServerMaster.StartProgram == ServerStartProgramm.IsTester)
            { // если это первый вызов сервера во время включённого тестера
                ServerMaster.CreateServer(ServerType.Tester, false);
                servers = ServerMaster.GetServers();
            }

            if (ServerMaster.StartProgram == ServerStartProgramm.IsTester)
            { // если это первый вызов сервера во время включённого тестера
                servers = ServerMaster.GetServers();
                Close();
                servers[0].ShowDialog();
            }

            CreateSourceGrid();
            RePaintSourceGrid();

            CheckBoxServerAutoOpen.IsChecked = ServerMaster.NeadToConnectAuto;
            CheckBoxServerAutoOpen.Click    += CheckBoxServerAutoOpen_Click;
            CheckBoxServerAutoOpen.ToolTip   = "При включении, мастер серверов будет пытаться автоматически развернуть " +
                                               "\r" +
                                               "сервера которые у него запрашивают роботы(панели). По одному разу на каждый сервер. ";

            for (int i = 0; servers != null && i < servers.Count; i++)
            {
                servers[i].ConnectStatusChangeEvent += ServerStatusChangeEvent;
            }
        }
示例#2
0
        /// <summary>
        /// пользователь запросил закрытие ордера по номеру
        /// </summary>
        private void PositionCloseForNumber_Click(object sender, EventArgs e)
        {
            try
            {
                if (_orders == null || _orders.Count == 0)
                {
                    return;
                }

                Order order = _orders[(_orders.Count - 1 - _gridOrders.CurrentCell.RowIndex)];

                if (order.State == OrderStateType.Activ &&
                    !string.IsNullOrEmpty(order.PortfolioNumber))
                {
                    IServer server = ServerMaster.GetServers().Find(server1 => server1.ServerType == order.ServerType);
                    if (server != null)
                    {
                        server.CanselOrder(order);
                    }
                }
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
示例#3
0
        /// <summary>
        /// пользователь запросил закрытие всех ордеров
        /// </summary>
        private void OrdersCloseAll_Click(object sender, EventArgs e)
        {
            try
            {
                if (_orders == null || _orders.Count == 0)
                {
                    return;
                }

                for (int i = 0; i < _orders.Count; i++)
                {
                    if (_orders[i].State == OrderStateType.Activ &&
                        !string.IsNullOrEmpty(_orders[i].PortfolioNumber))
                    {
                        IServer server = ServerMaster.GetServers().Find(server1 => server1.ServerType == _orders[i].ServerType);
                        if (server != null)
                        {
                            server.CanselOrder(_orders[i]);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
示例#4
0
        /// <summary>
        /// входящее событие. В сервермастере был развёрнут новый сервер
        /// </summary>
        private void ServerMaster_ServerCreateEvent()
        {
            List <IServer> servers = ServerMaster.GetServers();

            for (int i = 0; i < servers.Count; i++)
            {
                servers[i].PortfoliosChangeEvent -= _server_PortfoliosChangeEvent;
                servers[i].NewOrderIncomeEvent   -= _server_NewOrderIncomeEvent;
                servers[i].NewMyTradeEvent       -= serv_NewMyTradeEvent;

                servers[i].PortfoliosChangeEvent += _server_PortfoliosChangeEvent;
                servers[i].NewOrderIncomeEvent   += _server_NewOrderIncomeEvent;
                servers[i].NewMyTradeEvent       += serv_NewMyTradeEvent;
            }
        }
示例#5
0
        /// <summary>
        /// событие двойного клика на таблицу источников
        /// </summary>
        void _gridSources_DoubleClick(object sender, EventArgs e)
        {
            if (_gridSources.CurrentCell.RowIndex <= -1)
            {
                return;
            }

            ServerType type;

            Enum.TryParse(_gridSources.SelectedRows[0].Cells[0].Value.ToString(), out type);

            List <IServer> servers = ServerMaster.GetServers();

            if (servers == null ||
                servers.Find(serv => serv.ServerType == type) == null)
            {
                // нужно впервые создать сервер
                ServerMaster.CreateServer(type, true);

                servers = ServerMaster.GetServers();

                if (servers == null)
                { // чтото пошло не так
                    return;
                }
                else
                { // подписываемся на событие изменения статуса
                    IServer myServ = servers.Find(serv => serv.ServerType == type);

                    if (myServ != null)
                    {
                        myServ.ConnectStatusChangeEvent += ServerStatusChangeEvent;
                    }
                }
            }

            IServer myServer = servers.Find(serv => serv.ServerType == type);

            if (myServer == null)
            {
                return;
            }

            Close();

            myServer.ShowDialog();
        }
示例#6
0
        /// <summary>
        /// перерисовать таблицу источников
        /// </summary>
        private void RePaintSourceGrid()
        {
            if (_gridSources.InvokeRequired)
            {
                _gridSources.Invoke(new Action(RePaintSourceGrid));
                return;
            }

            _gridSources.Rows.Clear();

            List <IServer> servers = ServerMaster.GetServers();

            for (int i = 0; servers != null && i < servers.Count; i++)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = servers[i].ServerType;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = servers[i].ServerStatus;
                _gridSources.Rows.Add(row1);
            }

            bool bitMexIsOn   = false;
            bool quikIsOn     = false;
            bool smartcomIsOn = false;
            bool plazaIsOn    = false;
            bool ibIsOn       = false;
            bool finamIsOn    = false;
            bool astsIsOn     = false;
            bool quikLuaIsOn  = false;
            bool oandaIsOn    = false;

            for (int i = 0; i < _gridSources.Rows.Count; i++)
            {
                DataGridViewRow row1 = _gridSources.Rows[i];

                ServerType type;

                Enum.TryParse(row1.Cells[0].Value.ToString(), out type);

                if (type == ServerType.BitMex)
                {
                    bitMexIsOn = true;
                }

                if (type == ServerType.Oanda)
                {
                    oandaIsOn = true;
                }

                if (type == ServerType.QuikLua)
                {
                    quikLuaIsOn = true;
                }

                if (type == ServerType.QuikDde)
                {
                    quikIsOn = true;
                }
                if (type == ServerType.SmartCom)
                {
                    smartcomIsOn = true;
                }
                if (type == ServerType.Plaza)
                {
                    plazaIsOn = true;
                }
                if (type == ServerType.InteractivBrokers)
                {
                    ibIsOn = true;
                }
                if (type == ServerType.Finam)
                {
                    finamIsOn = true;
                }
                if (type == ServerType.AstsBridge)
                {
                    astsIsOn = true;
                }
            }
            if (quikIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.QuikDde;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (plazaIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Plaza;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (smartcomIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.SmartCom;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (bitMexIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.BitMex;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (quikLuaIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.QuikLua;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (oandaIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Oanda;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (astsIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.AstsBridge;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }

            if (ibIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.InteractivBrokers;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (finamIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Finam;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
        }