Documentation Index Fetch the complete documentation index at: https://docs.lfg.land/llms.txt
Use this file to discover all available pages before exploring further.
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 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
SelectedGasDenom.USDC or SelectedGasDenom.NATIVE
populateAccountNumberCache()
Pre-populate the account number cache for faster transactions.
await client . populateAccountNumberCache ( wallet . address );
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 placing the order
Market identifier (e.g., “ETH-USD”)
OrderSide.BUY or OrderSide.SELL
Order price in quote currency
Order size in base currency
Block height when order expires
timeInForce
Order_TimeInForce
required
Time in force policy
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
);
Order type (LIMIT, MARKET, STOP_LIMIT, STOP_MARKET)
GTT (Good-til-time), IOC (Immediate-or-cancel), or FOK (Fill-or-kill)
Seconds from now until order expires
Execution type (DEFAULT, POST_ONLY, IOC)
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 that placed the order
Client ID of order to cancel
Order type flags (SHORT_TERM or LONG_TERM)
New expiration block (for short-term)
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"
);
Amount in USDC (as 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"
);
Amount in USDC (as 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"
);
recipientSubaccountNumber
Recipient subaccount number
Amount in USDC (as 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 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" ));
}
IndexerClient Read-only market data queries
ValidatorClient Blockchain transaction operations
SubaccountInfo Trading account management
Orders Guide Complete orders guide