nrg.market API reference Interactive reference

Webhooks

The events we send to the endpoints you register with POST /webhooks. Each is an HTTP request from us to your URL; the request body below is what arrives, and the responses are what we expect back.

POST orderReady

order.ready — energy delivered, you can send

The main event. The send_before field is the deadline for sending the transaction. The countdown starts when energy has been delivered for the last item of the order, so in a batch the window is shared by all transfers.

duration_s beside it is the lease the order was sold as. The two answer different questions and neither can be computed from the other: the deadline is the lease less a margin, and in mode b it is cut shorter again by the signed transaction's own expiry. Read the term here rather than subtracting it out of the deadline.

Verifying a delivery

Three headers arrive with every delivery, this one and all the others:

HeaderWhat it is
X-NRG-TimestampUnix seconds, minted per attempt
X-NRG-SignatureHMAC-SHA256(secret, X-NRG-Timestamp + "." + raw body), hex
X-NRG-Event-IdCopy of the body's event_id
  1. Check the signature over the raw bytes. Compute HMAC-SHA256(secret, X-NRG-Timestamp + "." + raw body) and compare it to X-NRG-Signature with a constant-time comparison. Sign the bytes you received, not a re-serialized parse of them: your JSON encoder orders keys and spaces differently from ours and the signature will not match.
  2. Check the timestamp is fresh: accept ±5 minutes, refuse anything outside that window. A signature with no freshness window is replayable forever — the exact bytes we sent, with the exact headers we sent, verify just as well a year later in anyone's hands. Five minutes is generous enough for a clock that has drifted and short enough to be worth having; every attempt carries its own timestamp, so a retry twelve minutes after the event is still fresh when it arrives.
  3. Deduplicate on event_id, not on your own guesswork. It is stable across every retry of one event — the automatic ones and the replays you request — so "have I seen this id" is the whole check. Retries happen; the receiver being slow to answer is enough to cause one, and an event you have already processed must not be processed twice.
  4. Answer 2xx, quickly. Anything else, and anything slower than 5 seconds, counts as a failed attempt. Do the work after answering.

Retries and disabling

Five attempts, spread over about 13 minutes: the first one immediately, then — after each failure — a retry in 5 s, in 30 s, in 2 min and in 10 min. After the fifth failure the delivery is failed and is not tried again on its own; you can replay it with POST /webhooks/{id}/deliveries/{delivery_id}/retry, which restores the full five attempts and keeps the original event_id.

A failed attempt is any non-2xx answer, and equally no answer at all — a timeout, a refused connection, a host that stopped resolving. Redirects are not followed: a 3xx is a failed attempt too.

When 20 deliveries queued within 24 hours have used up all their attempts, the endpoint moves to status: disabled and stops receiving events entirely; probes sent with POST /webhooks/{id}/test never count towards this, and never trigger the check either. Counted are deliveries that spent all five attempts — a delivery that ends without a request ever being made (the two cases below) is not one of them.

No call re-enables an endpoint, and none is planned: register a new one, which issues a new signing secret. If you would rather keep this endpoint and its secret, write to [email protected] — we can switch it back on from our side once the receiver is fixed. Either way you hear about the switch-off: we send an email to everyone on the account, and GET /webhooks carries disabled_at and disabled_reason alongside the status.

Two things also end a delivery early, with no retries and without counting as an attempt: your URL resolving to a private or loopback address (the endpoint is disabled on the spot — that is a request we would be making into our own network) and the endpoint no longer being active when the queued event comes up for delivery.

Request body

Optional.

Content type application/json.

Schema: WebhookPayload.

FieldTypeRequiredDescription
eventDeliveredWebhookEventoptional
event_idstring (uuid)optional

Deduplication key, stable across every retry of this event — automatic ones and replays requested through POST /webhooks/{id}/deliveries/{delivery_id}/retry alike. Two requests carrying one event_id are one event; process the first and drop the rest.

It is inside the signed body on purpose, and mirrored in the X-NRG-Event-Id header only for convenience: a deduplication key that travelled outside the signature could be altered in transit, and a receiver dropping duplicates by it would drop a real event.

sent_atstring (date-time)optional
dataobjectoptional

Fields beyond these are allowed.

