# Graphql

How to use Graphql In Finmars and query examples

# Getting Started

## What is GraphQL

GraphQL is an API query language.

<span style="white-space: pre-wrap;">It lets the client ask </span>**exactly**<span style="white-space: pre-wrap;"> for the data it needs.</span>  
No more. No less.

Main ideas:

- One endpoint.
- Client chooses fields.
- Strong types.
- Clear schema.

GraphQL replaces many REST endpoints with one structured API.

---

## What We Use in Finmars

In Finmars, GraphQL is built with:

- **Django**
- **Strawberry GraphQL** [https://github.com/strawberry-graphql/strawberry](https://github.com/strawberry-graphql/strawberry)

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

Key points:

- Schema is written in Python.
- Types are strict.
- Queries are validated before execution.
- Errors are clear.

---

##   


---

# Access to Graphql from Browser Playground

Open the GraphQL playground in your browser:

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

<span style="white-space: pre-wrap;">E.g. </span>[https://eu-central.finmars.com/realm0v4ry/space063sw/graphql/](https://eu-central.finmars.com/realm0v4ry/space063sw/graphql/)<span style="white-space: pre-wrap;"> (Link is not lead to anything, just an example)</span>  
  
You will see:

- Query editor
- Schema explorer
- Result panel

You must be authenticated.  
  
[![Screenshot 2025-12-16 at 15.49.17.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-15-49-17.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-15-49-17.png)

---

### <span style="white-space: pre-wrap;">You can access Documentation </span>

Click ob button with Book icon in top left corner

[![Screenshot 2025-12-16 at 17.04.47.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-04-47.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-05-41.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-06-16.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-08-10.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/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:

- Queries
- Mutations
- Schema introspection

---

## How to Access the Endpoint

### Authentication

<span style="white-space: pre-wrap;">GraphQL uses the </span>**same authentication**<span style="white-space: pre-wrap;"> as the REST API.</span>

Usually:

- Keycloak Auth Token (web)
- <span style="white-space: pre-wrap;">Authorization header (JWT tokens) You can get Token here: </span>[https://docs.finmars.com/books/api-access-key/page/generate-and-use-access-token](https://docs.finmars.com/books/api-access-key/page/generate-and-use-access-token)

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

If you are not authenticated:

- Requests will fail
- Data will not be returned

---

### From Code

<span style="white-space: pre-wrap;">Send a </span>**POST**<span style="white-space: pre-wrap;"> request to </span>`<span class="editor-theme-code">/graphql/</span>`.

```python
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

```python
{
  "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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-01-09.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-01-09.png)

### GraphQL Query

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

---

### Python Example

```python
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

- Fetches a paginated list of accounts
- Returns only required fields
- Includes related account type
- Uses a single API call

---

### Notes

- <span style="white-space: pre-wrap;">Change </span>`<span class="editor-theme-code">limit</span>`<span style="white-space: pre-wrap;"> and </span>`<span class="editor-theme-code">offset</span>`<span style="white-space: pre-wrap;"> for paging</span>
- Add or remove fields as needed
- Query name helps with debugging and logs

# Get Portfolios in Graphql

This query returns a list of portfolios with basic fields.

---

[![Screenshot 2025-12-16 at 17.03.42.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-03-42.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-03-42.png)

### GraphQL Query

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

  }
}
```

---

### Python Example

```python
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

- Fetches a paginated list of portfolios
- Returns core portfolio fields
- Includes portfolio currency
- Uses one GraphQL request

---

# Get Portfolio History in Graphql

This query returns historical NAV values for portfolios.

[![Screenshot 2025-12-16 at 18.27.45.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-18-27-45.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-18-27-45.png)

---

### GraphQL Query

```graphql
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

```python
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

- <span style="white-space: pre-wrap;">Empty </span>`<span class="editor-theme-code">filters</span>`<span style="white-space: pre-wrap;"> block is valid</span>
- Add filters to limit results

Example filter:

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

- Pagination is required
- Dates use ISO format
- `<span class="editor-theme-code">status</span>`<span style="white-space: pre-wrap;"> shows calculation state</span>

# Get Currencies in Graphql

This query returns a list of currencies.

---

[![Screenshot 2025-12-16 at 17.11.35.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-11-35.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-11-35.png)

### GraphQL Query

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

---

### Python Example

```python
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

- Fetches a paginated list of currencies
- Returns standard currency fields
- One request, no extra endpoints

---

# Get FX Rates in Graphql

---

<span style="white-space: pre-wrap;">This query returns currency rates for a </span>**specific date**<span style="white-space: pre-wrap;"> and </span>**specific currency**.

[![Screenshot 2025-12-16 at 17.19.02.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-19-02.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-19-02.png)

---

### GraphQL Query

```graphql
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

```python
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

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

- Matches one exact value
- Type must match schema
- Dates are strings in ISO format

---

### Nested Filters

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

- Filters on related objects
- Works through foreign keys
- Depth depends on schema rules

---

### Common Filter Types

Typical filters you may see:

- `<span class="editor-theme-code">exact</span>`
- `<span class="editor-theme-code">in</span>`
- `<span class="editor-theme-code">contains</span>`
- `<span class="editor-theme-code">gte</span>`<span style="white-space: pre-wrap;">, </span>`<span class="editor-theme-code">lte</span>`
- `<span class="editor-theme-code">isnull</span>`

Available filters depend on the field type.

---

### Important Notes

- Filters are optional
- <span style="white-space: pre-wrap;">Multiple filters are combined with </span>**AND**
- Wrong field names cause schema errors
- Always check the schema panel

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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-42-03.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-42-03.png)

### GraphQL Query

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

---

### Python Example

```python
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

- Field names must match the schema (`<span class="editor-theme-code">maturity_date</span>`<span style="white-space: pre-wrap;">, </span>`<span class="editor-theme-code">instrument_type</span>`, etc.)
- <span style="white-space: pre-wrap;">Add filters the same way as in </span>`<span class="editor-theme-code">currency_history</span>`<span style="white-space: pre-wrap;"> when needed (Previous documentation page)</span>

# Get Prices in Graphql

<span style="white-space: pre-wrap;">This query returns price history rows for </span>**one instrument**<span style="white-space: pre-wrap;"> (by </span>`<span class="editor-theme-code">user_code</span>`).

[![Screenshot 2025-12-16 at 17.49.19.png](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-49-19.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-49-19.png)

---

### GraphQL Query

```graphql
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

### Filter by Related Object Field

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

- `<span class="editor-theme-code">instrument</span>`<span style="white-space: pre-wrap;"> is a related object.</span>
- You can filter it by its fields.
- `<span class="editor-theme-code">exact</span>`<span style="white-space: pre-wrap;"> means strict match.</span>

---

### <span style="white-space: pre-wrap;">Why Use </span>`<span class="editor-theme-code">user_code</span>`

- Stable identifier for business use.
- <span style="white-space: pre-wrap;">No need to know internal </span>`<span class="editor-theme-code">id</span>`.

---

### Notes

- Add a date filter if you want one day only:

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

- Pagination stays the same for list queries.

# 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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-17-57-40.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-17-57-40.png)

---

### GraphQL Query

```graphql
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)

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

- `<span class="editor-theme-code">portfolio</span>`<span style="white-space: pre-wrap;"> is a related object.</span>
- <span style="white-space: pre-wrap;">You filter it by its field </span>`<span class="editor-theme-code">user_code</span>`.
- `<span class="editor-theme-code">exact</span>`<span style="white-space: pre-wrap;"> means strict match.</span>

---

### Filter by Date Range

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

- `<span class="editor-theme-code">gte</span>`<span style="white-space: pre-wrap;"> = start date (inclusive)</span>
- `<span class="editor-theme-code">lte</span>`<span style="white-space: pre-wrap;"> = end date (inclusive)</span>
- <span style="white-space: pre-wrap;">Use ISO format: </span>`<span class="editor-theme-code">YYYY-MM-DD</span>`

---

### How filters work together

<span style="white-space: pre-wrap;">All filters in one </span>`<span class="editor-theme-code">filters</span>`<span style="white-space: pre-wrap;"> block are combined with </span>**AND**.

So this query means:

- <span style="white-space: pre-wrap;">portfolio user\_code is exactly </span>`<span class="editor-theme-code">"Commodity Portfolio"</span>`  
    AND
- <span style="white-space: pre-wrap;">accounting\_date is between </span>`<span class="editor-theme-code">2021-01-01</span>`<span style="white-space: pre-wrap;"> and </span>`<span class="editor-theme-code">2023-12-31</span>`

---

# 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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-18-12-20.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-18-12-20.png)

---

### GraphQL Query

```graphql
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

```graphql
report_date: "2024-05-01"
```

- Snapshot date
- ISO date format
- Required field

---

### Report Currency

```graphql
report_currency: "USD"
```

- Output currency
- Must exist in the system

---

### Pricing Policy

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

- Defines valuation rules
- Uses pricing engine configuration
- Required for valuation

---

### Portfolios

```graphql
portfolios: ["Commodity Portfolio"]
```

- List of portfolio user codes
- Supports multiple portfolios

---

### Python Code

```python
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

- <span style="white-space: pre-wrap;">This is </span>**not**<span style="white-space: pre-wrap;"> a list query.</span>
- No pagination.
- <span style="white-space: pre-wrap;">Uses </span>`<span class="editor-theme-code">input</span>`<span style="white-space: pre-wrap;"> instead of </span>`<span class="editor-theme-code">filters</span>`.
- Report queries execute calculations.

# 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](https://docs.finmars.com/uploads/images/gallery/2026-01/scaled-1680-/screenshot-2026-01-13-at-20-47-48.png)](https://docs.finmars.com/uploads/images/gallery/2026-01/screenshot-2026-01-13-at-20-47-48.png)

---

### GraphQL Query

```graphql
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

```graphql
report_date: "2024-05-01"
```

- Snapshot date
- ISO date format
- Required field

### PL First Date

```graphql
pl_first_date: "2024-01-01"
```

- Snapshot date
- ISO date format
- Required field
- Basically its a "date from"

---

### Report Currency

```graphql
report_currency: "USD"
```

- Output currency
- Must exist in the system

---

### Pricing Policy

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

- Defines valuation rules
- Uses pricing engine configuration
- Required for valuation

---

### Portfolios

```graphql
portfolios: ["Commodity Portfolio"]
```

- List of portfolio user codes
- Supports multiple portfolios

---

### Python Code

```python
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

- <span style="white-space: pre-wrap;">This is </span>**not**<span style="white-space: pre-wrap;"> a list query.</span>
- No pagination.
- <span style="white-space: pre-wrap;">Uses </span>`<span class="editor-theme-code">input</span>`<span style="white-space: pre-wrap;"> instead of </span>`<span class="editor-theme-code">filters</span>`.
- Report queries execute calculations.

# 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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-19-46-38.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-19-46-38.png)

---

### GraphQL Query

```graphql
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

### `<span class="editor-theme-code">end_date</span>`

```graphql
end_date: "2024-05-01"
```

- Report end date
- Required field
- ISO date format

---

### `<span class="editor-theme-code">registers</span>`

```graphql
registers: ["CH-BND-20394857"]
```

- List of portfolio register user codes
- At least one register is required
- Supports multiple registers

---

## Output Fields

### NAV Values

- `<span class="editor-theme-code">begin_nav</span>`<span style="white-space: pre-wrap;"> — NAV at period start</span>
- `<span class="editor-theme-code">end_nav</span>`<span style="white-space: pre-wrap;"> — NAV at period end</span>
- `<span class="editor-theme-code">grand_nav</span>`<span style="white-space: pre-wrap;"> — aggregated NAV</span>

---

### Cash Flow Metrics

- `<span class="editor-theme-code">grand_cash_flow</span>`
- `<span class="editor-theme-code">grand_cash_flow_weighted</span>`
- `<span class="editor-theme-code">grand_cash_inflow</span>`
- `<span class="editor-theme-code">grand_cash_outflow</span>`

---

### Performance Metrics

- `<span class="editor-theme-code">grand_absolute_pl</span>`<span style="white-space: pre-wrap;"> — absolute profit or loss</span>
- `<span class="editor-theme-code">grand_return</span>`<span style="white-space: pre-wrap;"> — total return</span>

---

## Python Code

```python
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

- <span style="white-space: pre-wrap;">This is a </span>**calculated report**
- No pagination
- <span style="white-space: pre-wrap;">Uses </span>`<span class="editor-theme-code">input</span>`<span style="white-space: pre-wrap;">, not </span>`<span class="editor-theme-code">filters</span>`
- Default calculation method is applied if not provided
- Execution time depends on data volume

# 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](https://docs.finmars.com/uploads/images/gallery/2025-12/scaled-1680-/screenshot-2025-12-16-at-20-57-06.png)](https://docs.finmars.com/uploads/images/gallery/2025-12/screenshot-2025-12-16-at-20-57-06.png)

---

### GraphQL Query

```graphql
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

### `<span class="editor-theme-code">begin_date</span>`

```graphql
begin_date: "2018-01-01"
```

- Report start date
- Optional in some setups
- ISO format

---

### `<span class="editor-theme-code">end_date</span>`

```graphql
end_date: "2025-05-01"
```

- Report end date
- Required
- ISO format

---

## Output Fields

Each item represents one report row.

- `<span class="editor-theme-code">transaction_code</span>`<span style="white-space: pre-wrap;"> — internal transaction identifier</span>
- `<span class="editor-theme-code">transaction_class</span>`<span style="white-space: pre-wrap;"> — transaction type</span>
- `<span class="editor-theme-code">entry_item_name</span>`<span style="white-space: pre-wrap;"> — report entry name</span>
- `<span class="editor-theme-code">entry_amount</span>`<span style="white-space: pre-wrap;"> — calculated amount</span>
- `<span class="editor-theme-code">cash_consideration</span>`<span style="white-space: pre-wrap;"> — cash movement value</span>

Only requested fields are returned.

---

## Python Example

```python
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

- <span style="white-space: pre-wrap;">This is a </span>**report query**, not a list endpoint
- No pagination
- <span style="white-space: pre-wrap;">Uses </span>`<span class="editor-theme-code">input</span>`<span style="white-space: pre-wrap;">, not </span>`<span class="editor-theme-code">filters</span>`
- Execution time depends on date range
- <span style="white-space: pre-wrap;">Add more fields to </span>`<span class="editor-theme-code">items</span>`<span style="white-space: pre-wrap;"> if needed</span>

# 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](https://docs.finmars.com/uploads/images/gallery/2026-01/scaled-1680-/screenshot-2026-01-13-at-20-52-41.png)](https://docs.finmars.com/uploads/images/gallery/2026-01/screenshot-2026-01-13-at-20-52-41.png)

---

### GraphQL Query

```graphql
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

```graphql
report_date: "2024-05-01"
```

- Snapshot date
- ISO date format
- Required field

### PL First Date

```graphql
pl_first_date: "2024-01-01"
```

- Snapshot date
- ISO date format
- Required field
- Basically its a "date from"

---

### Report Currency

```graphql
report_currency: "USD"
```

- Output currency
- Must exist in the system

---

### Pricing Policy

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

- Defines valuation rules
- Uses pricing engine configuration
- Required for valuation

---

### Portfolios

```graphql
portfolios: ["Commodity Portfolio"]
```

- List of portfolio user codes
- Supports multiple portfolios

---

### Python Code

```python
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

- <span style="white-space: pre-wrap;">This is </span>**not**<span style="white-space: pre-wrap;"> a list query.</span>
- No pagination.
- <span style="white-space: pre-wrap;">Uses </span>`<span class="editor-theme-code">input</span>`<span style="white-space: pre-wrap;"> instead of </span>`<span class="editor-theme-code">filters</span>`.
- Report queries execute calculations.