Injective | TS & dApps Docs
DocumentationInjective TS
  • Overview
  • Getting Started
    • Technical Concepts
    • Application Concepts
      • Calculations
        • Min Price Tick Size
        • Min Quantity Tick Size
      • Networks
      • CosmJs Support
    • Assets
      • Creating Tokens
      • Denom Client (deprecated)
      • Injective Lists
    • Running examples
  • Wallets
    • Getting Started
    • Accounts
    • Wallet Connections
    • Wallet Strategy
    • Offchain (Arbitrary) Data
  • Querying
    • Getting Started
    • Chain
      • Auction
      • Auth
      • Bank
      • Distribution
      • Exchange
      • Governance
      • IBC
      • Mint
      • Insurance Funds
      • Oracle
      • Peggy
      • Permissions
      • Staking
      • Tendermint
      • Wasm
      • WasmX
      • Token Factory
    • Indexer
      • Account
      • Auction
      • Derivatives
      • Explorer
      • Insurance Funds
      • Markets
      • Leaderboard
      • Mito
      • Oracle
      • Portfolio
      • Spot
      • Web3Gw Transactions
      • Streaming
        • Account
        • Auction
        • Derivatives
        • Oracle
        • Portfolio
        • Spot
        • Explorer
    • Ethereum (GraphQL)
  • Transactions
    • Getting Started
    • Cosmos
      • Ledger through Keplr Wallet
    • Ethereum
      • Ethereum Ledger
    • MsgBroadcaster
    • Private Key
    • Web3 Gateway
  • Core Modules (& examples)
    • Getting Started
    • Auction
    • AuthZ
    • Bank
    • Distribution
    • Exchange
    • Feegrant
    • Governance
    • IBC
    • Insurance
    • Peggy
    • Permissions
    • Staking
    • Tokenfactory
    • Wasm
  • Smart Contracts
    • Cosmwasm
      • Injective Name Service
      • Neptune Service
      • CW20 to Bank & Market Order in One Transaction
  • Bridges
    • Getting Started
    • Ethereum
    • IBC
    • Wormhole
  • Building Dapps
    • Getting Started
    • Configuring Nuxt
    • Configuring React
    • dApps Examples
      • Smart Contract
      • DEX
      • Bridge
      • Simple HTML example with Webpack
Powered by GitBook
On this page
  1. Querying
  2. Indexer

Account

PreviousIndexerNextAuction

Last updated 1 year ago

Example code snippets to query the indexer for subaccount related data.

Using gRPC

Fetch user's portfolio details

This includes available balance, unrealized Pnl, and portfolio value. Note: deprecated -> use instead

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const injectiveAddress = 'inj...'

const portfolio = await indexerGrpcAccountApi.fetchPortfolio(injectiveAddress)

console.log(portfolio)

Fetch user's trading rewards per epoch

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const injectiveAddress = 'inj...'
const epoch = -1 // current epoch

const tradingRewards = await indexerGrpcAccountApi.fetchRewards({
  address: injectiveAddress,
  epoch,
})

console.log(tradingRewards)

Fetch subaccounts associated with an injective address

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const injectiveAddress = 'inj...'

const subaccountsList = await indexerGrpcAccountApi.fetchSubaccountsList(
  injectiveAddress,
)

console.log(subaccountsList)

Fetch balance of a subaccount for a specific denom

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const subaccountId = '0x...'
const denom = 'inj'

const subaccountBalance = await indexerGrpcAccountApi.fetchSubaccountBalance(
  subaccountId,
  denom,
)

console.log(subaccountBalance)

Fetch of balances for a subaccount

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const subaccountId = '0x...'

const subaccountBalanceList =
  await indexerGrpcAccountApi.fetchSubaccountBalancesList(subaccountId)

console.log(subaccountBalanceList)

Fetch subacount history

import { PaginationOption, IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const subaccountId = '0x...'
const denom = 'inj'
const pagination = {...} as PaginationOption

const subaccountHistory = await indexerGrpcAccountApi.fetchSubaccountHistory({
  subaccountId,
  denom,
  pagination /* optional param */
})

console.log(subaccountHistory)

Fetch a summary of a subaccount's orders

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const subaccountId = '0x...'
const marketId = '0x'
const orderDirection = 'buy'

const orderSummary = await indexerGrpcAccountApi.fetchSubaccountOrderSummary({
  subaccountId,
  marketId,
  orderDirection,
})

console.log(orderSummary)

Fetch states of spot or (and) derivatives orders

import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const spotOrderHashes = ['0x...']
const derivativeOrderHashes = ['0x...']

const orderStates = await indexerGrpcAccountApi.fetchOrderStates({
  spotOrderHashes,
  derivativeOrderHashes,
})

console.log(orderStates)
Portfolio