Examples: Queries

Practical examples for common query patterns using the Sai Keeper API.

Table of Contents

Setup

These examples use Apollo Client, but the queries work with any GraphQL client.

import { ApolloClient, InMemoryCache, gql } from '@apollo/client'

const client = new ApolloClient({
  uri: 'https://sai-keeper.testnet-2.nibiru.fi/graphql',
  cache: new InMemoryCache()
})

Perp Queries

Example 1: Get All Open Positions for a Trader

Example 2: Get Trade History with Realized PnL

Example 3: Get Market Information and Funding Rates

Example 4: List All Available Markets


LP Queries

Example 5: Get All Vaults with Metrics

Example 6: Get User LP Positions

Example 7: Get Vault Deposit/Withdrawal History


Oracle Queries

Example 8: Get Current Token Prices

Example 9: Get Specific Token Price with Freshness Check


Fee Queries

Example 10: Get User Fee History

Example 11: Get Protocol Fee Summary

Example 12: Get Daily Fee Statistics


Advanced Patterns

Example 13: Combine Multiple Queries

Example 14: Pagination Pattern

Example 15: Error Handling Pattern

Last updated