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/sdkSource: 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"
);import asyncio
import anaxer
async def main():
async with anaxer.connect(api_key="...") as client:
async with client.stream("creations", exclude_mayhem=True) as sub:
async for token in sub:
print("new launch:", token.symbol, token.mint)
break
price = await client.tokens.price(
"DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"
)
print(price.price.usd)
asyncio.run(main())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.
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.
| Channel | Payload | Common filters |
|---|---|---|
| trades | SwapV1 | sources, mints, wallets, minVolumeUsd, maxVolumeUsd, solOnly |
| creations | CreatedV1 | sources, enriched, excludeMayhem |
| graduations | GraduatedV1 | sources, excludeMayhem, minLiquiditySol |
| transfers | TransferV1 | wallets, mints, minVolumeUsd, maxVolumeUsd, direction ("in" / "out", needs wallets) |
| prices | PriceUpdateV1 | sources, 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 reconnectasync with client.stream(
"trades",
mints=["EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"],
min_volume_usd=10,
) as sub:
async for swap in sub:
print(swap.signature, swap.swap.from_.symbol, "->", swap.swap.to.symbol, swap.volume_usd)
# break # or let the context exit to unsubscribe// 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),
);# Watch wallets for the SOL and tokens they send.
async with client.stream(
"transfers",
wallets=["5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh"],
direction="out",
) as sub:
async for t in sub:
print(t.wallet, "->", t.transfer.to, t.transfer.ui_amount, t.transfer.symbol, t.volume_usd)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 reconnectasync with anaxer.connect(api_key="...") as client:
# The server's connected frame — available as soon as the context opens
print("plan cap", client.connected.connections_per_stream)
print("transfers wallets", client.connected.transfers_wallet_cap)
client.on_error(lambda err: print(err.code, err.message))
# or consume them in order: async for err in client.errors: ...
# exiting the context closes the socket and disables reconnect- Heartbeat default
heartbeatMs: 15_000; set0to disable. - Reconnect is on by default;
reconnect: falsedisables it.unauthorizedis 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("|");def trade_key(s: anaxer.SwapV1) -> tuple[str, ...]:
return (s.signature, s.wallet, s.source,
s.swap.from_.mint, s.swap.from_.amount, s.swap.to.mint, s.swap.to.amount)
def transfer_key(t: anaxer.TransferV1) -> tuple[str, ...]:
return (t.signature, t.wallet, t.transfer.from_, t.transfer.to,
t.transfer.mint, t.transfer.amount)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.
| Method | Returns |
|---|---|
| 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 |
| Method | Returns |
|---|---|
| client.tokens.get(mint) | TokenMetadataV1 |
| client.tokens.batch(mints) | list[TokenMetadataV1] (up to 50 mints) |
| client.tokens.price(mint) | RestPriceV1 (the stream price plus stale) |
| client.tokens.batch_price(mints) | list[RestPriceV1] (up to 100 mints) |
| client.tokens.trades(mint, **opts) | Page[SwapV1]: mint on either side |
| client.wallets.trades(wallet, **opts) / iter_trades | Page[SwapV1]: the wallet's trades |
| client.wallets.transfers(wallet, **opts) / iter_transfers | 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:
| Option | tokens.trades | wallets.trades | wallets.transfers | creations | graduations |
|---|---|---|---|---|---|
| source (one) or sources (≤ 20) | ✓ | ✓ | — | ✓ | ✓ |
| mints (≤ 100) | path | ✓ either side | ✓ | — | — |
| minVolumeUsd / maxVolumeUsd | ✓ | ✓ | ✓ | — | — |
| solOnly | ✓ | ✓ | — | — | — |
| direction ("in" / "out") | — | — | ✓ | — | — |
| excludeMayhem | — | — | — | ✓ | ✓ |
| minLiquiditySol | — | — | — | — | ✓ |
| Option | tokens.trades | wallets.trades | wallets.transfers | creations | graduations |
|---|---|---|---|---|---|
| source (one) or sources (≤ 20) | ✓ | ✓ | — | ✓ | ✓ |
| mints (≤ 100) | path | ✓ either side | ✓ | — | — |
| min_volume_usd / max_volume_usd | ✓ | ✓ | ✓ | — | — |
| sol_only | ✓ | ✓ | — | — | — |
| direction ("in" / "out") | — | — | ✓ | — | — |
| exclude_mayhem | — | — | — | ✓ | ✓ |
| min_liquidity_sol | — | — | — | — | ✓ |
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"],
});page = await client.wallets.transfers(
"5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh", direction="in", min_volume_usd=100
)
print(len(page.data), page.window)
# every page, fetched as you iterate
async for t in client.wallets.iter_transfers(
"5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh", direction="in", min_volume_usd=100
):
print(t.transfer.from_, t.transfer.ui_amount, t.transfer.symbol)
# a wallet's trades on two venues
trades = await client.wallets.trades(
"5G75aiNzTwpycR5c2AyfcYq2nxFLBYV4fyAjsTAeKihh", sources=["pump_fun", "pump_amm"]
)
# REST-only (no WebSocket): sync Client
sync = anaxer.Client(api_key="...")
meta = sync.tokens.get("DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263")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
});anaxer.connect(
api_key="...", # required
base_url="https://api.anaxer.com", # optional
# ws_url derived from base_url → wss://…/v1/stream
reconnect=True, # or False | anaxer.Reconnect(base_delay=0.5, max_delay=30.0, max_retries=None)
heartbeat_interval=15.0, # seconds
rest_max_retries=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
}
}import anaxer
from anaxer import AnaxerError
async with anaxer.connect(api_key="...") as client:
try:
await client.tokens.get(mint)
except AnaxerError as e:
if e.code == "not_found":
# mint never observed
passSee 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