Skip to main content

Overview

CompositeClient is the main entry point for interacting with the LFG DEX. It combines the IndexerClient (read operations) and ValidatorClient (write operations) into a unified interface.
import { CompositeClient, Network } from "@oraichain/lfg-client-js";

Static Methods

connect()

Connect to a network and create a CompositeClient instance.
const network = Network.staging();
const client = await CompositeClient.connect(network);
network
Network
required
Network configuration to connect to
Returns: Promise<CompositeClient>

Properties

indexerClient

Access the IndexerClient for read-only operations.
const markets = await client.indexerClient.markets.getPerpetualMarkets();
const account = await client.indexerClient.account.getParentSubaccount(
  address,
  0
);

validatorClient

Access the ValidatorClient for blockchain operations.
const blockHeight = await client.validatorClient.get.latestBlockHeight();
const balances = await client.validatorClient.get.getAccountBalances(address);

Configuration Methods

setSelectedGasDenom()

Set which token to use for gas fees.
import { SelectedGasDenom } from "@oraichain/lfg-client-js";

client.setSelectedGasDenom(SelectedGasDenom.USDC); // Use USDC for gas
client.setSelectedGasDenom(SelectedGasDenom.NATIVE); // Use native token
denom
SelectedGasDenom
required
SelectedGasDenom.USDC or SelectedGasDenom.NATIVE

populateAccountNumberCache()

Pre-populate the account number cache for faster transactions.
await client.populateAccountNumberCache(wallet.address);
address
string
required
Address to cache account number for

Trading Methods

placeShortTermOrder()

Place a short-term order that expires based on block height.
import { OrderSide, Order_TimeInForce } from "@oraichain/lfg-client-js";

const tx = await client.placeShortTermOrder(
  subaccount,
  "ETH-USD",
  OrderSide.BUY,
  3800,
  0.1,
  clientId,
  goodTilBlock,
  Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED,
  false
);
subaccount
SubaccountInfo
required
Subaccount placing the order
marketId
string
required
Market identifier (e.g., “ETH-USD”)
side
OrderSide
required
OrderSide.BUY or OrderSide.SELL
price
number
required
Order price in quote currency
size
number
required
Order size in base currency
clientId
number
required
Unique order identifier
goodTilBlock
number
required
Block height when order expires
timeInForce
Order_TimeInForce
required
Time in force policy
reduceOnly
boolean
required
Whether order can only reduce position
Returns: Promise<BroadcastTxResponse>

placeOrder()

Place a long-term order with timestamp-based expiration.
import {
  OrderType,
  OrderTimeInForce,
  OrderExecution,
} from "@oraichain/lfg-client-js";

const tx = await client.placeOrder(
  subaccount,
  "ETH-USD",
  OrderType.LIMIT,
  OrderSide.BUY,
  3800,
  0.1,
  clientId,
  OrderTimeInForce.GTT,
  24 * 60 * 60, // 24 hours
  OrderExecution.DEFAULT,
  false,
  false
);
orderType
OrderType
required
Order type (LIMIT, MARKET, STOP_LIMIT, STOP_MARKET)
timeInForce
OrderTimeInForce
required
GTT (Good-til-time), IOC (Immediate-or-cancel), or FOK (Fill-or-kill)
goodTilTimeInSeconds
number
required
Seconds from now until order expires
execution
OrderExecution
required
Execution type (DEFAULT, POST_ONLY, IOC)
postOnly
boolean
required
Whether order must be maker
Returns: Promise<BroadcastTxResponse>

cancelOrder()

Cancel an existing order.
import { OrderFlags } from "@oraichain/lfg-client-js";

const tx = await client.cancelOrder(
  subaccount,
  clientId,
  OrderFlags.SHORT_TERM,
  "ETH-USD",
  goodTilBlock,
  0
);
subaccount
SubaccountInfo
required
Subaccount that placed the order
clientId
number
required
Client ID of order to cancel
orderFlags
OrderFlags
required
Order type flags (SHORT_TERM or LONG_TERM)
marketId
string
required
Market identifier
goodTilBlock
number
required
New expiration block (for short-term)
goodTilTimeInSeconds
number
required
Seconds until expiration (for long-term)
Returns: Promise<BroadcastTxResponse>

Fund Management Methods

depositToSubaccount()

Deposit funds from wallet to subaccount.
const tx = await client.depositToSubaccount(
  subaccount,
  "1000", // $1000 USDC
  "Initial deposit"
);
subaccount
SubaccountInfo
required
Destination subaccount
amount
string
required
Amount in USDC (as string)
memo
string
Optional transaction memo
Returns: Promise<BroadcastTxResponse>

withdrawFromSubaccount()

Withdraw funds from subaccount to wallet.
const tx = await client.withdrawFromSubaccount(
  subaccount,
  "500", // $500 USDC
  wallet.address,
  "Withdrawal to wallet"
);
subaccount
SubaccountInfo
required
Source subaccount
amount
string
required
Amount in USDC (as string)
recipient
string
required
Recipient address
memo
string
Optional transaction memo
Returns: Promise<BroadcastTxResponse>

transferToSubaccount()

Transfer funds between subaccounts.
const tx = await client.transferToSubaccount(
  sourceSubaccount,
  recipientAddress,
  recipientSubaccountNumber,
  "200", // $200 USDC
  "Transfer between subaccounts"
);
subaccount
SubaccountInfo
required
Source subaccount
recipientAddress
string
required
Recipient wallet address
recipientSubaccountNumber
number
required
Recipient subaccount number
amount
string
required
Amount in USDC (as string)
memo
string
Optional transaction memo
Returns: Promise<BroadcastTxResponse>

Authentication Methods

getAuthenticators()

Get authenticators for an address (used for API key trading).
const auths = await client.getAuthenticators(address);

for (const auth of auths.accountAuthenticators) {
  console.log("Authenticator ID:", auth.id);
  console.log("Type:", auth.type);
}
address
string
required
Address to query authenticators for
Returns: Promise<{ accountAuthenticators: Authenticator[] }>

Complete Example

import {
  Network,
  CompositeClient,
  LocalWallet,
  SubaccountInfo,
  OrderSide,
  Order_TimeInForce,
  SelectedGasDenom,
} from "@oraichain/lfg-client-js";

async function tradingExample() {
  // 1. Create wallet
  const wallet = await LocalWallet.fromMnemonic(mnemonic, "lfg");

  // 2. Connect to network
  const network = Network.staging();
  const client = await CompositeClient.connect(network);
  client.setSelectedGasDenom(SelectedGasDenom.USDC);

  // 3. Create subaccount
  const subaccount = SubaccountInfo.forLocalWallet(wallet, 0);
  await client.populateAccountNumberCache(subaccount.address);

  // 4. Get market data
  const markets = await client.indexerClient.markets.getPerpetualMarkets();
  const ethPrice = parseFloat(markets.markets["ETH-USD"].oraclePrice);

  // 5. Place order
  const currentBlock = await client.validatorClient.get.latestBlockHeight();
  const goodTilBlock = currentBlock + 20;
  const clientId = Math.floor(Math.random() * 100000000);

  const tx = await client.placeShortTermOrder(
    subaccount,
    "ETH-USD",
    OrderSide.BUY,
    ethPrice,
    0.01,
    clientId,
    goodTilBlock,
    Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED,
    false
  );

  console.log("Order placed:", Buffer.from(tx.hash).toString("hex"));
}