Skip to main content

Strikes

Retrieve a complete or filtered list of option strike prices for a given underlying symbol. Both real-time and historical requests are possible.

Making Requests

Utilize OptionStrikesRequest for querying the endpoint through one of the three available methods:

MethodExecutionReturn TypeDescription
GetDirect[]OptionStrikesImmediately fetches a slice of []OptionStrikes, allowing direct access to the options strikes data.
PackedIntermediate*OptionStrikesResponseDelivers a *OptionStrikesResponse object containing the data, which requires unpacking to access the []OptionStrikes slice.
RawLow-level*resty.ResponseOffers the unprocessed *resty.Response for those seeking full control and access to the raw JSON or *http.Response.

OptionStrikesRequest

type OptionStrikesRequest struct {
// contains filtered or unexported fields
}

OptionStrikesRequest represents a request to the /v1/options/strikes/ endpoint. It encapsulates parameters for underlying symbol, expiration, and date to be used in the request. This struct provides methods such as UnderlyingSymbol(), Expiration(), and Date() to set these parameters respectively.

Setter Methods

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.

resp, err := OptionStrikes().UnderlyingSymbol("AAPL").Date("2009-02-09").Get()
if err != nil {
fmt.Print(err)
return
}

for _, expiration := range resp {
fmt.Println(expiration)
}

Output

OptionStrikes{Expiration: 2009-02-20, Strikes: [40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00]}
OptionStrikes{Expiration: 2009-03-20, Strikes: [35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00]}
OptionStrikes{Expiration: 2009-04-17, Strikes: [15.00 17.50 20.00 22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 165.00 170.00 175.00 180.00 185.00 190.00 195.00 200.00 210.00 220.00 230.00 240.00 250.00 260.00 270.00 280.00 290.00 300.00]}
OptionStrikes{Expiration: 2009-07-17, Strikes: [12.50 15.00 17.50 20.00 22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 165.00 170.00 175.00 180.00 185.00 190.00]}
OptionStrikes{Expiration: 2010-01-15, Strikes: [22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 170.00 180.00 190.00 200.00 210.00 220.00 230.00 240.00 250.00 260.00 270.00 280.00 290.00 300.00 310.00 320.00 330.00 340.00 350.00 360.00 370.00 380.00 390.00 400.00]}
OptionStrikes{Expiration: 2011-01-21, Strikes: [20.00 30.00 40.00 50.00 60.00 70.00 80.00 85.00 90.00 95.00 100.00 110.00 120.00 125.00 130.00 140.00 150.00 160.00 170.00 180.00 190.00 200.00 210.00 220.00 230.00 240.00]}

OptionStrikes

func OptionStrikes() *OptionStrikesRequest

OptionStrikes creates a new OptionStrikesRequest and uses the default client. This function initializes the request with default parameters for underlying symbol, expiration, and date, and sets the request path based on the predefined endpoints for options strikes.

Returns

  • *OptionStrikesRequest

    A pointer to the newly created OptionStrikesRequest with default parameters.

OptionStrikesRequest Setter Methods

Date

func (o *OptionStrikesRequest) Date(date interface{}) *OptionStrikesRequest

Date sets the date parameter for the OptionStrikesRequest. This is used to make a historical request. This method is used to specify the date for which the options strikes data is requested.

Parameters

  • interface{}

    An interface{} representing the date to be set. It can be a string, a time.Time object, a Unix int, or any other type that the underlying dates package method can process.

Returns

  • *OptionStrikesRequest

    This method returns a pointer to the OptionStrikesRequest instance it was called on. This allows for method chaining.

Expiration

func (o *OptionStrikesRequest) Expiration(expiration string) *OptionStrikesRequest

Expiration sets the expiration parameter for the OptionStrikesRequest. This method is used to specify the expiration date of the options for which strikes data is requested.

Parameters

  • expiration

    A string representing the expiration date to be set.

Returns

  • *OptionStrikesRequest

    This method returns a pointer to the OptionStrikesRequest instance it was called on. This allows for method chaining.

UnderlyingSymbol

func (o *OptionStrikesRequest) UnderlyingSymbol(underlyingSymbol string) *OptionStrikesRequest

UnderlyingSymbol sets the underlying symbol parameter for the OptionStrikesRequest. This method is used to specify the symbol of the underlying asset for which options strikes data is requested.

Parameters

  • underlyingSymbol

    A string representing the symbol to be set.

Returns

  • *OptionStrikesRequest

    This method returns a pointer to the OptionStrikesRequest instance it was called on. This allows for method chaining.

OptionStrikesRequest Execution Methods

Get

func (osr *OptionStrikesRequest) Get() ([]models.OptionStrikes, error)

Get sends the OptionStrikesRequest, unpacks the OptionStrikesResponse, and returns a slice of OptionStrikes. It returns an error if the request or unpacking fails.

Returns

  • []models.OptionStrikes

    A slice of OptionStrikes containing the unpacked options strikes data from the response.

  • error

    An error object that indicates a failure in sending the request or unpacking the response.

Packed

func (osr *OptionStrikesRequest) Packed() (*models.OptionStrikesResponse, error)

Packed sends the OptionStrikesRequest and returns the OptionStrikesResponse.

Returns

  • *models.OptionStrikesResponse

    A pointer to the OptionStrikesResponse obtained from the request.

  • error

    An error object that indicates a failure in sending the request.

