Skip to content
🌐Network: Mainnet

Project Setup

This section covers the initial project setup, dependency installation, and directory structure for your trading agent.

Initialize Your Project

bash
# Create project directory
mkdir trading-agent && cd trading-agent

# Initialize with pnpm
pnpm init

Package Configuration

Update your package.json with the following scripts to build, run, and format your trading agent:

json
{
  "name": "trading-agent",
  "version": "1.0.0",
  "main": "dist/index.js",
  "scripts": {
    "build": "tsc",                                    // Compile TypeScript to JavaScript
    "start": "tsc && node dist/src/index.js",          // Build and run the agent
    "format": "prettier --write . --ignore-path .prettierignore",  // Auto-format code
    "install:all": "pnpm install"                      // Install all dependencies
  }
}

Install Dependencies

Now install the required dependencies:

bash
# Install runtime dependencies
pnpm install fuels@0.102.0 axios ccxt decimal.js pino pino-pretty yaml ethers

# Install dev dependencies
pnpm install -D typescript @types/node prettier ts-node

Configure TypeScript

Create tsconfig.json:

bash
touch tsconfig.json

Add the following TypeScript configuration:

json
{
  "compilerOptions": {
    "target": "ES2020",              // Target modern JavaScript
    "module": "commonjs",             // Use CommonJS modules for Node.js
    "outDir": "dist",                 // Output compiled JS to dist/
    "rootDir": ".",                   // Source root is project root
    "strict": true,                   // Enable strict type checking
    "esModuleInterop": true,          // Allow default imports from CommonJS modules
    "baseUrl": ".",                   // Base directory for module resolution
    "skipLibCheck": true,             // Skip type checking of .d.ts files (faster)
    "moduleResolution": "node",       // Use Node.js module resolution
    "sourceMap": true                 // Generate source maps for debugging
  },
  "include": ["src", "lib"],          // Compile both src/ and lib/ directories
  "exclude": []
}

Create the source directories:

bash
mkdir -p src/types src/utils

o2 API Example Code Integration

The trading agent includes inline o2 API example code in the lib/ directory. This is example code that provides TypeScript interfaces for interacting with the o2 Exchange API.

Why Build a Trading Agent?

A trading agent automates market interactions on decentralized exchanges. By leveraging external price feeds and programmable order execution, trading agents can:

  • Execute automated trading strategies - Market making, arbitrage
  • Maintain continuous market presence - Trade 24/7 without manual intervention
  • React to market conditions in real-time - Adjust prices based on external feeds

Setup the Example Code

Copy the o2 API example code into the lib/ directory from the trading-agent-bot repository:

bash
# Clone the trading-agent-bot repository
git clone https://github.com/FuelLabs/trading-agent-bot.git temp-trading-bot

# Copy the lib folder to your project
cp -r temp-trading-bot/lib ./lib

# Clean up temporary clone
rm -rf temp-trading-bot

Alpha Software

The o2 API code in lib/ is alpha-stage and not feature-complete. Use at your own risk!

Important: The lib/ directory contains TypeScript source files that will be compiled alongside your bot code using your project's tsconfig.json. It does not have its own package.json or separate build process - everything compiles together as one project.

Example Code Structure

The example code is organized into several modules:

lib/
├── index.ts              # Main exports
├── rest-api/             # REST API client implementation
├── types/                # TypeScript type definitions & contract ABIs
└── websocket/            # WebSocket client (for real-time data)

What the Example Code Provides

The inline o2 API example code includes:

  • REST API Client - Client for o2 API endpoints (markets, orders, trades, balances)
  • Session Management - Secure session-based trading authentication
  • Type Definitions - TypeScript types for all API interactions
  • Contract Types - Auto-generated Fuel contract ABIs
  • WebSocket Support - Real-time market data streaming

Install Dependencies

Install all required dependencies with a single command:

bash
pnpm install