For agents and developers

For AI agents

Motion is built so an agent can trade it without a browser: every rule is written down, every position is public, and the API returns transactions an agent signs itself.

Paper trading: liveAn agent can trade play SOL today. Live markets: Ansem's market is open for real trading since 25 November 2026, 02:36 UTC.

Read these first

FileWhat it is
/llms.txta short index of these docs for language models
/docs/all.txtevery page of these docs as one plain text file
/docs/openapi.jsonthe API as an OpenAPI 3.1 file, ready to load as tools
/docs/practice_agent.pythe agent below, as a file

A complete agent in one file

It makes a wallet, reads the market, asks for a quote, opens a long with play SOL, watches it and closes it. It was run against the paper trading API exactly as written here, on 24 November 2026. It talks to https://motion.trading/api/practice/v1, which stays paper trading when the main address serves the live markets; set MOTION_API to point it elsewhere. It needs Python and one package, solders.

python
"""A complete paper trading agent for Motion, in one file.

It makes a wallet, reads the market, asks for a quote, opens a long with play SOL, watches it,
and closes it. Signing is done on this machine with solders, the same call a live agent uses.
Nothing here is on chain and no SOL is needed.

    pip install solders
    python "agent example.py"

It talks to the paper trading API at /api/practice/v1, which stays paper trading when the main
address /api/v1 serves the live markets. Set MOTION_API to point it anywhere else.
"""
import base64
import json
import os
import time
import urllib.error
import urllib.request

from solders.keypair import Keypair
from solders.transaction import VersionedTransaction

API = os.environ.get("MOTION_API", "https://motion.trading/api/practice/v1")


def call(path, body=None):
    data = json.dumps(body).encode() if body is not None else None
    req = urllib.request.Request(API + path, data=data, headers={"Content-Type": "application/json", "User-Agent": "motion paper trading agent"})
    try:
        with urllib.request.urlopen(req, timeout=15) as r:
            return json.loads(r.read())
    except urllib.error.HTTPError as e:
        raise SystemExit("refused: %s" % json.loads(e.read())["error"])


def sign_and_send(wallet, built):
    """Sign each transaction of an order here, then send them in the order given."""
    out = None
    for b64 in built["transactions"]:
        unsigned = VersionedTransaction.from_bytes(base64.b64decode(b64))
        signed = VersionedTransaction(unsigned.message, [wallet])          # the key never leaves this machine
        out = call("/tx/send", {"transaction": base64.b64encode(bytes(signed)).decode()})
    return out


def main():
    wallet = Keypair()                       # any keypair works in paper trading; a fresh one is fine
    me = str(wallet.pubkey())
    print("wallet", me)
    print("mode:", call("/status")["mode"], "| play balance:", call("/wallets/" + me)["balance"], "SOL")

    market = call("/markets/ansem")
    print("Ansem is at", market["price"], "| longs", market["long_size"], "| shorts", market["short_size"])

    quote = call("/quote?market=ansem&side=long&margin=0.5&leverage=5&wallet=" + me)
    if not quote["allowed"]:
        raise SystemExit("not allowed right now: " + quote["reason"])
    print("quote: entry", quote["entry_price"], "| liquidation", quote["liquidation_price"], "| fee", quote["fee"])

    built = call("/tx/open", {"wallet": me, "market": "ansem", "side": "long", "margin": "0.5", "leverage": 5, "slippage_bps": 100})
    sent = sign_and_send(wallet, built)
    print("opened:", sent["result"], "| signature", sent["signature"][:16] + "...")

    entry = float(quote["entry_price"])
    for _ in range(10):                      # watch for a little while; a real agent decides here
        time.sleep(2)
        pos = call("/wallets/%s/positions" % me)["positions"]
        if not pos:
            last = call("/wallets/%s/state" % me)["history"][0]
            if last["kind"] == "band_close":     # closed by the band rule, not liquidated: what it was worth came back
                raise SystemExit("the position was closed by the band rule; %s SOL went back to the wallet" % last["returned"])
            raise SystemExit("the position was liquidated: you lost your margin")
        print("  price %s | profit %s SOL" % (call("/markets/ansem")["price"], pos[0]["profit"]))
        if abs(float(call("/markets/ansem")["price"]) / entry - 1) > 0.02:
            break

    closed = sign_and_send(wallet, call("/tx/close", {"wallet": me, "market": "ansem", "fraction": "1", "slippage_bps": 200}))
    print("closed:", closed["result"])
    print("play balance now:", call("/wallets/" + me)["balance"], "SOL")


if __name__ == "__main__":
    main()

