To use the features described below, activate the greeks plugin
 
require 'ib-api' 
ib =  IB::Connection.new
ib.activate_plugin :greeks
ib.try_connection!

Greeks

If we ask for market-data of an IB::Option, the TWS returns price data and Option Greeks.

IB::Option.request_greeks populates the IB::Option.greek property ( and returns the greeks as hash ).

It accepts the parameter :what { :model, :bid, :ask, :last, :bidask, :all }, default is model, ie. the calculated Greeks. For batch-processing, a threaded approach is supported via the parameter thread: true.

The processing is expensive, it takes about 2 seconds to receive the data from the tws-server.

cien =  Option.new( symbol: 'CIEN', 
                      strike: 50, 
                      expiry: IB::Optipon.next_expiry, 
                       right: :put, 
                    exchange: :smart ).verify.first
puts cien.to_human
  => <Option: CIEN 20240719 put 50.0 SMART USD>

cien.request_greeks
	 => {:tick_type=>83, :implied_volatility=>0.3860515283461521e0, 
       :delta=>-0.3163006034515305e0, :option_price=>0.16924407617796515e1,
       :pv_dividend=>0.0, :gamma=>0.4684449764772187e-1, 
       :vega=>0.7141634363804972e-1, 
       :theta=>-0.2681911830789842e-1, :under_price=>0.53e2} 

puts cien.greek.to_human
	<  optionPrice: 1.70818, UnderlyingPrice: 52.95 impl.Vola: 0.386052 ; dividend: 0; 
         Greeks::  delta:  -0.318621; gamma: 0.0470364, vega: 0.0733351; theta: -0.026878 >
Tags: