Skip to content

ShengTRX API

Buy Energy and Bandwidth for TRON addresses from your own application: from the same balance and at the same prices as in the account. Large-volume clients can ask support for an individual price; it then applies in both the account and the API. The API is HTTPS + JSON; every request is signed with your secret key.

Key

  • The key is created in the account, in the "API access" section, and only with two-factor authentication enabled and a code from your authenticator app.
  • A key has two parts: an identifier (fk_…, the X-API-Key header, not a secret) and a secret (fks_…). The secret is shown only once, so store it right away in your server's secrets storage. If you lose it, rotate the key.
  • Scopes: "Read" (read: balance, options, quotes, order status) and "Orders" (orders: purchases, which debit the balance). read is enough for monitoring.
  • Allowed IPs: up to 20 IPv4/IPv6 addresses or networks (203.0.113.0/24, 2001:db8::/48). An empty list means any address. A request from another address gets 403 ip_not_allowed.
  • Up to 10 active keys per account. Changing scopes or the IP list, creating and rotating a key are confirmed with a 2FA code; revoking is immediate, with no code.
  • Rotation: the new secret is shown once; the old one may keep working for up to 24 hours so you can switch your application over without downtime.
  • Password recovery, disabling 2FA, and a 2FA reset or an «end all sessions» by support revoke all keys of the account. We send an email about every new key, every rotation and every widening of scopes or the IP list.

Request signing

Every request carries three headers:

X-API-Key:   fk_…
X-Timestamp: <unix seconds>                 (±300 s of the server clock)
X-Signature: hex(HMAC-SHA256(secret, timestamp + "\n" + METHOD + "\n" + path?query + "\n" + hex(sha256(body))))
  • secret is the string exactly as shown (with the fks_ prefix).
  • path?query is the path and query string exactly as in the request, for example /v1/api/orders/bot-1.
  • The body is the raw bytes you send; for an empty body, use the sha256 of the empty string (e3b0c442…b855). Serialize the JSON once and sign those same bytes.
  • A signature is accepted only once (401 replayed): sign every request anew, retries included.
  • An unknown key, a revoked key and a wrong signature all give the same 401 unauthorized; a time outside the window gives 401 stale_timestamp.

Test vectors — check your implementation. Secret fks_example_secret_do_not_use, X-Timestamp: 1763164800:

Request X-Signature
GET /v1/api/balance, no body 660828264f1a3ca3c9263048dd5d4d2e1bf857a5c0280aa4c418b2731e234ddc
POST /v1/api/orders, body {"client_order_id":"bot-1","address":"TPEWRr6wWVnU6Hmpe5oFfVq8vqoXtoxN3D","energy_units":65000,"duration_hours":1} 0015a86d1a3844fefeb11dec3542c6512d88c294de49e3a8f70a0b189370107c

Endpoints

Base URL: https://shengtrx.com/v1/api.

Method Path Scope What it does
GET /v1/api/balance read account balance in TRX
GET /v1/api/options read available durations, volume limits, address activation, quote lifetime
POST /v1/api/quote read quote: address, energy_units and/or bandwidth_units, duration_hours, activate; valid for 60 s
POST /v1/api/orders orders order by quote_id or in one step (quote fields + max_total); client_order_id is required. If max_total is set, it also bounds an order by quote_id.
GET /v1/api/orders/{client_order_id} read order status: delivered, refunded to balance, delegation transaction

Amounts are decimal TRX strings with 6 decimal places ("2.600000"), never floating-point numbers. An order debits exactly the quote amount. If delivery fails or is only partial, the difference is returned to the balance (the refunded field).

Order statuses: paid → delegating → delegated (delivered) | delegated_partial (partially delivered, the rest refunded) | credited (refunded to balance); manual_review — we are checking it manually.

An error response always has the same shape: {"error": {"code": "…", "message": "…"}}. Your program should rely on code.

Idempotency

client_order_id (1–64 characters A-Z a-z 0-9 . _ : -) is your idempotency key, shared across all keys of the account.

  • A repeat with the same body returns 200 with the first result, with no second debit.
  • With a different body — 409 idempotency_conflict. «The same body» means the same fields after JSON parsing, not the same bytes: "max_total":"3" and "3.0" are different bodies.
  • A rejection (insufficient balance, expired quote, price above max_total) records nothing, so the same client_order_id can be retried.

Limits

Exceeding a limit gives 429 rate_limited with a Retry-After header (seconds).

What Limit
All requests from one address (IPv6: a /64 network) 600 per minute
All requests of one key 300 per minute
All requests of an account 600 per minute
Quotes and options (shared with the account pages) 30 per minute per account
Orders (shared with the account pages) 20 per minute per account

Temporarily busy gives 503 busy with Retry-After. The request body is up to 16 KiB, JSON only.

Examples

curl + openssl

