Dex paid on charts

Draw a DexData Paid line on a token's price chart, with code for TradingView and Lightweight Charts.

Web page: https://docs.dexdata.org/api/charts

Where the line goes

paidAt is the Unix ms time the token became dex paid: the payment time of its oldest approved order. It's null while the token isn't dex paid. It's where a chart draws its dex-paid line, and it only moves if that order is taken down in review, when it becomes the next approved order's time, or null.

1. Look it up on your server

The chart runs in the browser, so it gets the status from your server, which calls dexdata with your key. Cache it for a minute or so.

// Your server: look up dex-paid status with your key (never send the key to a browser).
app.get("/api/dex-paid/:mint", async (req, res) => {
  const r = await fetch(`https://api.dexdata.org/v1/tokens/${req.params.mint}/paid`, {
    headers: { "x-api-key": process.env.DEXDATA_API_KEY },
  });
  if (!r.ok) return res.status(r.status === 400 ? 400 : 502).end();
  const { paid, paidAt, url } = await r.json();
  res.set("cache-control", "public, max-age=60").json({ paid, paidAt, url });
});

2. Draw it

// TradingView Advanced Charts: a dashed vertical line where the token became dex paid.
const { paid, paidAt } = await fetch(`/api/dex-paid/${mint}`).then((r) => r.json());

widget.onChartReady(() => {
  if (!paid) return;
  widget.activeChart().createShape(
    { time: Math.floor(paidAt / 1000) }, // Unix seconds
    {
      shape: "vertical_line",
      text: "DexData Paid",
      lock: true,
      disableSelection: true,
      disableSave: true,
      overrides: { linecolor: "#1c4ae8", linewidth: 1, linestyle: 2, showLabel: true, textcolor: "#1c4ae8" },
    },
  );
});
// Or a mark on the time axis, from your datafeed. onReady must report supports_timescale_marks: true.
getTimescaleMarks(symbolInfo, from, to, onResult) {
  const t = paid ? Math.floor(paidAt / 1000) : null;
  onResult(t !== null && t >= from && t <= to
    ? [{ id: "dexdata-paid", time: t, color: "#1c4ae8", label: "DD", tooltip: ["DexData Paid"], imageUrl: "https://dexdata.org/brand/dex-circle.svg" }]
    : []);
},
// Lightweight Charts (v5): a marker on the candle the payment fell in.
import { createSeriesMarkers } from "lightweight-charts";

const { paid, paidAt } = await fetch(`/api/dex-paid/${mint}`).then((r) => r.json());
if (paid) {
  const at = Math.floor(paidAt / 1000); // Unix seconds, like the candles' time
  const candle = candles.findLast((c) => c.time <= at) ?? candles[0];
  createSeriesMarkers(series, [
    { time: candle.time, position: "aboveBar", shape: "arrowDown", color: "#1c4ae8", text: "DexData Paid" },
  ]);
}

dexdata developer docs: https://docs.dexdata.org/api.md · All docs: https://docs.dexdata.org/index.md · Full API reference: https://dexdata.org/llms.txt