Lookup
Resolve an option contract to its standard OCC option symbol from the underlying symbol, expiration date, strike price, and option type.
Making Requests
Lookup takes the four contract attributes as ordinary Go arguments and
returns the OCC option symbol as a string, suitable for use with
Quote and Quotes. Choose the call style that fits
your code:
| Method | Return | Description |
|---|---|---|
GetLookup(underlying, expiration, strike, optionType) | (string, error) | Convenience; uses a background context. |
Lookup(ctx, underlying, expiration, strike, optionType) | (string, *response.Response, error) | Context-aware; also returns the raw response and rate-limit metadata. |
Lookup
func (s *Service) Lookup(ctx context.Context, underlying string, expiration time.Time, strike float64, optionType OptionType) (string, *response.Response, error)
func (s *Service) GetLookup(underlying string, expiration time.Time, strike float64, optionType OptionType) (string, error)
Lookup builds an OCC option symbol (for example AAPL250117C00150000) from
a contract description. The underlying symbol, the expiration date, the strike
price, and the option type are all required. The resolved symbol can then be
passed to Quote or
Quotes.
Parameters
underlying(string) — the underlying stock symbol (for example"AAPL"). Required; an empty string is rejected with amarketdata.ValidationErrorbefore any request is made.expiration(time.Time) — the contract's expiration date. Only the calendar date is used (formatted as2006-01-02).strike(float64) — the strike price (for example150.0).optionType(options.OptionType) — the contract type:options.Calloroptions.Put.
Returns
string— the OCC option symbol. Empty when the contract cannot be resolved (see Notes).*response.Response— the raw response plus rate-limit metadata (context method only).error— non-nil on a validation failure, transport error, or unexpected API status.
Notes
- The OCC symbol format is
SYMBOL + YYMMDD + C/P + STRIKE (8 digits). For example,AAPL250117C00150000is an AAPL January 17, 2025 $150 call. - If the API cannot resolve the contract (HTTP 404),
Lookupreturns an empty string, a response whoseNoDatafield istrue, and anilerror. Check for an empty string before using the result. - The lookup query is sent as a single URL path segment; there are no query parameters and no functional options for this endpoint.
- Get (simple)
- Context + Response
- Lookup then Quote
package main
import (
"fmt"
"log"
"time"
"github.com/MarketDataApp/sdk-go/v2/marketdata"
"github.com/MarketDataApp/sdk-go/v2/marketdata/options"
)
func main() {
client, err := marketdata.NewClient(marketdata.WithToken("YOUR_TOKEN"))
if err != nil {
log.Fatal(err)
}
defer client.Close()
expiration := time.Date(2025, time.January, 17, 0, 0, 0, 0, time.UTC)
symbol, err := client.Options.GetLookup("AAPL", expiration, 150.0, options.Call)
if err != nil {
log.Fatal(err)
}
if symbol == "" {
fmt.Println("Contract could not be resolved.")
return
}
fmt.Printf("OCC symbol: %s\n", symbol)
}
Output
OCC symbol: AAPL250117C00150000
ctx := context.Background()
expiration := time.Date(2025, time.January, 17, 0, 0, 0, 0, time.UTC)
symbol, resp, err := client.Options.Lookup(ctx, "AAPL", expiration, 150.0, options.Call)
if err != nil {
log.Fatal(err)
}
fmt.Printf("OCC symbol: %s\n", symbol)
fmt.Printf("Requests remaining: %d\n", resp.RateLimit.Remaining)
ctx := context.Background()
expiration := time.Date(2025, time.January, 17, 0, 0, 0, 0, time.UTC)
// Resolve the OCC symbol, then fetch its quote.
symbol, _, err := client.Options.Lookup(ctx, "AAPL", expiration, 150.0, options.Call)
if err != nil {
log.Fatal(err)
}
quote, _, err := client.Options.Quote(ctx, symbol)
if err != nil {
log.Fatal(err)
}
if quote != nil {
fmt.Printf("%s Bid: %.2f Ask: %.2f\n", quote.OptionSymbol, quote.Bid, quote.Ask)
}
OptionType
type OptionType string
const (
Call OptionType = "call"
Put OptionType = "put"
)
OptionType identifies a contract as a call or a put. It is the required
contract-type argument to Lookup and the Type field of an
OptionQuote. Use the options.Call and
options.Put constants.