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); }
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"); }
public void Dispose() { try { lock (_smartComServerLocker) { if (SmartServer != null && SmartServer.IsConnected()) { SmartServer.disconnect(); } } } catch (Exception error) { SendLogMessage(error.ToString(), LogMessageType.Error); } if (SmartServer != null) { 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; } _startedSecurities = new List <string>(); _numsSendToExecuteOrders = new List <TransactioinSmartComSendState>(); _numsSendToCancelOrders = new List <TransactioinSmartComSendState>(); _numsIncomeExecuteOrders = new List <int>(); _numsIncomeCancelOrders = new List <int>(); lock (_smartComServerLocker) { SmartServer = null; } ServerStatus = ServerConnectStatus.Disconnect; }
public ServerEventsListener(StServerClass server, IProducer <Null, string> kafkaProducer, ILogger logger) { _smartCom = server; _producer = kafkaProducer; _logger = logger; }