Guides

Trading and alerts

Alerts and notifications

A price alert watches an instrument on our servers, with your browser open or closed, and tells you when the price meets its condition: in the terminal, and on the channels you choose.

Create an alert

In Alerts, choose New alert, or use Alert at in the menu of a chart to start from a price. An alert has a name, an instrument, a condition and a price. It can fire once and turn off, or stay on, and it can expire at a time you choose.

Your plan sets how many alerts are active at once, from 5 to 5,000. An alert that is paused or expired does not count.

Conditions

Crossing up
Fires when the price, seen below your price, reaches it or goes above.
Crossing down
Fires when the price, seen above your price, reaches it or goes below.
Crossing
Either way.
Greater than
Fires while the price is above yours: at once if it already is, and again only after it leaves and comes back.
Less than
The same, below your price.

The price is the one of the last trade on the exchange. An alert that stays on fires at most once per second.

Channels

Every alert shows in the terminal. To be told elsewhere, choose Set up channels… in an alert, add the channels you want and verify each one; then choose, on each alert, which channels it uses:

Browser notifications
Turned on in a browser, they reach it even with the terminal closed. The browser that turns them on is its own proof.
Email
Verified with a code we send to the address.
Telegram
Messages from our bot to your chat: open the bot and press Start to link it.
Webhook
An HTTPS POST to your URL, signed so that you can check it came from us. It is verified when your URL answers our ping.
SMS and WhatsApp
A message to a phone with its country code, verified with a code. SMS is available in the countries listed in the plan table; WhatsApp, in all of them.

Each channel can send a test, and its messages come in English or in Spanish. If our servers have no provider for a channel yet, the terminal says so.

Quotas

Browser notifications, email and Telegram have no monthly quota. Webhooks, SMS and WhatsApp count against the monthly quota of your plan: a message past it is not sent, and the channel says why.

FeatureFreePlusProQuantUltimate
Active price alerts5504002,0005,000
Webhooks per monthNot included5005,00050,000200,000
SMS per monthNot included51550100
WhatsApp messages per monthNot included2060200500

Verify a webhook

Each request is a POST with a JSON body and a PT-Signature header: t= the time it was sent, in Unix seconds, and v1= the HMAC-SHA256, in hex, of that time, a dot and the body, keyed with the secret of the webhook. The secret is shown once, when you add the webhook: keep it on your server.

To verify a request, compute the same HMAC over the body exactly as it arrived, before parsing it, compare the two in constant time, and refuse a time far from your clock, so that a request someone captured cannot be sent again. In Node.js:

verify-webhook.mjs · Node.js
import { Buffer } from "node:buffer";
import { createHmac, timingSafeEqual } from "node:crypto";
import process from "node:process";

// How far, in seconds, the time of a request may be from the clock of this server.
const TOLERANCE_SECONDS = 300;

/**
 * Checks the PT-Signature header of a request from PlotTerminal.
 *
 * @param {string} header the PT-Signature header: "t=<unix seconds>,v1=<hex HMAC-SHA256>"
 * @param {Buffer | string} body the raw body, exactly as it arrived
 * @param {string} secret the secret PlotTerminal showed once, when you added the webhook
 * @param {number} [now] the current time, in Unix seconds
 * @returns {boolean} whether PlotTerminal signed this body, recently
 */
export function verifySignature(header, body, secret, now = Math.floor(Date.now() / 1000)) {
  /** @type {Map<string, string>} */
  const fields = new Map();
  for (const part of header.split(",")) {
    const separator = part.indexOf("=");
    if (separator > 0) {
      fields.set(part.slice(0, separator).trim(), part.slice(separator + 1).trim());
    }
  }
  const time = fields.get("t") ?? "";
  const signature = fields.get("v1") ?? "";
  // A request from too long ago, or from the future, may be a replay: refuse it.
  if (!/^\d+$/.test(time) || Math.abs(now - Number(time)) > TOLERANCE_SECONDS) {
    return false;
  }
  const expected = createHmac("sha256", secret).update(`${time}.`).update(body).digest();
  const received = Buffer.from(signature, "hex");
  return received.length === expected.length && timingSafeEqual(received, expected);
}

/**
 * A handler for node:http: `createServer(handleWebhook).listen(8000)`. It reads the secret from
 * the environment, answers at once, and only then reads the notification.
 *
 * @param {import("node:http").IncomingMessage} request
 * @param {import("node:http").ServerResponse} response
 */
export function handleWebhook(request, response) {
  /** @type {Buffer[]} */
  const chunks = [];
  request.on("data", (/** @type {Buffer} */ chunk) => {
    chunks.push(chunk);
  });
  request.on("end", () => {
    const body = Buffer.concat(chunks);
    const header = request.headers["pt-signature"];
    const secret = process.env.PT_WEBHOOK_SECRET ?? "";
    if (typeof header !== "string" || !verifySignature(header, body, secret)) {
      response.writeHead(401).end();
      return;
    }
    response.writeHead(204).end();
    const notification = JSON.parse(body.toString("utf8"));
    if (notification.type === "alert_fired") {
      // Your work here: notification.alert holds the alert that fired.
    }
  });
}

What a request says

The body is the notification as JSON. type is alert_fired, or ping for the request that verifies the URL and for a test; alert is the alert that fired, with its name, its instrument, the price that fired it and the time. Fields that are empty or zero may be left out. Answer with a 2xx status at once, and do your work after.

Body of a request
{
  "type": "alert_fired",
  "targetId": "8c9e2f4a-5b1d-4c7e-9f20-3d6a1b7e4c55",
  "alert": {
    "eventId": "f1b7c3d9-2e4a-4f6b-8c1d-5a9e7b3f2c10",
    "alertId": "0d4f6a8c-1e3b-4d5f-a7c9-2b4d6f8a0c1e",
    "name": "BTC 100k",
    "market": {
      "venue": "binance",
      "mkt": "usdm",
      "inst": "btc-usdt-perp"
    },
    "value": "100000.1",
    "timeMs": "1767225600000",
    "origin": "ALERT_ORIGIN_PRICE"
  },
  "sentMs": "1767225600250"
}