예제 #1
0
        /// <summary>
        /// пользователь изменил тип сервера для подключения
        /// </summary>
        void ComboBoxTypeServer_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            try
            {
                List <IServer> serversAll = ServerMaster.GetServers();

                IServer server = serversAll.Find(server1 => server1.ServerType == _selectedType);

                if (server != null)
                {
                    server.SecuritiesChangeEvent -= server_SecuritiesCharngeEvent;
                    server.PortfoliosChangeEvent -= server_PortfoliosChangeEvent;
                }

                Enum.TryParse(ComboBoxTypeServer.SelectedItem.ToString(), true, out _selectedType);

                IServer server2 = serversAll.Find(server1 => server1.ServerType == _selectedType);

                if (server2 != null)
                {
                    server2.SecuritiesChangeEvent += server_SecuritiesCharngeEvent;
                    server2.PortfoliosChangeEvent += server_PortfoliosChangeEvent;
                }
                LoadPortfolioOnBox();
                LoadClassOnBox();
                LoadSecurityOnBox();
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
        /// <summary>
        /// user requested closing order by number
        /// пользователь запросил закрытие ордера по номеру
        /// </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 || order.State == OrderStateType.Pending)
                    &&
                    !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);
            }
        }
        /// <summary>
        /// user requested closing all orders
        /// пользователь запросил закрытие всех ордеров
        /// </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>
        /// incoming events. a new server has been deployed in server-master
        /// входящее событие. В сервермастере был развёрнут новый сервер
        /// </summary>
        private void ServerMaster_ServerCreateEvent(IServer server)
        {
            List <IServer> servers = ServerMaster.GetServers();

            for (int i = 0; i < servers.Count; i++)
            {
                try
                {
                    if (servers[i] == null)
                    {
                        continue;
                    }
                    if (servers[i].ServerType == ServerType.Optimizer)
                    {
                        continue;
                    }
                    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;
                }
                catch
                {
                    // ignore
                }
            }
        }
예제 #5
0
        /// <summary>
        /// constructor
        /// конструктор
        /// </summary>
        /// <param name="isTester">shows whether the method is called from the tester / вызывается ли метод из тестера </param>
        public ServerMasterUi(bool isTester)
        {
            InitializeComponent();

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

            if (isTester)
            {
                servers = ServerMaster.GetServers();

                if (servers == null ||
                    servers.Find(s => s.ServerType == ServerType.Tester) == null)
                {
                    ServerMaster.CreateServer(ServerType.Tester, false);
                }

                Close();

                servers = ServerMaster.GetServers();
                servers.Find(s => s.ServerType == ServerType.Tester).ShowDialog();
            }

            Title           = OsLocalization.Market.TitleServerMasterUi;
            TabItem1.Header = OsLocalization.Market.TabItem1;
            TabItem2.Header = OsLocalization.Market.TabItem2;
            CheckBoxServerAutoOpen.Content = OsLocalization.Market.Label20;

            ServerMasterPainter painter = new ServerMasterPainter(HostSource, HostLog, CheckBoxServerAutoOpen);

            Closing += delegate(object sender, CancelEventArgs args)
            {
                painter.Dispose();
                painter = null;
            };
        }
예제 #6
0
        public ServerMasterPainter(WindowsFormsHost hostServers,
                                   WindowsFormsHost hostLog,
                                   System.Windows.Controls.CheckBox boxCreateServerАutomatically)
        {
            _boxCreateServerАutomatically = boxCreateServerАutomatically;

            _hostServers = hostServers;

            _hostLog = hostLog;

            _boxCreateServerАutomatically.IsChecked = ServerMaster.NeadToConnectAuto;
            _boxCreateServerАutomatically.Click    += CheckBoxServerAutoOpen_Click;

            ServerMaster.Log.StartPaint(_hostLog);

            _servers = ServerMaster.GetServers();

            for (int i = 0; _servers != null && i < _servers.Count; i++)
            {
                _servers[i].ConnectStatusChangeEvent += ServerStatusChangeEvent;
            }

            ServerMaster.ServerCreateEvent += ServerMasterOnServerCreateEvent;

            CreateSourceGrid();
            RePaintSourceGrid();
        }
예제 #7
0
        /// <summary>
        /// constructor
        /// конструктор
        /// </summary>
        /// <param name="isTester">shows whether the method is called from the tester / вызывается ли метод из тестера </param>
        public ServerMasterUi(bool isTester)
        {
            InitializeComponent();

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

            if (isTester)
            {
                servers = ServerMaster.GetServers();

                if (servers == null ||
                    servers.Find(s => s.ServerType == ServerType.Tester) == null)
                {
                    ServerMaster.CreateServer(ServerType.Tester, false);
                }

                Close();

                servers = ServerMaster.GetServers();
                servers.Find(s => s.ServerType == ServerType.Tester).ShowDialog();
            }

            CreateSourceGrid();
            RePaintSourceGrid();

            CheckBoxServerAutoOpen.IsChecked = ServerMaster.NeadToConnectAuto;
            CheckBoxServerAutoOpen.Click    += CheckBoxServerAutoOpen_Click;

            ServerMaster.Log.StartPaint(HostLog);

            for (int i = 0; servers != null && i < servers.Count; i++)
            {
                servers[i].ConnectStatusChangeEvent += ServerStatusChangeEvent;
            }

            Title           = OsLocalization.Market.TitleServerMasterUi;
            TabItem1.Header = OsLocalization.Market.TabItem1;
            TabItem2.Header = OsLocalization.Market.TabItem2;
            CheckBoxServerAutoOpen.Content = OsLocalization.Market.Label20;

            ServerMaster.ServerCreateEvent += ServerMasterOnServerCreateEvent;

            Closing += delegate(object sender, CancelEventArgs args)
            {
                ServerMaster.ServerCreateEvent -= ServerMasterOnServerCreateEvent;

                for (int i = 0; servers != null && i < servers.Count; i++)
                {
                    IServer serv = servers[i];

                    if (serv == null)
                    {
                        continue;
                    }

                    serv.ConnectStatusChangeEvent -= ServerStatusChangeEvent;
                }
            };
        }
예제 #8
0
        /// <summary>
        /// перерисовать таблицу источников
        /// </summary>
        private void RePaintSourceGrid()
        {
            if (_gridSources.InvokeRequired)
            {
                _gridSources.Invoke(new Action(RePaintSourceGrid));
                return;
            }

            _gridSources.Rows.Clear();

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

            List <ServerType> serverTypes = ServerMaster.ServersTypes;

            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);

                serverTypes.Remove(serverTypes.Find(s => s == servers[i].ServerType));

                if (servers[i].ServerStatus == ServerConnectStatus.Connect)
                {
                    DataGridViewCellStyle style = new DataGridViewCellStyle();
                    style.BackColor          = Color.MediumSeaGreen;
                    style.SelectionBackColor = Color.Green;
                    style.ForeColor          = Color.Black;
                    style.SelectionForeColor = Color.Black;
                    row1.Cells[1].Style      = style;
                    row1.Cells[0].Style      = style;
                }
                else
                {
                    DataGridViewCellStyle style = new DataGridViewCellStyle();
                    style.BackColor          = Color.Coral;
                    style.SelectionBackColor = Color.Chocolate;
                    style.ForeColor          = Color.Black;
                    style.SelectionForeColor = Color.Black;
                    row1.Cells[1].Style      = style;
                    row1.Cells[0].Style      = style;
                }
            }

            for (int i = 0; i < serverTypes.Count; i++)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = serverTypes[i].ToString();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disabled";
                _gridSources.Rows.Add(row1);
            }
        }
