Skip to content
On this page

Action: Filter

It is possible to let the server filter data before it is sent to you. This allows you to manage your bandwidth and only receive the data you actually need. You can filter by any field in the data, and you can use multiple filters at once. You can also change your filters at any time.

Example

WARNING

The below example uses fictitious keys to illustrate the concept of filtering. For actual keys, you should use the properties as defined in the data structure of the stream type you are filtering for, for example Streams: Trade for trades. The same principles apply to any other stream.

At any time after authentication you can update the set of filters used as predicates to determine whether an object should be emitted. To do so, send a message with the following structure through the WebSocket connection:

json
{
   "action": "update_filters",
   "body": [
      {
         "key": "quantity",
         "value": "0.5",
         "operator":">"
      },
      {
         "key": "buyerMarketMaker",
         "value": true
      }
   ]
}

Which would accept trades for which trade.quantity > 0.5 and trade.buyerMarketMaker == true hold true. Note that == is the default operator. You are allowed to use up to ten filters and all the filters must be met for a trade to be accepted. If any of the filters reject a trade, the trade is not emitted. If a filter object is not structured correctly, it is discarded and doesn't count towards the maximum limit of filters. However, if a filter is valid in its structure but invalid in the context its being run in, for example if it checks an invalid key or the operator does not make sense for the value the key corresponds to, then it does count towards the maximum limit however it will not be used to filter trades. Here follows a list of valid operators

  • == and !=
  • <, >, <=, >=, for numeric values
  • IN, compares the value corresponding to the supplied key as a string to a list of comma separated values
  • LIKE, matches a string but with % as wildcard operator, allowing you to match "seafood" using a value of "%foo%" or "%food"
  • UNLIKE is the logical negation of the LIKE operator