SDKs

The Anaxer SDKs are the official TypeScript (@anaxer/sdk) and Python (anaxer) clients for the Anaxer API: typed WebSocket streams and REST calls, with auth, heartbeat and reconnecting handled for you.

Language

Showing TypeScript (@anaxer/sdk) examples below.

Install

Node.js ≥ 20 (ESM + CommonJS). Package @anaxer/sdk, current version 0.2.0.

npm install @anaxer/sdk

Source: Anaxer-v2/anaxer-sdk-js · Package: @anaxer/sdk on npm · MIT

Quickstart

import { connect } from "@anaxer/sdk";

const client = connect({ apiKey: process.env.ANAXER_API_KEY! });

client.stream("creations", { excludeMayhem: true }).on("data", (token) => {
  console.log("new launch:", token.symbol, token.mint);
});

const price = await client.tokens.price(
  "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"
);

connect() returns immediately. The WebSocket opens on the first stream() call (or await client.ready()). Auth is Authorization: Bearer for both WS and REST.

What it handles

  • Auth — attaches your API key for WebSocket and REST.
  • Typed events — channel payloads match the public WebSocket and REST v1 shapes.
  • Heartbeat — client pings; the socket is treated as dead if no inbound traffic arrives within 2× the interval.
  • Reconnection — exponential backoff with jitter; re-sends every active subscription after reconnect.
Upgrade to 0.2.0. 0.2.0 adds transfers, the wallet endpoints, sources lists and size filters. 0.1.1 and later keep working without them; 0.0.x and 0.1.0 reject the connectedframe and don't connect. Run npm install @anaxer/sdk@latest.

Streaming

Subscribe with client.stream(channel, filters?). Each call returns a subscription you can listen on and close independently.

ChannelPayloadCommon filters
tradesSwapV1sources, mints, wallets, minVolumeUsd, maxVolumeUsd, solOnly
creationsCreatedV1sources, enriched, excludeMayhem
graduationsGraduatedV1sources, excludeMayhem, minLiquiditySol
transfersTransferV1wallets, mints, minVolumeUsd, maxVolumeUsd, direction ("in" / "out", needs wallets)
pricesPriceUpdateV1sources, mints
const sub = client.stream("trades", {
  mints: ["EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"],
  minVolumeUsd: 10,
});

sub.on("subscribed", (filters) => console.log("live", filters));
sub.on("data", (swap) =>
  console.log(swap.signature, swap.swap.from.symbol, "→", swap.swap.to.symbol, swap.volumeUsd),
);
sub.on("error", (err) => console.error(err.code, err.message));

// later
sub.close(); // unsubscribe; not resurrected after reconnect
// Watch wallets for the SOL and tokens they send.
client
  .stream("transfers", {
    wallets: ["5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh"],
    direction: "out",
  })
  .on("data", (t) =>
    console.log(t.wallet, "→", t.transfer.to, t.transfer.uiAmount, t.transfer.symbol, t.volumeUsd),
  );

Filter types are per channel, so TypeScript rejects a filter the channel doesn't take (sources on transfers, direction on trades, …). The server rejects them too, with invalid_filters, as it does an unknown source name. A routed swap arrives as one trade per hop, all with the same signature. Trade legs and transfers carry symbol, which is null until the token is resolved; key on mint. Plan rules (Starter must send mints on trades and wallets or mints on transfers) are on the Streams page.

Connection events

client.on("connected", (limits) => {
  console.log("plan cap", limits.connectionsPerStream, limits.transfersWalletCap);
});
client.on("reconnect", (attempt) => console.log("retry", attempt));
client.on("error", (err) => console.error(err.code, err.message));

const limits = await client.ready();  // resolves on first connected frame, with the limits
await client.close();  // graceful shutdown; disables reconnect
  • Heartbeat default heartbeatMs: 15_000; set 0 to disable.
  • Reconnect is on by default; reconnect: false disables it. unauthorized is terminal (bad key — no retry loop).
  • The connected limits include transfersRequiresFilter, transfersWalletCap, transfersMintCap. They are optional: a gateway that predates transfers doesn't send them, and the SDK connects either way.

Gap recovery

