About Gateway
Add trading to your app through the API. You create a user for each of your customers, and your servers place orders on their behalf from that user's own wallets. If you want to trade your own account from code, use the Trading API.
Every trade moves real funds on-chain. A first trade costs a few dollars of USDC, and we pay the network fees.
Where Gateway fits
Every wallet transaction needs two signatures: yours, made with the signer key on that user, and ours. Neither of us can move a user's funds alone.
How a trade works
Your servers mint an organization token from your API key and send it on every call, with TM-On-Behalf-Of naming the user. Placing an order or transfer returns unsigned wallet transactions, called payloads. You sign each one with your signer key and post the signatures to execute. Nothing moves until you do.
- TypeScript
- Python
- curl
const forUser = { "TM-On-Behalf-Of": userId };
const order = await post(
"/v1/gateway/orders",
{
asset_id: assetId,
qty: "2",
qty_unit: "quote",
side: "buy",
type: "market",
},
forUser,
);
const signatures = await Promise.all(
order.payloads.map((p) => stamp(p.payload)),
);
await post(
`/v1/gateway/orders/${orderId}/execute`,
{
signatures,
auth_type: "api_key",
},
forUser,
);
for_user = {"TM-On-Behalf-Of": user_id}
order = post(
"/v1/gateway/orders",
{
"asset_id": asset_id,
"qty": "2",
"qty_unit": "quote",
"side": "buy",
"type": "market",
},
for_user,
)
signatures = [stamp(p["payload"]) for p in order["payloads"]]
post(
f"/v1/gateway/orders/{order_id}/execute",
{
"signatures": signatures,
"auth_type": "api_key",
},
for_user,
)
curl -s -X POST https://api.truemarkets.co/v1/gateway/orders \
-H "Authorization: Bearer $ORG_TOKEN" \
-H "TM-On-Behalf-Of: $USER_ID" \
-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 $ORG_TOKEN" \
-H "TM-On-Behalf-Of: $USER_ID" \
-H "Content-Type: application/json" \
-d '{
"signatures": '"$SIGNATURES"',
"auth_type": "api_key"
}'
post() sends your organization token. stamp() signs a payload with your signer key. Getting started defines both.
What you can build
Start building
You can also create a test user on the console's Users page and look at its wallets before you write any code.