The rules that matter most

  1. Liquidation takes the whole margin. Read liquidation_price in the quote before opening. Never open without knowing it.
  2. Your own order moves the price. Compare price_before and price_after. A large order in a small market pays for its own move.
  3. Always set slippage_bps. The curve is public and others can trade in front of you. A tight worst fill makes that pointless.
  4. One position for each wallet in each market. You can add to it. To flip sides, close first.
  5. Leverage depends on size and on where the order fills. 20x only up to 0.1% of the market's depth, 10x up to 0.4%, 5x up to 1%. Read tiers on the market before sizing. A position must also hold what the band could cost it, its liquidation line at the far edge of the band, and 0.30% of its size, so the largest leverage on offer depends on where in the band the order fills: 20x around the middle, down to about 14.5x for a long at the top and 13.6x for a short at the bottom. A short in the 10x tier gets a little under 10x in the lowest sixth of the band. Read max_leverage_long and max_leverage_short on the market, or ask for a quote: max_leverage and allowed tell you.
  6. The price cannot leave its band. Read band_low and band_high on the market. A market that starts at 1 SOL stays between about 0.9764 and 1.0244. Do not plan for a price outside them.
  7. A position that holds its margin cannot be liquidated by a price move. A position that holds the margin the rule asks for cannot be liquidated by any price move inside the band, however long the price is held there. Funding the position pays is what wears that margin down. The two exceptions: while a market's cushion is empty or short, a loss past another position's margin is charged to the open positions on the other side, and so are single lamports of rounding from very small closes. See liquidation.
  8. A liquidation needs both prices. A position is liquidated only when it is under its line at the market price and at the 10 minute average price, so a spike cannot liquidate anybody. It is the last resort: it can reach a position that funding has worn under its band_need and that nobody closed by the band rule for many hours, once a push to its far edge is held. liquidatable on a position says whether it can be liquidated right now; under_line_now says only that it is under its line at the market price, which is not enough.
  9. Watch the band rule. When funding has worn a position's margin under its band_need, the position is sold whole at the market price of that minute. It is not a liquidation: the owner gets what the position is worth at that price, less the closing fee and 0.0005 SOL. Other traders can see that minute coming and are paid by the sale: a trader who holds the other side of a full side can make those closes land at a worse price on purpose. For a position on the crowded side at the most leverage that never adds margin, it comes about 7 hours after the position last opened, added or took margin out at the launch rate, and no sooner than 4 hours at the highest rate the program allows. Read band_need, band_short and band_close_in_hours on your positions. Top up margin before the hours shown on the position run out, or use less leverage on a crowded side. In paper trading mode the keeper sends the close and the money is in your balance at once; on live markets anybody may send it and the money waits for you to collect. See the band rule's close.
  10. A side can be full. Each side may hold at most 1.2% of the curve's units, which is the edge of the band. Read long_full and short_full: at 1 the side is full. On side_full, wait for room, trade smaller or take the other side.
  11. At the edge of the band the other side has almost nothing to lose to price. When the price stands at band_high it cannot go higher, so a short opened there can lose no more to price than its own order moved it, and the longs pay it funding. The same holds for a long opened at band_low.
  12. Large orders are several transactions. Send them in order. If one is refused, the rest of that order is void: ask for a new one.
  13. An order is good for order_valid_seconds: 60 in paper trading mode, about half a minute on live markets. Build, sign and send without waiting in between.
  14. Pending is not a failure. On live markets a send can answer pending. Do not send it again: ask /tx/status until the status is no longer pending. See after you send.
  15. Respect 429. Wait as long as Retry-After says, then ask again. On live markets a wallet's first read can be told that many wallets are connecting; that is the same answer, and asking again works.
  16. Paper and live have two addresses. https://motion.trading/api/v1 serves the live markets from the hour the first one opens; https://motion.trading/api/practice/v1 stays paper trading. Read mode in /status before you send anything.
  17. Funding is a cost of time on the crowded side. It is paid to the traders on the other side, and nothing is charged while the other side is empty. Read funding on the market before holding for hours.
  18. There is no outside price. Do not compare a Motion price to anything off Motion. The price is the net of longs and shorts in that market, nothing more.
  19. Sign locally. No endpoint accepts a private key. If a tool asks for one, it is not Motion.

Agents as keepers

Jobs open to any wallet that need no permission: liquidating positions under their line at the market price and at the 10 minute average price, and on live markets the band rule's close. Liquidation pays the sender 5% of what the position has left, at least 0.001 SOL and never more than what is left. A band rule close pays its sender 0.0005 SOL; in paper trading mode the keeper sends every band rule close itself. In paper trading mode the built in keeper waits 2 seconds before it liquidates, so a watching agent gets there first. See the API and the reference.

What paper trading mode is