Skip to main content
The Trading API lets you estimate the price of trading an asset and trade it between two accounts of a user, with orders that either trade the whole quantity or nothing.
This is a preview of the new Trading API. It is available in Sandbox only, where trades are simulated, and it can change before release.

Endpoints

It uses the same OAuth 2.0 token endpoint and credentials as the Core API, with its own scopes: trading.prices:read, trading.orders:create and trading.orders:read.

Assets and pairs

An order trades one asset for another. The base asset is the one bought or sold and the quote asset is the one prices are expressed in, so for BTC and USD the base asset is BTC. A quantity is in the base asset and a price is in the quote asset per one unit of the base asset. All amounts are decimal strings. The assets of an order are the ones of its origin and destination accounts. A pair that cannot be traded is refused with asset_pair_not_supported, and an amount that breaks a bound of the venue is refused with a 409 whose details name the rule and its limit.

Price estimates

A price estimate is the volume-weighted price at which a quantity of the base asset would trade on a side, calculated from the order book. It is nonbinding, and the snapshotAt of the response says when the book was read. If the book cannot cover the quantity, the request fails with the depth that is available.

Orders

An order debits the origin account and credits the destination account of the same user. In this preview you sell the base asset, so the origin holds the base asset and the destination the quote asset. The type is market, which trades at the price the book offers, or limit, which trades only at its price or better and needs one. timeInForce is fok: the whole quantity trades or nothing does.

Retrying safely

The clientOrderId is an idempotency key you choose, up to 64 characters. Send one with every order: a new value for each order, and the same value when you repeat a request. Replaying it with the same payload returns the existing order with a 200, and reusing it with a different payload is refused with a 409. This keeps the risk of trading the same quantity twice low. The number of orders that are being placed at the same time is limited, overall and for each user. Above it, the request is refused with a 429 and nothing is created, so send the order again after a moment. The orders you already placed do not count, whatever their status. A 429 can also mean that a rate limit was exceeded. When trading is temporarily unavailable, an order or a price estimate is refused with a 409 operation_not_allowed whose reason is venue-unavailable, and nothing is created. Send it again after a moment, with the same clientOrderId for an order.

Order lifecycle

A processing order is still being processed, so retrieve it again until it is completed or failed. A processing order whose timeline ends with a failed event is being checked by Uphold, so its outcome is not known yet: do not send it again under a new clientOrderId. A completed order has one trade, returned by List order trades. A failed order is final and did not execute: its statusDetails.reason tells why, so you can send a new order. Instead of retrieving an order again, you can receive webhooks when it is created (trading.order.created) and when its status changes to completed or failed (trading.order.status-changed). Events are not delivered in order, so rely on the status and the updatedAt of the order to know its latest state. A delivery can be sent again, so use the Webhook-Id header to ignore the ones you have already processed. There is no event for a processing order whose timeline ends with a failed event, so retrieve it again until it has a final status.

Trying it in Sandbox

Sandbox sells BTC for USD against a simulated venue. You need a test user with a BTC account holding the BTC to sell and a USD account, and a new clientOrderId with every order. An order takes from 0.0001 to 10 BTC, with up to 8 decimals. An amount outside them is refused with a 409 whose details name the rule and its limit: The origin account must hold the quantity: an order it cannot cover is accepted and then fails with the reason insufficient-funds, without trading.