Example: ready
{
  "event": "order.ready",
  "event_id": "3f9a1d2e-6c47-4b1a-9f0e-8d5c2a7b4e13",
  "sent_at": "2026-08-06T12:00:03Z",
  "data": {
    "order_id": "ord_9c1f2a",
    "status": "ready",
    "duration_s": 3600,
    "send_before": "2026-08-06T12:59:57Z"
  }
}

Responses

200

Delivery acknowledged

No body.

POST orderLifecycle

Other order and billing events

The order's closing events — order.completed, order.partially_completed and order.failed — and the per-transfer ones, order.item.sent and order.item.expired.

A closing payload carries order_id, status, duration_s and charged_trx. duration_s is the lease the order was sold as, on every order.* payload alike (see order.ready): with several products the amount no longer says what it was for, and the same charged_trx can be a large five-minute order or a small hourly one.

The item events carry order_id, item_id and — on order.item.sent — the txid of the transfer we saw. They are about one transfer rather than about the order, and they carry no lease.

order.item.expired means "the energy was delivered, the transfer did not happen, it is charged". In modes a and c it comes when the send window closes on an item still ready. In mode b it comes when your signed transaction fails on its own after delivery — the node refused it for what it is (error: broadcast_failed), or it was mined and the contract refused it, or it ran out of energy having spent less than the transfer's requirement — the energy we delivered was not on the address (error: transaction_reverted) — and the item is closed expired and charged. A mode b item we failed to broadcast, one no node could take, or one mined and run out of energy where the shortfall is shown to be ours, is refunded and gets no item event.

Request body

Optional.

Content type application/json.

Schema: WebhookPayload.

FieldTypeRequiredDescription
eventDeliveredWebhookEventoptional
event_idstring (uuid)optional

Deduplication key, stable across every retry of this event — automatic ones and replays requested through POST /webhooks/{id}/deliveries/{delivery_id}/retry alike. Two requests carrying one event_id are one event; process the first and drop the rest.

It is inside the signed body on purpose, and mirrored in the X-NRG-Event-Id header only for convenience: a deduplication key that travelled outside the signature could be altered in transit, and a receiver dropping duplicates by it would drop a real event.

sent_atstring (date-time)optional
dataobjectoptional

Fields beyond these are allowed.

Example: completed
{
  "event": "order.completed",
  "event_id": "8c2b7f10-4d6e-4a3b-9c15-2e7f6a0b3d94",
  "sent_at": "2026-08-06T12:05:11Z",
  "data": {
    "order_id": "ord_9c1f2a",
    "status": "completed",
    "duration_s": 3600,
    "charged_trx": "1.235000"
  }
}

Responses

200

Delivery acknowledged

No body.

POST orderRepriced

order.repriced — the order's price moved at fulfillment

Sent when a position of the order was raised to the market right before it was bought, and when a volume raise that nothing more was bought after is taken back (see "Order price" in the introduction). One order can send it more than once; an order whose price never moves never sends it.

