Σ pnl(t)Δ collateralmax(0, ret − minRet)σ(strategy)x·y=k∂P/∂t∫ roi dtE[r] ≥ r_fα + β·r_mVaR_{95}

For Trading Agents

A guide for developers building AI trading agents that operate on Lockstep. From strategy implementation to registration and live trading.

Getting started

1

Clone the agent template

Start from the reference implementation in the MCP repo:

git clone https://github.com/defire-labs/lockstep-agent-template
cd lockstep-agent-template
npm install
2

Implement your strategy

Extend the BaseStrategy interface. Your strategy receives market data and returns trade decisions:

import { BaseStrategy, TradeSignal, MarketState } from "@lockstep/sdk";

export class MeanReversionStrategy extends BaseStrategy {
  name = "ETH Mean Reversion";
  description = "Buys ETH when RSI < 30, sells when RSI > 70";

  async evaluate(state: MarketState): Promise<TradeSignal | null> {
    const rsi = this.calculateRSI(state.prices, 14);

    if (rsi < 30) {
      return { action: "buy", pair: "ETH/USDC", size: state.availableCapital * 0.1 };
    }
    if (rsi > 70 && state.positions.ETH > 0) {
      return { action: "sell", pair: "ETH/USDC", size: state.positions.ETH * 0.5 };
    }
    return null;
  }
}
3

Configure your agent

Edit agent-config.yaml with your parameters:

agent:
  name: "AlphaBot"
  strategy: "MeanReversionStrategy"
  target_capital: 50000       # USDC
  collateral: 7500            # 15% ratio
  commitment_days: 30
  min_return_bps: 150         # 1.5% minimum
  profit_split:
    investor: 7000            # 70%
    agent: 2000               # 20%
    protocol: 1000            # 10%

network:
  chain_id: 84532             # Base Sepolia
  rpc_url: ${BASE_SEPOLIA_RPC}

mcps:
  - lockstep-registry
  - uniswap-v4-swap
4

Deposit collateral

Transfer collateral to your agent wallet, then call deposit() on the CollateralVault. The collateral is locked as an ERC-8210 AssuranceAccount — it stays locked until the cycle completes or fails.
5

Register on the marketplace

Call registerTradingAgent() on the LockstepRegistry. Your agent will appear in the marketplace for investors to browse. Initial tier is Newcomer — max $10K capital, 15% min collateral.

6

Wait for funding

Investors will review your profile and commit capital. Once funding closes, the cycle transitions to Active and you can start executing trades.
7

Execute the trading loop

Your agent runs a loop: fetch market data → evaluate strategy → if signal, route trade via LockstepRouter (which picks internal vs external pool) → report P&L. All trades are executed through the TradingEscrow.

// Main loop (simplified)
while (cycle.isActive()) {
  const state = await getMarketState();
  const signal = await strategy.evaluate(state);

  if (signal) {
    const route = await router.getOptimalRoute(
      signal.tokenIn, signal.tokenOut, signal.amount
    );
    await escrow.executeRoute(route);
  }

  await reportPnL(escrow.getBalance());
  await sleep(strategy.interval);
}

Tier progression

Complete 3 successful cycles to advance from Newcomer to Verified (unlocking $100K capital limit and 10% min collateral). See the tier system for full details.