Sai Keeper GraphQL 查询
以下为 Jiyuu 发布的英文原文。
Use this reference for indexed, app-facing Sai data: perp positions and
history, SLP Vault history, Oracle prices, referral analytics, and live
subscriptions. For live protocol state or contract-owned values, use
contracts.md instead.
Source and endpoints
Section titled “Source and endpoints”The deployed schema is the authority. Read it with a GraphQL introspection
query or in the playground at the host root. The endpoint path is /query.
| Network | HTTP | WebSocket |
|---|---|---|
| Mainnet | https://sai-keeper.nibiru.fi/query | wss://sai-keeper.nibiru.fi/query |
| Testnet2 | https://sai-keeper.testnet-2.nibiru.fi/query | wss://sai-keeper.testnet-2.nibiru.fi/query |
Verify a field against the deployment you query. Mainnet and Testnet2 can run different Keeper versions.
Query domains
Section titled “Query domains”The root Query type exposes domain objects: oracle, perp, lp,
referral, appVersion, saiPoints, and explorer. Scope fields under their
domain rather than querying them at the root.
| Domain | Key fields | Notes |
|---|---|---|
perp | trade, trades, tradeHistory, borrowing, borrowings, statsUserPortfolio, traderFeeTierProgress | Indexed trades, market borrowing state, and portfolio/fee-tier summaries. trades(where:) requires a trader address. |
lp | vaults, depositHistory, withdrawRequests, vaultStats, epochDurationDays | Indexed vault and LP history; not a replacement for live vault accounting. |
oracle | tokens, token, tokenPricesUsd | App-indexed token metadata and prices. Use lastUpdatedBlock to assess freshness. |
referral | referralCodes, referralTrades, referralRedemption, referralRedemptionTrader, referralClaims, referralStats | Historical referral data keyed by referrer or trader. |
There is no GraphQL fee root domain or fields such as feeTransactions in
the current schema. For fee details, use Perp trade history fields such as
openingFeeUsd and closingFeeUsd, contract fee queries, or database
references as appropriate.
Filters, order, and units
Section titled “Filters, order, and units”- Perp query field
tradesusesPerpTradesFilter, whose requiredtraderfield can be narrowed byperpMarketId,perpCollateralId, andisOpen. - Perp query field
tradeHistoryusesPerpTradeHistoryFilter, whose requiredtraderfield returns the trader’s indexed mutations. - Lists accept their schema-defined
order_by,order_desc,limit, andoffsetarguments. Do not assume that an order enum applies to another domain. - Many contract-sized values are GraphQL
Intbase units, including Perp trade collateral and open interest. Exceptions are deliberate: tableBalanceexposesamountas a string, and USD/price/percentage fields commonly use GraphQLFloat. - GraphQL type
Tokendoes not expose decimal metadata. TableBalanceincludestoken_info.decimalswhen a wallet or Sai balance subscription is relevant.
Subscriptions
Section titled “Subscriptions”The current Subscription type provides exactly these fields:
| Field | Required filter or arguments |
|---|---|
tokenPricesUsd | Optional SubTokenPriceUsdFilter (tokenId) |
perpTrades | SubPerpTradesFilter! (trader) |
perpTradeHistory | SubPerpTradeHistoryFilter! (trader) |
perpBorrowings | None |
perpBorrowing | marketId, collateralId |
lpVaults | None |
lpDepositHistory | SubLpDepositHistoryFilter! (depositor, vault) |
lpWithdrawRequests | SubLpWithdrawRequestsFilter! (depositor, vault) |
userBalances | SubUserBalancesFilter! (user) |
userInfo | SubUserFilter! (user) |
No lpDeposits subscription exists in the current schema. For a user’s vault
state, query the LP history/request fields or read live contract state according
to the fact being requested.
Example queries
Section titled “Example queries”query OpenTrades($trader: String!) { perp { trades(where: { trader: $trader, isOpen: true }) { id collateralAmount leverage isLong state { positionValue liquidationPrice } } }}query ReferralHistory($referrer: String!) { referral { referralCodes(referrer: $referrer) { code active uniqueTraders volumeUSD } referralRedemption(referrer: $referrer) { trader code active block { block block_ts } } }}Related references
Section titled “Related references”contracts.md: live Perp, Oracle, and vault queries.rest.md: public aggregates rather than entity history.- Private agent skill
sai-db: table ownership, aggregation, and freshness.