Expirations
Get a list of current or historical option expiration dates for an underlying symbol.
Making Requests
Utilize OptionsExpirationsRequest for querying the endpoint through one of the three available methods:
Method | Execution | Return Type | Description |
---|---|---|---|
Get | Direct | []time.Time | Immediately fetches and returns a slice of []time.Time , allowing direct access to each expiration date. |
Packed | Intermediate | *OptionsExpirationsResponse | Delivers a *OptionsExpirationsResponse object containing the data, which requires unpacking to access the []time.Time slice. |
Raw | Low-level | *resty.Response | Offers the unprocessed *resty.Response for those seeking full control and access to the raw JSON or *http.Response . |
OptionsExpirationsRequest
type OptionsExpirationsRequest struct {
// contains filtered or unexported fields
}
OptionsExpirationsRequest represents a request for retrieving options expirations data from the /v1/options/expirations/ endpoint. It encapsulates parameters for the underlying symbol and strike price to be used in the request. This struct provides methods such as UnderlyingSymbol() and Strike() to set these parameters respectively.
Generated By
-
OptionsExpirations() *OptionsExpirationsRequest
OptionsExpirations creates a new *OptionsExpirationsRequest and returns a pointer to the request allowing for method chaining.
Setter Methods
-
Strike(float64) *OptionsExpirationsRequest
Sets the strike price parameter for the options expirations request.
-
UnderlyingSymbol(string) *OptionsExpirationsRequest
Sets the underlying symbol parameter for the options expirations request.
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() ([]time.Time, error)
Sends the request, unpacks the response, and returns []time.Time allowing direct-access to the data.
-
Packed() (*OptionsExpirationsResponse, error)
Returns a struct that contains equal-length slices of primitives. This packed response mirrors Market Data's JSON response.
-
Raw() (*resty.Response, error)
Sends the request as is and returns the raw HTTP response.
OptionsExpirations
func OptionsExpirations() *OptionsExpirationsRequest
OptionsExpirations creates a new OptionsExpirationsRequest with the default client.
Returns
-
*OptionsExpirationsRequest
A pointer to the newly created OptionsExpirationsRequest with default parameters.
OptionsExpirationsRequest Setter Methods
Date
func (oer *OptionsExpirationsRequest) Date(q interface{}) *OptionsExpirationsRequest
Date sets the date parameter for the OptionsExpirationsRequest. This method is used to specify the date for which the options expirations are requested. It modifies the dateParams field of the OptionsExpirationsRequest 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
-
*OptionsExpirationsRequest
This method returns a pointer to the OptionsExpirationsRequest instance it was called on. This allows for method chaining. If the receiver (*OptionsExpirationsRequest) is nil, it returns nil to prevent a panic.
Strike
func (o *OptionsExpirationsRequest) Strike(strike float64) *OptionsExpirationsRequest
Strike sets the strike price parameter for the OptionsExpirationsRequest. This method is used to specify a particular strike price for filtering the options expirations.
Parameters
-
float64
A float64 representing the strike price to be set.
Returns
-
*OptionsExpirationsRequest
This method returns a pointer to the OptionsExpirationsRequest instance it was called on, allowing for method chaining.
UnderlyingSymbol
func (o *OptionsExpirationsRequest) UnderlyingSymbol(symbol string) *OptionsExpirationsRequest
UnderlyingSymbol sets the underlying symbol parameter for the OptionsExpirationsRequest. This method is used to specify the symbol of the underlying asset for which the options expirations are requested.
Parameters
-
string
A string representing the underlying symbol to be set.
Returns
-
*OptionsExpirationsRequest
This method returns a pointer to the OptionsExpirationsRequest instance it was called on, allowing for method chaining.
OptionsExpirationsRequest Execution Methods
Get
func (o *OptionsExpirationsRequest) Get() ([]time.Time, error)
Get sends the OptionsExpirationsRequest, unpacks the OptionsExpirationsResponse, and returns a slice of time.Time. It returns an error if the request or unpacking fails. This method uses the default client for the request.
Returns
-
[]time.Time
A slice of time.Time containing the unpacked options expirations data from the response.
-
error
An error object that indicates a failure in sending the request or unpacking the response.
Packed
func (o *OptionsExpirationsRequest) Packed() (*models.OptionsExpirationsResponse, error)
Packed sends the OptionsExpirationsRequest and returns the OptionsExpirationsResponse. This method uses the default client for the request.
Returns
-
*models.OptionsExpirationsResponse
A pointer to the OptionsExpirationsResponse obtained from the request.
-
error
An error object that indicates a failure in sending the request.
Raw
func (oer *OptionsExpirationsRequest) Raw() (*resty.Response, error)
Raw executes the OptionsExpirationsRequest and returns the raw *resty.Response. This method uses the default client for the request. The *resty.Response can be used to directly access the raw JSON or *http.Response.
Returns
-
*resty.Response
The raw HTTP response from the executed OptionsExpirationsRequest.
-
error
An error object if the OptionsExpirationsRequest is nil or if an error occurs during the request execution.
OptionsExpirationsResponse
type OptionsExpirationsResponse struct {
Expirations []string // Expirations is a slice of strings representing the expiration dates of options.
Updated int64 // Updated is a UNIX timestamp indicating when the data was last updated.
}
OptionsExpirationsResponse encapsulates the expiration dates of options and the last update timestamp.
Generated By
-
OptionsExpirationsRequest.Packed()
Generates an OptionsExpirationsResponse after fetching data from Market Data.
Methods
-
IsValid() bool
Checks if the expiration dates are valid and correctly formatted.
-
String() string
Returns a string representation of the OptionsExpirationsResponse.
-
Unpack() ([]time.Time, error)
Converts expiration date strings to a slice of time.Time objects.
Notes
- The Expirations field contains dates in string format which should be parsed considering the "America/New_York" timezone.
IsValid
func (oer *OptionsExpirationsResponse) IsValid() bool
IsValid checks the validity of the OptionsExpirationsResponse. This method is primarily used to ensure that the Expirations slice is not empty and that each expiration date string within it can be successfully parsed into a time.Time object according to the "America/New_York" timezone. This validation is crucial for preventing errors in subsequent operations that rely on the integrity of the expiration dates data.
Returns
-
bool
Indicates whether the OptionsExpirationsResponse is valid. A return value of true means all expiration dates are correctly formatted and the Expirations slice is not empty.
Notes
- The parsing of expiration date strings is sensitive to the timezone specified. Incorrect timezone handling may lead to validation errors.
String
func (oer *OptionsExpirationsResponse) String() string
String returns a string representation of the OptionsExpirationsResponse. This method is primarily used for logging or debugging purposes, where a human-readable format of the OptionsExpirationsResponse is required. It formats the expirations and the updated timestamp into a readable string.
Returns
-
string
A string that represents the OptionsExpirationsResponse object.
Unpack
func (oer *OptionsExpirationsResponse) Unpack() ([]time.Time, error)
Unpack converts the expiration date strings in the OptionsExpirationsResponse to a slice of time.Time objects, adjusting each to 4:00 PM Eastern Time, the typical expiration time for options contracts. This method is essential for users who need to work with the actual expiration times of options rather than just the dates.
Returns
-
[]time.Time
A slice of time.Time objects representing the expiration dates and times.
-
error
An error if any date string cannot be parsed or if the "America/New_York" timezone cannot be loaded.
Notes
- This method assumes that all expiration times are at 4:00 PM Eastern Time, which may not be accurate for all options contracts.