Standard Webhooks

Webhooks

Signed HTTPS callbacks when something happens on your accounts, instead of polling.

Overview

Register an HTTPS endpoint and choose the events you want. tZERO then sends your endpoint a signed POST each time one of them happens: an account is created or changes status, a KYC result changes, an order is accepted, filled or canceled, a bank account, deposit or withdrawal changes status, cash or tokens are posted to an account, or an investment or its payment changes status.

Webhooks are notifications; the API remains the record. Reconcile anything still in progress, such as open orders and pending transfers, against the API from time to time.

Transport

An HTTPS POST of one event as JSON to the url you register.

Signing

Standard Webhooks: an HMAC-SHA256 signature made with your whsec_ secret.

Delivery

Answer any 2xx within 10 seconds. Anything else is retried for up to 72 hours.

Ordering

Events about the same resource arrive in the order they happened.

Getting started

  1. 1

    Register an endpoint

    Send POST /pi/v1/webhooks/subscriptions with your endpoint's url and the eventTypes to receive. An event type can be exact (order.filled), a family wildcard (order.*), or * for every published type.

    The url must be an HTTPS endpoint on port 443 of a host that resolves to publicly reachable addresses. Redirects are not followed, so register the final URL.

    Register an endpoint
    cURL
    1curl -X POST https://gateway-web-api.tzero.com/app/pi/v1/webhooks/subscriptions \
    2 -H 'x-apikey: <YOUR_API_KEY>' \
    3 -H 'Authorization: <ACCESS_TOKEN>' \
    4 -H 'Content-Type: application/json' \
    5 -d '{"url":"https://api.example.com/tzero/webhooks","eventTypes":["order.*","account.status_changed"],"description":"Production order and account events"}'

    The response carries the endpoint's signing secret. It is returned only here and when you rotate it, so store it securely.

    201 Created
    JSON
    1{
    2 "id": "4f6b1c2e-8a3d-4e2b-9f61-0c5d7a1b2e33",
    3 "url": "https://api.example.com/tzero/webhooks",
    4 "eventTypes": [
    5 "order.*",
    6 "account.status_changed"
    7 ],
    8 "description": "Production order and account events",
    9 "status": "ACTIVE",
    10 "createdAt": "2026-10-07T15:04:05.123Z",
    11 "secret": "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw"
    12}
  2. 2

    Verify every delivery

    Check the signature and timestamp of each request before trusting it, as described in Verifying signatures.

  3. 3

    Send yourself a test event

    POST /pi/v1/webhooks/subscriptions/{subscriptionId}/test queues a webhook.test event to that subscription only, signed and delivered like any other event. Its outcome appears in the subscription's delivery history.

  4. 4

    Answer fast, then process

    Answer with any 2xx within 10 seconds, then process the event.

Receiving events

Each delivery is a POST of one event as JSON, with these headers:

HeaderValue
Content-Typeapplication/json
User-AgenttZERO-Webhooks/1.0
webhook-idThe event id. The same event may arrive more than once; deduplicate on it.
webhook-timestampUnix seconds when this attempt was signed. Reject anything older than 5 minutes.
webhook-signaturev1,<base64 HMAC-SHA256>. During a secret rotation two signatures are sent, separated by a space; accept either.

Every event has the same envelope, and data depends on type. Every time in an event is a UTC ISO-8601 instant. A field without a value is omitted.

FieldTypeReq'dDescription
idstringY

Unique event id, also sent as webhook-id. Deduplicate on it.

typestringY

What happened.

apiVersionstringY

The version of the event format.

createdAtstring (date-time)Y

When the event was published.

occurredAtstring (date-time)Y

When what it reports happened.

accountIdstringN

The account the event is about. Absent on webhook.test.

resourceobjectY

What the event is about. type and id together name the resource, and version orders its events.

resource.typestringY

The kind of resource. Each event schema names the one it is about.

One of: account, account_kyc, investor_kyc, order, bank_account, transfer, wallet_transaction, investment, investment_payment, subscription

resource.idstringY

The resource's id: the account, order, bank account, transfer, transaction, investment, payment or subscription id. For investor_kyc it is <accountId>:<userId>.

resource.versioninteger (int64)N

Increases with each change to the resource. Ignore an event whose version is lower than one you have processed. Absent on webhook.test.

dataobjectY

What happened, in fields that depend on type. Never carries personal data.

