コード例 #1
0
        public void GetLiveBarsWithEvents()
        {
            _simulateMarketOrder = new SimulateMarketOrder();
            _simulateLimitOrder  = new SimulateLimitOrder();

            // Initialize Controller
            _marketDataControler      = new MarketDataControler(_fetchData, _communicationController);
            _simulatedOrderController = new SimulatedOrderController(_communicationController, _simulateMarketOrder, _simulateLimitOrder);

            // Add Controllers as Parameters to FetchData.cs
            _fetchData.MarketDataControler      = _marketDataControler;
            _fetchData.SimulatedOrderController = _simulatedOrderController;

            var watch = Stopwatch.StartNew();

            _fetchData.ReadData(_barDataRequest);

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Logger.Debug("Time consumer: " + elapsedMs, "SimulatorControler.Test.Unit", "GetLiveBarsWithEvents");
        }
コード例 #2
0
        public void TestLimitRejection()
        {
            var manualBarEvent = new ManualResetEvent(false);
            var count          = 0;
            SimulateLimitOrder simulateLimitOrder = new SimulateLimitOrder();

            simulateLimitOrder.LimitOrderRejection += delegate(Rejection rejection)
            {
                count = 1;
            };

            LimitOrder limitOrder = new LimitOrder("1", OrderSide.SELL, 10, OrderTif.DAY, "USD", new Security()
            {
                Symbol = "AAPL"
            }, OrderExecutionProvider.SimulatedExchange)
            {
                LimitPrice = 0
            };

            simulateLimitOrder.NewLimitOrderArrived(limitOrder);
            manualBarEvent.WaitOne(500);
            Assert.AreEqual(1, count);
        }
コード例 #3
0
        public void TestLimitOrderLogic()
        {
            var                manualBarEvent     = new ManualResetEvent(false);
            string             executionId        = null;
            SimulateLimitOrder simulateLimitOrder = new SimulateLimitOrder();
            decimal            executionPrice     = 0;

            simulateLimitOrder.NewArrived += delegate(Order order)
            {
                executionId = order.OrderID;
            };
            simulateLimitOrder.NewExecution += delegate(Execution orderExecution)
            {
                executionPrice = orderExecution.Fill.ExecutionPrice;
            };
            manualBarEvent.WaitOne(500);
            LimitOrder limitOrder = new LimitOrder("1", OrderSide.SELL, 10, OrderTif.DAY, "USD", new Security()
            {
                Symbol = "AAPL"
            }, OrderExecutionProvider.SimulatedExchange)
            {
                LimitPrice = 100
            };
            Bar bar = new Bar(new Security()
            {
                Symbol = "AAPL"
            }, MarketDataProvider.SimulatedExchange, "123")
            {
                Low = 120, Close = 130
            };

            simulateLimitOrder.NewLimitOrderArrived(limitOrder);
            simulateLimitOrder.NewBarArrived(bar);
            manualBarEvent.WaitOne(500);
            Assert.AreEqual("1", executionId);
            Assert.AreEqual(100, executionPrice);
        }