/// <summary> /// Called when new cancel order request is recieved /// </summary> /// <param name="cancelOrder"></param> public void CancelOrderArrived(Order cancelOrder) { try { foreach (var order in _limitOrders.ToArray()) { if (order.Value.OrderID.Equals(cancelOrder.OrderID)) { _limitOrders.Remove(order.Key); //set order status to cancel cancelOrder.OrderStatus = OrderStatus.CANCELLED; if (CancellationArrived != null) { CancellationArrived(cancelOrder); } if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Cancelled the Order: " + cancelOrder, _type.FullName, "CancelOrderArrived"); } break; } } } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "CancelOrderArrived"); } }
/// <summary> /// Sends Positon info request to PE-Server /// </summary> /// <param name="provider">Broker from which to receive position updates</param> /// <returns></returns> public bool Subscribe(string provider) { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("New subscription request received", _type.FullName, "Subscribe"); } // Check for existing connection if (_isConnected) { // Forward Request to PE-Client _positionEngineClient.SubscribeProviderPosition(provider); return(true); } if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Request not sent to PE as PE-Client is not connected.", _type.FullName, "Subscribe"); } return(false); } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "Subscribe"); return(false); } }
/// <summary> /// Called when bar received from <see cref="MarketDataListener"/> /// </summary> /// <param name="bar"></param> private void OnBarArrived(Bar bar) { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug(bar.ToString(), _type.FullName, "OnBarArrived"); } _orderExecutor.BarArrived(bar); _tradeHubStrategy.OnBarArrived(bar); }
/// <summary> /// Called when bar received from <see cref="MarketDataListener"/> /// </summary> /// <param name="bar"></param> private void OnBarArrived(Common.Core.DomainModels.Bar bar) { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug(bar.ToString(), _type.FullName, "OnBarArrived"); } //_statistics.Flag = false; _statistics.UpdateBar(bar); //_prevBar = _currentBar; //_currentBar = bar; _orderExecutor.BarArrived(bar); _tradeHubStrategy.OnBarArrived(bar); //Check(); _statistics.CalculatePnlAfterBar(); }
private void StartStrategyExecution() { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Starting strategy instance for optimization.", _type.FullName, "StratStrategyExecution"); } if (_strategiesCollection.Count > 0) { // Get the iteration to be executed; var strategyExecutor = _strategiesCollection.ElementAt(0).Value; // Execute strategy if its not already executing/executed if (strategyExecutor.StrategyStatus.Equals(Infrastructure.Constants.StrategyStatus.None)) { strategyExecutor.ExecuteStrategy(); } } // Execute each instance on a separate thread // Parallel.ForEach(_strategiesCollection.Values, // strategyExecutor => Task.Factory.StartNew(strategyExecutor.ExecuteStrategy)); } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "StratStrategyExecution"); } }
/// <summary> /// Strats executing individual strategy instances created for each iteration /// </summary> private void StartStrategyExecution() { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Starting strategy instance for optimization.", _type.FullName, "StratStrategyExecution"); } if (_strategiesCollection.Count > 0) { // Get the iteration to be executed; var strategyExecutor = _strategiesCollection.ElementAt(0).Value; // Execute strategy if its not already executing/executed if (strategyExecutor.StrategyStatus.Equals(StrategyStatus.None)) { strategyExecutor.ExecuteStrategy(); } } else { // Change Status to indicate on UI _optimizationParameters.Status = OptimizationStatus.Completed; EventSystem.Publish <UiElement>(); } // Execute each instance on a separate thread // Parallel.ForEach(_strategiesCollection.Values, // strategyExecutor => Task.Factory.StartNew(strategyExecutor.ExecuteStrategy)); } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "StratStrategyExecution"); } }
/// <summary> /// Called when Market Order Request is receieved /// </summary> /// <param name="messageArray"></param> private void OnMarketOrderReceived(string[] messageArray) { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Market Order request received: " + messageArray[1], _type.FullName, "OnMarketOrderReceived"); } MarketOrder marketOrder = new MarketOrder(messageArray[7]); // Parse incoming message into Market Order if (ParseToMarketOrder(marketOrder, messageArray)) { // Send New Marker Order for execution _orderExecutor.NewMarketOrderArrived(marketOrder); } }
/// <summary> /// Fire Historical Bar Data /// </summary> /// <param name="historicBarData">TradeHub HistoricalBarData contains requested historical bars</param> private void HistoricDataArrived(HistoricBarData historicBarData) { try { if (HistoricDataReceived != null) { HistoricDataReceived(historicBarData); } if (_classLogger.IsDebugEnabled) { _classLogger.Debug(historicBarData.ToString(), _type.FullName, "HistoricDataArrived"); } } catch (Exception exception) { _classLogger.Error(exception, _type.FullName, "HistoricDataArrived"); } }
/// <summary> /// Handles the new incoming Server Heartbeat /// </summary> /// <param name="serverHeartbeatInterval">Time Interval after which MDE will send response Heartbeat</param> public void Update(int serverHeartbeatInterval) { try { // Stop Timer for processing StopValidationTimer(); if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Server Heartbeat received", _type.FullName, "Update"); } // Start Timer after processing StartValidationTimer(serverHeartbeatInterval); } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "Update"); } }
/// <summary> /// Raised when a custom loaded strategy status changes /// </summary> /// <param name="status">Indicated if the strategy is Running/Stopped</param> /// <param name="strategyKey">Unique Key to identify Strategy Instance</param> private void OnStatusChanged(bool status, string strategyKey) { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Stratgey: " + strategyKey + " is running: " + status, _type.FullName, "OnStatusChanged"); } // Create a new instance to be used with event aggregator UpdateStrategy updateStrategy = new UpdateStrategy(strategyKey, status); // Publish event to notify listeners EventSystem.Publish <UpdateStrategy>(updateStrategy); } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "OnStatusChanged"); } }
public virtual IEnumerable <Bar> ReadBars(DateTime startTime, DateTime endTime, string providerName, BarDataRequest request) { IList <string> listOfFileNames = ReturnExistingFileName(startTime, endTime, providerName, request); if (_classLogger.IsDebugEnabled) { _classLogger.Debug("Number of files read: " + listOfFileNames.Count, _type.FullName, "LiveBars - ReadBars"); } //Read Bar from File And Return all Selected File. return(from name in listOfFileNames from line in ReadLineByLine(name) select ParseToBar(line, request.Id)); }
/// <summary> /// Called when MDE-Client receives new historic bar data message from MDE-Server /// </summary> private void OnHistoricBarsArrived(HistoricBarData historicBarData) { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Data received from: " + historicBarData.MarketDataProvider, _type.FullName, "OnHistoricBarsArrived"); } HistoricDataRequest barsInformation; if (_subscriptionRequests.TryGetValue(historicBarData.ReqId, out barsInformation)) { // Insert received bars information historicBarData.BarsInformation = barsInformation; } if (_historicalDataArrived != null) { _historicalDataArrived(historicBarData); } } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "OnHistoricBarsArrived"); } }
/// <summary> /// Initializes Strategy Executor to manages user strategy for Genetic Algo Optimization /// </summary> private bool InitializeStrategyExecutor() { try { if (_logger.IsInfoEnabled) { _logger.Info("Initializing Strategy Executor array.", _type.FullName, "InitializeStrategyExecutor"); } if (_singleExecution) { _strategyExecutorArray[0] = new StrategyExecutorGeneticAlgo(_strategyType, _ctorArgumentsArray[0]); } else { // Initialize executor array for parallel execution for (int i = 0; i < _arrayLength; i++) { _strategyExecutorArray[i] = new StrategyExecutorGeneticAlgo(_strategyType, _ctorArgumentsArray[i]); } } if (_logger.IsDebugEnabled) { _logger.Debug("Initialization complete.", _type.FullName, "InitializeStrategyExecutor"); } // Indicates initialization was successful return(true); } catch (Exception exception) { _logger.Error(exception, _type.FullName, "InitializeStrategyExecutor"); return(false); } }
/// <summary> /// Manages new incoming Tick Data request /// </summary> /// <param name="subscribe">Contains info for Tick data to be subscribed</param> public void SubscribeTickData(Subscribe subscribe) { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug( "Sending tick subscription request to data handler for: " + subscribe.Security.Symbol, _type.FullName, "SubscribeTickData"); } // Send request to DataHandler _dataHandler.SubscribeSymbol(subscribe); }
/// <summary> /// Called when OEE-Client receives new order event from OEE-Server /// </summary> /// <param name="order">TradeHub Order containing accepted/submitted order info</param> private void OnNewArrived(Order order) { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("New Order Event received: " + order, _type.FullName, "OnNewArrived"); } Order clientOrder; if (_ordersMap.TryGetValue(order.OrderID, out clientOrder)) { // Change Order Status for accepted order order.OrderStatus = TradeHubConstants.OrderStatus.SUBMITTED; if (_newArrived != null) { _newArrived(order); } return; } if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("No client order available for the arrived order id: " + order.OrderID, _type.FullName, "OnNewArrived"); } } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "OnNewArrived"); } }
/// <summary> /// Sends Login request to the Order Execution Engine /// </summary> /// <param name="login">TradeHub Login message to be sent</param> public void SendLoginRequest(Login login) { try { if (_asyncClassLogger.IsDebugEnabled) { _asyncClassLogger.Debug("Sending login request message for: " + login.OrderExecutionProvider, _type.FullName, "SendLoginRequest"); } // Send Message through the MQ Server _mqServer.SendLoginMessage(login); } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "SendLoginRequest"); } }