order.filled
JSON
1{
2 "id": "evt_6c1a0f4b2d8e4c9a9e2b7d3f1a5c8e00",
3 "type": "order.filled",
4 "apiVersion": "2026-10-01",
5 "createdAt": "2026-10-07T15:04:05.300Z",
6 "occurredAt": "2026-10-07T15:04:05.120Z",
7 "accountId": "0327624635",
8 "resource": {
9 "type": "order",
10 "id": "4RsyflboJ3dtnItf2oCSZK",
11 "version": 3
12 },
13 "data": {
14 "orderId": "4RsyflboJ3dtnItf2oCSZK",
15 "status": "FILLED",
16 "symbol": "TZROP",
17 "side": "BUY",
18 "quantity": "100",
19 "cumulativeQuantity": "100",
20 "leavesQuantity": "0",
21 "averagePrice": "12.34",
22 "createdTs": "2026-10-07T15:03:58.101Z",
23 "executionTs": "2026-10-07T15:04:05.120Z",
24 "lastFillQuantity": "60",
25 "lastFillPrice": "12.35"
26 }
27}

Event types

The event catalog lists every field of each type, with a complete example. webhook.test is sent only when you request one.

Verifying signatures

Deliveries are signed as the Standard Webhooks specification describes, so its libraries can verify them. To verify one yourself:

  1. Take the request body exactly as received. Parsing and re-encoding the JSON changes the bytes, and the signature no longer matches.
  2. Build the signed content <webhook-id>.<webhook-timestamp>.<raw body>.
  3. Compute its HMAC-SHA256, keyed with the base64-decoded part of your secret after whsec_, and base64-encode the result.
  4. Compare it in constant time with each v1, entry of webhook-signature, and accept the delivery when any one matches.
  5. Reject a delivery whose webhook-timestamp is more than 5 minutes from your clock.
verify-webhook.mjs
Node.js
1import { createHmac, timingSafeEqual } from "node:crypto";
2
3const TOLERANCE_SECONDS = 5 * 60;
4
5/**
6 * Verifies a tZERO webhook delivery.
7 *
8 * @param {string} secret The subscription's signing secret, `whsec_...`.
9 * @param {Record<string, string>} headers The request headers, names in lower case as Node.js gives them.
10 * @param {Buffer} rawBody The request body exactly as received, before any JSON parsing.
11 * @param {number} [nowSeconds] The current Unix time in seconds.
12 * @returns {boolean} Whether the delivery is recent and signed with the secret.
13 */
14export function verifyWebhook(secret, headers, rawBody, nowSeconds = Date.now() / 1000) {
15 const id = headers["webhook-id"];
16 const timestamp = headers["webhook-timestamp"];
17 const signatures = headers["webhook-signature"];
18 if (!id || !timestamp || !signatures) return false;
19 if (!(Math.abs(nowSeconds - Number(timestamp)) <= TOLERANCE_SECONDS)) return false;
20
21 const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
22 const expected = createHmac("sha256", key).update(`${id}.${timestamp}.`).update(rawBody).digest();
23
24 return signatures.split(" ").some((entry) => {
25 const [version, signature] = entry.split(",", 2);
26 if (version !== "v1" || !signature) return false;
27 const received = Buffer.from(signature, "base64");
28 return received.length === expected.length && timingSafeEqual(received, expected);
29 });
30}
verify_webhook.py
Python
1import base64
2import hashlib
3import hmac
4import time
5from typing import Mapping, Optional
6
7TOLERANCE_SECONDS = 5 * 60
8
9
10def verify_webhook(secret: str, headers: Mapping[str, str], raw_body: bytes, now: Optional[float] = None) -> bool:
11 """Verifies a tZERO webhook delivery.
12
13 `headers` maps lower-case header names to values, and `raw_body` is the request body exactly
14 as received, before any JSON parsing. Returns whether the delivery is recent and signed with
15 the subscription's `whsec_` secret.
16 """
17 msg_id = headers.get("webhook-id")
18 timestamp = headers.get("webhook-timestamp")
19 signatures = headers.get("webhook-signature")
20 if not (msg_id and timestamp and signatures):
21 return False
22 try:
23 sent = int(timestamp)
24 except ValueError:
25 return False
26 if abs((time.time() if now is None else now) - sent) > TOLERANCE_SECONDS:
27 return False
28
29 key = base64.b64decode(secret.removeprefix("whsec_"))
30 signed = f"{msg_id}.{timestamp}.".encode() + raw_body
31 expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
32
33 for entry in signatures.split(" "):
34 version, _, signature = entry.partition(",")
35 if version == "v1" and hmac.compare_digest(signature, expected):
36 return True
37 return False
WebhookVerifier.java
Java
1import java.nio.charset.StandardCharsets;
2import java.security.GeneralSecurityException;
3import java.security.MessageDigest;
4import java.time.Instant;
5import java.util.Base64;
6import javax.crypto.Mac;
7import javax.crypto.spec.SecretKeySpec;
8
9/** Verifies tZERO webhook deliveries. */
10public final class WebhookVerifier {
11
12 private static final long TOLERANCE_SECONDS = 5 * 60;
13
14 private WebhookVerifier() {
15 }
16
17 /**
18 * Whether a delivery is recent and signed with the subscription's {@code whsec_} secret.
19 *
20 * @param rawBody The request body exactly as received, before any JSON parsing.
21 */
22 public static boolean verify(String secret, String id, String timestamp, String signatures, byte[] rawBody)
23 throws GeneralSecurityException {
24 return verify(secret, id, timestamp, signatures, rawBody, Instant.now().getEpochSecond());
25 }
26
27 static boolean verify(String secret, String id, String timestamp, String signatures, byte[] rawBody, long nowSeconds)
28 throws GeneralSecurityException {
29 if (id == null || timestamp == null || signatures == null) {
30 return false;
31 }
32 long sent;
33 try {
34 sent = Long.parseLong(timestamp);
35 } catch (NumberFormatException e) {
36 return false;
37 }
38 if (Math.abs(nowSeconds - sent) > TOLERANCE_SECONDS) {
39 return false;
40 }
41
42 byte[] key = Base64.getDecoder().decode(secret.startsWith("whsec_") ? secret.substring(6) : secret);
43 Mac mac = Mac.getInstance("HmacSHA256");
44 mac.init(new SecretKeySpec(key, "HmacSHA256"));
45 mac.update((id + "." + timestamp + ".").getBytes(StandardCharsets.UTF_8));
46 byte[] expected = mac.doFinal(rawBody);
47
48 for (String entry : signatures.split(" ")) {
49 String[] parts = entry.split(",", 2);
50 if (parts.length == 2 && parts[0].equals("v1")) {
51 try {
52 if (MessageDigest.isEqual(Base64.getDecoder().decode(parts[1]), expected)) {
53 return true;
54 }
55 } catch (IllegalArgumentException notBase64) {
56 // A malformed entry cannot match; the next one still might.
57 }
58 }
59 }
60 return false;
61 }
62}

