🎓 Tutorials

OpenClaw + Xerolite: Set Up an AI Trading Bot for Interactive Brokers — Step-by-Step (2026)

⚠️ Disclosure: Some links on this page are affiliate links. If you sign up through them, I may earn a commission — at no extra cost to you. I only review tools I actually use.
# OpenClaw + Xerolite: Set Up an AI Trading Bot for Interactive Brokers — Step-by-Step (2026)

What if you could tell your AI assistant "buy 10 shares of AAPL" and it actually executed the trade on Interactive Brokers?

That's exactly what the Xerolite skill for OpenClaw does. Launched in March 2026, it bridges the gap between conversational AI and real brokerage execution — no Python scripts, no manual order entry, no API documentation to wade through.

I've been running an automated trading system on Interactive Brokers for over a year (a USDJPY momentum strategy that executes through IB Gateway). Setting that up required weeks of Python development, debugging TWS API quirks, and building a custom daemon. Xerolite compresses that entire setup into something you can configure in under an hour.

Here's exactly how to set it up.

What You Need Before Starting

Before touching Xerolite or OpenClaw, make sure you have:

You do NOT need Python experience. That's the whole point.

Architecture: How the Pieces Fit Together

Here's how data flows when you say "buy 10 shares of TSLA":

You (natural language)
  → OpenClaw (understands intent, extracts parameters)
    → Xerolite Skill (formats order, calls REST API)
      → Xerolite Server (validates, routes to broker)
        → IB Gateway / TWS (executes on exchange)
          → Interactive Brokers (fills order)

Each layer handles one job:

This separation matters for security — OpenClaw never touches your IB credentials directly.

Step 1: Install and Configure IB Gateway

IB Gateway is the headless version of TWS (Trader Workstation). It uses less memory and doesn't need a GUI, making it ideal for server deployments.

Download IB Gateway

Go to Interactive Brokers' download page and grab the latest stable release for your OS.

For Linux:

# Download the installer
chmod +x ibgateway-stable-standalone-linux-x64.sh
./ibgateway-stable-standalone-linux-x64.sh

# Default install location: ~/Jts/ibgateway/

Configure API Access

Launch IB Gateway and log in with your IB credentials. Then:

1. Go to Configure → Settings → API → Settings

2. Check "Enable ActiveX and Socket Clients" 3. Set the Socket port to 4001 (live) or 4002 (paper trading) 4. Check "Allow connections from localhost only" (critical for security) 5. Uncheck "Read-Only API" — Xerolite needs write access to place orders

Set Up 2FA (IB Key)

IB Gateway requires two-factor authentication on every login. This is the single biggest pain point for automated trading setups.

Options:

> From experience: IB Key failures are the #1 cause of trading system downtime. If your phone dies or you're traveling without signal, your bot goes offline. Check our IB 2FA troubleshooting guide for recovery procedures.

Run IB Gateway as a Service (Linux)

For production use, run IB Gateway as a systemd service so it survives reboots:

# /etc/systemd/system/ibgateway.service
[Unit]
Description=IB Gateway
After=network.target

[Service]
Type=simple
User=your_username
ExecStart=/home/your_username/Jts/ibgateway/ibgateway
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target

sudo systemctl enable ibgateway
sudo systemctl start ibgateway

Step 2: Install Xerolite

Xerolite runs as a middleware server between OpenClaw and IB Gateway.

Install via Docker (Recommended)

docker pull xeroflex/xerolite:latest

docker run -d \
  --name xerolite \
  --network host \
  -e IB_GATEWAY_HOST=127.0.0.1 \
  -e IB_GATEWAY_PORT=4001 \
  -e XEROLITE_API_KEY=your_secure_api_key_here \
  xeroflex/xerolite:latest

Install from Source

git clone https://github.com/xeroflex/xerolite.git
cd xerolite
pip install -r requirements.txt

# Configure
cp config.example.yaml config.yaml
# Edit config.yaml with your IB Gateway host/port

Verify the Connection

curl http://localhost:8080/health
# Should return: {"status": "connected", "broker": "interactive_brokers"}

curl http://localhost:8080/api/search?symbol=AAPL \
  -H "Authorization: Bearer your_secure_api_key_here"
# Should return AAPL contract details

