Calcola Prezzo
POST /v1/orders/calculate
Restituisce il prezzo esatto in TRX per un ordine ipotetico senza crearne uno. Usalo per mostrare agli utenti il costo prima che si impegnino con un deposito.
Questo è un endpoint di puro calcolo del prezzo — non interagisce con la rete TRON.
Corpo della richiesta
| Field | Type | Required | Description |
|---|---|---|---|
duration | integer | sì | Durata del noleggio delle risorse in ore. Deve essere 1. |
activation | boolean | no | Se true, include la commissione di attivazione dell'account nel total. Il valore predefinito è false. |
resources.energy | integer | no* | Quantità di energia da consegnare. |
resources.bandwidth | integer | no* | Quantità di bandwidth da consegnare. |
* Almeno uno tra resources.energy e resources.bandwidth deve essere maggiore di zero.
Esempi
bash
curl -X POST https://api.tronzap.com/v1/orders/calculate \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"duration": 1,
"activation": false,
"resources": {
"energy": 65000,
"bandwidth": 345
}
}'javascript
const response = await fetch('https://api.tronzap.com/v1/orders/calculate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
duration: 1,
activation: false,
resources: { energy: 65000, bandwidth: 345 },
}),
})
const data = await response.json()
console.log(data.result.total, data.result.currency)php
$response = file_get_contents('https://api.tronzap.com/v1/orders/calculate', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\nAccept: application/json",
'content' => json_encode([
'duration' => 1,
'activation' => false,
'resources' => ['energy' => 65000, 'bandwidth' => 345],
]),
],
]));
$data = json_decode($response, true);
echo $data['result']['total'] . ' ' . $data['result']['currency'];python
import requests
resp = requests.post('https://api.tronzap.com/v1/orders/calculate', json={
'duration': 1,
'activation': False,
'resources': {'energy': 65000, 'bandwidth': 345},
})
result = resp.json()['result']
print(result['total'], result['currency'])Risposta
json
{
"code": 0,
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"result": {
"energy": { "amount": 65000, "price": 2.34 },
"bandwidth": { "amount": 345, "price": 0.35 },
"activation": { "required": false, "price": 0 },
"total": 2.69,
"currency": "TRX",
"duration": 1
}
}Con activation: true (attivazione di un nuovo account):
json
{
"code": 0,
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"result": {
"energy": { "amount": 65000, "price": 2.34 },
"bandwidth": { "amount": 345, "price": 0.35 },
"activation": { "required": true, "price": 1.40 },
"total": 4.09,
"currency": "TRX",
"duration": 1
}
}Campi della risposta
| Field | Type | Description |
|---|---|---|
energy.amount | integer | Eco della quantità di energia richiesta. |
energy.price | number | Costo in TRX per l'energia. |
bandwidth.amount | integer | Eco della quantità di bandwidth richiesta. |
bandwidth.price | number | Costo in TRX per il bandwidth. |
activation.required | boolean | Eco del flag activation inviato. |
activation.price | number | Costo in TRX dell'attivazione. 0 quando non richiesta. |
total | number | Somma dei prezzi di energia + bandwidth + attivazione. |
currency | string | Sempre TRX. |
duration | integer | Eco della durata richiesta. |
total corrisponde all'importo di create-order
Il total di questo endpoint è uguale all'amount che POST /v1/orders richiederà, dati gli stessi input e il medesimo risultato di activation.
