Graphql

How to use Graphql In Finmars and query examples

Getting Started

What is GraphQL

GraphQL is an API query language.

It lets the client ask exactly for the data it needs.
No more. No less.

Main ideas:

GraphQL replaces many REST endpoints with one structured API.


What We Use in Finmars

In Finmars, GraphQL is built with:

Strawberry is a Python GraphQL library.
It works well with Django models.
It uses Python type hints to define the schema.

Key points:




Access to Graphql from Browser Playground

Open the GraphQL playground in your browser:

https://<your-finmars-domain>/:realm_code:/space_code:/graphql/

E.g. https://eu-central.finmars.com/realm0v4ry/space063sw/graphql/ (Link is not lead to anything, just an example)

You will see:

You must be authenticated.

Screenshot 2025-12-16 at 15.49.17.png


You can access Documentation


Click ob button with Book icon in top left corner


Screenshot 2025-12-16 at 17.04.47.png

Now you can navigate on Schema

To see what operation you could call, click on "Query"




Screenshot 2025-12-16 at 17.05.41.png

Here is the list of supported operations.


Screenshot 2025-12-16 at 17.06.16.png

So, here you can see "Type" it will show to you all available Fields to work with in your Query

Also you can see "Filters" and "Pagination". These sections will show you how to configure your Query to work with data



Screenshot 2025-12-16 at 17.08.10.png


For example you could see that there is String filters and Data Filters. Other Relations fields also could be filters


Access to Graphql from code

GraphQL Endpoint

Finmars exposes GraphQL via a single endpoint.

:realm_code:/:space_code:/graphql/

This endpoint supports:


How to Access the Endpoint

Authentication

GraphQL uses the same authentication as the REST API.

Usually:


"DEFAULT_AUTHENTICATION_CLASSES": (   
   "poms.common.authentication.JWTAuthentication",    
   "poms.common.authentication.KeycloakAuthentication",
),


If you are not authenticated:


From Code

Send a POST request to /graphql/.

import requests

url = "https://finmars.example.com/:realm_code:/:space_code:/graphql/"

headers = {
    "Authorization": "Bearer JWT_TOKEN",
    "Content-Type": "application/json"
}

query = """
query {
  account(pagination: {
    limit: 20
    offset: 0
  }) {
    id
    user_code
    name
    type {
      id
      name
      user_code
    }
  }
}
"""

payload = {
    "query": query
}