예제 #9
0
        /// <summary>
        /// выгрузить данные из хранилища на форму
        /// </summary>
        private void LoadSecurityOnBox()
        {
            try
            {
                List <IServer> serversAll = ServerMaster.GetServers();

                IServer server = serversAll.Find(server1 => server1.ServerType == _selectedType);

                if (server == null)
                {
                    return;
                }
                // стираем всё

                ComboBoxSecurities.Items.Clear();
                // грузим инструменты доступные для скачивания

                var securities = server.Securities;

                if (securities != null)
                {
                    for (int i = 0; i < securities.Count; i++)
                    {
                        string classSec = securities[i].NameClass;
                        if (ComboBoxClass.SelectedItem != null && classSec == ComboBoxClass.SelectedItem.ToString())
                        {
                            ComboBoxSecurities.Items.Add(securities[i].Name);
                            ComboBoxSecurities.SelectedItem = securities[i];
                        }
                    }
                }

                // грузим уже запущенные инструменты

                string paper = _connectorBot.NamePaper;

                if (paper != null)
                {
                    ComboBoxSecurities.Text = paper;

                    if (ComboBoxSecurities.Text == null)
                    {
                        ComboBoxSecurities.Items.Add(_connectorBot.NamePaper);
                        ComboBoxSecurities.Text = _connectorBot.NamePaper;
                    }
                }
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
예제 #10
0
        private void ServerMasterOnServerCreateEvent(IServer newServer)
        {
            List <IServer> servers = ServerMaster.GetServers();

            for (int i = 0; i < servers.Count; i++)
            {
                if (servers[i].ServerType == ServerType.Optimizer)
                {
                    continue;
                }
                servers[i].ConnectStatusChangeEvent -= ServerStatusChangeEvent;
                servers[i].ConnectStatusChangeEvent += ServerStatusChangeEvent;
            }
            RePaintSourceGrid();
        }
예제 #11
0
        /// <summary>
        /// double click evet on the source table
        /// событие двойного клика на таблицу источников
        /// </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)
            {
                // need to create a server for the first time
                // нужно впервые создать сервер
                ServerMaster.CreateServer(type, true);

                servers = ServerMaster.GetServers();

                if (servers == null)
                { // something went wrong / что-то пошло не так
                    return;
                }
                else
                { // subscribe to the change status event / подписываемся на событие изменения статуса
                    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;
            }

            myServer.ShowDialog();
        }
예제 #12
0
        private void GetTimeFramesInTester()
        {
            if (ComboBoxSecurities.SelectedItem == null)
            {
                return;
            }
            TesterServer server = (TesterServer)ServerMaster.GetServers()[0];

            if (server.TypeTesterData != TesterDataType.Candle)
            {
                return;
            }

            List <SecurityTester> securities = server.SecuritiesTester;

            string name = ComboBoxSecurities.SelectedItem.ToString();

            string lastTf = null;

            if (ComboBoxTimeFrame.SelectedItem != null)
            {
                lastTf = ComboBoxTimeFrame.SelectedItem.ToString();
            }

            ComboBoxTimeFrame.Items.Clear();

            for (int i = 0; i < securities.Count; i++)
            {
                if (name == securities[i].Security.Name)
                {
                    ComboBoxTimeFrame.Items.Add(securities[i].TimeFrame);
                }
            }
            if (lastTf == null)
            {
                ComboBoxTimeFrame.SelectedItem = securities[0].TimeFrame;
            }
            else
            {
                TimeFrame oldFrame;
                Enum.TryParse(lastTf, out oldFrame);

                ComboBoxTimeFrame.SelectedItem = oldFrame;
            }
        }
예제 #13
0
        /// <summary>
        /// показать окно настроек
        /// </summary>
        public void ShowDialog()
        {
            try
            {
                if (ServerMaster.GetServers() == null)
                {
                    AlertMessageSimpleUi uiMessage = new AlertMessageSimpleUi("Ни одного соединения с биржей не найдено! " +
                                                                              " Нажмите на кнопку ^Сервер^ ");
                    uiMessage.Show();
                    return;
                }

                ConnectorUi ui = new ConnectorUi(this);
                ui.LogMessageEvent += SendNewLogMessage;
                ui.ShowDialog();
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
예제 #14
0
        /// <summary>
        /// конструктор
        /// </summary>
        /// <param name="isTester">вызывается ли метод из тестера</param>
        public ServerMasterUi(bool isTester)
        {
            InitializeComponent();

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

            if (isTester)
            {
                servers = ServerMaster.GetServers();

                if (servers == null ||
                    servers.Find(s => s.ServerType == ServerType.Tester) == null)
                {
                    ServerMaster.CreateServer(ServerType.Tester, false);
                }

                Close();

                servers = ServerMaster.GetServers();
                servers.Find(s => s.ServerType == ServerType.Tester).ShowDialog();
            }

            CreateSourceGrid();
            RePaintSourceGrid();

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

            ServerMaster.Log.StartPaint(HostLog);

            for (int i = 0; servers != null && i < servers.Count; i++)
            {
                servers[i].ConnectStatusChangeEvent += ServerStatusChangeEvent;
            }
        }
        /// <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 lmaxIsOn     = false;
            bool bitfinex     = false;
            bool bitMexIsOn   = false;
            bool quikIsOn     = false;
            bool smartcomIsOn = false;
            bool plazaIsOn    = false;
            bool ibIsOn       = false;
            bool astsIsOn     = false;
            bool quikLuaIsOn  = false;
            bool oandaIsOn    = false;
            bool krakenIsOn   = false;
            bool bitStampIsOn = false;
            bool binanceIsOn  = false;
            bool ninjaIsOn    = 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.Lmax)
                {
                    lmaxIsOn = true;
                }

                if (type == ServerType.Bitfinex)
                {
                    bitfinex = true;
                }

                if (type == ServerType.Binance)
                {
                    binanceIsOn = true;
                }

                if (type == ServerType.NinjaTrader)
                {
                    ninjaIsOn = true;
                }

                if (type == ServerType.BitStamp)
                {
                    bitStampIsOn = true;
                }

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

                if (type == ServerType.Kraken)
                {
                    krakenIsOn = 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.AstsBridge)
                {
                    astsIsOn = true;
                }
            }

            if (lmaxIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Lmax;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            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 (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 (ninjaIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.NinjaTrader;
                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 (binanceIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Binance;
                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 (bitfinex == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Bitfinex;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (krakenIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.Kraken;
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[1].Value = "Disconnect";
                _gridSources.Rows.Add(row1);
            }
            if (bitStampIsOn == false)
            {
                DataGridViewRow row1 = new DataGridViewRow();
                row1.Cells.Add(new DataGridViewTextBoxCell());
                row1.Cells[0].Value = ServerType.BitStamp;
                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 (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);
            }
        }
예제 #16
0
        private void LoadTimeFrameBox()
        {
            ComboBoxTimeFrame.Items.Clear();

            if (ServerMaster.StartProgram == ServerStartProgramm.IsTester)
            {
                // таймФрейм
                TesterServer server = (TesterServer)ServerMaster.GetServers()[0];
                if (server.TypeTesterData != TesterDataType.Candle)
                {
                    // если строим данные на тиках или стаканах, то можно использовать любой ТФ
                    // менеджер свечей построит любой
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Day);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Hour2);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Hour1);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min45);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min30);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min20);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min15);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min10);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min5);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min3);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min2);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Min1);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec30);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec20);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec15);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec10);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec5);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec2);
                    ComboBoxTimeFrame.Items.Add(TimeFrame.Sec1);

                    ComboBoxCandleMarketDataType.SelectedItem = CandleMarketDataType.Tick;
                    ComboBoxCandleMarketDataType.IsEnabled    = false;
                }
                else
                {
                    // далее, если используем готовые свечки, то нужно ставить только те ТФ, которые есть
                    // и вставляются они только когда мы выбираем бумагу в методе

                    ComboBoxSecurities.SelectionChanged += ComboBoxSecurities_SelectionChanged;
                    GetTimeFramesInTester();
                    ComboBoxCandleCreateMethodType.SelectedItem = CandleCreateMethodType.Simple;
                    ComboBoxCandleCreateMethodType.IsEnabled    = false;

                    ComboBoxCandleMarketDataType.SelectedItem = CandleMarketDataType.Tick;
                    ComboBoxCandleMarketDataType.IsEnabled    = false;
                }
            }
            else
            {
                ComboBoxTimeFrame.Items.Add(TimeFrame.Day);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Hour2);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Hour1);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min45);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min30);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min20);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min15);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min10);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min5);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min3);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min2);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Min1);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec30);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec20);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec15);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec10);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec5);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec2);
                ComboBoxTimeFrame.Items.Add(TimeFrame.Sec1);

                CandleMarketDataType createType = CandleMarketDataType.Tick;
                if (ComboBoxCandleMarketDataType.SelectedItem != null)
                {
                    Enum.TryParse(ComboBoxCandleMarketDataType.SelectedItem.ToString(), true, out createType);
                }
            }

            ComboBoxTimeFrame.SelectedItem = _connectorBot.TimeFrame;

            if (ComboBoxTimeFrame.SelectedItem == null)
            {
                ComboBoxTimeFrame.SelectedItem = TimeFrame.Min1;
            }
        }
