Overview

The o1.exchange Trading API enables programmatic trading with enterprise-grade features including built-in MEV protection, Permit2 support for gasless approvals, and automatic slippage handling.

Key Benefits

  • MEV Protection: Private mempool routing to prevent sandwich attacks
  • Gasless Approvals: One-time Permit2 signatures for unlimited trading
  • Automatic Slippage: Built-in slippage protection with customizable limits

Prerequisites

Wallet

Ethereum wallet with private key

Gas Fees

ETH for transaction costs

Runtime

Node.js environment

Quick Start

1. Generate API Key

1

Navigate to API Trading

2

Create API Key

Generate your secure API token for authentication

2. Create Transaction Batch

Endpoint: POST https://o1.exchange/api/v1/transaction-batches/createHeaders:
{
  "Authorization": "Bearer <YOUR_API_TOKEN>",
  "Content-Type": "application/json"
}
Body:
{
  "signerAddress": "0x...",  // Your wallet address
  "tokenAddress": "0x...",   // Token contract address
  "uiAmount": "1.0",         // Amount in human-readable format
  "direction": "buy",        // "buy" or "sell"
  "slippageBps": 300,        // Slippage in basis points (300 = 3%)
  "mevProtection": true      // Enable MEV protection
}

3. Sign Transaction and Permit2

4. Submit Transaction

Endpoint: POST https://o1.exchange/api/v1/transaction-batches/submitHeaders:
{
  "Authorization": "Bearer <YOUR_API_TOKEN>",
  "Content-Type": "application/json"
}
Body:
{
  "id": "batch_123...",     // Batch ID from create response
  "transactions": [
    {
      "id": "tx_456...",     // Transaction ID
      "signed": "0x...",     // Signed transaction hex
      "permit2": {
        "eip712": {
          "signature": "0x..." // Permit2 signature
        }
      }
    }
  ]
}

Interactive Example

Complete CLI Trading App

See execute-trade-interactive.js for a fully functional CLI trading application that demonstrates all integration steps with proper error handling and user interaction.

Setup Environment

Create a .env.local file:
EXECUTE_TRADE_PRIVATE_KEY=<YOUR_PRIVATE_KEY>
EXECUTE_TRADE_API_TOKEN=<YOUR_API_TOKEN>
EXECUTE_TRADE_BASE_URL=<API_BASE_URL>
EXECUTE_TRADE_RPC_URL=<ETHEREUM_RPC_URL>

Run Interactive CLI

node execute-trade-interactive.js
1

Token Address

Enter token contract address (e.g., 0x06ca615ac72a18e76b63bd4b5c320b6c8e291f8b)
2

Trade Direction

Choose buy or sell
3

Amount

Enter amount in ETH (for buy) or tokens (for sell)
4

Confirm

Review trade details and execute
5

Results

View balance changes after execution

Advanced Features

Permit2 Integration

Gasless token approvals using EIP-712 signatures

  • Automatic signature placeholder replacement
  • One-time approval for unlimited trading
  • Reduced gas costs for frequent traders

MEV Protection

Protection against sandwich attacks

  • Private mempool routing
  • Reduced slippage from MEV bots
  • Enable with mevProtection: true

Slippage Control

Specify slippageBps in basis points where 100 bps = 1%Recommendations:
  • Normal conditions: 300 bps (3%)
  • Volatile tokens: 500-1000 bps (5-10%)
  • Large trades: Increase as needed

Error Handling

Always implement proper error handling for:
  • Network connectivity issues
  • Insufficient balance or gas
  • Transaction reverts
  • API rate limiting
The interactive example includes comprehensive error handling patterns you can reference for your own implementation.