Check your implementation against these values, which must verify:

Secretwhsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw
webhook-idmsg_p5jXN8AQM9LWM0D4loKWxJek
webhook-timestamp1614265330
Body{"test": 2432232314}
webhook-signaturev1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=

Responding and retries

Answer with any 2xx within 10 seconds, then process the event. Anything else, including a timeout, is retried with growing gaps (about 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours, then every 12 hours) for up to 72 hours.

Failed deliveries never disable a subscription; to stop deliveries, disable or delete it. The subscription's delivery history shows each delivery's status and, when an attempt got no response, the reason in lastError.

Ordering and duplicates

Events about the same resource (an order, a transfer, an account) are delivered in the order they happened; events about different resources may arrive in any order.

resource.type and resource.id together name the resource, and resource.version increases with each change to it, so an older number is easy to spot. Ignore an event whose version is lower than one you have processed.

The same event may arrive more than once. Deduplicate on webhook-id, which is also the event's id.

Catching up

GET /pi/v1/webhooks/events lists your events in the order they were published, oldest first, exactly as they are delivered. It is the record to reconcile against: after an outage, pass as after the id of the last event you read from this list, and read until hasNextPage is false. Events can be listed and redelivered for 30 days.

POST /pi/v1/webhooks/events/{eventId}/redeliver sends one event again to every active subscription that selects its type, with a fresh retry window. To recover a longer outage, read the events list instead.

GET /pi/v1/webhooks/subscriptions/{subscriptionId}/deliveries lists a subscription's deliveries, newest first, each with its latest attempt. A FAILED delivery ran out of retries; redeliver its event to send it again.

Managing subscriptions

PATCH /pi/v1/webhooks/subscriptions/{subscriptionId} changes the url, event types or description, or enables or disables the subscription. While a subscription is disabled its deliveries, including those of events that arrive meanwhile, wait as PAUSED; enabling it resumes them with a fresh retry window.

DELETE /pi/v1/webhooks/subscriptions/{subscriptionId} removes the subscription. Pending deliveries to it are not sent, and its events stay readable from the events list.

Rotating the secret

POST /pi/v1/webhooks/subscriptions/{subscriptionId}/rotate-secret issues a new signing secret, returned only in that response. For the next 24 hours every delivery carries signatures from both the new and the previous secret, so the new one can be deployed without missing a delivery.

Endpoints

Each operation is documented in full, with every field, response and error, in the API reference.

tZERO Technologies · Webhooks