Skip to main content

Overview

SubaccountInfo represents a trading subaccount under a wallet, used for all trading operations.
import { SubaccountInfo } from "@oraichain/lfg-client-js";

Static Methods

forLocalWallet()

Create a subaccount for standard wallet-based trading.
const subaccount = SubaccountInfo.forLocalWallet(wallet, 0);
wallet
LocalWallet
required
The LocalWallet instance
subaccountNumber
number
required
Subaccount index (0-127). Use 0 for primary account.
Returns: SubaccountInfo

forPermissionedWallet()

Create a subaccount for API key-based trading.
const subaccount = SubaccountInfo.forPermissionedWallet(
  apiKeyWallet,
  mainWalletAddress,
  0,
  [authenticatorId]
);
wallet
LocalWallet
required
API key wallet (signs transactions)
address
string
required
Main wallet address (owns funds)
subaccountNumber
number
required
Subaccount index (0-127)
authenticatorIds
number[]
required
Authenticator IDs granting permission
Returns: SubaccountInfo

Properties

address

The wallet address owning this subaccount.
console.log(subaccount.address); // "lfg1..."
Type: string

subaccountNumber

The subaccount number (0-127).
console.log(subaccount.subaccountNumber); // 0
Type: number

Usage Examples

Multiple Subaccounts

const wallet = await LocalWallet.fromMnemonic(mnemonic, "lfg");

// Create multiple subaccounts for different strategies
const spotHedging = SubaccountInfo.forLocalWallet(wallet, 0);
const momentumTrading = SubaccountInfo.forLocalWallet(wallet, 1);
const marketMaking = SubaccountInfo.forLocalWallet(wallet, 2);

API Key Trading

const apiKeyWallet = await LocalWallet.fromPrivateKey(apiKey, "lfg");
const mainAddress = "lfg1mainwalletaddress...";

// Get authenticator ID
const auths = await client.getAuthenticators(mainAddress);
const authenticatorId = auths.accountAuthenticators[0].id;

// Create permissioned subaccount
const subaccount = SubaccountInfo.forPermissionedWallet(
  apiKeyWallet,
  mainAddress,
  0,
  [authenticatorId]
);

// Place order using API key
await client.placeShortTermOrder(subaccount /* ... */);