public frmMonitor() { InitializeComponent(); Dictionary <string, Stock> stks = StocksDefinitions.GetStocks(); comboStocksQueryOrders.DataSource = stks.Values.ToList(); comboStocksQueryOrders.DisplayMember = "NameEn"; comboStocksQueryOrders.ValueMember = "Code"; comboStocksQueryOrders.SelectedIndex = -1; m_LoadDone = true; gridQueryOrders.DataError += gridQueryOrders_DataError; gridSearchOrder.DataError += gridSearchOrder_DataError; gridSessions.DataError += gridSessions_DataError; this.FormClosing += frmMonitor_FormClosing; this.WindowState = FormWindowState.Minimized; }
public bool Handle(IRequestMessage msg) { try { Type msgType = msg.GetType(); if (typeof(IRequestMessage).IsAssignableFrom(msgType)) { if (typeof(NewSingleOrder) == msgType) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); Counters.IncrementCounter(CountersConstants.ClientsNewOrderReqs); NewSingleOrder order = (NewSingleOrder)msg; #region validate client key if (order.ClientKey == Guid.Empty || order.ClientKey == null) { SystemLogger.LogEventAsync(string.Format("ClientKey [{0}] not valid! ", order.ClientKey.ToString())); return(true); } string username = Sessions.GetUsername(order.ClientKey); if (!Sessions.IsSubscribedToSendMsg(username)) { SystemLogger.LogEventAsync(string.Format("ClientKey [{0}] not subscribed", order.ClientKey)); return(true); } #endregion validate client key #region validate stock group Stock stock = StocksDefinitions.GetStockByCode(order.SecurityID); if (stock == null) { Sessions.Push(Sessions.GetUsername(order.ClientKey), new IResponseMessage[] { new Fix_OrderRefusedByService() { ClientKey = order.ClientKey, RefuseMessage = "Stock Not Found!", RequesterOrderID = order.RequesterOrderID } }); } #endregion validate stock group #region validate currency CurrencyItem currency = Currencies.GetCurrencyByCode(stock.CurrencyCode); #endregion validate currency #region validate order details string validation = ValidateOrder(username, order); #endregion validate order details #region not valid order if (validation != "valid") { try { SystemLogger.LogEventAsync(string.Format("OrderRefusedByService RequesterOrderID: {0}, Reason: {1}", order.RequesterOrderID, validation)); Sessions.Push(Sessions.GetUsername(order.ClientKey), new IResponseMessage[] { new Fix_OrderRefusedByService() { ClientKey = order.ClientKey, RefuseMessage = validation, RequesterOrderID = order.RequesterOrderID } }); } catch (Exception ex) { Counters.IncrementCounter(CountersConstants.ExceptionMessages); SystemLogger.LogEventAsync(string.Format("Error sending refused order to the client, ClientKey {0}, Error: {1}", order.ClientKey, ex.Message)); } return(true); } #endregion not valid order OrdersManager.HandleNewSingleOrder(username, order.ClientKey, order.RequesterOrderID, order.ClientID, order.CustodyID, order.SecurityID, order.OrderSide, Math.Round(order.Price, m_orderPriceDigitsRounding), order.Quantity, order.OrderType, DateTime.Now, order.TimeInForce, currency, order.ExchangeID, order.DateTime, stock.GroupID, stock.MarketID, order.HandleInst, order.ExpirationDateTime, order.OptionalParam); sw.Stop(); SystemLogger.LogEventAsync(string.Format("new order handled in {0} ms ", sw.ElapsedMilliseconds)); sw = null; return(true); } } return(false); } catch (Exception ex) { Counters.IncrementCounter(CountersConstants.ExceptionMessages); SystemLogger.LogErrorAsync("NewSingleOrderHandler Error: " + ex.Message); return(true); } }
protected void OnStartInternally(object arguments) { string[] args = (string[])arguments; try { /*if (!IsAdministrator()) * { * // Restart program and run as admin * var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; * ProcessStartInfo startInfo = new ProcessStartInfo(exeName); * startInfo.Verb = "runas"; * System.Diagnostics.Process.Start(startInfo); * Environment.Exit(0); * return; * }*/ // check multiple processes //commented by khazbak to avoid requirement to start in admin mode /* * if (bool.Parse(SystemConfigurations.GetAppSetting("CheckMultipleInstances"))) * { * string currProcName = Process.GetCurrentProcess().ProcessName; * int currProcID = Process.GetCurrentProcess().Id; * Process[] processes = Process.GetProcessesByName(currProcName); * if (processes.Length > 1) * { * foreach (Process p in processes) * { * if (p.Id != currProcID) * { * int id = p.Id; * p.Kill(); * SystemLogger.WriteOnConsoleAsync(true, "Process has been killed ID: " + id, ConsoleColor.Gray, ConsoleColor.White, false); * } * } * } * }*/ Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); SystemLogger.LogEventAsync("Starting FIX Service..."); try { if (bool.Parse(SystemConfigurations.GetAppSetting("ReinitializeCounters"))) { Counters.ReInitialize(); } else { Counters.Initialize(); } } catch (Exception ex) { SystemLogger.WriteOnConsoleAsync(true, "Error initializing counters, Error: " + ex.ToString(), ConsoleColor.Red, ConsoleColor.Black, true); } DatabaseMethods db = new DatabaseMethods(); if (!db.IsTodaySequenceReset()) // reset the counters only if the service starts for first time today { Counters.ResetCounters(); } // Check queue existance if (bool.Parse(SystemConfigurations.GetAppSetting("CheckQueueExistance"))) { CheckAndSetPermissionsToQueues(); } FixExchangesInfo.Initialize(); Currencies.Initialize(); StocksDefinitions.Initialize(); Lookups.Initialize(); string seqFilePath = SystemConfigurations.GetAppSetting("SequenceFilePath"); if (!db.IsTodaySequenceReset()) { SystemLogger.LogEventAsync("Resetting FIX sequence.."); db.UpdateTodaySequenceReset(); SystemLogger.LogEventAsync("Sequence reset successfully"); //try //{ // System.IO.File.Delete(seqFilePath); //} //catch (Exception ex) //{ // Counters.IncrementCounter(CountersConstants.ExceptionMessages); // SystemLogger.WriteOnConsoleAsync(true, "Deleting Sequence File Error: " + ex.Message, ConsoleColor.Red, ConsoleColor.Black, true); //} } Router responsesRouter = new Router(typeof(ResponsesProcessor), int.Parse(SystemConfigurations.GetAppSetting("ResponsesRouterProcessorsNum"))); m_FixSessionStatusChangedDelegate = new FixSessionStatusChangedDelegate(OnFixStatusChange); bool AllowMcsdAllocation = Convert.ToBoolean(SystemConfigurations.GetAppSetting("AllowMcsdAllocation")); // maghrabi if (AllowMcsdAllocation) //MCSD { Router mcsdResponsesRouter = new Router(typeof(ResponsesProcessorMcsd), int.Parse(SystemConfigurations.GetAppSetting("McsdResponsesRouterProcessorsNum"))); McsdGatwayManager.Initialize(mcsdResponsesRouter); // maghrabi McsdGatwayManager.LoginToMCSD(); // maghrabi } string fixClientSettings = Environment.CurrentDirectory + @"\" + SystemConfigurations.GetAppSetting("FixClientSettingsFile"); string fixServerSettings = Environment.CurrentDirectory + @"\" + SystemConfigurations.GetAppSetting("FixServerSettingsFile"); MarketFixClient.Initialize(fixClientSettings, responsesRouter, m_FixSessionStatusChangedDelegate); SvcFixServer.InitializeServer(fixServerSettings); OrdersManager.Initialize(); Sessions.Initialize(); //RepSessions.Initialize(); InitializeService(); if (_resetSequenceNumber) { // MarketFixClient.ResetSequence(); } MarketFixClient.Logon(); SystemLogger.WriteOnConsoleAsync(true, "Awaiting for Fix server response ...", ConsoleColor.Yellow, ConsoleColor.Black, false); System.Windows.Forms.Application.Run(new frmMonitor()); //maghrabi //while (true) { Console.ReadKey(); } //StopService(); } catch (Exception ex) { Counters.IncrementCounter(CountersConstants.ExceptionMessages); SystemLogger.WriteOnConsoleAsync(true, "Main Error: " + ex.ToString(), ConsoleColor.Red, ConsoleColor.Black, true); try { string[] cc = SystemConfigurations.GetAppSetting("SupportMailCC").Split(','); NotificationSender.Send(true, true, false, SystemConfigurations.GetAppSetting("SupportMailFrom"), SystemConfigurations.GetAppSetting("SupportMailTo"), cc, "Fix Service Down", "Fix Service Down", string.Format("Service startup error state on machine {0} at {1}, Error : {2}", SystemConfigurations.GetMachineIP(), DateTime.Now.ToString(), ex.ToString()), null); } catch (Exception inex) { Counters.IncrementCounter(CountersConstants.ExceptionMessages); SystemLogger.WriteOnConsoleAsync(true, "Sending Mail Error: " + inex.Message, ConsoleColor.Red, ConsoleColor.Black, false); } //Console.ReadKey(); } }