Skip to main content

Filtering

Edges and nodes

To filter results, queries should be sent via path field edges.

When working with arrays of data, you may need to refine your query, leaving only the data that matches your current interests in the response. To do this, you can use the tools for filtering the returned data.


Filtering argument

Data can be filtered by the properties of the returned objects. The where argument of the path root field is used for this purpose.

The XModelFilterInput input data groups are used as a filter, where X is the name of the interface whose data is used for filtering:

  • InstrumentModelFilterInput — filters of the Instrument interface.
  • BondFilterInput — filters of Bond interface
  • DerivativeFilterInput — filters of the Derivative interface.
  • StockFilterInput — filters of the Stock interface.

For example, as filters for the Instrument interface you can use the path fields basicInformation, currencyInformation, tradingDetails, financialAttributes, boardInformation and additionalInformation, as well as all data fields included in them.


Input values

As a value, the filter can expect either a random value corresponding to the input data format or one of the predefined values from the schema. Thus, according to the schema, for filtering on the field symbol a ticker in string format is expected (for example, “SBER”), while for the field market one of the values from the list enum Market will be required.

Example from schema

"""
List of possible filters for the BasicInformation field
"""
input BasicInformationFilterInput {
and: [BasicInformationFilterInput!]
or: [BasicInformationFilterInput!]
symbol: StringOperationFilterInput
exchange: ExchangeOperationFilterInput
description: StringOperationFilterInput
shortName: StringOperationFilterInput
type: StringOperationFilterInput
market: MarketOperationFilterInput
}

"""
List of possible keys for the market field
"""
input MarketOperationFilterInput {
eq: Market
neq: Market
in: [Market!]
nin: [Market!]
}

"""
List of possible values for the market field
"""
enum Market {
FOND
CURR
FORTS
SPBX
UNITED
BE
INFO
ITS
}

Filtering keys

Each filter has a key that determines the match between the actual value of the field and the specified value. The complete list of keys depends on the scheme of the selected field. The keys can be as follows:

  • eq/neq - the actual value is (not) equal to the specified value
  • contains/ncontains - the actual value (does not) contain the specified value
  • in/nin - actual value (not) included in list of values
  • startsWith/nstartsWith - the actual value (does not) start with the specified value
  • endsWith/nendsWith - the actual value (does not) end with the specified value
Request example
{
instruments(where: { basicInformation: { symbol: { contains: "SBER" } } }) {
edges {
node {
basicInformation {
symbol
...
}
}
}
}
}
Response example
{
"data": {
"instruments": {
"edges": [
{
"node": {
"basicInformation": {
"symbol": "SBER",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP300424CE310",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP080524CE320",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP150524PE310",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP080524CE310",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP300424PE290",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP300424CE320",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP150524CE320",
...
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP080524PE310",
...
}
}
}
]
}
}
}

Filter grouping

Filters can be grouped using logical operators to obtain more accurate data. Two operators are available:

  • and — all specified filters must be executed
  • or — at least one of the specified filters must be executed
Request example
{
instruments(where: { and: [ { basicInformation: { symbol: { contains: "SBER" } market: { eq: FOND } } } ] }) {
edges {
node {
basicInformation {
symbol
...
market
}
}
}
}
}
Response example
{
"data": {
"instruments": {
"edges": [
{
"node": {
"basicInformation": {
"symbol": "SBER",
...
"market": "FOND"
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBERP",
...
"market": "FOND"
}
}
},
{
"node": {
"basicInformation": {
"symbol": "SBER-ME",
...
"market": "FOND"
}
}
}
]
}
}
}

Grouped filters must correspond to the scheme both in spelling and structure. An additional filter can be added either as a separate object or as part of an existing filter (only if different data fields are used). For example, both of the following variants of adding filters will be correct:

Request example
{
instruments(where: { and: [ { basicInformation: { symbol: { contains: "SBER" } market: { eq: FOND } } } ] }) {
edges {
node {
basicInformation {
...
}
}
}
}
}
Request example
{
instruments(where: { and: [ { basicInformation: { symbol: { contains: "SBER" } } } { basicInformation: {market: { eq: FOND }}} ] }) {
edges {
node {
basicInformation {
...
}
}
}
}
}

Logical operators can be combined to increase selection variability:

Request example
{
instruments(where: {
and: [ { basicInformation: { symbol: { contains: "SBER" } } } { or: [ { basicInformation: { market: { eq: FOND } } } { basicInformation: { market: { eq: FORTS } } } ] } ] }) {
edges {
node {
basicInformation {
symbol
...
market
}
}
}
}
}

The system will return all objects with SBER value in the symbol field and market field value equal to FOND or FORTS (an example of such a response is above).

A group of one

The logical operators and and or can be used even with a single filter. This will have no effect on the output results, but it will not cause an error in query processing.


Filtering by value lists

The in/nin filter keys, unlike other keys, expect to receive not a single value, but a whole list to be compared against. The availability of this key for the selected field and the allowed values and their format are defined by the schema.

To add a list of values to compare against actual field values, enclose all values of interest in square brackets [ ]:

Request example
{
instruments(where: { and: [ { basicInformation: { symbol: { contains: "SBER" } } } { basicInformation: { market: { in: [FOND FORTS] } } } ] }) {
edges {
node {
basicInformation {
...
}
}
}
}
}

In response, the system will return all objects in which the value of SBER in the symbol field is found and the value of the market field matches one of the values specified in the list - FOND or FORTS (an example of such response is above).


What's next?

Additionally, we recommend reading the following related articles: