Skip to main content

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.

An order for one of your users
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,
);

Where it works​

These are the calls you use most. The API reference marks the header on every endpoint that accepts it.

RouteHeader
/orders and every route under itaccepted
/transfers and every route under itaccepted
GET /balances, GET /portfolio, GET /positionsaccepted
GET /transactionsaccepted
GET /organizations/{organization_id}/transactionsrejected: the feed already covers every user

When it fails​

StatusMeaning
400You sent the header with an API trader's token instead of an organization token, sent it twice, or the value isn't a UUID.
401The token is missing, invalid or expired, or you called a user route with an organization token and no header.
403The 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_idThe wallet can't fund the buy. quote.issues says why, and no order was created.
422 with insufficient_balanceThe wallet can't fund a sell or a perpetual order.
422 with quote_staleThe 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