-
Notifications
You must be signed in to change notification settings - Fork 198
02QueryingAPI
Bojan Angjelkoski edited this page Dec 20, 2022
·
8 revisions
Example code snippets to query the accounts module on the API using the gRPC protocol.
- Fetching address's trading accounts
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts"
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)
const subaccountLists = await indexerGrpcAccountApi.fetchSubaccountsList(
injectiveAddress
);
console.log(subaccountLists);
- Fetching trading account's balances
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts"
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)
const [subaccountId] = await indexerGrpcAccountApi.fetchSubaccountsList(
injectiveAddress
);
const balances = await indexerGrpcAccountApi.fetchSubaccountBalancesList(
subaccount
);
console.log(balances);
Example code snippets to query the explorer module on the API using the gRPC protocol.
- Fetching address's transactions
import { IndexerGrpcExplorerApi } from "@injectivelabs/sdk-ts"
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const network = getNetworkInfo(Network.TestnetK8s);
const indexerGrpcExplorerApi = new IndexerGrpcExplorerApi(endpoints.indexer)
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const limit = 10
const txs = await indexerGrpcExplorerApi.fetchAccountTransactions({
address,
limit,
});
console.log(txs);
Example code snippets to query the spot module on the API using the gRPC protocol.
- Fetching orderbooks for an array of marketIds
import { IndexerGrpcSpotApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
(async () => {
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const indexerGrpcSpotApi = new IndexerGrpcSpotApi(endpoints.indexer);
const marketIds = [""]; // Your marketIds in an array
const orderbook = await indexerGrpcSpotApi.fetchOrderbooks(marketIds);
console.log(orderbook);
})();
Example code snippets to query the explorer module on the API using the REST protocol.
- Fetching address's transactions
import { IndexerRestExplorerApi } from "@injectivelabs/sdk-ts"
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const network = getNetworkInfo(Network.TestnetK8s);
const indexerRestExplorerApi = new IndexerRestExplorerApi(endpoints.indexer)
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const limit = 10
const txs = await indexerRestExplorerApi.fetchAccountTransactions({
address,
limit,
});
console.log(txs);
Powering the future of decentralized finance.