Configuration Management
Your bot's behavior is controlled through a YAML configuration file. This section covers configuration structure, best practices, and examples for different use cases.
Type Definitions
Create the type definitions file:
touch src/types/config.tsNow add the following content to src/types/config.ts:
import { OrderType } from '../../lib/rest-api/types';
export interface GeneralConfig {
log_level: string;
network_url: string;
}
export interface MarketConfig {
market_id: string;
contract_id: string;
base_symbol: string;
quote_symbol: string;
order_usdc_value: number;
order_interval_seconds: number;
order_pairs_interval_seconds: number;
bitget_symbol: string;
reciprocal_rate: boolean;
convert_to_usdc: boolean;
price_adjustment_factor: number;
order_type: OrderType;
}
export interface O2AccountConfig {
private_key: string;
}
export interface O2Config {
base_url: string;
market: MarketConfig;
account: O2AccountConfig;
}
export interface BotConfig {
general: GeneralConfig;
o2: O2Config;
}Config Loader
Create the config loader file:
touch src/config.tsAdd the following content to src/config.ts:
import fs from 'fs';
import yaml from 'yaml';
import { BotConfig } from './types/config';
import { OrderType } from '../lib/rest-api/types';
export function loadConfig(path: string = 'config.yaml'): BotConfig {
const file = fs.readFileSync(path, 'utf8');
const configs = yaml.parse(file) as BotConfig;
if (![OrderType.Spot, OrderType.FillOrKill].includes(configs.o2.market.order_type)) {
throw new Error(`Invalid order_type: ${configs.o2.market.order_type}. Must be either 'Spot' or 'FillOrKill'.`);
}
return configs;
}Configuration File
Create the main configuration file:
touch config.yamlAdd the following content to config.yaml for testnet (recommended):
# Example configuration file for the Trading Agent Bot
# General Settings
general:
# The logging level (e.g., DEBUG, INFO, WARNING, ERROR)
log_level: INFO
# The URL of the Fuel network
network_url: https://testnet.fuel.network/v1/graphql
# o2 Trading Agent Bot Settings
o2:
# The base URL for the O2 API
base_url: https://api.testnet.o2.app
# o2 Market configuration
# Adjust these settings to specify which market to trade on
# As of now, only one market configuration is supported
market:
# Market identifiers
market_id: '0x09c17f779eb0a7658424e48935b2bef24013766f8b3da757becb2264406f9e96'
contract_id: '0x2a78ab167c28f474d2ad62daabe7a42ce03f066dd8aa7cf57b984d14e4bd907b'
# Trading pair symbols
base_symbol: ETH
quote_symbol: USDC
# Order sizing
# Value of each buy/sell order in terms of USDC
order_usdc_value: 10
# Timing configuration
# Interval between a single buy and sell order, in seconds
order_interval_seconds: 1
# Interval between multiple buy & sell order pairs, in seconds
order_pairs_interval_seconds: 2.5
# Price feed configuration
# Corresponding Bitget trading symbol (format: BASE/QUOTE)
# This is used to determine the price of orders on O2
bitget_symbol: ETH/USDC
# If true, use the inverse price (1/price) instead of the regular price
# Useful for inverse pairs e.g. USDC/USDT -> USDT/USDC
reciprocal_rate: false
# Whether to convert the Bitget price quotation to USDC
# Useful for O2 assets that do not have a USDC pair on Bitget
# Example: To get FUEL/USDC price, fetch FUEL/USDT and USDT/USDC from Bitget
convert_to_usdc: false
# Strategy configuration
# A factor to adjust the price fetched from Bitget
# Example: 0.05 increases buy price by 5% and decreases sell price by 5%
price_adjustment_factor: 0.1
# Order type for trading
# Available options: Spot, FillOrKill
order_type: Spot
# Account credentials
account:
# Private key of a wallet with funds on O2
private_key: '<YOUR_PRIVATE_KEY_HERE>'Logging
The bot logs at different levels controlled by the log_level configuration:
INFO (Default)
[13:45:03] INFO: Reference price: 2500.50
[13:45:03] INFO: Adjusted prices - Buy: 2750550000000, Sell: 2250450000000 (±10%)
[13:45:03] INFO: Order size: 40000000 ETH
[13:45:03] INFO: Buy order placed (234ms) - Price: 2750550000000, Qty: 40000000DEBUG (Detailed)
general:
log_level: DEBUGShows:
- Price conversion steps
- Precision calculations
- API request/response bodies
ERROR (Critical)
[13:45:10] ERROR: Failed to fetch price, skipping cycle
[13:45:15] ERROR: Buy order failed, continuing to sellEnvironment Variables
For security, you can use environment variables for sensitive data:
# config.yaml
account:
private_key: ${SESSION_PRIVATE_KEY}Then set the environment variable:
export SESSION_PRIVATE_KEY="0xYourActualKey"The config loader in src/config.ts can be extended to support environment variable interpolation by replacing ${VARIABLE_NAME} patterns with their actual values from process.env.