Skip to main content
LitePart of the Lite plan; Developer and Professional include it too. See plans · Get your key

24-hour replay stream

You can replay 24 hours of the stream. Whatever drops between the chain and your bot, the events arrive late instead of never.

How the 24 hours are covered
  • Your socket resumes from any slot of the last 24 hours. Pass sinceSlot on reconnect and everything since that slot is sent first, marked replayed, then live events follow. It does not matter which side dropped: your connection, or a restart on ours.
  • The last two minutes are sent at once. Anything older is replayed from the chain for you, built exactly as the live events were, faster than live so it catches up: the further back, the longer it takes.
  • Older than 24 hours: the hourly replay files hold every event of every hour, in the same format as the stream, for backtests too.

Resume from a slot​

Every event on the Advanced Data Stream carries block, the slot it was in. Keep the last one you handled. On reconnect, pass it as sinceSlot and everything published since that slot is sent to you first, through your usual filter, then the live events follow.

Plain WebSocket​

Add sinceSlot to the address. The replayed events come right after connected, then a resumed message says how far back the replay reached, then the live events. An event published while the replay ran is sent once, not twice. While an older stretch is replayed, {"type":"replaying","slot":…} arrives every 15 seconds to show where it is, and you can change the filter or ping meanwhile.

import WebSocket from "ws";

let lastSlot = 0;

function connect() {
const since = lastSlot ? `&sinceSlot=${lastSlot}` : "";
const ws = new WebSocket(`wss://sol.shrine.trade/api/stream/ws?key=sk_…&protocols=PUMPFUN,PUMPSWAP${since}`);
ws.on("message", (raw) => {
const e = JSON.parse(raw);
// {"type":"resumed","sinceSlot":…,"oldestSlot":…,"replayed":…}
if (e.type === "resumed" && e.oldestSlot > e.sinceSlot) console.warn("gap before slot", e.oldestSlot);
if (e.type) return;
lastSlot = Math.max(lastSlot, e.block);
if (e.replayed) { /* delivered late, not live */ }
// ...
});
ws.on("close", () => setTimeout(connect, 1000));
}
connect();

Socket.IO​

Pass sinceSlot in subscribe_stream; the acknowledgement comes when the replay is done and says how far back it reached. Live events keep arriving while it runs, so take your last slot from the replayed events until then.

import { io } from "socket.io-client";

const socket = io("https://sol.shrine.trade", { auth: { api_key: "sk_…" } });
let lastSlot = 0;
let replaying = false;

socket.on("connect", () => {
replaying = lastSlot > 0;
socket.emit("subscribe_stream", { protocols: ["PUMPFUN", "PUMPSWAP"], sinceSlot: lastSlot || undefined }, (ack) => {
// ack.replayed events were sent before this ack; ack.oldestSlot is how far back we could reach
replaying = false;
if (lastSlot && ack.oldestSlot > lastSlot) console.warn("gap before slot", ack.oldestSlot);
});
});

socket.on("stream", (e) => {
// During a replay, live events arrive too: only the replayed ones move the slot on.
if (!replaying || e.replayed) lastSlot = Math.max(lastSlot, e.block);
if (e.replayed) { /* delivered late, not live */ }
// ...
});

A replay runs up to your plan's number at once per key: one on Lite, three on Developer, five on Professional. Another sinceSlot while those run answers limit_exceeded (on the WebSocket, an HTTP 429 when connecting); connect without it, or retry when one ends.

Replayed events are the original events with "replayed": true added, in their original order. The resumed message, or on Socket.IO the acknowledgement, carries replayed (how many were sent) and oldestSlot, the slot from which on you have everything: your sinceSlot, or the oldest slot still kept when yours is older than 24 hours. If oldestSlot is newer than your sinceSlot, the stretch before it is in the hourly files.

A replay that could not run says why in error (all replays busy, for instance); you still get the last two minutes. Resume again from your last slot a minute later.

At the boundary

The resume includes sinceSlot itself, so the last slot you handled is sent again. Deduplicate on signature plus pool if a double counts for you.

LimitsLite 1 socketDeveloper 3 socketsProfessional 5 socketsSee plans →