Raw

func (osr *OptionStrikesRequest) Raw() (*resty.Response, error)

Raw executes the OptionStrikesRequest and returns the raw *resty.Response. This method returns the *resty.Response which can be used to directly access the raw JSON or *http.Response.

Returns

  • *resty.Response

    The raw HTTP response from the executed OptionStrikesRequest.

  • error

    An error object if the OptionStrikesRequest is nil or if an error occurs during the request execution.

OptionStrikesResponse

type OptionStrikesResponse struct {
Updated int `json:"updated"` // Updated is a UNIX timestamp indicating when the data was last updated.
Strikes *orderedmap.OrderedMap `json:"-"` // Strikes is a map where each key is a date string and the value is a slice of strike prices for that date.
}

OptionStrikesResponse encapsulates the response structure for a request to retrieve option strikes, including the last update timestamp and a map of strikes organized by expiration date. The map uses ordered keys to maintain the chronological order of expiration dates.

Generated By

Methods

  • UnmarshalJSON(data []byte) error

    Custom unmarshals JSON data, initializing the Strikes map with ordered expiration dates and their corresponding strike prices.

  • IsValid() bool

    Checks if the OptionStrikesResponse contains valid data.

  • Validate() error

    Validates the integrity of the OptionStrikesResponse, ensuring it contains valid strikes data.

  • String() string

    Returns a string representation of the OptionStrikesResponse, detailing strikes and their prices.

  • Unpack() ([]OptionStrikes, error)

    Converts the ordered map of strikes into a slice of OptionStrikes, each representing a set of strikes and their corresponding expiration date.

Notes

  • The Strikes field is represented as an ordered map to maintain the order of dates, which is crucial.
  • The Updated field uses a UNIX timestamp to indicate the last time the data was updated.

IsValid

func (osr *OptionStrikesResponse) IsValid() bool

IsValid determines the validity of the OptionStrikesResponse object by invoking the Validate method. This method is primarily used to quickly assess whether the response received from an options strikes request adheres to the expected structure and contains valid data. It simplifies error handling by providing a boolean indicator of validity, which can be particularly useful in conditional logic where a binary valid/invalid decision is required.

Returns

  • bool

    Indicates whether the OptionStrikesResponse is valid. A return value of true signifies a valid response, while false indicates an invalid response.

Notes

  • This method is a convenience wrapper around the Validate method, offering a simplified interface for validity checking.

String

func (osr *OptionStrikesResponse) String() string

String returns a string representation of the OptionStrikesResponse struct, encapsulating the details of strikes and their corresponding prices in a human-readable format. This method is primarily used for logging, debugging, or any scenario where a textual representation of the OptionStrikesResponse data is necessary for understanding or analysis.

Returns

  • string

    The string representation of the OptionStrikesResponse, detailing the strikes and their prices.

Notes

  • This method formats the strikes data into a string, making it easier to visualize the structure and content of the OptionStrikesResponse.

UnmarshalJSON

func (osr *OptionStrikesResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshals the JSON data into the OptionStrikesResponse struct.

Parameters

  • data []byte

    The JSON data to be unmarshaled.

Returns

  • error

    An error if unmarshaling fails, nil otherwise.

Unpack

func (osr *OptionStrikesResponse) Unpack() ([]OptionStrikes, error)

Unpack converts the ordered map of strikes contained within the OptionStrikesResponse into a slice of OptionStrikes. This method is primarily used when a user needs to work with a structured list of strikes and their expiration dates, rather than dealing with the map data structure. It simplifies the process of iterating over strikes and performing operations on them.

Returns

  • []OptionStrikes

    A slice of OptionStrikes, each representing a set of strikes and their corresponding expiration date.

  • error

    An error if the validation of the OptionStrikesResponse fails or if there are issues parsing the dates.

Notes

  • This method first validates the OptionStrikesResponse to ensure it contains valid data before attempting to unpack the strikes.

Validate

func (osr *OptionStrikesResponse) Validate() error

Validate assesses the integrity of the OptionStrikesResponse object. It is primarily used to ensure that the response received from an options strikes request contains valid and expected data, such as non-empty strikes data. This method is crucial for error handling and data validation in financial market data applications, preventing the further processing of invalid responses.

Returns

  • error

    An error indicating that the OptionStrikesResponse is invalid, typically due to missing strikes data, or nil if the response is valid.

Notes

  • This method is a fundamental part of the data validation process, ensuring that only responses with valid strikes data are processed.

OptionStrikes

type OptionStrikes struct {
Expiration time.Time // Expiration is the date and time when the option expires.
Strikes []float64 // Strikes is a slice of strike prices available for the option.
}

OptionStrikes encapsulates the expiration date and available strike prices for an option contract.

Generated By

Methods

  • String() string

    Returns a string representation of the OptionStrikes, detailing its expiration and formatted strike prices.

Notes

  • This struct is primarily used to represent the structured data of option strikes and their expiration dates after unpacking from a JSON response.

String

func (os OptionStrikes) String() string

String provides a human-readable representation of the OptionStrikes struct, including its expiration and strike prices. This method is primarily used for logging, debugging, or displaying the OptionStrikes in a format that is easy to read and understand.

Returns

  • string

    A formatted string encapsulating the details of the OptionStrikes, particularly its expiration and formatted strike prices.

Notes

  • This method formats strike prices to two decimal places and joins them with a space for readability.