Option Chain
Retrieve a a complete or filtered options chain for a given underlying symbol. Both real-time and historical requests are possible.
Making Requests
Utilize OptionChainRequest for querying the endpoint through one of the three available methods:
| Method | Execution Level | Return Type | Description |
|---|---|---|---|
| Get | Direct | []OptionQuote | Immediately fetches a slice of []OptionQuote, allowing direct access to the options chain data. |
| Packed | Intermediate | *OptionQuotesResponse | Delivers a *OptionQuotesResponse object containing the data, which requires unpacking to access the OptionQuote data. |
| Raw | Low-level | *resty.Response | Offers the unprocessed *resty.Response for those seeking full control and access to the raw JSON or *http.Response. |
OptionChainRequest
type OptionChainRequest struct {
// contains filtered or unexported fields
}
OptionChainRequest represents a request to the /v1/options/chain/ endpoint. It encapsulates parameters for symbol, date, and various option-specific parameters to be used in the request. This struct provides methods to set these parameters, such as UnderlyingSymbol(), Date(), Expiration(), and Strike(), among others.
Generated By
-
OptionChain() *OptionChainRequestOptionChain creates a new *OptionChainRequest and returns a pointer to the request allowing for method chaining.
Setter Methods
These methods are used to set the parameters of the request. They allow for method chaining by returning a pointer to the *OptionChainRequest instance they modify.
-
UnderlyingSymbol(string) *OptionChainRequestSets the underlying symbol parameter for the request.
-
Date(interface{}) *OptionChainRequestSets the date parameter for the request.
-
Expiration(interface{}) *OptionChainRequestSets the expiration parameter for the request.
-
Strike(float64) *OptionChainRequestSets the strike price parameter for the request.
-
Monthly(bool) *OptionChainRequestInclues or excludes monthly option expirations from the result.
-
Weekly(bool) *OptionChainRequestInclues or excludes weekly option expirations from the result.
-
Quarterly(bool) *OptionChainRequestInclues or excludes quarterly option expirations from the result.
-
Nonstandard(bool) *OptionChainRequestInclues or excludes non-standard option expirations from the result.
-
Month(int) *OptionChainRequestRequests results from the specific specific month.
-
Year(int) *OptionChainRequestSets the year parameter for the request.
-
DTE(int) *OptionChainRequestSets the Days to Expiration parameter for the request.
-
Delta(float64) *OptionChainRequestSets the Delta parameter for the request.
-
Side(string) *OptionChainRequestSets the side of the market (call or put) for the request.
-
Range(string) *OptionChainRequestSets the range parameter for the request.
-
StrikeLimit(int) *OptionChainRequestSets the maximum number of strike prices to be included in the option chain.
-
MinOpenInterest(int) *OptionChainRequestSets the minimum open interest for options to be included in the option chain.
-
MinVolume(int) *OptionChainRequestSets the minimum volume for options to be included in the option chain.
-
MaxBidAskSpread(float64) *OptionChainRequestSets the maximum bid-ask spread for options to be included in the option chain.
-
MaxBidAskSpreadPct(float64) *OptionChainRequestSets the maximum bid-ask spread percentage for options to be included in the option chain.
Execution Methods
These methods are used to send the request in different formats or retrieve the data. They handle the actual communication with the API endpoint.
-
Get() ([]OptionQuote, error)Sends the request, unpacks the response, and returns the data in a user-friendly format.
-
Packed() (*OptionQuotesResponse, error)Packs the request parameters and sends the request, returning a *OptionQuotesResponse response.
-
Raw() (*resty.Response, error)Sends the request as is and returns the raw HTTP response.
- Example (Get)
- Example (Packed)
resp, err := OptionChain().UnderlyingSymbol("AAPL").Side("call").Date("2022-01-03").DTE(60).StrikeLimit(2).Range("itm").Get()
if err != nil {
fmt.Println("Error fetching option chain:", err)
return
}
for _, contract := range resp {
fmt.Println(contract)
}
Output
OptionQuote{OptionSymbol: "AAPL220318C00175000", Underlying: "AAPL", Expiration: 2022-03-18 16:00:00 -04:00, Side: "call", Strike: 175, FirstTraded: 2021-07-13 09:30:00 -04:00, DTE: 74, Ask: 13.1, AskSize: 2, Bid: 12.95, BidSize: 3, Mid: 13.02, Last: 12.9, Volume: 1295, OpenInterest: 15232, UnderlyingPrice: 182.01, InTheMoney: true, Updated: "2022-01-03 16:00:00 -05:00", IV: nil, Delta: nil, Gamma: nil, Theta: nil, Vega: nil, IntrinsicValue: 7.01, ExtrinsicValue: 6.02}
OptionQuote{OptionSymbol: "AAPL220318C00180000", Underlying: "AAPL", Expiration: 2022-03-18 16:00:00 -04:00, Side: "call", Strike: 180, FirstTraded: 2021-07-13 09:30:00 -04:00, DTE: 74, Ask: 10.2, AskSize: 12, Bid: 10, BidSize: 38, Mid: 10.1, Last: 10.1, Volume: 4609, OpenInterest: 18299, UnderlyingPrice: 182.01, InTheMoney: true, Updated: "2022-01-03 16:00:00 -05:00", IV: nil, Delta: nil, Gamma: nil, Theta: nil, Vega: nil, IntrinsicValue: 2.01, ExtrinsicValue: 8.09}
resp, err := OptionChain().UnderlyingSymbol("AAPL").Side("call").Date("2022-01-03").
Month(2).Year(2022).Range("itm").Strike(150).Weekly(false).Monthly(true).Quarterly(false).Nonstandard(false).Packed()
if err != nil {
fmt.Println("Error fetching packed option chain:", err)
return
}
fmt.Println(resp)
Output
OptionQuotesResponse{OptionSymbol: ["AAPL220121C00150000"], Underlying: ["AAPL"], Expiration: [1642798800], Side: ["call"], Strike: [150], FirstTraded: [1568640600], DTE: [18], Ask: [32.15], AskSize: [2], Bid: [31.8], BidSize: [359], Mid: [31.98], Last: [32], Volume: [3763], OpenInterest: [98804], UnderlyingPrice: [182.01], InTheMoney: [true], Updated: [1641243600], IV: [nil], Delta: [nil], Gamma: [nil], Theta: [nil], Vega: [nil], IntrinsicValue: [32.01], ExtrinsicValue: [0.03]}
OptionChain
func OptionChain() *OptionChainRequest
OptionChain creates a new OptionChainRequest and associates it with the default client. This function initializes the request with default parameters for symbol, date, and option-specific parameters, and sets the request path based on the predefined endpoints for option chains.
Returns
-
*OptionChainRequestA pointer to the newly created OptionChainRequest with default parameters and associated client.
OptionChainRequest Setter Methods
DTE
func (ocr *OptionChainRequest) DTE(dte int) *OptionChainRequest
DTE (Days to Expiration) sets the DTE parameter for the OptionChainRequest. This method specifies the number of days to expiration for the options in the option chain.
Parameters
-
intRequests an expiration date from the option chain based on the number of days from the present date.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Date
func (ocr *OptionChainRequest) Date(q interface{}) *OptionChainRequest
Date sets the date parameter for the OptionChainRequest. This method is used to specify the date for which the option chain is requested. It modifies the dateParams field of the OptionChainRequest instance to store the date value.
Parameters
-
interface{}An interface{} that represents the starting date. It can be a string, a time.Time object, a Unix timestamp or any other type that the underlying dates package can process.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Delta
func (ocr *OptionChainRequest) Delta(delta float64) *OptionChainRequest
Delta sets the Delta parameter for the OptionChainRequest. This method is used to specify a particular Delta value for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the Delta value.
Parameters
-
float64The Delta value to be set.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Expiration
func (ocr *OptionChainRequest) Expiration(q interface{}) *OptionChainRequest
Expiration sets the expiration parameter for the OptionChainRequest. This method is used to specify the expiration date for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the expiration value.
Parameters
-
interface{}An interface{} representing the expiration date to be set.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MaxAsk
func (ocr *OptionChainRequest) MaxAsk(maxAsk float64) *OptionChainRequest
MaxAsk sets the MaxAsk parameter for the OptionChainRequest. This method is used to specify the maximum ask price for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the maximum ask price value.
Parameters
-
float64A float64 representing the maximum ask price to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MaxBid
func (ocr *OptionChainRequest) MaxBid(maxBid float64) *OptionChainRequest
MaxBid sets the MaxBid parameter for the OptionChainRequest. This method is used to specify the maximum bid price for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the maximum bid price value.
Parameters
-
float64A float64 representing the maximum bid price to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MaxBidAskSpread
func (ocr *OptionChainRequest) MaxBidAskSpread(maxBidAskSpread float64) *OptionChainRequest
MaxBidAskSpread sets the MaxBidAskSpread parameter for the OptionChainRequest. This method is used to specify the maximum bid-ask spread for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the maximum bid-ask spread value.
Parameters
-
float64A float64 representing the maximum bid-ask spread neeeded to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MaxBidAskSpreadPct
func (ocr *OptionChainRequest) MaxBidAskSpreadPct(maxBidAskSpreadPct float64) *OptionChainRequest
MaxBidAskSpreadPct sets the MaxBidAskSpreadPct parameter for the OptionChainRequest. This method is used to specify the maximum bid-ask spread percentage for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the maximum bid-ask spread percentage value.
Parameters
-
float64A float64 representing the maximum bid-ask spread percentage to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MinAsk
func (ocr *OptionChainRequest) MinAsk(minAsk float64) *OptionChainRequest
MinAsk sets the MinAsk parameter for the OptionChainRequest. This method is used to specify the minimum ask price for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the minimum ask price value.
Parameters
-
float64A float64 representing the minimum ask price to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MinBid
func (ocr *OptionChainRequest) MinBid(minBid float64) *OptionChainRequest
MinBid sets the MinBid parameter for the OptionChainRequest. This method is used to specify the minimum bid price for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the minimum bid price value.
Parameters
-
float64A float64 representing the minimum bid price to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MinOpenInterest
func (ocr *OptionChainRequest) MinOpenInterest(minOpenInterest int) *OptionChainRequest
MinOpenInterest sets the MinOpenInterest parameter for the OptionChainRequest. This method is used to specify the minimum open interest for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the minimum open interest value.
Parameters
-
intAn int representing the minimum open interest required to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
MinVolume
func (ocr *OptionChainRequest) MinVolume(minVolume int) *OptionChainRequest
MinVolume sets the MinVolume parameter for the OptionChainRequest. This method is used to specify the minimum volume for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the minimum volume value.
Parameters
-
intAn int representing the minimum volume needed to be included in the result.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Month
func (ocr *OptionChainRequest) Month(month int) *OptionChainRequest
Month sets the month parameter for the OptionChainRequest. This method is used to specify the month for which the option chain is requested. It modifies the optionParams field of the OptionChainRequest instance to store the month value.
Parameters
-
intThe month to be set.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Monthly
func (ocr *OptionChainRequest) Monthly(monthly bool) *OptionChainRequest
Monthly sets the monthly parameter for the OptionChainRequest. This method is used to specify whether to include monthly options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the monthly value.
Parameters
-
boolWhether to include monthly options.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Nonstandard
func (ocr *OptionChainRequest) Nonstandard(nonstandard bool) *OptionChainRequest
Nonstandard sets the nonstandard parameter for the OptionChainRequest. This method is used to specify whether to include nonstandard options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the nonstandard value.
Parameters
-
boolWhether to include nonstandard options.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Quarterly
func (ocr *OptionChainRequest) Quarterly(quarterly bool) *OptionChainRequest
Quarterly sets the quarterly parameter for the OptionChainRequest. This method is used to specify whether to include quarterly options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the quarterly value.
Parameters
-
boolWhether to include quarterly options.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Range
func (ocr *OptionChainRequest) Range(rangeParam string) *OptionChainRequest
Range sets the Range parameter for the OptionChainRequest. This method is used to specify the range of options to be included in the option chain based on their strike price. It modifies the optionParams field of the OptionChainRequest instance to store the range value.
Parameters
-
stringA string representing the range of options to be included. The expected values can vary, such as "ITM" (In The Money), "OTM" (Out of The Money), "ATM" (At The Money), etc.
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Side
func (ocr *OptionChainRequest) Side(side string) *OptionChainRequest
Side sets the Side parameter for the OptionChainRequest. This method is used to specify the side of the market for the options in the option chain (e.g., call or put). It modifies the optionParams field of the OptionChainRequest instance to store the side value.
Parameters
-
stringA string representing the side of the market chain to be set. Expected value is "call" or "put".
Returns
-
*OptionChainRequestThis method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
Strike
func (ocr *OptionChainRequest) Strike(strike float64) *OptionChainRequest
Strike sets the strike price parameter for the OptionChainRequest. This method is used to specify a particular strike price for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the strike price value.
Parameters
-
float64The strike price to be set.