If you get a connection error, check that IB Gateway is running and the port matches.

Step 3: Install the Xerolite Skill in OpenClaw

OpenClaw uses "skills" — modular plugins that give your AI new capabilities. The Xerolite skill teaches it how to place trades.

Install the Skill

openclaw skill install xerolite

Configure the Skill

Edit your OpenClaw configuration to point at your Xerolite server:

{
  "skills": {
    "xerolite": {
      "api_url": "http://localhost:8080",
      "api_key": "your_secure_api_key_here",
      "default_currency": "USD",
      "default_exchange": "SMART",
      "default_sec_type": "STK"
    }
  }
}

Test It

Open a chat with your OpenClaw instance and try:

You: Search for AAPL
OpenClaw: Found AAPL — Apple Inc., STOCK, USD, SMART exchange.
         Contract ID: 265598

You: What about TSLA?
OpenClaw: Found TSLA — Tesla Inc., STOCK, USD, SMART exchange.
         Contract ID: 76792991

If search works, your pipeline is connected end-to-end.

💡 Interactive Brokers

Like what you're reading? Try it yourself — this link supports ChartedTrader at no cost to you.

Open an Interactive Brokers Account →

Step 4: Place Your First Trade

Start with a small test order on your paper trading account (port 4002) before going live.

You: Buy 1 share of SPY
OpenClaw: ✅ Order placed — 1 share of SPY (STOCK/USD) at market price via SMART exchange.
         Order ID: 42

Conversational Context

Because OpenClaw maintains conversation history, you can build on previous queries:

You: Search for NVDA
OpenClaw: Found NVDA — NVIDIA Corporation, STOCK, USD, SMART exchange.

You: Buy 5 shares
OpenClaw: ✅ Order placed — 5 shares of NVDA at market price.

What You Can Trade

Through Interactive Brokers, Xerolite supports:

For forex, I still prefer a dedicated Python setup — my USDJPY momentum strategy needs custom signal logic that goes beyond simple order placement. But for stock trades, Xerolite is faster than anything I've built manually.

Security: Protecting Your Brokerage Account

You're giving an AI assistant access to place real trades on a real brokerage account. Take security seriously.

1. Use a Sub-Account

Interactive Brokers lets you create sub-accounts with limited permissions. Create one specifically for AI trading:

2. Lock Down Network Access

# IB Gateway: localhost only
# In IB Gateway → Configure → API → Settings:
# ✅ "Allow connections from localhost only"

# Xerolite: bind to localhost or use firewall
# In config.yaml:
# host: 127.0.0.1

# If running remotely, use SSH tunnel:
ssh -L 8080:localhost:8080 your_server

3. Use Strong API Keys

Generate a random API key for Xerolite:

openssl rand -hex 32
# Use this as XEROLITE_API_KEY

Never reuse passwords or use guessable keys.

4. Start with Paper Trading

Use IB Gateway port 4002 (paper trading) until you're confident the system works correctly. Paper trading uses simulated fills — no real money at risk.

5. Set Position Limits

In your IB account settings, configure:

> Lesson from my own system: I once had a bug that opened a reverse position instead of closing an existing one. The loss was small ($1.32), but it could have been catastrophic without position limits. Always assume your code has bugs. Always have guardrails.

Xerolite vs. Building Your Own IB Bot

Having built a production IB trading system from scratch (Python, ibapi, custom daemon, systemd services), I can compare honestly:

AspectCustom Python BotXerolite + OpenClaw
Setup time2-4 weeks1-2 hours
Programming requiredAdvanced PythonNone
CustomizationUnlimitedLimited to supported commands
Signal logicCustom strategiesManual decisions via chat
MonitoringCustom dashboardsOpenClaw chat interface
ReliabilityDepends on your codeDepends on Xerolite + IB Gateway
Best forSystematic strategiesDiscretionary traders
My take: If you're running a systematic strategy (like my USDJPY momentum system), you still need custom code. The strategy logic — signal generation, position sizing, risk management — requires more than "buy X shares."

But if you're a discretionary trader who wants to place trades without clicking through TWS, or you want a quick way to act on ideas without building infrastructure, Xerolite is genuinely useful.

Combining Xerolite with TradingView Alerts

The real power emerges when you connect TradingView alerts to OpenClaw:

