Calculate
Before executing a trade, use the calculate endpoint to determine the exact asset weight (grams) or currency amount required. This endpoint also factors in commissions and any partner-specific price adjustments.
Transaction Lifecycle
For a complete purchase or sale, follow this four-step sequence to ensure data consistency between your platform and Treasury:
- Calculate: Call this endpoint to determine prices and grams. You will receive a
calculate_uid. - Initiate (Buy/Sell): Pass the
calculate_uidto either the Buy or Sell endpoint to create apendinginvoice. - User Confirmation: Present the invoice details to your user for final confirmation.
- Notify: Send a Buy Notify or Sell Notify request with either a
confirmedorcancelledstatus to finalize the transaction.
Validity Period: Each calculate_uid is generated based on the current asset price assigned to your partner profile. If Treasury updates the price to a newer interval before you initiate the trade step, the calculation will expire, and you will need to request a fresh calculation.
Calculate Transaction
POST /asset/transaction/calculate
Headers
| Header / Type | Condition | Description |
|---|---|---|
Authorizationstring | required | Bearer token retrieved from the Authentication endpoint. |
X-User-Idstring | optional | Unique user identifier from Treasury. Recommended when process_name is sell. |
X-Partner-User-Idstring | optional | Your internal user identifier. Recommended when process_name is sell. |
Pro Tip: Providing a user identifier (via X-User-Id or X-Partner-User-Id) is especially useful for sell operations. It allows the system to verify the user's current balance and return a sufficient-balance or insufficient-balance status in the response.
Request Body
| Field / Type | Condition | Description |
|---|---|---|
process_namestring enum | required | Type of transaction. Value: buy or sell. |
asset_typestring enum | required | The asset type. Value: gold or silver. |
adjustment_amount_per_gramnumeric | optional | Adjust the base price per gram for this request. |
gramsnumeric | optional-when amount | Target weight in grams. |
amountnumeric | optional-when grams | Target final currency amount. |
Response
Sample Response (200 OK)
{
"code" : 200,
"message": "success",
"data" : {
"calculate_uid" : "eYr...",
"asset_grams" : 0.1,
"amount" : 254144,
"commission_amount": 0,
"adjustment_amount": 1000,
"buy_price" : 2641223,
"sell_price" : 2556440,
"user" : {
"status" : "active",
"kyc_status" : "verified",
"asset_grams": 0.5,
"condition" : "sufficient-balance"
}
}
}