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.
Read these first
| File | What it is |
|---|---|
| /llms.txt | a short index of these docs for language models |
| /docs/all.txt | every page of these docs as one plain text file |
| /docs/openapi.json | the API as an OpenAPI 3.1 file, ready to load as tools |
| /docs/practice_agent.py | the 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.
"""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
- Liquidation takes the whole margin. Read
liquidation_pricein the quote before opening. Never open without knowing it. - Your own order moves the price. Compare
price_beforeandprice_after. A large order in a small market pays for its own move. - Always set
slippage_bps. The curve is public and others can trade in front of you. A tight worst fill makes that pointless. - One position for each wallet in each market. You can add to it. To flip sides, close first.
- 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
tierson 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. Readmax_leverage_longandmax_leverage_shorton the market, or ask for a quote:max_leverageandallowedtell you. - The price cannot leave its band. Read
band_lowandband_highon 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. - 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.
- 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_needand that nobody closed by the band rule for many hours, once a push to its far edge is held.liquidatableon a position says whether it can be liquidated right now;under_line_nowsays only that it is under its line at the market price, which is not enough. - 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. Readband_need,band_shortandband_close_in_hourson 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. - 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_fullandshort_full: at 1 the side is full. Onside_full, wait for room, trade smaller or take the other side. - At the edge of the band the other side has almost nothing to lose to price. When the price stands at
band_highit 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 atband_low. - 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.
- 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.
- Pending is not a failure. On live markets a send can answer pending. Do not send it again: ask
/tx/statusuntil the status is no longer pending. See after you send. - Respect 429. Wait as long as
Retry-Aftersays, 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. - Paper and live have two addresses.
https://motion.trading/api/v1serves the live markets from the hour the first one opens;https://motion.trading/api/practice/v1stays paper trading. Readmodein/statusbefore you send anything. - 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
fundingon the market before holding for hours. - 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.
- 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
- One shared market for every agent and every person in the app, with a simulated crowd in it. Simulated traders are marked
"simulated": true. - The same engine, limits, fees and liquidation rules as the docs. Its books are checked every 30 seconds, and
/statussays whether they balance. - Play SOL with no value. The market can be reset at any time.
- Nothing on chain. A paper trading transaction cannot be sent to Solana.