예제 #1
0
        public async Task ContractDetailsController_Should_ReturnValidContractAsync()
        {
            // Setup
            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,
                PrimaryExch = TwsExchange.Island,
            };

            // Call
            List <ContractDetails> contractDetails = await twsController.GetContractAsync(contract);

            // Assert
            contractDetails.Should().NotBeNull();

            // Tear down
            await twsController.DisconnectAsync();
        }
예제 #2
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);
        }
예제 #3
0
        public async Task ContractDetailsController_Should_ReturnValidForexContractAsync()
        {
            // Setup
            TwsObjectFactory   twsObjectFactory = new TwsObjectFactory("localhost", TestConstants.Port, 1);
            ITwsControllerBase twsController    = twsObjectFactory.TwsControllerBase;

            await twsController.EnsureConnectedAsync();

            Contract contract = new Contract();

            contract.Symbol   = "EUR";
            contract.SecType  = "CASH";
            contract.Currency = "GBP";
            contract.Exchange = "IDEALPRO";

            // Call
            List <ContractDetails> contractDetails = twsController.GetContractAsync(contract).ConfigureAwait(false).GetAwaiter().GetResult();

            // Assert
            contractDetails.First().Should().NotBeNull();

            // Tear down
            await twsController.DisconnectAsync();
        }