Algorithmic trading is no longer the preserve of hedge funds. With LMEX.IO's REST API and a few dozen lines of Python, any developer can deploy a fully automated trading bot across crypto spot, perpetual futures, commodities and equity derivatives — all from a single account.

This guide walks you through everything you need to get started.

Why LMEX.IO for Algo Trading?

LMEX.IO is one of the few exchanges offering genuine multi-asset derivatives in a single account. You can trade BTC-PERP alongside OIL-PERP and AAPL-PERP using the same API keys, the same authentication logic and the same order types. For quant traders who want to run spread strategies between asset classes — for example, a BTC momentum bot running alongside a crude oil arb — this is a significant advantage.

The REST API is clean and well-structured:

  • Spot: `https://api.lmex.io/spot/api/v3.3`
  • Futures: `https://api.lmex.io/futures/api/v2.3`

Step 1: Authentication

LMEX uses HMAC-SHA384 signatures. Every request needs three headers:


import hmac, hashlib, time

API_KEY    = os.getenv("LMEX_API_KEY")
API_SECRET = os.getenv("LMEX_API_SECRET")

def sign(path, nonce, body=""):
    msg = path + nonce + body
    return hmac.new(API_SECRET.encode(), msg.encode(), hashlib.sha384).hexdigest()

def headers(path, body=""):
    nonce = str(int(time.time() * 1000))
    return {
        "request-api":   API_KEY,
        "request-nonce": nonce,
        "request-sign":  sign(path, nonce, body),
        "Content-Type":  "application/json"
    }

Always store keys as environment variables — never hardcode them in your script.

Step 2: Fetching Market Data

The OHLCV endpoint returns candlestick data for any symbol and resolution:


import pandas as pd, requests

def get_ohlcv(symbol, resolution="60", limit=100):
    path = "/api/v2.3/ohlcv"
    params = {"symbol": symbol, "resolution": resolution, "limit": limit}
    data = requests.get(BASE_URL + path, params=params, headers=headers(path)).json()
    df = pd.DataFrame(data, columns=["time","open","high","low","close","volume"])
    df[["open","high","low","close","volume"]] = df[["open","high","low","close","volume"]].astype(float)
    return df

Resolutions available: 1, 5, 15, 60, 240, 1440 (minutes).

Step 3: Building a Simple EMA Crossover Signal


def calculate_signals(df, fast=9, slow=21):
    df["ema_fast"] = df["close"].ewm(span=fast, adjust=False).mean()
    df["ema_slow"] = df["close"].ewm(span=slow, adjust=False).mean()
    df["signal"] = 0
    df.loc[df["ema_fast"] > df["ema_slow"], "signal"] = 1   # Long
    df.loc[df["ema_fast"] < df["ema_slow"], "signal"] = -1  # Short
    return df

Step 4: Placing Orders

For LMEX futures, orders are sent as integer contracts. For BTC-PERP, 100,000 contracts = 1 BTC.


def place_order(symbol, side, contracts):
    path = "/api/v2.3/order"
    payload = {"symbol": symbol, "side": side, "orderType": "MARKET", "size": contracts}
    body = json.dumps(payload, separators=(",", ":"))
    return requests.post(BASE_URL + path, data=body, headers=headers(path, body)).json()

Step 5: Running Safely

Before going live: set PAPER_TRADE = True in your bot to simulate signals without placing real orders. Watch for 24-48 hours. Also set your LMEX account to One-Way Position Mode (Futures → Settings → Position Mode) — all standard bots expect this mode.

Get the Full Bot

The LMEX.AI Strategy Builder generates complete, ready-to-run Python bots for 12 proven strategies — EMA Crossover, RSI Reversion, Grid Trading, VWAP, Supertrend and more. Configure your parameters, download, and run.

Visit LMEX.AI Algo Academy →