Skip to content
🌐Network: Mainnet

Trading Agent Guide

This guide walks you through using the o2 Exchange API to build trading applications. You'll learn the core concepts of programmatic market interaction, session-based authentication, and real-time order execution on Fuel's high performance blockchain.

What You'll Learn

This guide teaches you how to interact with the o2 Exchange API programmatically. You'll understand:

  • How to authenticate with session-based API authentication
  • How to place and manage orders programmatically
  • How to integrate external price data sources
  • How to build automated trading applications on Fuel Network

How the o2 API Works

The o2 Exchange API enables you to interact with the exchange programmatically. Here's a typical workflow:

  1. Authenticate: Create a session using your wallet signature
  2. Fetch Market Data: Get current market prices and order book state
  3. Place Orders: Submit buy/sell limit orders through the API
  4. Monitor Status: Track order fills and account balances
  5. Manage Orders: Cancel or modify existing orders as needed

Key Concept: The API uses session-based authentication where you sign a message with your wallet once, then receive a session token for subsequent API calls. This allows you to interact with the exchange without signing every transaction.

Example: Placing an Order via API

Here's how you might use external price data to place strategic orders:

Current Market Price (from external source): $2,500.00
Your Strategy: Place limit orders at specific price levels

Buy Order:  $2,450.00 (2% below market)
Sell Order: $2,550.00 (2% above market)

The example trading agent demonstrates this pattern by fetching prices from external sources and placing orders through the o2 API.

API Integration Architecture

mermaid
graph LR
    subgraph App["Your Trading Application"]
        direction TB
        PriceFeed["External Price Feed<br/>e.g., Bitget, Binance"]
        space1[" "]
        APIClient["o2 API Client<br/>Session Management<br/>Order Submission"]
        space2[" "]
        Logic["Your Trading Logic<br/>Strategy implementation<br/>Risk management<br/>Order placement decisions"]

        PriceFeed -.->|"Market Data"| Logic
        APIClient -.->|"API Methods"| Logic
        
        style space1 fill:none,stroke:none
        style space2 fill:none,stroke:none
    end

    space3[" "]

    subgraph Infra["o2 Exchange Infrastructure"]
        direction TB
        o2API["o2 Exchange API<br/>REST Endpoints<br/>Session Authentication<br/>Order Management"]
        space4[" "]
        Fuel["Fuel Network<br/>Smart Contracts<br/>Order Book State<br/>Trade Settlement"]
        
        style space4 fill:none,stroke:none
    end

    Logic ==>|"HTTP Requests"| o2API
    o2API ==>|"Blockchain Transactions"| Fuel
    
    style space3 fill:none,stroke:none

Prerequisites

Before starting, ensure you have:

  • Node.js v18+ installed
  • Basic TypeScript knowledge for understanding the codebase
  • Familiarity with DEX concepts (order books, limit orders, market making)
  • A funded wallet on Fuel Network with ETH, FUEL, or USDC