예제 #1
0
        public async Task MarketDataTypeController_Should_ReturnMarketDataType()
        {
            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", TestConstants.Port, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            MarketDataTypeEventArgs marketDataTypeEventArgs = null;
            TickPriceEventArgs      tickPriceEventArgs      = null;

            twsObjectFactory.TwsCallbackHandler.MarketDataTypeEvent +=
                (sender, args) => { marketDataTypeEventArgs = args; };
            twsObjectFactory.TwsCallbackHandler.TickPriceEvent +=
                (sender, args) => { tickPriceEventArgs = args; };

            // This contract provide delayed data when requested
            Contract contract = new Contract
            {
                SecType     = TwsContractSecType.Stock,
                Symbol      = "MSFT",
                Exchange    = TwsExchange.Smart,
                PrimaryExch = TwsExchange.Island,
            };

            // Request delayed data feed
            twsObjectFactory.TwsControllerBase.RequestMarketDataType(3);
            var marketDataResult = await twsObjectFactory.TwsControllerBase.RequestMarketDataAsync(contract, "233", false, false, null);

            marketDataResult.Should().NotBeNull();
            tickPriceEventArgs.Should().NotBeNull();
            tickPriceEventArgs.TickerId.Should().IsSameOrEqualTo(marketDataResult.TickerId);

            marketDataTypeEventArgs.Should().NotBeNull();
            marketDataTypeEventArgs.MarketDataType.Should().Be(3);
        }
예제 #2
0
        public async Task MarketDataController_Should_ReturnMarketDataType()
        {
            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", TestConstants.Port, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            MarketDataTypeEventArgs marketDataTypeEventArgs = null;
            TickPriceEventArgs      tickPriceEventArgs      = null;

            twsObjectFactory.TwsCallbackHandler.MarketDataTypeEvent +=
                (sender, args) => { marketDataTypeEventArgs = args; };
            twsObjectFactory.TwsCallbackHandler.TickPriceEvent +=
                (sender, args) => { tickPriceEventArgs = args; };

            // Only real-time data provided for this contract
            var contract = new Contract()
            {
                Symbol   = TwsCurrency.Eur,
                Exchange = TwsExchange.Idealpro,
                SecType  = TwsContractSecType.Cash,
                Currency = TwsCurrency.Usd
            };

            var marketDataResult = await twsObjectFactory.TwsControllerBase.RequestMarketDataAsync(contract, "233", false, false, null);

            marketDataResult.Should().NotBeNull();
            tickPriceEventArgs.Should().NotBeNull();
            tickPriceEventArgs.TickerId.Should().IsSameOrEqualTo(marketDataResult.TickerId);

            marketDataTypeEventArgs.Should().NotBeNull();
            marketDataTypeEventArgs.MarketDataType.Should().Be(1);
        }