예제 #17
0
        public ConnectorUi(Connector connectorBot)
        {
            try
            {
                InitializeComponent();

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

                if (servers == null)
                {// если сервер для подключения к бирже ещё не создан
                    Close();
                    return;
                }

                // сохраняем коннекторы
                _connectorBot = connectorBot;

                // загружаем настройки в контролы
                for (int i = 0; i < servers.Count; i++)
                {
                    ComboBoxTypeServer.Items.Add(servers[i].ServerType);
                }

                if (connectorBot.ServerType != ServerType.Unknown)
                {
                    ComboBoxTypeServer.SelectedItem = connectorBot.ServerType;
                    _selectedType = connectorBot.ServerType;
                }
                else
                {
                    ComboBoxTypeServer.SelectedItem = servers[0].ServerType;
                    _selectedType = servers[0].ServerType;
                }

                if (ServerMaster.StartProgram == ServerStartProgramm.IsTester)
                {
                    ComboBoxTypeServer.IsEnabled    = false;
                    CheckBoxIsEmulator.IsEnabled    = false;
                    CheckBoxSetForeign.IsEnabled    = false;
                    ComboBoxTypeServer.SelectedItem = ServerType.Tester;
                    //ComboBoxClass.SelectedItem = ServerMaster.GetServers()[0].Securities[0].NameClass;
                    //ComboBoxPortfolio.SelectedItem = ServerMaster.GetServers()[0].Portfolios[0].Number;

                    connectorBot.ServerType = ServerType.Tester;
                    _selectedType           = ServerType.Tester;
                }



                LoadClassOnBox();

                LoadSecurityOnBox();

                LoadPortfolioOnBox();

                ComboBoxClass.SelectionChanged += ComboBoxClass_SelectionChanged;

                CheckBoxIsEmulator.IsChecked = _connectorBot.EmulatorIsOn;

                CheckBoxSetForeign.IsChecked = _connectorBot.SetForeign;

                ComboBoxTypeServer.SelectionChanged += ComboBoxTypeServer_SelectionChanged;

                BoxTimeFrame.SelectionChanged += BoxTimeFrame_SelectionChanged;

                CreateTimeFrameBox();

                BoxTimeFrame.ToolTip = "ТФ Delta не имеет чёткого критерия закрытия и закрывает свечи по изменению дельты \n(разницы между объёмом текущих покупок и продаж прошедших с утра) на N(настраивается отдельно) пунктов";



                BoxTimeCandleCreateType.Items.Add(CandleSeriesCreateDataType.Tick);
                BoxTimeCandleCreateType.Items.Add(CandleSeriesCreateDataType.MarketDepth);
                BoxTimeCandleCreateType.SelectedItem      = _connectorBot.CandleCreateType;
                BoxTimeCandleCreateType.SelectionChanged += BoxTimeCandleCreateType_SelectionChanged;
                TextBoxCountTradesInCandle.Text           = _connectorBot.CountTradeInCandle.ToString();
                TextBoxCountTradesInCandle.TextChanged   += TextBoxCountTradesInCandle_TextChanged;
            }
            catch (Exception error)
            {
                MessageBox.Show("Ошибка в конструкторе " + error);
            }
        }
