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:

  1. Calculate: Call this endpoint to determine prices and grams. You will receive a calculate_uid.
  2. Initiate (Buy/Sell): Pass the calculate_uid to either the Buy or Sell endpoint to create a pending invoice.
  3. User Confirmation: Present the invoice details to your user for final confirmation.
  4. Notify: Send a Buy Notify or Sell Notify request with either a confirmed or cancelled status 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 / TypeConditionDescription
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 / TypeConditionDescription
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)

json
{
  "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"
    }
  }
}