Account Configuration β
Before running your trading agent, you need to understand o2's session-based authentication model and prepare your trading account. The o2 API example code handles most of the complexityβyour main task is funding your account and understanding how sessions work.
Understanding Session Keys β
o2 uses a two key security model that separates account ownership from trading operations:
Owner Key (Your Main Wallet) β
- Controls the trading account contract
- Can withdraw funds and manage sessions
- Signs session creation and revocation
- Never exposed to the trading agent
- Keep extremely secure (hardware wallet recommended)
Session Key (Agent Wallet) β
- Temporary ephemeral key with limited permissions
- Can only execute trades on whitelisted contracts
- Cannot withdraw funds or transfer assets
- Expires automatically (typically 30 days)
- Safe to store in agent configuration
- Used by the agent for all trading operations
Prerequisites Checklist β
Before building the trading agent, ensure you have:
1. A Trading Account on o2 β
Your trading account is a smart contract on Fuel that holds your assets and executes trades. The easiest way to create one is through the o2 web interface at https://testnet.o2.app.
2. Funded Trading Account β
Your trading account must have sufficient funds for both assets in the trading pair you plan to trade.
For example, to trade the ETH/USDC market:
- You need both ETH (base asset) and USDC (quote asset) in your trading account
- The agent places buy orders (spending USDC to get ETH) and sell orders (spending ETH to get USDC)
- Without both assets, the agent will fail to place orders
Note: This tutorial uses testnet. Once comfortable, adapt to mainnet by changing network URLs in your configuration.
3. Market Information β
You'll need the market details for the trading pair you want to use. The easiest way is through the o2 web interface at https://testnet.o2.app, or you can query the Market Data API.
Save these values for your target market:
market_id: Identifies the trading paircontract_id: Used in session whitelisting and bot configuration
Example market query:
curl https://api.testnet.o2.app/v1/marketsExample response:
{
"markets": [
{
"market_id": "0x09c17f779eb0a7658424e48935b2bef24013766f8b3da757becb2264406f9e96",
"contract_id": "0x9ad52fb8a2be1c4603dfeeb8118a922c8cfafa8f260eeb41d68ade8d442be65b",
"base": {
"symbol": "ETH",
"asset_id": "0x...",
"decimals": 9
},
"quote": {
"symbol": "USDC",
"asset_id": "0x...",
"decimals": 9
}
}
]
}How the o2 API Example Code Handles This β
The o2 API example code (in lib/) automatically handles:
- β Session based transaction signing
- β Account state queries
- β Order placement and management
- β Market data fetching
- β Type safe API interactions
You only need to:
- Provide a Fuel Ignition private key in
config.yaml - Ensure your owner wallet's trading account is funded with both assets
- Configure which market to trade
The trading agent creates a wallet from this session private key and uses it to sign trading transactions. The session must be registered and authorized by your owner wallet beforehand.