Trade for a user
To trade for a user, make the request with your organization token and add TM-On-Behalf-Of: <user_id>. The request runs against that user's wallet, and everything else about it stays the same.
How an order runs
Place the order, sign each payload with your signer key, execute, then read the order until its status is final. Place orders for a user walks through each call, and Getting started shows the signing code.
Send the header
The value is the user_id you got from User accounts. Send the header once per request. In code, keep it in one object and pass it to every call for that user, as the post() and get() helpers from Getting started do. The request uses your organization's permissions and acts only on that user's wallet.
- 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,
);
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,
)
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"
}'
Where it works
These are the calls you use most. The API reference marks the header on every endpoint that accepts it.
| Route | Header |
|---|---|
/orders and every route under it | accepted |
/transfers and every route under it | accepted |
GET /balances, GET /portfolio, GET /positions | accepted |
GET /transactions | accepted |
GET /organizations/{organization_id}/transactions | rejected: the feed already covers every user |
When it fails
| Status | Meaning |
|---|---|
400 | You sent the header with an API trader's token instead of an organization token, sent it twice, or the value isn't a UUID. |
401 | The token is missing, invalid or expired, or you called a user route with an organization token and no header. |
403 | The user isn't in your organization, or trading that asset isn't available in the country your request comes from. GET /assets/availability shows what's available. |
201 with an empty order_id | The wallet can't fund the buy. quote.issues says why, and no order was created. |
422 with insufficient_balance | The wallet can't fund a sell or a perpetual order. |
422 with quote_stale | The quote expired or the price moved before execute landed. Place the order again. |
Errors shows the error body and which errors to retry. The API reference lists every code for each endpoint.
Next: Place orders for a user