-
Notifications
You must be signed in to change notification settings - Fork 196
02QueryingIndexerAccount
Ivan Angelkoski edited this page Jun 12, 2023
·
5 revisions
Example code snippets to query the indexer for subaccount related data.
- Get the user's portfolio details, such as their available balance, unrealized Pnl, or their portfolio value.
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);
const injectiveAddress = "inj...";
const portfolio = await indexerGrpcAccountApi.fetchPortfolio(injectiveAddress);
console.log(portfolio);
- Get the user's trading rewards per epoch
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
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);
- Get a list of subaccounts associated with an injective address
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);
const injectiveAddress = "inj...";
const subaccountsList = await indexerGrpcAccountApi.fetchSubaccountsList(
injectiveAddress
);
console.log(subaccountsList);
- Get the balance of a subaccount for a specific denom
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);
const subaccountId = "0x...";
const denom = "inj";
const subaccountBalance = await indexerGrpcAccountApi.fetchSubaccountBalance(
subaccountId,
denom
);
console.log(subaccountBalance);
- Get a list of balances for a subaccount
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);
const subaccountId = "0x...";
const subaccountBalanceList =
await indexerGrpcAccountApi.fetchSubaccountBalancesList(subaccountId);
console.log(subaccountBalanceList);
- Get the history of a subaccount
import { PaginationOption, IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
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)
- Get a summary of a subaccount's orders
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
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);
- Get states of a list of spot and/or derivatives orders
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);
const spotOrderHashes = ["0x..."];
const derivativeOrderHashes = ["0x..."];
const orderStates = await indexerGrpcAccountApi.fetchOrderStates({
spotOrderHashes,
derivativeOrderHashes,
});
console.log(orderStates);
Powering the future of decentralized finance.