Exemplo n.º 1
0
        public async Task Should_GetOptionsContracts()
        {
            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", TestConstants.Port, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            Contract contract = new Contract
            {
                SecType  = TwsContractSecType.Stock,
                Symbol   = "MSFT",
                Exchange = TwsExchange.Smart,
            };

            // Get the contract details of the STOCK so that you can find the underlying security ID, required for the security definitions call.
            var contractDetails = await twsController.GetContractAsync(contract);

            var securityDefinitions = await twsController.RequestSecurityDefinitionOptionParameters("MSFT", "", "STK", contractDetails.First().Contract.ConId);

            securityDefinitions.Count.Should().BeGreaterThan(1);

            await twsController.DisconnectAsync();

            ////// If you want, you can request the contract details from this info or get historical data for it
            ////Contract option = new Contract()
            ////{
            ////    SecType = TwsContractSecType.Option,
            ////    Symbol = "MSFT",
            ////    Exchange = "SMART",
            ////    Strike = 150,
            ////    LastTradeDateOrContractMonth = securityDefinitions[0].Expirations.First(), // March 27, 20
            ////    Right = "C",
            ////    Multiplier = securityDefinitions[0].Multiplier,
            ////    Currency = TwsCurrency.Usd,
            ////};

            ////var optionContractDetails = await twsContractDetailsController.GetContractAsync(option);
            ////var queryTime = DateTime.Now;
            ////List<HistoricalDataEventArgs> historicalDataEvents = await twsHistoricalDataController.GetHistoricalDataAsync(option, queryTime, TwsDuration.OneMonth, TwsBarSizeSetting.OneMinute, TwsHistoricalDataRequestType.Trades);
        }