コード例 #1
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);
        }
コード例 #2
0
        void tws_TickOptionComputation(object sender, TickOptionComputationEventArgs e)
        {
            // get tick object
            if (!tick_list.ContainsKey(e.TickerId))
            {
                return;
            }
            TickData t = tick_list[e.TickerId];

            switch (e.TickType)
            {
            default:
                break;
            }

            // remove from pending requests
            t.pending_requests.Remove(e.TickType);
            if (t.pending_requests.Count == 0)
            {
                t.ready_event.Set();
            }
        }
コード例 #3
0
        /// <inheritdoc/>
        public void tickOptionComputation(int tickerId, int field, double impliedVolatility, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice)
        {
            var eventArgs = new TickOptionComputationEventArgs(tickerId, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice);

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