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.