KEY=fk_...; SECRET=fks_...; BASE=https://shengtrx.com
TS=$(date +%s); BODY='{"client_order_id":"bot-1","address":"TPEWRr6wWVnU6Hmpe5oFfVq8vqoXtoxN3D","energy_units":65000,"duration_hours":1}'
HASH=$(printf '%s' "$BODY" | openssl dgst -sha256 -hex | sed 's/^.*= //')
SIG=$(printf '%s\n%s\n%s\n%s' "$TS" POST /v1/api/orders "$HASH" | openssl dgst -sha256 -hmac "$SECRET" -hex | sed 's/^.*= //')
curl -sS "$BASE/v1/api/orders" -H "X-API-Key: $KEY" -H "X-Timestamp: $TS" -H "X-Signature: $SIG" \
  -H 'Content-Type: application/json' --data-raw "$BODY"

Python 3 (standard library only)

import hashlib, hmac, json, time, urllib.request

class Client:
    def __init__(self, key, secret, base="https://shengtrx.com"):
        self.key, self.secret, self.base = key, secret.encode(), base

    def call(self, method, path, body=None):
        data = b"" if body is None else json.dumps(body, separators=(",", ":")).encode()
        ts = str(int(time.time()))
        canon = "\n".join([ts, method.upper(), path, hashlib.sha256(data).hexdigest()])
        sig = hmac.new(self.secret, canon.encode(), hashlib.sha256).hexdigest()
        req = urllib.request.Request(self.base + path, data=data or None, method=method.upper(), headers={
            "X-API-Key": self.key, "X-Timestamp": ts, "X-Signature": sig, "Content-Type": "application/json"})
        with urllib.request.urlopen(req, timeout=15) as r:
            return json.load(r)

api = Client("fk_...", "fks_...")
print(api.call("GET", "/v1/api/balance"))
order = api.call("POST", "/v1/api/orders", {"client_order_id": "bot-1",
    "address": "TPEWRr6wWVnU6Hmpe5oFfVq8vqoXtoxN3D", "energy_units": 65000, "duration_hours": 1, "max_total": "3"})
print(api.call("GET", "/v1/api/orders/bot-1"))

Node.js 18+

import crypto from 'node:crypto'

export async function apiCall(key, secret, method, path, body, base = 'https://shengtrx.com') {
  const data = body === undefined ? '' : JSON.stringify(body)
  const ts = String(Math.floor(Date.now() / 1000))
  const hash = crypto.createHash('sha256').update(data).digest('hex')
  const sig = crypto.createHmac('sha256', secret).update(`${ts}\n${method.toUpperCase()}\n${path}\n${hash}`).digest('hex')
  const res = await fetch(base + path, { method, body: data || undefined, headers: {
    'X-API-Key': key, 'X-Timestamp': ts, 'X-Signature': sig, 'Content-Type': 'application/json' } })
  const json = await res.json()
  if (!res.ok) throw Object.assign(new Error(json.error?.message), { status: res.status, code: json.error?.code })
  return json
}

Go

func call(ctx context.Context, key, secret, method, path string, body []byte) (*http.Response, error) {
	ts := strconv.FormatInt(time.Now().Unix(), 10)
	sum := sha256.Sum256(body)
	mac := hmac.New(sha256.New, []byte(secret))
	mac.Write([]byte(ts + "\n" + strings.ToUpper(method) + "\n" + path + "\n" + hex.EncodeToString(sum[:])))
	req, err := http.NewRequestWithContext(ctx, method, "https://shengtrx.com"+path, bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	req.Header.Set("X-API-Key", key)
	req.Header.Set("X-Timestamp", ts)
	req.Header.Set("X-Signature", hex.EncodeToString(mac.Sum(nil)))
	req.Header.Set("Content-Type", "application/json")
	return http.DefaultClient.Do(req)
}

Bot workflow

  1. GET /v1/api/options once every few minutes — available durations and volumes.
  2. In one step: POST /v1/api/orders with client_order_id (the id of your job) and max_total as the price ceiling.
  3. Network error or timeout — retry the same client_order_id with the same body (and a new signature): a second debit is impossible.
  4. GET /v1/api/orders/{client_order_id} every 3–5 s until the status becomes delegated, delegated_partial or credited. manual_review is not final: we are checking it manually, which may take hours, so poll less often from then on (every few minutes). reverted is final (the payment that paid for the order was reversed on chain; not expected for orders paid from the balance).

Error codes

Code Meaning
unauthorized unknown or revoked key, or wrong signature
stale_timestamp X-Timestamp differs from the server time by more than 300 s
replayed this signature has already been used — sign the request anew
ip_not_allowed the address is not in the key's allowed IPs
insufficient_scope the key lacks the required scope
account_blocked the account is blocked — contact support
insufficient_balance not enough TRX on the balance — nothing was debited
quote_expired, quote_used the quote has expired or was already used — get a new one
price_above_max the price is above max_total — nothing was debited
idempotency_conflict client_order_id was already used with a different body
address_not_activated the address is not yet activated on the network; pass "activate": true if options.activation allows it
rate_limited, busy wait Retry-After seconds