Inheritance: IConfiguration
コード例 #1
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            var viewModel = new StartupViewModel();
            var view = new Startup();

            viewModel.OkCommand = new RelayCommand(() =>
            {
                int clientId;
                if (!int.TryParse(viewModel.ClientId, out clientId))
                {
                    MessageBox.Show("Client id must be a number");
                    return;
                }

                int serverCommandPort;
                if (!int.TryParse(viewModel.CommandPort, out serverCommandPort))
                {
                    MessageBox.Show("Command port must be a number");
                    return;
                }

                int serverPublishPort;
                if (!int.TryParse(viewModel.PublishPort, out serverPublishPort))
                {
                    MessageBox.Show("Publish port must be a number");
                    return;
                }

                var config = new Configuration
                {
                    ClientId = clientId,
                    ServerAddress = viewModel.ServerAddress,
                    ServerCommandPort = serverCommandPort,
                    ServerPublishPort = serverPublishPort
                };
                StartApplication(config);
                view.Close();
            });

            viewModel.CancelCommand = new RelayCommand(() =>
            {
                view.Close();
                App_OnExit(this, null);
            });

            view.DataContext = viewModel;
            view.ShowDialog();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            config = new Configuration
            {
                ClientId = 99,
                ServerAddress = "localhost",
                ServerCommandPort = 9192,
                ServerPublishPort = 9193
            };

            var dependencyInjection = new DependencyInjection();
            dependencyInjection.Initialize(config);

            var prices = new List<double>();
            for (double x = 0; x < 90; x += 1)
            {
                double val = Math.Round(Math.Sin(x / Math.PI), 4) + 2;
                prices.Add(val);
            }

            string symbol = string.Format("{0}{1}{2}", GetLetter(), GetLetter(), GetLetter());
            var client = DependencyInjection.Container.Resolve<IClient>();
            client.Start(config.ClientId, config.ServerAddress, config.ServerCommandPort, config.ServerPublishPort);
            client.LimitOrderAccepted += (sender, dto) =>
            {
                while (true)
                {
                    for (int c = 0; c < prices.Count; c++)
                    {
                        client.ModifyLimitOrder(dto.ExchangeOrderId, prices[c], 100);
                        Thread.Sleep(0);
                    }
                }
            };

            client.SubmitLimitOrder(symbol, 90, 90, WayEnum.Buy);

            Console.WriteLine("Sending orders on symbol '{0}' ...", symbol);
            Console.ReadKey();
            client.Stop();
        }