Skip to main content

Agent Connect API

Build Trading Agents That Trade

Connect your AI to live markets, read portfolios, and execute trades programmatically. Start in sandbox, go live when ready.

API Key Auth
HMAC-SHA256 signed requests
Live Data
Real-time via CoinGecko
Sandbox Mode
Paper trade risk-free
60 req/min
Rate limited & throttled

Quick Start

Get your AI agent trading in 3 steps:

1

Register your agent

bash
# Register your AI agent
curl -X POST https://api.next.exchange/v1/agent/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Alpha Bot",
    "permissions": ["read:market", "read:portfolio", "write:orders"],
    "mode": "sandbox"
  }'

# Response:
{
  "agent": {
    "id": "agent_a1b2c3d4e5f6...",
    "apiKey": "nx_test_Abc123...",
    "apiSecret": "s3cr3t_k3y_h3r3...",  // Save this! Only shown once.
    "permissions": ["read:market", "read:portfolio", "write:orders"],
    "mode": "sandbox",
    "rateLimit": "60 requests/min"
  }
}
2

Connect & trade

python
import requests
import hmac
import hashlib
import time

API_KEY = "nx_test_your_key_here"
API_SECRET = "your_secret_here"
BASE_URL = "https://api.next.exchange/v1/agent"

class NextExchangeAgent:
    def __init__(self, api_key, api_secret, base_url):
        self.api_key = api_key
        self.api_secret = api_secret
        self.base_url = base_url

    def _headers(self, method, path, body=""):
        timestamp = str(int(time.time() * 1000))
        payload = f"{timestamp}{method}{path}{body}"
        signature = hmac.new(
            self.api_secret.encode(),
            payload.encode(),
            hashlib.sha256
        ).hexdigest()
        return {
            "X-NX-Key": self.api_key,
            "X-NX-Signature": signature,
            "X-NX-Timestamp": timestamp,
            "Content-Type": "application/json"
        }

    def get_market_data(self, coins=None):
        """Fetch live market data for specified coins."""
        path = "/market"
        params = f"?coins={coins}" if coins else ""
        headers = self._headers("GET", path)
        resp = requests.get(
            f"{self.base_url}{path}{params}",
            headers=headers
        )
        return resp.json()

    def get_portfolio(self):
        """Read current portfolio positions."""
        path = "/portfolio"
        headers = self._headers("GET", path)
        resp = requests.get(
            f"{self.base_url}{path}",
            headers=headers
        )
        return resp.json()

    def place_order(self, symbol, side, order_type, quantity, price=None):
        """Place a trading order."""
        import json
        path = "/orders"
        body = json.dumps({
            "symbol": symbol,
            "side": side,
            "type": order_type,
            "quantity": quantity,
            "price": price
        })
        headers = self._headers("POST", path, body)
        resp = requests.post(
            f"{self.base_url}{path}",
            headers=headers,
            data=body
        )
        return resp.json()

# Initialize
agent = NextExchangeAgent(API_KEY, API_SECRET, BASE_URL)

# Get Bitcoin price
market = agent.get_market_data("bitcoin")
btc = market["data"][0]
print(f"BTC: ${btc['price']:,.2f} ({btc['change24h']:+.2f}%)")

# Check portfolio
portfolio = agent.get_portfolio()
print(f"Portfolio: ${portfolio['data']['totalValue']:,.2f}")

# Place a trade
order = agent.place_order("BTC", "buy", "market", 0.01)
print(f"Order {order['order']['orderId']}: {order['order']['status']}")
3

Go live

Once you're confident in sandbox, register a live mode agent to trade with real funds. Live agents require HMAC-SHA256 signed requests for security. Set dailyLossLimit and maxPositionSize as circuit breakers.

Permissions

Granular access control — grant only what your agent needs:

Market Data
read:market

Read prices, charts, order books

Portfolio
read:portfolio

Read positions and balances

Trading
write:orders

Place, modify, and cancel orders

Sentiment
read:sentiment

Read AI sentiment analysis

Social Data
read:social

Read social trading feed

Webhooks
write:webhook

Register event webhooks

API Reference

All endpoints, documented:

Authentication

Two modes, one API:

Sandbox Mode

nx_test_...
  • API key only — no HMAC required
  • Paper trading with mock balances
  • Real market data from CoinGecko
  • Perfect for development & testing

Live Mode

nx_live_...
  • HMAC-SHA256 signed requests required
  • Real money, real trades
  • Circuit breakers: daily loss limit + position cap
  • 30-second request window

HMAC Signature (Live Mode)

Sign requests by computing: HMAC-SHA256(secret, timestamp + METHOD + path + body)

Header: X-NX-Key = your_api_key
Header: X-NX-Signature = hmac_hex_digest
Header: X-NX-Timestamp = unix_ms

Ready to Build?

Register your agent in sandbox mode and start trading in minutes. No credit card required.