1. TradingView fires a webhook when your Pine Script indicator triggers

2. OpenClaw receives the webhook and interprets the signal 3. Xerolite executes the trade on Interactive Brokers

This creates a no-code pipeline from chart analysis to execution. You write the Pine Script indicator, set the alert, and the rest happens automatically.

We covered the TradingView side in our Pine Script momentum indicator tutorial — the same logic applies here, but execution goes through Xerolite instead of custom Python.

Troubleshooting Common Issues

"Connection refused" from Xerolite

IB Gateway isn't running or the port doesn't match. Check:

# Is IB Gateway running?
ps aux | grep ibgateway

# Is the port correct?
netstat -tlnp | grep 4001

"Order rejected" errors

Common causes:

IB Gateway disconnects randomly

IB Gateway drops connections after ~24 hours of inactivity. Solutions:

What's Next

The Xerolite integration is version 1 — basic order placement and contract search. Here's what would make it genuinely powerful:

For now, it's a fast way to get from idea to execution without building infrastructure. If you're already running OpenClaw as your personal AI assistant, adding Xerolite takes minutes and opens up a genuinely new workflow.

---

*Ready to try it? You'll need an Interactive Brokers account to connect — new accounts get up to $1,000 in IBKR stock through the referral program.*

> 💡 Did you know? Interactive Brokers pays $200 cash for each friend you refer, and your friend gets up to $1,000 in IBKR stock. Learn how the IBKR referral program works →

Frequently Asked Questions

Is Xerolite free to use?

Xerolite is open-source and self-hosted. You run it on your own server alongside IB Gateway. There are no subscription fees — your only costs are Interactive Brokers' standard commissions and market data subscriptions.

Can I use Xerolite with a paper trading account?

Yes. Point Xerolite at IB Gateway port 4002 instead of 4001. Paper trading uses simulated fills with real market data, so you can test the full pipeline without risking real money.

Does this work with IBKR Lite or only IBKR Pro?

Both work, but IBKR Pro gives better execution quality and access to more order types. For API trading, Pro is strongly recommended — the commission savings on Lite accounts come with wider spreads and slower fills.

What happens if my internet goes down during a trade?

Once an order reaches Interactive Brokers' servers, it executes regardless of your connection. If your connection drops before the order is sent, nothing happens — no partial state. IB Gateway handles the connection reliability; your local setup just needs to stay online long enough to submit the order.

Can I trade options or futures through Xerolite?

The current version supports stocks and ETFs with the default configuration. Options and futures require specifying additional contract parameters (expiry, strike, right). Check Xerolite's documentation for the extended order format — it's supported but requires more specific commands.

Interactive Brokers

Ready to get started? Use the link below — it helps support ChartedTrader at no cost to you.

Open an Interactive Brokers Account →
📈

About the author

I'm a systematic trader running live strategies on IB (USDJPY momentum) and Hyperliquid (crypto perps). Every tool reviewed here is something I've used with real capital. Questions? Reach out.

📚 Related Articles

🎓 Tutorials

TradingView Free Plan Indicator Limit: How to Combine RSI, EMA, and MACD Into One Pine Script (2026)

Hit TradingView's 2-indicator limit on the free plan? Learn how to combine RSI, EMA, and MACD into a single all-in-one Pine Script v6 indicator — with full copy-paste code, visual customization tips, and a clear upgrade path when you outgrow the workaround.

March 23, 2026 ⏱ 10 min read
🎓 Tutorials

TradingView Webhook to Telegram Bot: Get Real-Time Alerts on Your Phone (2026 Setup Guide)

Learn how to send TradingView alerts directly to Telegram using webhooks. Step-by-step guide covering BotFather setup, free relay options, JSON payload formatting, and real trading alert examples — no coding experience required.

March 22, 2026 ⏱ 14 min read
🎓 Tutorials

TradingView Pine Script SuperTrend Strategy: Build a Custom Indicator Step by Step (2026)

Learn how to build a custom SuperTrend strategy indicator in Pine Script v6 with complete code. Includes RSI filter, multi-timeframe confirmation, stop loss/take profit, and backtesting setup for TradingView.

March 21, 2026 ⏱ 17 min read

📬 Get weekly trading insights

Real trades, honest reviews, no fluff. One email per week.