---
title: Lookup
sidebar_position: 2
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";





Lookup the official option symbol based on a user's text input.

## Making Requests

Utilize \[OptionsLookupRequest\] for querying the endpoint through one of the three available methods:

| Method     | Execution       | Return Type                  | Description                                                                                                             |
|------------|-----------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| **Get**    | Direct          | `string`                     | Immediately fetches and `string`, allowing direct access to the option symbol.                                          |
| **Packed** | Intermediate    | `*OptionLookupResponse`      | Delivers a `*OptionLookupResponse` object containing the data, which requires unpacking to access the `string` 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`. |


<a name="OptionLookupRequest"></a>
## OptionLookupRequest

```go
type OptionLookupRequest struct {
    // contains filtered or unexported fields
}
```

OptionsLookupRequest represents a request to the [/v1/options/lookup/](<https://www.marketdata.app/docs/api/options/lookup>) endpoint for retrieving an OCC\-formatted option symbol based on user input. It encapsulates parameters for user input to be used in the request.

#### Generated By

- <a href="#OptionsLookup">`OptionsLookup() *OptionsLookupRequest`</a>

  OptionsLookup creates a new \*OptionsLookupRequest and returns a pointer to the request allowing for method chaining.


#### Setter Methods

- <a href="#OptionLookupRequest.UserInput">`UserInput(string) *OptionLookupRequest`</a>

  Sets the user input parameter for the 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.

- <a href="#OptionLookupRequest.Get">`Get() (string, error)`</a>

  Sends the request, unpacks the response, and returns the data in a user\-friendly format.

- <a href="#OptionLookupRequest.Packed">`Packed() (*OptionLookupResponse, error)`</a>

  Returns a struct that contains equal\-length slices of primitives. This packed response mirrors Market Data's JSON response.

- <a href="#OptionLookupRequest.Raw">`Raw() (*resty.Response, error)`</a>

  Sends the request as is and returns the raw HTTP response.




<Tabs>
<TabItem value="Example (Get)" label="Example (Get)">




```go
resp, err := OptionLookup().UserInput("AAPL 7/28/2023 200 Call").Get()
if err != nil {
	fmt.Print(err)
	return
}

fmt.Println(resp)
```

#### Output

```
AAPL230728C00200000
```

</TabItem>

<TabItem value="Example (Packed)" label="Example (Packed)">




```go
resp, err := OptionLookup().UserInput("AAPL 7/28/2023 200 Call").Packed()
if err != nil {
	fmt.Print(err)
	return
}

fmt.Println(resp)
```

#### Output

```
OptionLookupResponse{OptionSymbol: "AAPL230728C00200000"}
```

</TabItem>
</Tabs>

<a name="OptionLookup"></a>
### OptionLookup

```go
func OptionLookup() *OptionLookupRequest
```

OptionLookup creates a new OptionsLookupRequest and uses the default client.

#### Returns

- `*OptionsLookupRequest`

  A pointer to the newly created OptionsLookupRequest with default parameters and associated client.

## OptionLookupRequest Setter Methods

<a name="OptionLookupRequest.UserInput"></a>
### UserInput

```go
func (o *OptionLookupRequest) UserInput(userInput string) *OptionLookupRequest
```

UserInput sets the user input parameter for the OptionsLookupRequest. This method is used to specify the user input for which the options data is requested.

#### Parameters

- `string`

  A string representing the text to lookup with the OptionsLookupRequest endpoint.


#### Returns

- `*OptionsLookupRequest`

  This method returns a pointer to the OptionsLookupRequest instance it was called on, allowing for method chaining.



## OptionLookupRequest Execution Methods
<a name="OptionLookupRequest.Get"></a>
### Get

```go
func (o *OptionLookupRequest) Get() (string, error)
```

Get sends the OptionLookupRequest, unpacks the OptionsLookupResponse, and returns the unpacked data as a string. It returns an error if the request or unpacking fails.

#### Returns

- `string`

  A string containing the unpacked options data from the response.

- `error`

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



<a name="OptionLookupRequest.Packed"></a>
### Packed

```go
func (o *OptionLookupRequest) Packed() (*models.OptionLookupResponse, error)
```

Packed sends the OptionLookupRequest and returns the OptionsLookupResponse.

#### Returns

- `*models.OptionsLookupResponse`

  A pointer to the OptionsLookupResponse obtained from the request.

- `error`

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


<a name="OptionLookupRequest.Raw"></a>
### Raw

```go
func (olr *OptionLookupRequest) Raw() (*resty.Response, error)
```

Raw executes the OptionLookupRequest and returns the raw \*resty.Response. The \*resty.Response allows access to the raw JSON or \*http.Response for further processing.

#### Returns

- `*resty.Response`

  The raw HTTP response from the executed OptionLookupRequest.

- `error`

  An error object if the request fails due to being nil, or other execution errors.



<a name="OptionLookupResponse"></a>
## OptionLookupResponse

```go
type OptionLookupResponse struct {
    OptionSymbol string `json:"optionSymbol"` // OptionSymbol is the symbol of the option.
}
```

OptionLookupResponse encapsulates the response data for an option lookup request, primarily containing the option's symbol.

#### Generated By

- <a href="#OptionLookupRequest.Packed">`OptionLookupRequest.Packed()`</a>

  Unmarshals the JSON response from OptionLookupRequest into OptionLookupResponse.


#### Methods

- <a href="#OptionLookupResponse.IsValid">`IsValid() bool`</a>

  Checks if the OptionLookupResponse is valid by verifying the OptionSymbol is not empty.

- <a href="#OptionLookupResponse.String">`String() string`</a>

  Provides a string representation of the OptionLookupResponse, including the OptionSymbol.

- <a href="#OptionLookupResponse.Unpack">`Unpack() (string, error)`</a>

  Validates the OptionLookupResponse and returns the OptionSymbol if valid; otherwise, returns an error.


#### Notes

- This struct is primarily used for handling the response of an options lookup request in financial market data applications.



<a name="OptionLookupResponse.IsValid"></a>
### IsValid

```go
func (olr *OptionLookupResponse) IsValid() bool
```

IsValid determines the validity of the OptionLookupResponse. It is primarily used to ensure that the response received from an option lookup request contains a non\-empty OptionSymbol, indicating a successful lookup and a valid option.

#### Returns

- `bool`

  Indicates the validity of the OptionLookupResponse. Returns true if the OptionSymbol is not empty, otherwise false.


<a name="OptionLookupResponse.String"></a>
### String

```go
func (olr *OptionLookupResponse) String() string
```

#### Notes

- This method is primarily intended for debugging purposes or when there's a need to log the response details in a human\-readable format.

<a name="OptionLookupResponse.Unpack"></a>
### Unpack

```go
func (olr *OptionLookupResponse) Unpack() (string, error)
```

Unpack checks the validity of the OptionLookupResponse and returns the OptionSymbol if the response is deemed valid. This method is primarily used when one needs to extract the OptionSymbol from a valid OptionLookupResponse, ensuring that the response is not empty or malformed before proceeding with further processing.

#### Returns

- `string`

  The OptionSymbol contained within a valid OptionLookupResponse.

- `error`

  An error indicating that the OptionLookupResponse is invalid, typically due to an empty OptionSymbol.


#### Notes

- This method is crucial for error handling and data validation in financial market data applications, ensuring that only valid responses are processed.









