예제 #1
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public StrategyController()
        {
            IPersistRepository <object> persistRepository = ContextRegistry.GetContext()["PersistRepository"] as IPersistRepository <object>;

            // Save UI thread reference
            _currentDispatcher = Dispatcher.CurrentDispatcher;

            PersistencePublisher.InitializeDisruptor(persistRepository);
        }
예제 #2
0
 /// <summary>
 /// Persist the received Trade Object
 /// </summary>
 /// <param name="trade">Trade to be stored</param>
 private void PersistTrade(Trade trade)
 {
     try
     {
         // Persist Trade
         PersistencePublisher.PublishDataForPersistence(trade);
     }
     catch (Exception exception)
     {
         Logger.Error(exception, _type.FullName, "PersistTrade");
     }
 }
        /// <summary>
        /// Starts Communicator to open communication medium with clients
        /// </summary>
        public void StartCommunicator()
        {
            // Check for Null Reference
            if (_communicator != null)
            {
                // Connect Communication Server
                _communicator.Connect();

                IPersistRepository <object> persistRepository = ContextRegistry.GetContext()["PersistRepository"] as IPersistRepository <object>;
                PersistencePublisher.InitializeDisruptor(true, persistRepository);
            }
        }
예제 #4
0
        /// <summary>
        /// Called when Custom Strategy receives requested order accepted message
        /// </summary>
        /// <param name="order">Accepted Order details</param>
        private void OnOrderAccepted(Order order)
        {
            //OrderDetails orderDetails = new OrderDetails();
            //orderDetails.ID = order.OrderID;
            ////orderDetails.Price = order.;
            //orderDetails.Quantity = order.OrderSize;
            //orderDetails.Side = order.OrderSide;
            ////orderDetails.Type = order.;
            //orderDetails.Status = order.OrderStatus;

            //// Update UI
            //AddOrderDetails(orderDetails);

            PersistencePublisher.PublishDataForPersistence(order);
        }
예제 #5
0
        /// <summary>
        /// Called when Custom Strategy receives notification from Order Cancellation
        /// </summary>
        /// <param name="order">Contains cancelled order information</param>
        private void OnCancellationReceived(Order order)
        {
            OrderDetails orderDetails = new OrderDetails(order.OrderExecutionProvider);

            orderDetails.ID       = order.OrderID;
            orderDetails.Security = order.Security;
            orderDetails.Quantity = order.OrderSize;
            orderDetails.Side     = order.OrderSide;
            orderDetails.Time     = order.OrderDateTime;
            orderDetails.Status   = order.OrderStatus;

            // Update UI
            AddOrderDetails(orderDetails);

            // Handle Persistence
            PersistencePublisher.PublishDataForPersistence(order);
        }
예제 #6
0
        /// <summary>
        /// Called when Custom Strategy receives new execution message
        /// </summary>
        /// <param name="execution">Contains Execution Info</param>
        private void OnNewExecutionReceived(Execution execution)
        {
            // Update Stats
            OrderDetails orderDetails = new OrderDetails(execution.OrderExecutionProvider);

            orderDetails.ID       = execution.Fill.OrderId;
            orderDetails.Security = execution.Fill.Security;
            orderDetails.Price    = execution.Fill.ExecutionPrice;
            orderDetails.Quantity = execution.Fill.ExecutionSize;
            orderDetails.Side     = execution.Fill.ExecutionSide;
            orderDetails.Status   = execution.Order.OrderStatus;
            orderDetails.Time     = execution.Fill.ExecutionDateTime;

            // Update UI
            AddOrderDetails(orderDetails);

            PersistencePublisher.PublishDataForPersistence(execution.Fill);
            PersistencePublisher.PublishDataForPersistence(execution.Order);
        }
예제 #7
0
        /// <summary>
        /// Execute selected strategy
        /// </summary>
        private void RunSelectedStrategy(string key)
        {
            try
            {
                IPersistRepository <object> persistRepository = ContextRegistry.GetContext()["PersistRepository"] as IPersistRepository <object>;
                PersistencePublisher.InitializeDisruptor(EnablePersistence, persistRepository);
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Going to execute the selected strategy: ", _type.FullName, "RunSelectedStrategy");
                }

                // Create new instance to pass to event aggregator
                RunStrategy runStrategy = new RunStrategy(key);

                // Publish event to notify listeners
                EventSystem.Publish <RunStrategy>(runStrategy);
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "RunSelectedStrategy");
            }
        }
예제 #8
0
 /// <summary>
 /// Called when New order status received from <see cref="OrderExecutor"/>
 /// </summary>
 /// <param name="order"></param>
 private void OnOrderExecutorNewArrived(Order order)
 {
     _tradeHubStrategy.NewArrived(order);
     PersistencePublisher.PublishDataForPersistence(order);
 }
예제 #9
0
 /// <summary>
 /// Called when Executions received from <see cref="OrderExecutor"/>
 /// </summary>
 /// <param name="execution"></param>
 private void OnOrderExecutorExecutionArrived(Execution execution)
 {
     _tradeHubStrategy.ExecutionArrived(execution);
     PersistencePublisher.PublishDataForPersistence(execution.Fill);
     PersistencePublisher.PublishDataForPersistence(execution.Order);
 }
예제 #10
0
 /// <summary>
 /// Sets database persistence status
 /// </summary>
 /// <param name="enablePersistence">indicates if the orders are to be persisted or not</param>
 public void AllowPersistence(bool enablePersistence)
 {
     PersistencePublisher.AllowPersistence(enablePersistence);
 }