Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            DotNetEnv.Env.Load();

            var kafkaConfig = new ProducerConfig {
                BootstrapServers = DotNetEnv.Env.GetString("KAFKA_PRODUCER_HOST")
            };
            var producer = new ProducerBuilder <Null, string>(kafkaConfig).Build();
            var smartCom = new StServerClass();
            var logger   = new ConsoleLogger();

            ServerEventsListener listener = new ServerEventsListener(smartCom, producer, logger);

            listener.Start();

            smartCom.connect(
                DotNetEnv.Env.GetString("SMARTCOM_SERVER_HOST"),
                (ushort)DotNetEnv.Env.GetDouble("SMARTCOM_SERVER_PORT"),
                DotNetEnv.Env.GetString("SMARTCOM_SERVER_LOGIN"),
                DotNetEnv.Env.GetString("SMARTCOM_SERVER_PASSWORD")
                );

            var gRpcPort = new ServerPort(
                "",
                DotNetEnv.Env.GetInt("GRPC_PORT"),
                ServerCredentials.Insecure
                );

            var brokerService = new BrokerService(smartCom, logger);

            Server server = new Server
            {
                Services = { ITICapitalAPI.BindService(brokerService) },
                Ports    = { gRpcPort }
            };

            server.Start();

            logger.Write($"Start gRPC on {gRpcPort.Host}:{gRpcPort.Port}");
            logger.Write($"Listen kafka on {kafkaConfig.BootstrapServers}");

            var isStopped = false;

            AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) =>
            {
                isStopped = true;
                logger.Write("Stop signal");
            };

            while (!isStopped)
            {
            }

            logger.Write("Stopping gRPC and SmartCOM...");

            smartCom.disconnect();
            server.ShutdownAsync().Wait();

            logger.Write("Stopped");
        }
Ejemplo n.º 2
0
        public void Connect()
        {
            if (SmartServer == null)
            {
                SmartServer = new StServerClass();
                SmartServer.ConfigureClient("logLevel=0;maxWorkerThreads=10");

                SmartServer.Connected            += SmartServerOnConnected;
                SmartServer.Disconnected         += SmartServerOnDisconnected;
                SmartServer.AddSymbol            += SmartServerOnAddSymbol;
                SmartServer.AddPortfolio         += SmartServerOnAddPortfolio;
                SmartServer.SetPortfolio         += SmartServerOnSetPortfolio;
                SmartServer.UpdatePosition       += SmartServerOnUpdatePosition;
                SmartServer.AddTick              += SmartServerOnAddTick;
                SmartServer.AddTrade             += SmartServerOnAddTrade;
                SmartServer.AddBar               += SmartServerOnAddBar;
                SmartServer.UpdateBidAsk         += SmartServerOnUpdateBidAsk;
                SmartServer.UpdateOrder          += SmartServerOnUpdateOrder;
                SmartServer.OrderFailed          += SmartServerOnOrderFailed;
                SmartServer.OrderSucceeded       += SmartServerOnOrderSucceeded;
                SmartServer.OrderCancelFailed    += SmartServerOnOrderCancelFailed;
                SmartServer.OrderCancelSucceeded += SmartServerOnOrderCancelSucceeded;
            }

            string ip           = ((ServerParameterString)ServerParameters[0]).Value;
            ushort port         = Convert.ToUInt16(((ServerParameterString)ServerParameters[1]).Value);
            string username     = ((ServerParameterString)ServerParameters[2]).Value;
            string userpassword = ((ServerParameterPassword)ServerParameters[3]).Value;

            SmartServer.connect(ip, port, username, userpassword);

            Thread.Sleep(10000);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Метод подключения к серверу
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button1_Click(object sender, EventArgs e)
 {
     if (SmartCom.IsConnected())
     {
         try
         {
             label3.Text = $"[{DateTime.Now}]: Выполняется отключение.....";
             SmartCom.disconnect();
         }
         catch { label3.Text = $"[{DateTime.Now}]: Возникла ошибка!"; }
     }
     else
     {
         try
         {
             label3.Text = $"[{DateTime.Now}]: Выполняется подключение.....";
             SmartCom.connect("mx2.ittrade.ru", 8443, Login, Password);
             SmartCom.Connected    += ConStatus;
             SmartCom.Disconnected += DisConStatus;
         }
         catch (Exception ex)
         {
             label3.Text = $"[{DateTime.Now}]: {ex.Message}!";
         }
     }
 }