After a disconnect the SDKs reconnect and re-subscribe, but resume the live feed only. Backfill the gap over REST with from / to (7 days of history on every plan): creations and graduations with their list methods, trades with mints per token, trades and transfers with wallets per wallet through client.wallets. An unfiltered firehose has no chain-wide backfill. Recovery is at-least-once, so deduplicate on these keys (not on signature alone, since a routed swap is one row per hop, and not on symbol, volumeUsd or timestamp, which can differ between the live event and the backfilled row):

import type { SwapV1, TransferV1 } from "@anaxer/sdk";

const tradeKey = (s: SwapV1) =>
  [s.signature, s.wallet, s.source, s.swap.from.mint, s.swap.from.amount, s.swap.to.mint, s.swap.to.amount].join("|");
const transferKey = (t: TransferV1) =>
  [t.signature, t.wallet, t.transfer.from, t.transfer.to, t.transfer.mint, t.transfer.amount].join("|");

Watching both ends of a transfer delivers it twice, once per watched wallet; drop wallet from the transfer key to collapse them.

REST

All calls are authenticated GETs. Transient 429 / 5xx retry up to restMaxRetries (default 2), honoring Retry-After. Other 4xx throw immediately.

MethodReturns
client.tokens.get(mint)TokenMetadataV1
client.tokens.batch(mints)TokenMetadataV1[] (up to 50 mints)
client.tokens.price(mint)RestPriceV1 (the stream price plus stale)
client.tokens.batchPrice(mints)RestPriceV1[] (up to 100 mints)
client.tokens.trades(mint, opts?)Page<SwapV1>: mint on either side
client.wallets.trades(wallet, opts?)Page<SwapV1>: the wallet's trades
client.wallets.transfers(wallet, opts?)Page<TransferV1>: the wallet's transfers, sent and received
client.creations(opts?)Page<CreatedV1>
client.graduations(opts?)Page<GraduatedV1>
client.launchpads.stats(opts?)LaunchpadStatsV1

Every list takes limit (1–200, default 50), cursor, from and to, plus:

Optiontokens.tradeswallets.tradeswallets.transferscreationsgraduations
source (one) or sources (≤ 20)✓✓—✓✓
mints (≤ 100)path✓ either side✓——
minVolumeUsd / maxVolumeUsd✓✓✓——
solOnly✓✓———
direction ("in" / "out")——✓——
excludeMayhem———✓✓
minLiquiditySol————✓

source and sources are exclusive; passing both fails with invalid_request before any request is sent. A set volume bound excludes rows with a null volumeUsd. REST prices carry stale, true when the trade behind the price is over 15 minutes old.

List endpoints return a Page<T> with .data, .next, and .window. It is also an async iterable that walks next on the same endpoint until null:

const page = await client.wallets.transfers("5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh", {
  direction: "in",
  minVolumeUsd: 100,
});
console.log(page.data.length, page.window);

for await (const t of page) {
  console.log(t.transfer.from, t.transfer.uiAmount, t.transfer.symbol);
}

// A wallet's trades on two venues
const trades = await client.wallets.trades("5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh", {
  sources: ["pump_fun", "pump_amm"],
});

Config

connect({
  apiKey: process.env.ANAXER_API_KEY!, // required
  baseUrl: "https://api.anaxer.com",   // optional
  // wsUrl derived from baseUrl → wss://…/v1/stream
  reconnect: true,                     // or false | { baseDelayMs, maxDelayMs, maxRetries }
  heartbeatMs: 15_000,                 // 0 disables
  restMaxRetries: 2,                   // 0 disables REST retries
});

Errors

REST non-2xx throws AnaxerError (code, message, status). WebSocket error frames emit on the matching subscription (when an id is present) or on the client.

import { AnaxerError, connect } from "@anaxer/sdk";

const client = connect({ apiKey: process.env.ANAXER_API_KEY! });

try {
  await client.tokens.get(mint);
} catch (e) {
  if (e instanceof AnaxerError && e.code === "not_found") {
    // mint never observed
  }
}

See the full error codes reference.

Types

Payload and filter types are exported from the package (SwapV1, TransferV1, TokenLegV1, CreatedV1, TradesFilters, TransfersFilters, ConnectionLimits, …). WIRE_VERSION is 1 (envelope v, independent of the npm package version).

Last updated · Changelog