Skip to main content
A filter decides which trades a subscription receives. The server evaluates it before sending, and replayed trades go through the same filter. Pass it in params.filters when you subscribe.

Grammar

A filter is a JSON object with exactly one key, the operator. An object with no key, an unknown key, or two keys is rejected with Each condition has one operator: eq, in, gt, gte, lt, lte, and, or.
  • eq and in values are JSON strings.
  • Comparison values are JSON numbers. The string "100000" is rejected.
  • eq and in don’t work on tokenAmountUsd, and comparisons don’t work on any other field. Use gte and lte together for an exact USD range.

Fields

  • Pool type values are the lowercase protocol slugs used across the API, such as uniswap-v2, uniswap-v3, uniswap-v4, pancakeswap-v3 or clanker-v4. See Protocols and launchpads. "Uniswap-V3" matches nothing.
  • A trade without a poolType never matches a poolType condition.
  • An invalid address is rejected with Invalid <field>: must be a valid token or wallet address, or for poolAddress, Invalid poolAddress: must be a valid token address or pool id.

type: buy or sell

The payload has no side field, so the server works out a side for each trade:
  1. Reference token. If the whole filter names exactly one distinct tokenAddress (through eq or in, anywhere in the tree, including inside or) and that token is in the trade, it is the reference. Otherwise the reference is the trade’s baseToken.
  2. Side. If the reference token’s raw amount is positive (it went into the pool), the side is sell. Otherwise it is buy.
So { "and": [{ "eq": ["tokenAddress", WETH] }, { "eq": ["type", "buy"] }] } matches trades where WETH was bought, whichever side of the pool WETH is on.
If the filter names two or more tokens, the side is taken from each trade’s baseToken, even for trades of the tokens you named. { "in": ["tokenAddress", [A, B]] } combined with { "eq": ["type", "buy"] } means “the base token was bought”. To filter buys of several specific tokens, use one subscription per token.
See Deriving buy or sell to compute the same side on the client.

Limits

The whole subscribe message must also fit in 64 KiB. A full list of 500 addresses takes about 22 KB, so at most two full lists fit in one message. See Limits and subscription cost.

One filter or one per event kind

filters takes two forms:
  • One filter. A single condition applies to every kind in events.
  • A map. An object whose keys are all event kinds (swap, swap-enriched) gives each kind its own filter. No event kind is named like an operator, so the two forms can’t be confused.
Map rules:
  • Every kind in events needs an entry. A missing one fails with filters.<kind>: every requested event needs a filter.
  • A key that isn’t in events fails with filters.<key>: not in events.
  • You can’t leave one kind unfiltered inside a map. Use a second subscription instead.
Without filters, every trade on the requested chains is delivered.

Cookbook

Each example shows the value of params.filters and its cost per pair. “Chain-wide” filters cost 10 per pair because the server checks them against every trade on the chain.
{ "in": ["poolType", ["uniswap-v3", "uniswap-v4"]] } is equivalent.
Matches trades where the token is on either side, including WETH/USDC and memecoin/WETH pools.
The gte branch pins nothing, so the whole or is chain-wide. See Limits and subscription cost.

Validation errors

An invalid filter fails the subscription with code INVALID_PARAMETERS. Each problem is listed in details with a dotted field path:
  • The path starts with filters, then the event kind when you use the map form, then the operators and array indexes down to the bad value.
  • filters.and.0.gte.0 is the field name (index 0) of the gte condition that is the first child of and.
  • filters.swap-enriched.and.0.gte.0 is the same position in the swap-enriched filter of a map.
Filter errors always use INVALID_PARAMETERS, including bad addresses.
Rely on the field path and code in your code. The wording of type and range messages (such as an expected number) may change.