data carries order_id, status (the order's status at that moment — purchasing as a rule), duration_s and three amounts:

  • quoted_total_trx — the order's total at creation, the same in every order.repriced of one order;
  • previous_total_trx — the order's total_trx before this change;
  • total_trx — its total_trx after it, the amount now held for the order. Above previous_total_trx on a raise; below it on a raise taken back, and never below quoted_total_trx.

The difference was held from your available balance at the same moment (released back to it, on a take-back), and GET /ledger shows it as a hold (or hold_release) entry carrying the order's id. The raise is made before the purchase it pays for, so it does not mean the energy was bought: order.ready and the closing events follow as usual, and the closing event's charged_trx is counted at the price the positions stand at by then.

A raise your balance cannot cover, or one above the cap, is never made and sends no order.repriced. A transfer position then fails with purchase_failed and its hold comes back in full; a volume position is refused that way only while nothing has been bought for it and allow_partial is off, and otherwise ends short, charged for what was delivered. The order's closing event says which.

Deliveries are retried independently and can arrive out of order. Deduplicate on event_id as always, and take the order's current total_trx from GET /orders/{order_id} rather than adding events up.

Request body

Optional.

Content type application/json.

Schema: WebhookPayload.

FieldTypeRequiredDescription
eventDeliveredWebhookEventoptional
event_idstring (uuid)optional

Deduplication key, stable across every retry of this event — automatic ones and replays requested through POST /webhooks/{id}/deliveries/{delivery_id}/retry alike. Two requests carrying one event_id are one event; process the first and drop the rest.

It is inside the signed body on purpose, and mirrored in the X-NRG-Event-Id header only for convenience: a deduplication key that travelled outside the signature could be altered in transit, and a receiver dropping duplicates by it would drop a real event.

sent_atstring (date-time)optional
dataobjectoptional

Fields beyond these are allowed.

Example: A volume raised to the market between two pieces
{
  "event": "order.repriced",
  "event_id": "6d0e2b71-58c3-4f9a-a1d4-3e7c90b2f518",
  "sent_at": "2026-10-15T15:31:07Z",
  "data": {
    "order_id": "ord_9c1f2a",
    "status": "purchasing",
    "duration_s": 3600,
    "quoted_total_trx": "20.000000",
    "previous_total_trx": "20.000000",
    "total_trx": "25.000000"
  }
}
Example: The same raise taken back — the fill ended short without buying anything after it, so the volume returns to the price its last piece was bought at
{
  "event": "order.repriced",
  "event_id": "1f7a9c34-0b26-4e58-9d13-a6c2e8f40b97",
  "sent_at": "2026-10-15T15:33:42Z",
  "data": {
    "order_id": "ord_9c1f2a",
    "status": "purchasing",
    "duration_s": 3600,
    "quoted_total_trx": "20.000000",
    "previous_total_trx": "25.000000",
    "total_trx": "20.000000"
  }
}

Responses

200

Delivery acknowledged

No body.

POST topupLifecycle

Top-up request events

The life of a request for TRX (GET /topup-requests). All three are sent only while auto_topup.enabled is on.

topup.requested — we are asking you for money: an order was refused for lack of balance, or the available balance fell under your balance_low threshold. It can arrive twice with the same topup_request_id, and the second one supersedes the first: a further need raises the open request instead of opening a second one.

It is re-sent when either of two things happens, and only one of them is the amount:

  • amount_trx grew;
  • reason escalated from balance_low to order_insufficient_balance — an order has now been refused and is waiting on this deposit. amount_trx may be unchanged.

The escalation is one-way; reason never goes back. expires_at is pushed out a fresh TTL on every re-send, because a raise makes it a different ask.

Do not deduplicate on (topup_request_id, amount_trx): a repeat at the same amount is not a copy, it is a change of reason and of expires_at. Deduplicate on event_id like every other event, and act on the newest state you have seen for that topup_request_id.

topup.fulfilled — deposits credited since the request add up to amount_trx (credited_trx says how much), or your target_trx was reached by some other route. txid is the transaction that finished it, which may be the last of several — and it is null when nothing on chain finished it: a released hold, a refund or an operator adjustment can carry the balance to the target, and that closure is found by a periodic pass rather than by a credit, so there is no transaction to name. Do not key on txid being present.

topup.expired — nobody answered within a day. This refuses no money: TRX arriving at the address afterwards is credited exactly as ever, and a new request is raised the next time the balance is short.

topup.* is not maintenance.topup. That one is energy delivered to a wallet under an auto-refill rule; these are TRX for the prepaid balance. And the money landing is still deposit.credited — topup.fulfilled is news about the request, not a second announcement of the deposit, so an integration crediting its own books should key on deposit.credited and not on this. A deposit below 1 TRX has no deposit.credited at all (see WebhookEvent), though a request it completes still gets topup.fulfilled with its txid; books kept to the last sun reconcile against GET /balance and GET /ledger.

Request body

Optional.

Content type application/json.

Schema: WebhookPayload.

FieldTypeRequiredDescription
eventDeliveredWebhookEventoptional
event_idstring (uuid)optional

Deduplication key, stable across every retry of this event — automatic ones and replays requested through POST /webhooks/{id}/deliveries/{delivery_id}/retry alike. Two requests carrying one event_id are one event; process the first and drop the rest.

It is inside the signed body on purpose, and mirrored in the X-NRG-Event-Id header only for convenience: a deduplication key that travelled outside the signature could be altered in transit, and a receiver dropping duplicates by it would drop a real event.

sent_atstring (date-time)optional
dataobjectoptional

Fields beyond these are allowed.

Example: requested
{
  "event": "topup.requested",
  "event_id": "2a9f13c7-6d84-4e02-b1ef-70c5a83d4b16",
  "sent_at": "2026-09-04T11:02:18Z",
  "data": {
    "topup_request_id": "9c4f0b52-31ad-4e6b-8d70-1f2a5c9e7b83",
    "amount_trx": "120.000000",
    "deposit_address": "TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9",
    "reason": "order_insufficient_balance",
    "order_id": null,
    "expires_at": "2026-09-05T11:02:18Z",
    "available_trx": "1.020000"
  }
}
Example: fulfilled
{
  "event": "topup.fulfilled",
  "event_id": "5f1b8d90-4c27-4a3e-9b06-8ad2e14f7c35",
  "sent_at": "2026-09-04T11:29:44Z",
  "data": {
    "topup_request_id": "9c4f0b52-31ad-4e6b-8d70-1f2a5c9e7b83",
    "amount_trx": "120.000000",
    "credited_trx": "150.000000",
    "txid": "3f9d1a6c58b24e07af31d20e9c7b45816ad3f0e2c94b7815d6a0f32c8e14b7d9",
    "order_id": null,
    "balance_trx": "151.020000"
  }
}
Example: The target was reached by something other than a deposit — txid is null
{
  "event": "topup.fulfilled",
  "event_id": "b7302c19-8d54-4f6a-91ee-2c0d5a83f174",
  "sent_at": "2026-09-04T12:04:09Z",
  "data": {
    "topup_request_id": "9c4f0b52-31ad-4e6b-8d70-1f2a5c9e7b83",
    "amount_trx": "120.000000",
    "credited_trx": "0.000000",
    "txid": null,
    "order_id": null,
    "balance_trx": "205.400000"
  }
}
Example: expired
{
  "event": "topup.expired",
  "event_id": "8e6c2f41-0b73-4d95-a2c8-63f19d4e70ba",
  "sent_at": "2026-09-05T11:02:20Z",
  "data": {
    "topup_request_id": "9c4f0b52-31ad-4e6b-8d70-1f2a5c9e7b83",
    "amount_trx": "120.000000",
    "reason": "order_insufficient_balance",
    "order_id": null
  }
}

Responses

200

Delivery acknowledged

No body.

POST maintenanceLifecycle

Energy maintenance events

maintenance.topup — energy delivered to the rule's wallet; maintenance.budget_exhausted — the daily budget is exhausted, no more top-ups until the end of the UTC day; maintenance.paused — the rule has been stopped (currently the only reason is insufficient_balance) and resumes only via a PATCH request.

Request body

Optional.

Content type application/json.

Schema: WebhookPayload.

FieldTypeRequiredDescription
eventDeliveredWebhookEventoptional
event_idstring (uuid)optional

Deduplication key, stable across every retry of this event — automatic ones and replays requested through POST /webhooks/{id}/deliveries/{delivery_id}/retry alike. Two requests carrying one event_id are one event; process the first and drop the rest.

It is inside the signed body on purpose, and mirrored in the X-NRG-Event-Id header only for convenience: a deduplication key that travelled outside the signature could be altered in transit, and a receiver dropping duplicates by it would drop a real event.

sent_atstring (date-time)optional
dataobjectoptional

Fields beyond these are allowed.

Example: topup
{
  "event": "maintenance.topup",
  "event_id": "7b2c9e04-1f83-4d6a-8e57-0a3b6c1d9f42",
  "sent_at": "2026-08-18T09:15:02Z",
  "data": {
    "rule_id": "mnt_4b7d1c",
    "address": "TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9",
    "units": 131000,
    "charged_trx": "4.192000"
  }
}
Example: budget_exhausted
{
  "event": "maintenance.budget_exhausted",
  "event_id": "c41e7a58-90b2-4f31-a6d8-52e7f0c3b19d",
  "sent_at": "2026-08-18T17:40:11Z",
  "data": {
    "rule_id": "mnt_4b7d1c",
    "address": "TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9",
    "spent_today_trx": "19.552000",
    "daily_budget_trx": "20.000000"
  }
}

Responses

200

Delivery acknowledged

No body.

POST queueLifecycle

Queue session events

The life of a queue session (api-spec.md §12). Six events, one envelope, and every data carries session_id and the session's counters:

  • queue.started — Start went through and the hold is placed;
  • queue.packet_delivered — one packet was seen delivered on-chain and charged; this is the only event that moves money, and it comes once per packet rather than as a total;
  • queue.paused / queue.resumed — with the reason; a pause lifts itself, so queue.resumed needs nothing from you;
  • queue.completed — the queue was exhausted and the last delivered packet has expired; the counters are final and the hold is released;
  • queue.stopped — you stopped it; packets in flight at that moment are still settled afterwards, each with its own queue.packet_delivered.

The six names are in the subscribable list (WebhookEvent), so a subscription may name them today; they are sent from the moment the mode is enabled for the account and a session is started.

Request body

Optional.

Content type application/json.

Every field of WebhookPayload, and the fields below.

Example: packet_delivered
{
  "event": "queue.packet_delivered",
  "event_id": "5e1c8a3f-7b2d-4c96-a0e4-93f1d2b7c608",
  "sent_at": "2026-09-17T10:12:41Z",
  "data": {
    "session_id": "qs_2f8e41",
    "packet_id": "184",
    "units": 650000,
    "price_sun": 35,
    "charged_trx": "22.750000",
    "hold_trx": "14.000000",
    "counters": {
      "items_total": 120,
      "items_pending": 97,
      "items_sent": 23,
      "items_skipped": 0,
      "packets_bought": 4,
      "packets_confirmed": 4,
      "units_delivered": 2600000,
      "charged_trx": "91.000000"
    }
  }
}
Example: paused
{
  "event": "queue.paused",
  "event_id": "9a7d0c2e-13f4-4b8a-9d61-4c2e7f80b153",
  "sent_at": "2026-09-17T10:20:03Z",
  "data": {
    "session_id": "qs_2f8e41",
    "reason": "insufficient_balance",
    "counters": {
      "items_total": 120,
      "items_pending": 61,
      "items_sent": 59,
      "items_skipped": 0,
      "packets_bought": 9,
      "packets_confirmed": 9,
      "units_delivered": 5850000,
      "charged_trx": "204.750000"
    }
  }
}
Example: completed
{
  "event": "queue.completed",
  "event_id": "0c3b6e19-8d47-4f5a-b2e8-6a91c0d4f7e2",
  "sent_at": "2026-09-17T10:41:17Z",
  "data": {
    "session_id": "qs_2f8e41",
    "reason": "queue_exhausted",
    "hold_trx": "0.000000",
    "counters": {
      "items_total": 120,
      "items_pending": 0,
      "items_sent": 118,
      "items_skipped": 2,
      "packets_bought": 17,
      "packets_confirmed": 17,
      "units_delivered": 11050000,
      "charged_trx": "386.750000"
    }
  }
}

Responses

200

Delivery acknowledged

No body.

POST webhookTest

webhook.test — a probe you asked for

Sent only by POST /webhooks/{id}/test, never by anything that happens to your account. Signed, headed and logged exactly like a real event, so it is a genuine end-to-end check of your handler — which is why the event name is unmistakable: dispatch on it and return 2xx, and never let it fall through to the branch that fills an order.

Not subscribable, and not affected by your endpoint's events: it goes to the endpoint you named. One attempt, no retry ladder, and its failures do not count towards disabling the endpoint.

Request body

Optional.

Content type application/json.

Schema: WebhookPayload.

FieldTypeRequiredDescription
eventDeliveredWebhookEventoptional
event_idstring (uuid)optional

Deduplication key, stable across every retry of this event — automatic ones and replays requested through POST /webhooks/{id}/deliveries/{delivery_id}/retry alike. Two requests carrying one event_id are one event; process the first and drop the rest.

It is inside the signed body on purpose, and mirrored in the X-NRG-Event-Id header only for convenience: a deduplication key that travelled outside the signature could be altered in transit, and a receiver dropping duplicates by it would drop a real event.

sent_atstring (date-time)optional
dataobjectoptional

Fields beyond these are allowed.

Example: test
{
  "event": "webhook.test",
  "event_id": "0f0f6b1e-4a1e-4a5f-9b8a-2f5f0d9c1a77",
  "sent_at": "2026-08-26T10:31:44Z",
  "data": {
    "message": "This is a test event from nrg.market. No order was created."
  }
}

Responses

200

Delivery acknowledged

No body.