Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
0
        public async Task MarketOptionDataController_Should_ReturnMarketDataType()
        {
            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", 7497, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            MarketDataTypeEventArgs        marketDataTypeEventArgs        = null;
            TickPriceEventArgs             tickPriceEventArgs             = null;
            TickOptionComputationEventArgs tickOptionComputationEventArgs = null;

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


            Contract contract = new Contract
            {
                SecType    = TwsContractSecType.Option,
                Symbol     = "MSFT",
                Exchange   = TwsExchange.Smart,
                Multiplier = "100",
                Currency   = "USD",
                Right      = "C",
                Strike     = 200,
                LastTradeDateOrContractMonth = "20201113"
            };

            twsObjectFactory.TwsControllerBase.RequestMarketDataType(1);
            var marketDataResult = await twsObjectFactory.TwsControllerBase.RequestMarketDataAsync(contract, null, false, false, null);

            marketDataResult.Should().NotBeNull();
            tickPriceEventArgs.Should().NotBeNull();
            tickPriceEventArgs.TickerId.Should().IsSameOrEqualTo(marketDataResult.TickerId);
            tickOptionComputationEventArgs.Should().NotBeNull();
            tickOptionComputationEventArgs.TickerId.Should().IsSameOrEqualTo(marketDataResult.TickerId);
        }
        /// <inheritdoc/>
        public void marketDataType(int reqId, int marketDataType)
        {
            var eventArgs = new MarketDataTypeEventArgs(reqId, marketDataType);

            this.MarketDataTypeEvent?.Invoke(this, eventArgs);
        }