response = requests.post(url, json=payload, headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print(response.status_code, response.text)

And Response

{
  "data": {
    "account": [
      {
        "id": "11",
        "user_code": "129900RGLDPQ3DT2T5H1",
        "name": "Securities Vault Alpha",
        "type": {
          "id": "2",
          "name": "Default Account Type",
          "user_code": "com.finmars.standard-other:accounts.accounttype:default"
        }
      },
      {
        "id": "12",
        "user_code": "2398002D4FTG8TG3L9K7",
        "name": "Alpine Depository Services",
        "type": {
          "id": "2",
          "name": "Default Account Type",
          "user_code": "com.finmars.standard-other:accounts.accounttype:default"
        }
      }
    ]
  }
}


Well done!

Get Accounts in Graphql

This query returns a list of accounts with basic fields and account type.



Screenshot 2025-12-16 at 17.01.09.png


GraphQL Query

query GetAccountList {
  account(
    pagination: {
      limit: 20
      offset: 0
    }
  ) {
    id
    user_code
    name
    type {
      id
      name
      user_code
    }
  }
}

Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetAccountList {
      account(
        pagination: {
          limit: 20
          offset: 0
        }
      ) {
        id
        user_code
        name
        type {
          id
          name
          user_code
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

What This Query Does


Notes


Get Portfolios in Graphql

This query returns a list of portfolios with basic fields.



Screenshot 2025-12-16 at 17.03.42.png

GraphQL Query

query GetPortfolioList {
  portfolio(
    pagination: {
      limit: 20
      offset: 0
    }
  ) {
    id
    user_code
    name,
    portfolio_type {
      pk
    }

  }
}

Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetPortfolioList {
      portfolio(
        pagination: {
          limit: 20
          offset: 0
        }
      ) {
        id
        user_code
        name
        portfolio_type {
          pk
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

What This Query Does


Get Portfolio History in Graphql

This query returns historical NAV values for portfolios.

Screenshot 2025-12-16 at 18.27.45.png


GraphQL Query

query GetPortfolioHistoryList {
  portfolio_history(
    pagination: {
      limit: 20
      offset: 0
    }
    filters: {
    }
  ) {
    id
    date
    nav
    portfolio {
      id
      name
      user_code
    }
    currency {
      id
      user_code
      name
    }
    status
  }
}

Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetPortfolioHistoryList {
      portfolio_history(
        pagination: {
          limit: 20
          offset: 0
        }
        filters: {
        }
      ) {
        id
        date
        nav
        portfolio {
          id
          name
          user_code
        }
        currency {
          id
          user_code
          name
        }
        status
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Notes

Example filter:

portfolio: {
  user_code: { exact: "Commodity Portfolio" }
}

Get Currencies in Graphql

This query returns a list of currencies.



Screenshot 2025-12-16 at 17.11.35.png

GraphQL Query

query GetCurrencyList {
  currency(
    pagination: {
      limit: 20
      offset: 0
    }
  ) {
    id
    user_code
    name,
    country {
      id,
      name,
      user_code
    }
  }
}

Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetCurrencyList {
      currency(
        pagination: {
          limit: 20
          offset: 0
        }
      ) {
        id
        user_code
        name
        country {
          id,
          name,
          user_code
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

What This Query Does


Get FX Rates in Graphql


This query returns currency rates for a specific date and specific currency.


Screenshot 2025-12-16 at 17.19.02.png


GraphQL Query

query GetCurrencyHistoryList {
  currency_history(
    pagination: {
      limit: 20
      offset: 0
    }
    filters: {
      date: {
        exact: "2023-12-01"
      }
      pricing_policy: {
        user_code:{
          exact: "com.finmars.standard-pricing:standard"
        }
      }
      currency: {
        user_code: {
          exact: "CHF"
        }
      }
    }
  ) {
    id
    date
    fx_rate
    currency {
      id
      user_code
      name
    }
  }
}

Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetCurrencyHistoryList {
      currency_history(
        pagination: {
          limit: 20
          offset: 0
        }
        filters: {
          date: {
            exact: "2023-12-01"
          }
          pricing_policy: {
            user_code:{
              exact: "com.finmars.standard-pricing:standard"
            }
          }
          currency: {
            user_code: {
              exact: "CHF"
            }
          }
        }
      ) {
        id
        date
        fx_rate
        currency {
          id
          user_code
          name
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Filter Highlights

Exact Match

date: {
  exact: "2023-12-01"
}

Nested Filters

currency: {
  user_code: {
    exact: "CHF"
  }
}

Common Filter Types

Typical filters you may see:

Available filters depend on the field type.


Important Notes

This pattern applies to all list queries in Finmars GraphQL.

Get Instruments in Graphql

This query returns a list of instruments with basic fields and instrument type.


Screenshot 2025-12-16 at 17.42.03.png

GraphQL Query

query GetInstrumentList {
  instrument(
    pagination: {
      limit: 20
      offset: 0
    }
  ) {
    id
    user_code
    name
    maturity_date
    instrument_type {
      id
      user_code
      name
    }
  }
}

Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetInstrumentList {
      instrument(
        pagination: {
          limit: 20
          offset: 0
        }
      ) {
        id
        user_code
        name
        maturity_date
        instrument_type {
          id
          user_code
          name
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Notes

Get Prices in Graphql

This query returns price history rows for one instrument (by user_code).


Screenshot 2025-12-16 at 17.49.19.png


GraphQL Query

query GetPriceHistoryList {
  price_history(
    pagination: {
      limit: 20
      offset: 0
    }
    filters: {
      instrument: {
        user_code: {
          exact: "XS2200244072"
        }
      }
      pricing_policy: {
        user_code:{
          exact: "com.finmars.standard-pricing:standard"
        }
      }
    }
  ) {
    id
    date
    principal_price
    instrument {
      id
      user_code
      name
    }
    pricing_policy {
      id
      user_code
    }
  }
}

Filter Highlights

filters: {
  instrument: {
    user_code: { exact: "XS2200244072" }
  }
}

Why Use user_code


Notes

date: { exact: "2023-12-01" }

Get Transactions in Graphql


This query returns transactions for one portfolio and an accounting date range.

Screenshot 2025-12-16 at 17.57.40.png



GraphQL Query

query GetTransactionList {
  transaction(
    pagination: {
      limit: 20
      offset: 0
    }
    filters: {
      portfolio: {
        user_code: {
          exact: "Commodity Portfolio"
        }
      }
      accounting_date: {
        gte: "2021-01-01"
        lte: "2023-12-31"
      }
    }
  ) {
    id
    accounting_date
    position_size_with_sign
    cash_consideration
    trade_price
    instrument {
      id
      user_code
      name
    }
    portfolio {
      id
      user_code
      name
    }
    account_cash {
      id
      user_code
      name
    }
    account_position {
      id
      user_code
      name
    }
    transaction_class {
      id
      user_code
      name
    }
  }
}

Filter Highlights

Filter by Portfolio (nested filter)

portfolio: {
  user_code: { exact: "Commodity Portfolio" }
}

Filter by Date Range

accounting_date: {
  gte: "2021-01-01"
  lte: "2023-12-31"
}

How filters work together

All filters in one filters block are combined with AND.

So this query means:


Get Balance Report In Graphql

This query returns a balance report for selected portfolios on a given date.

Screenshot 2025-12-16 at 18.12.20.png


GraphQL Query

query GetBalanceReport {
  balance_report(
    input: {
      report_date: "2024-05-01"
      report_currency: "USD"
      pricing_policy: "com.finmars.standard-pricing:standard"
      portfolios: ["Commodity Portfolio"]
    }
  ) {
    items {
      id
      item_type
      item_type_name
      name
      market_value
      position_size
    }
  }
}

Input Highlights

Report Date

report_date: "2024-05-01"

Report Currency

report_currency: "USD"

Pricing Policy

pricing_policy: "com.finmars.standard-pricing:standard"

Portfolios

portfolios: ["Commodity Portfolio"]

Python Code

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetBalanceReport {
      balance_report(
        input: {
          report_date: "2024-05-01"
          report_currency: "USD"
          pricing_policy: "com.finmars.standard-pricing:standard"
          portfolios: ["Commodity Portfolio"]
        }
      ) {
        items {
          id
          item_type
          item_type_name
          name
          market_value
          position_size
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())



Notes

Get Profit & Loss (PNL) Report in Graphql

This query returns a pnl report for selected portfolios on a given date.


Screenshot 2026-01-13 at 20.47.48.png


GraphQL Query

query GetPLReport {
  pl_report(
    input: {
      report_date: "2024-05-01"
      pricing_policy: "com.finmars.standard-pricing:standard"
      portfolios: ["Commodity Portfolio"]
    }
  ) {
    items {
      id
      item_type
      item_type_name
      name
      market_value
      position_size
    }
  }
}

Input Highlights

Report Date

report_date: "2024-05-01"

PL First Date

pl_first_date: "2024-01-01"

Report Currency

report_currency: "USD"

Pricing Policy

pricing_policy: "com.finmars.standard-pricing:standard"

Portfolios

portfolios: ["Commodity Portfolio"]

Python Code

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
query GetPLReport {
  pl_report(
    input: {
      report_date: "2024-05-01"
      pricing_policy: "com.finmars.standard-pricing:standard"
      portfolios: ["Commodity Portfolio"]
    }
  ) {
    items {
      id
      item_type
      item_type_name
      name
      market_value
      position_size
    }
  }
}
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())



Notes

Get Performance Report in Graphql

This query returns performance metrics for one or more portfolio registers.

Screenshot 2025-12-16 at 19.46.38.png


GraphQL Query

query GetPerformanceReport {
  performance_report(
    input: {
      end_date: "2024-05-01"
      registers: ["CH-BND-20394857"]
    }
  ) {
    begin_nav
    end_nav
    grand_absolute_pl
    grand_cash_flow
    grand_cash_flow_weighted
    grand_cash_inflow
    grand_cash_outflow
    grand_nav
    grand_return
  }
}

Input Fields

end_date

end_date: "2024-05-01"

registers

registers: ["CH-BND-20394857"]

Output Fields

NAV Values


Cash Flow Metrics


Performance Metrics


Python Code

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetPerformanceReport {
      performance_report(
        input: {
          end_date: "2024-05-01"
          registers: ["CH-BND-20394857"]
        }
      ) {
        begin_nav
        end_nav
        grand_absolute_pl
        grand_cash_flow
        grand_cash_flow_weighted
        grand_cash_inflow
        grand_cash_outflow
        grand_nav
        grand_return
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Notes

Get Transaction Report in Graphql


This query returns calculated transaction report rows for a given date range.

Screenshot 2025-12-16 at 20.57.06.png


GraphQL Query

query GetTransactionReport {
  transaction_report(
    input: {
      begin_date: "2018-01-01"
      end_date: "2025-05-01"
    }
  ) {
    items {
      transaction_code
      transaction_class
      entry_item_name
      entry_amount
      cash_consideration
    }
  }
}

Input Fields

begin_date

begin_date: "2018-01-01"

end_date

end_date: "2025-05-01"

Output Fields

Each item represents one report row.

Only requested fields are returned.


Python Example

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
    query GetTransactionReport {
      transaction_report(
        input: {
          begin_date: "2018-01-01"
          end_date: "2025-05-01"
        }
      ) {
        items {
          transaction_code
          transaction_class
          entry_item_name
          entry_amount
          cash_consideration
        }
      }
    }
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Notes

Get Price History Check

This query returns a price history check report on a given date.


Screenshot 2026-01-13 at 20.52.41.png


GraphQL Query

query GetPriceHistoryCheck {
  price_history_check(
    input: {
      report_date: "2024-05-01"
      pricing_policy: "com.finmars.standard-pricing:standard"
    }
  ) {
    items {
      id
			type
      name
      position_size
      accounting_date
      transaction_currency_id
      transaction_currency_name
      transaction_currency_user_code
      settlement_currency_name
      settlement_currency_user_code
    }
  }
}

Input Highlights

Report Date

report_date: "2024-05-01"

PL First Date

pl_first_date: "2024-01-01"

Report Currency

report_currency: "USD"

Pricing Policy

pricing_policy: "com.finmars.standard-pricing:standard"

Portfolios

portfolios: ["Commodity Portfolio"]

Python Code

import requests

url = "https://<domain_name>/<realm_code>/<space_code>/graphql/"

headers = {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
}

payload = {
    "query": """
query GetPriceHistoryCheck {
  price_history_check(
    input: {
      report_date: "2024-05-01"
      pricing_policy: "com.finmars.standard-pricing:standard"
    }
  ) {
    items {
      id
			type
      name
      position_size
      accounting_date
      transaction_currency_id
      transaction_currency_name
      transaction_currency_user_code
      settlement_currency_name
      settlement_currency_user_code
    }
  }
}
    """
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())



Notes