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. Chain

Exchange

Example code snippets to query the exchange module on the chain.

Using gRPC

Fetch parameters such as the default spot and derivatives fees/trading rewards

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const moduleParams = await chainGrpcExchangeApi.fetchModuleParams()

console.log(moduleParams)

Fetch the fee discount schedules

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const feeDiscountSchedule =
  await chainGrpcExchangeApi.fetchFeeDiscountSchedule()

console.log(feeDiscountSchedule)

Fetch the fee discounts associated with an injective address

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const injectiveAddress = 'inj...'

const feeDiscountAccountInfo =
  await chainGrpcExchangeApi.fetchFeeDiscountAccountInfo(injectiveAddress)

console.log(feeDiscountAccountInfo)

Fetch the details regarding the trading reward campaign, such as the total reward points

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const tradingRewardsCampaign =
  await chainGrpcExchangeApi.fetchTradingRewardsCampaign()

console.log(tradingRewardsCampaign)

Fetch the trading rewards points for an injective address

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const injectiveAddress = 'inj...'

const tradeRewardsPoints = await chainGrpcExchangeApi.fetchTradeRewardsPoints(
  injectiveAddress,
)

console.log(tradeRewardsPoints)

Fetch the pending trading rewards points for injective addresses

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const injectiveAddresses = ['inj...']

const pendingTradeRewardsPoints =
  await chainGrpcExchangeApi.fetchPendingTradeRewardPoints(injectiveAddresses)

console.log(pendingTradeRewardsPoints)

Fetch the current positions, such as subaccountId, marketId, and position

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const positions = await chainGrpcExchangeApi.fetchPositions(injectiveAddresses)

console.log(positions)

Fetch the subaccount trade nonce

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

const endpoints = getNetworkEndpoints(Network.Testnet)
const chainGrpcExchangeApi = new ChainGrpcExchangeApi(endpoints.grpc)

const subaccountId = '0x...'

const subaccountTradeNonce =
  await chainGrpcExchangeApi.fetchSubaccountTradeNonce(subaccountId)

console.log(subaccountTradeNonce)
PreviousDistributionNextGovernance

Last updated 1 year ago