amittleider / AutoFinance.Broker

A Dotnet Core library to interact with Interactive Broker's Trader Workstation (IB TWS)
32 stars 16 forks source link

Option Greeks Snapshot/Stream #40

Open debegr92 opened 1 year ago

debegr92 commented 1 year ago

Hi, I tested the RequestMarketDataAsync function for getting option greeks of SPX. I also implemented the callback OnTickOptionComputationEvent, but it throws a NotImplemented error. Why is there no event for this callback?

amittleider commented 1 year ago

Hi Dennis,

Not all events are implemented, especially for derivatives contracts that require paying for specific market data packages. But, it looks like this might be a rather easy one to implement.

Implement the tickOptionComputation callback in the TwsCallbackHander here https://github.com/amittleider/AutoFinance.Broker/blob/master/AutoFinance.Broker/InteractiveBrokers/Wrappers/TwsCallbackHandler.cs#L763 . As you have noticed, the TickOptionComputationEventArgs class is already implemented, it just remains unused. You could look at any other method in this class to find the pattern; something like the following:

        /// <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, pvDivident, gamma, vega, theta, undPrice);
            this.TickOptionComputationEvent?.Invoke(this, eventArgs);
        }

Because the TwsControllerBase already registers the callback, you shouldn't need to modify anything in that class https://github.com/amittleider/AutoFinance.Broker/blob/master/AutoFinance.Broker/InteractiveBrokers/Controllers/TwsControllerBase.cs#L844 .

It might be just these 2 lines to add -- I didn't test it though, so there might be a bit more to do somewhere.