About Trading API
The Trading API lets you trade your own True Markets account from code. You create a key at app.truemarkets.co, and that key signs your requests and your orders. If you're building an app for your customers, read the Gateway documentation.
Every trade moves real funds. A first trade costs a few dollars of USDC, and we pay the network fees.
How a trade works
Your code mints a token from your key file and sends it on every call. Placing an order or transfer returns unsigned wallet transactions, called payloads. You sign each one with the same key and post the signatures to execute. Nothing moves until you do.
- TypeScript
- Python
- curl
const order = await post("/v1/gateway/orders", {
asset_id: assetId,
qty: "2",
qty_unit: "quote",
side: "buy",
type: "market",
});
const signatures = await Promise.all(
order.payloads.map((p) => stamp(p.payload)),
);
await post(`/v1/gateway/orders/${orderId}/execute`, {
signatures,
auth_type: "api_key",
});
order = post("/v1/gateway/orders", {
"asset_id": asset_id,
"qty": "2",
"qty_unit": "quote",
"side": "buy",
"type": "market",
})
signatures = [stamp(p["payload"]) for p in order["payloads"]]
post(f"/v1/gateway/orders/{order_id}/execute", {
"signatures": signatures,
"auth_type": "api_key",
})
curl -s -X POST https://api.truemarkets.co/v1/gateway/orders \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"asset_id": "'"$ASSET_ID"'",
"qty": "2",
"qty_unit": "quote",
"side": "buy",
"type": "market"
}'
# $SIGNATURES is the JSON array your code signed
curl -s -X POST https://api.truemarkets.co/v1/gateway/orders/$ORDER_ID/execute \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"signatures": '"$SIGNATURES"',
"auth_type": "api_key"
}'
post() sends your token. stamp() signs a payload with your key. Getting started defines both.
Trading API use cases
- A script or bot that trades your account on a schedule or on a signal.
- A service that reads your balances and rebalances your holdings.
How it differs from Gateway
The Trading API and Gateway share the same endpoints, documented in the Trading REST reference. What changes is whose account a request acts on.
- Your token acts as you. A Gateway client adds a header to name which of its users a request is for. You never send it.
- Your account already exists. You sign up at app.truemarkets.co, and the app creates your wallet when you set up a passkey, so there are no users to create.
- One key does both jobs. The same key mints your tokens and signs your orders. A Gateway client holds two keys for those two jobs.
- You can refresh tokens. Minting a token also returns a refresh token, so you can get a new access token without signing again.
Get started
Trade
Before you raise your amounts, work through the Go live checklist.