Skip to main content

General Questions

The @oraichain/lfg-client-js SDK is the official TypeScript/JavaScript client for interacting with the Oraichain LFG Perpetual DEX. It provides complete access to trading, market data, and account management.
The SDK supports:
  • Staging/Testnet: For development and testing with test tokens
  • Mainnet: For production trading with real assets
Access via Network.staging() and Network.mainnet().
  • Node.js 18+ or modern browser
  • TypeScript 5+ (recommended)
  • Internet connection for API access

Trading Questions

Use client.placeShortTermOrder() for quick orders or client.placeOrder() for long-term orders:
const tx = await client.placeShortTermOrder(
  subaccount,
  "ETH-USD",
  OrderSide.BUY,
  3800,
  0.1,
  clientId,
  goodTilBlock,
  Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED,
  false
);
See the Orders Guide for details.
  • Short-term orders: Expire based on block height, lower gas, faster execution
  • Long-term orders: Expire based on timestamp, can stay on orderbook for days
Use short-term for HFT/market-making, long-term for position building.
Use client.cancelOrder() with the original client ID:
await client.cancelOrder(
  subaccount,
  clientId,
  OrderFlags.SHORT_TERM,
  "ETH-USD",
  goodTilBlock,
  0
);

Account Questions

Subaccounts are isolated trading accounts under your wallet. Each has:
  • Separate collateral balance
  • Independent positions and orders
  • Risk isolation from other subaccounts
You can have up to 128 subaccounts (0-127).
Use client.depositToSubaccount():
await client.depositToSubaccount(
  subaccount,
  "1000" // $1000 USDC
);
See the Transfers Guide for details.
Query the Indexer:
const account = await client.indexerClient.account.getParentSubaccount(
  wallet.address,
  0
);
console.log("Equity:", account.subaccount.equity);

Technical Questions

Implement retry logic:
async function withRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
    }
  }
  throw new Error("Max retries exceeded");
}
Yes! The SDK works in modern browsers. However, never expose private keys in client-side code. Consider using a backend API for sensitive operations.
Create an API key wallet and use SubaccountInfo.forPermissionedWallet():
const apiKeyWallet = await LocalWallet.fromPrivateKey(apiKey, "lfg");
const subaccount = SubaccountInfo.forPermissionedWallet(
  apiKeyWallet,
  mainWalletAddress,
  0,
  [authenticatorId]
);
See the Wallets Guide for details.

Troubleshooting

Common reasons:
  • Price too far from market (limit order)
  • Insufficient liquidity
  • Order expired
Check market price and orderbook depth before placing orders.
You need more free collateral. Either:
  • Deposit more USDC
  • Close some positions
  • Reduce order size
Check: account.subaccount.freeCollateral
Common causes:
  • Insufficient gas
  • Expired block height
  • Network connectivity
  • Invalid parameters
Check error message and see Error Handling.