예제 #18
0
        /// <summary>
        /// поместить классы в окно
        /// </summary>
        private void LoadClassOnBox()
        {
            try
            {
                if (!ComboBoxClass.Dispatcher.CheckAccess())
                {
                    ComboBoxClass.Dispatcher.Invoke(LoadClassOnBox);
                    return;
                }
                List <IServer> serversAll = ServerMaster.GetServers();

                IServer server = serversAll.Find(server1 => server1.ServerType == _selectedType);

                if (server == null)
                {
                    return;
                }

                if (ComboBoxClass.Items.Count != 0)
                {
                    ComboBoxClass.Items.Clear();
                }

                var securities = server.Securities;

                ComboBoxClass.Items.Clear();

                if (securities == null)
                {
                    return;
                }

                for (int i1 = 0; i1 < securities.Count; i1++)
                {
                    string clas = securities[i1].NameClass;

                    if (ComboBoxClass.Items.Count == 0)
                    {
                        ComboBoxClass.Items.Add(clas);
                        continue;
                    }

                    bool isInArray = false;

                    for (int i = 0; i < ComboBoxClass.Items.Count; i++)
                    {
                        string item = ComboBoxClass.Items[i].ToString();
                        if (item == clas)
                        {
                            isInArray = true;
                            break;
                        }
                    }

                    if (isInArray == false)
                    {
                        ComboBoxClass.Items.Add(clas);
                    }
                }
                if (_connectorBot.Security != null)
                {
                    ComboBoxClass.SelectedItem = _connectorBot.Security.NameClass;
                }
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
예제 #19
0
        /// <summary>
        /// выгружает счета на форму
        /// </summary>
        private void LoadPortfolioOnBox()
        {
            try
            {
                List <IServer> serversAll = ServerMaster.GetServers();

                IServer server = serversAll.Find(server1 => server1.ServerType == _selectedType);

                if (server == null)
                {
                    return;
                }


                if (!ComboBoxClass.CheckAccess())
                {
                    ComboBoxClass.Dispatcher.Invoke(LoadPortfolioOnBox);
                    return;
                }

                string curPortfolio = null;

                if (ComboBoxPortfolio.SelectedItem != null)
                {
                    curPortfolio = ComboBoxPortfolio.SelectedItem.ToString();
                }

                ComboBoxPortfolio.Items.Clear();


                string portfolio = _connectorBot.PortfolioName;


                if (portfolio != null)
                {
                    ComboBoxPortfolio.Items.Add(_connectorBot.PortfolioName);
                    ComboBoxPortfolio.Text = _connectorBot.PortfolioName;
                }

                List <Portfolio> portfolios = server.Portfolios;

                if (portfolios == null)
                {
                    return;
                }

                for (int i = 0; i < portfolios.Count; i++)
                {
                    bool isInArray = false;

                    for (int i2 = 0; i2 < ComboBoxPortfolio.Items.Count; i2++)
                    {
                        if (ComboBoxPortfolio.Items[i2].ToString() == portfolios[i].Number)
                        {
                            isInArray = true;
                        }
                    }

                    if (isInArray == true)
                    {
                        continue;
                    }
                    ComboBoxPortfolio.Items.Add(portfolios[i].Number);
                }
                if (curPortfolio != null)
                {
                    for (int i = 0; i < ComboBoxPortfolio.Items.Count; i++)
                    {
                        if (ComboBoxPortfolio.Items[i].ToString() == curPortfolio)
                        {
                            ComboBoxPortfolio.SelectedItem = curPortfolio;
                            break;
                        }
                    }
                }
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
예제 #20
0
        /// <summary>
        /// подписаться на получение свечек
        /// </summary>
        private void Subscrable()
        {
            try
            {
                while (true)
                {
                    Thread.Sleep(50);

                    if (_neadToStopThread)
                    {
                        return;
                    }

                    if (ServerType == ServerType.Unknown ||
                        string.IsNullOrWhiteSpace(NamePaper))
                    {
                        continue;
                    }

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

                    if (servers == null)
                    {
                        if (ServerType != ServerType.Unknown)
                        {
                            ServerMaster.SetNeedServer(ServerType);
                        }
                        continue;
                    }

                    _myServer = servers.Find(server => server.ServerType == ServerType);

                    if (_myServer == null)
                    {
                        if (ServerType != ServerType.Unknown)
                        {
                            ServerMaster.SetNeedServer(ServerType);
                        }
                        continue;
                    }
                    else
                    {
                        _myServer.NewBidAscIncomeEvent  -= ConnectorBotNewBidAscIncomeEvent;
                        _myServer.NewMyTradeEvent       -= ConnectorBot_NewMyTradeEvent;
                        _myServer.NewOrderIncomeEvent   -= ConnectorBot_NewOrderIncomeEvent;
                        _myServer.NewMarketDepthEvent   -= ConnectorBot_NewMarketDepthEvent;
                        _myServer.NewTradeEvent         -= ConnectorBot_NewTradeEvent;
                        _myServer.TimeServerChangeEvent -= myServer_TimeServerChangeEvent;
                        _myServer.NeadToReconnectEvent  -= _myServer_NeadToReconnectEvent;

                        _myServer.NewBidAscIncomeEvent  += ConnectorBotNewBidAscIncomeEvent;
                        _myServer.NewMyTradeEvent       += ConnectorBot_NewMyTradeEvent;
                        _myServer.NewOrderIncomeEvent   += ConnectorBot_NewOrderIncomeEvent;
                        _myServer.NewMarketDepthEvent   += ConnectorBot_NewMarketDepthEvent;
                        _myServer.NewTradeEvent         += ConnectorBot_NewTradeEvent;
                        _myServer.TimeServerChangeEvent += myServer_TimeServerChangeEvent;
                        _myServer.NeadToReconnectEvent  += _myServer_NeadToReconnectEvent;

                        if (ServerMaster.StartProgram == ServerStartProgramm.IsTester)
                        {
                            ((TesterServer)_myServer).TestingEndEvent -= ConnectorReal_TestingEndEvent;
                            ((TesterServer)_myServer).TestingEndEvent += ConnectorReal_TestingEndEvent;
                        }
                    }

                    Thread.Sleep(50);

                    ServerConnectStatus stat = _myServer.ServerStatus;

                    if (stat != ServerConnectStatus.Connect)
                    {
                        continue;
                    }
                    lock (_subscrableLocker)
                    {
                        if (_mySeries == null)
                        {
                            while (_mySeries == null)
                            {
                                if (_neadToStopThread)
                                {
                                    return;
                                }

                                Thread.Sleep(100);
                                _mySeries = _myServer.StartThisSecurity(_namePaper, TimeFrameBuilder);
                            }


                            _mySeries.СandleUpdeteEvent   += MySeries_СandleUpdeteEvent;
                            _mySeries.СandleFinishedEvent += MySeries_СandleFinishedEvent;
                            _subscrabler = null;
                        }
                    }

                    _subscrabler = null;
                    return;
                }
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
예제 #21
0
        public ConnectorUi(Connector connectorBot)
        {
            try
            {
                InitializeComponent();

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

                if (servers == null)
                {// если сервер для подключения к бирже ещё не создан
                    Close();
                    return;
                }

                // сохраняем коннекторы
                _connectorBot = connectorBot;

                // загружаем настройки в контролы
                for (int i = 0; i < servers.Count; i++)
                {
                    ComboBoxTypeServer.Items.Add(servers[i].ServerType);
                }

                if (connectorBot.ServerType != ServerType.Unknown)
                {
                    ComboBoxTypeServer.SelectedItem = connectorBot.ServerType;
                    _selectedType = connectorBot.ServerType;
                }
                else
                {
                    ComboBoxTypeServer.SelectedItem = servers[0].ServerType;
                    _selectedType = servers[0].ServerType;
                }

                if (ServerMaster.StartProgram == ServerStartProgramm.IsTester)
                {
                    ComboBoxTypeServer.IsEnabled    = false;
                    CheckBoxIsEmulator.IsEnabled    = false;
                    CheckBoxSetForeign.IsEnabled    = false;
                    ComboBoxTypeServer.SelectedItem = ServerType.Tester;
                    //ComboBoxClass.SelectedItem = ServerMaster.GetServers()[0].Securities[0].NameClass;
                    //ComboBoxPortfolio.SelectedItem = ServerMaster.GetServers()[0].Portfolios[0].Number;

                    connectorBot.ServerType = ServerType.Tester;
                    _selectedType           = ServerType.Tester;
                }

                LoadClassOnBox();

                LoadSecurityOnBox();

                LoadPortfolioOnBox();

                ComboBoxClass.SelectionChanged += ComboBoxClass_SelectionChanged;

                CheckBoxIsEmulator.IsChecked = _connectorBot.EmulatorIsOn;

                ComboBoxTypeServer.SelectionChanged += ComboBoxTypeServer_SelectionChanged;

                ComboBoxCandleMarketDataType.Items.Add(CandleMarketDataType.Tick);
                ComboBoxCandleMarketDataType.Items.Add(CandleMarketDataType.MarketDepth);
                ComboBoxCandleMarketDataType.SelectedItem = _connectorBot.CandleMarketDataType;

                ComboBoxCandleCreateMethodType.Items.Add(CandleCreateMethodType.Simple);
                ComboBoxCandleCreateMethodType.Items.Add(CandleCreateMethodType.Renko);
                ComboBoxCandleCreateMethodType.Items.Add(CandleCreateMethodType.HeikenAshi);
                ComboBoxCandleCreateMethodType.Items.Add(CandleCreateMethodType.Delta);
                ComboBoxCandleCreateMethodType.Items.Add(CandleCreateMethodType.Volume);
                ComboBoxCandleCreateMethodType.Items.Add(CandleCreateMethodType.Ticks);

                ComboBoxCandleCreateMethodType.SelectedItem = _connectorBot.CandleCreateMethodType;

                CheckBoxSetForeign.IsChecked = _connectorBot.SetForeign;

                LoadTimeFrameBox();

                TextBoxCountTradesInCandle.Text         = _connectorBot.CountTradeInCandle.ToString();
                _countTradesInCandle                    = _connectorBot.CountTradeInCandle;
                TextBoxCountTradesInCandle.TextChanged += TextBoxCountTradesInCandle_TextChanged;

                TextBoxVolumeToClose.Text         = _connectorBot.VolumeToCloseCandleInVolumeType.ToString();
                _volumeToClose                    = _connectorBot.VolumeToCloseCandleInVolumeType;
                TextBoxVolumeToClose.TextChanged += TextBoxVolumeToClose_TextChanged;

                TextBoxRencoPunkts.Text         = _connectorBot.RencoPunktsToCloseCandleInRencoType.ToString();
                _rencoPuncts                    = _connectorBot.RencoPunktsToCloseCandleInRencoType;
                TextBoxRencoPunkts.TextChanged += TextBoxRencoPunkts_TextChanged;

                TextBoxDeltaPeriods.Text         = _connectorBot.DeltaPeriods.ToString();
                TextBoxDeltaPeriods.TextChanged += TextBoxDeltaPeriods_TextChanged;
                _deltaPeriods = _connectorBot.DeltaPeriods;

                ShowDopCandleSettings();

                ComboBoxCandleCreateMethodType.SelectionChanged += ComboBoxCandleCreateMethodType_SelectionChanged;
            }
            catch (Exception error)
            {
                MessageBox.Show("Ошибка в конструкторе " + error);
            }
        }