> For the complete documentation index, see [llms.txt](https://docs.thetanuts.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.thetanuts.finance/sdk/pricing/filters-utilities.md).

# Filters & Utilities

Helper methods on `MMPricingModule` for filtering, sorting, and selecting pricing data from a pricing array.

## Setup

All utilities are methods on `client.mmPricing`. Start by fetching a pricing array:

```typescript
import { ThetanutsClient } from '@thetanuts-finance/thetanuts-client';

const client = new ThetanutsClient({ chainId: 8453 });

const all = await client.mmPricing.getAllPricing('ETH');
const values = Object.values(all);
```

***

## filterExpired

Removes options whose expiry has already passed.

```typescript
const active = client.mmPricing.filterExpired(values);
// Returns only options with expiry > Date.now()
```

***

## sortByExpiryAndStrike

Sorts options by nearest expiry first, then ascending strike within each expiry.

```typescript
const sorted = client.mmPricing.sortByExpiryAndStrike(values);
// [{ expiry: 1710547200, strike: 1800 }, { expiry: 1710547200, strike: 2000 }, ...]
```

***

## getUniqueExpiries

Returns a deduplicated list of expiry date strings in `YYYY-MM-DD` format, sorted ascending.

```typescript
const expiries = client.mmPricing.getUniqueExpiries(values);
// ['2025-02-16', '2025-03-16', '2025-06-27', ...]
```

***

## filterByType

Filters the array to only calls (`isCall: true`) or only puts (`isCall: false`).

```typescript
const puts  = client.mmPricing.filterByType(values, false);
const calls = client.mmPricing.filterByType(values, true);
```

***

## filterByExpiry

Filters the array to options expiring on a specific date string (`YYYY-MM-DD`).

```typescript
const feb16 = client.mmPricing.filterByExpiry(values, '2025-02-16');
```

***

## filterByStrikeRange

Filters the array to options whose strike falls within `[min, max]` (inclusive).

```typescript
const nearATM = client.mmPricing.filterByStrikeRange(values, 1800, 2200);
```

***

## getPricingArray

Convenience method: fetches all pricing for an underlying, removes expired entries, and returns the result as a sorted array in one call.

```typescript
const pricing = await client.mmPricing.getPricingArray('ETH');
// Equivalent to:
// const all = await client.mmPricing.getAllPricing('ETH');
// const sorted = client.mmPricing.sortByExpiryAndStrike(
//   client.mmPricing.filterExpired(Object.values(all))
// );
```

***

## Combining Utilities

Utilities can be chained to build a precise subset. Example: active put options near ATM for a specific expiry.

```typescript
import { ThetanutsClient } from '@thetanuts-finance/thetanuts-client';

const client = new ThetanutsClient({ chainId: 8453 });

const pricing = await client.mmPricing.getPricingArray('ETH');

const nearATMPuts = client.mmPricing.filterByStrikeRange(
  client.mmPricing.filterByType(
    client.mmPricing.filterByExpiry(pricing, '2025-03-16'),
    false  // puts only
  ),
  1800,
  2200
);

console.log(nearATMPuts.map(p => p.strike));
// [1800, 1900, 2000, 2100, 2200]
```

***

## See Also

* [MM Pricing Overview](/sdk/pricing/mm-pricing.md) - `getAllPricing`, `getTickerPricing`, and `MMPricingModule` method table
* [Position & Spread Pricing](/sdk/pricing/position-spread-pricing.md) - `getPositionPricing` and `getSpreadPricing`
* [Collateral Cost Reference](/sdk/pricing/collateral-cost.md) - APR rates and carrying cost formula


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.thetanuts.finance/sdk/pricing/filters-utilities.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
