SDK reference

SDK reference

Every public @agg-build/sdk method, the HTTP operation it calls, and its API reference page

@agg-build/sdk is a thin client over the REST API. Each method below calls one HTTP operation. Follow the link for the full request and response schema.

import { createAggClient } from "@agg-build/sdk";

const client = createAggClient({
  baseUrl: "https://api.t.sufwankhalid.com",
  appId: "your-app-id",
});

createAggClient() returns an AggClient. It adds the x-app-id and Authorization headers for you and keeps the user's session. See Base URL, app IDs & API keys for the base URL and Quickstart: REST for a full trade.

Auth

MethodHTTPReference
authStart()POST /auth/startStart authentication
startAuth()Alias of authStart()Start authentication
buildSiweMessage()None. Builds the EIP-4361 message locallyQuickstart: REST
buildSiwsMessage()None. Builds the Solana sign-in message locallyQuickstart: REST
verify()POST /auth/verifyVerify sign-in
verifySignIn()Alias of verify()Verify sign-in
exchangeAuthCode()POST /auth/token/exchangeComplete redirect sign-in
refreshAccessToken()POST /auth/token/refreshRefresh access token
signOut()POST /auth/sign-outSign out
setSession()None. Stores tokens from a redirect callbackAuthentication
setAccessToken()None. Replaces the stored access tokenAuthentication
clearAccessToken()None. Clears the local sessionAuthentication
onAuthStateChange()None. Subscribes to sign-in and sign-outAuthentication

Read-only session properties: isAuthenticated, authStatus, user, address, appId.

Users

MethodHTTPReference
getCurrentUser()GET /users/meGet current user
updateUser()PATCH /users/meUpdate username
linkExternalId()POST /users/me/external-idLink partner external user ID
createAvatarUploadUrl()POST /users/me/avatarGet avatar upload URL
linkAccount()POST /users/me/link-account/startStart account linking
linkAccountConfirm()POST /users/me/link-account/confirmConfirm account linking
disconnectAccount()DELETE /users/me/accounts/{provider}Disconnect auth provider
getSharedKycStatus()GET /kyc/statusGet shared KYC status
initiateKyc()POST /kyc/{venue}Initiate KYC
upsertVenueKey()PUT /venue-keysUpsert a venue API key
listVenueKeys()GET /venue-keysList venue keys
getVenueKeyStatus()GET /venue-keys/{venue}/statusGet venue key connection status
deleteVenueKey()DELETE /venue-keys/{venue}Delete a venue key

Markets

MethodHTTPReference
search()GET /searchSearch events or markets
getVenueEvents()GET /venue-eventsList venue events
getVenueEventById()GET /venue-events/{id}Get venue event
getEventBootstrap()GET /venue-events/{id}/bootstrapGet the first useful event view
getVenueMarkets()GET /venue-marketsList venue markets
getCategories()GET /categoriesList categories
getCatalogChanges()GET /catalog/changes. One page; pass nextCursor back until hasMore is false. A 410 is isCatalogResyncRequired(err)List catalog changes
listRecurringCryptoMarkets()GET /crypto/recurring-marketsList recurring crypto window markets
getAppConfig()GET /app/config. Public UI config for this appGet the per-app UI config
getNewsFeeds()GET /news-feedList available news feeds
getNewsFeed()GET /news-feed/{category}Article-centric news feed
getNewsFeedMarkets()GET /news-feed/{category}/marketsMarket-centric news feed
getMarketNews()POST /news-feed/market-newsNews for markets
getMarketCorrelatedSignals()GET /correlated-markets/{venueMarketId}Correlated market signals
queryCorrelatedMarkets()POST /correlated-markets/queryFind correlated markets
getCorrelatedMarketCascade()GET /correlated-markets/cascade/{venueMarketId}Ripple effect of a resolution
resolveCorrelatedMarkets()POST /correlated-markets/resolveResolve a market and return cascade

GET /venue-market-outcomes has no dedicated method. Call it with request(). See Look up venue market outcomes by external identifier.

Market data

MethodHTTPReference
getOutcomeOrderbooks()GET /orderbooks/outcomesGet bounded outcome snapshots
getOrderbooks()GET /orderbooksGet live orderbooks
getOutcomeOrderbook()GET /orderbook/outcome/{outcomeId}Get live orderbook for one outcome
getMidpoints()GET /midpointsGet live midpoints
getChartBars()GET /charts/barsGet chart bars
getChartHistoryManifest()GET /charts/history/manifestGet versioned chart history references
getCryptoReferencePrices()POST /crypto/reference-pricesGet live crypto reference prices
getSportsLive()GET /sports/liveGet live sports scores

Trading

MethodHTTPReference
getSmartRoute()GET /orderbook/{venueMarketOutcomeId}/routeGet a quote
executeManaged()POST /execution/fillExecute quote
fillSelfCustody()POST /execution/fill, then polls status and submits signaturesSelf-custody trading
submitFillSignatures()POST /execution/fill/{quoteId}/signaturesSubmit signatures
getExecutionStatus()GET /execution/statusGet execution status
placeOrder()POST /execution/ordersPlace an order directly
placeLimitOrder()POST /execution/limit-ordersPlace limit order
cancelManagedOrder()POST /execution/orders/cancel with orderIdCancel an order
cancelVenueOrder()POST /execution/orders/cancel for an order placed outside sufwan-local-testCancel an order
redeem()POST /execution/redeemRedeem winnings
redeemSelfCustody()Sell quote on a resolved market, then fillSelfCustody()Self-custody trading
getVenueGeoPolicy()GET /app/venue-geo-policyPer-venue blocked countries

Portfolio

MethodHTTPReference
getManagedBalances()GET /execution/balancesGet balances
getPositions()GET /execution/positionsGet user positions
getExecutionPositions()GET /execution/positions with cursor paginationGet user positions
getExecutionOrders()GET /execution/ordersGet user orders
getUserActivity()GET /users/activityGet user activity feed
getLeaderboard()GET /leaderboardTrader leaderboard
getLeaderboardSeries()GET /leaderboard/seriesTrader leaderboard series

Funding

MethodHTTPReference
getDepositAddresses()GET /execution/deposit-addressesGet deposit addresses
getWithdrawalQuote()POST /execution/withdrawable/quoteQuote withdrawable amount
withdrawPreview()POST /execution/withdraw/previewPreview a withdrawal
withdrawManaged()POST /execution/withdrawWithdraw funds
getWithdrawalStatus()GET /execution/withdrawals/{withdrawalId}Get withdrawal status
submitWithdrawalSignatures()POST /execution/withdrawals/{withdrawalId}/signaturesSubmit withdrawal signatures
getBalanceRefillPolicies()GET /execution/balance-refill-policiesList refill policies
createBalanceRefillPolicy()POST /execution/balance-refill-policiesCreate a refill policy
updateBalanceRefillPolicy()PATCH /execution/balance-refill-policies/{policyId}Update or pause a refill policy
getBalanceRefillAttempts()GET /execution/balance-refill-policies/{policyId}/attemptsList refill attempts
getRampQuotes()POST /ramp/quotesGet crypto purchase quotes
createRampSession()POST /ramp/sessionCreate a ramp widget session
getHostedVenueAccount()GET /users/me/venue-accounts/{venue}Get hosted venue account
provisionHostedVenueAccount()POST /users/me/venue-accounts/{venue}Provision hosted venue account
getHostedVenueActivity()GET /users/me/venue-accounts/{venue}/activityGet hosted venue account activity
getHostedVenueDepositAddress()GET /users/me/venue-accounts/{venue}/deposit-addressGet hosted venue deposit address
withdrawHostedVenue()POST /users/me/venue-accounts/{venue}/withdrawalsWithdraw hosted venue funds
getHostedVenueWithdrawal()GET /users/me/venue-accounts/{venue}/withdrawals/{withdrawalId}Get hosted venue withdrawal

Paper trading

mode: "paper" on getSmartRoute() / executeManaged() is the user path (user JWT plus x-app-id). The methods below are the admin path. They call /apps/{appId}/paper-trading/... and need a server-side x-app-api-key. See Paper trading.

MethodHTTPReference
createPaperTradingAccount()POST .../accountsCreate a paper trading account
listPaperTradingAccounts()GET .../accountsList paper trading accounts
getPaperTradingAccount()GET .../accounts/{accountId}Get a paper trading account
setPaperTradingBalance()PATCH .../accounts/{accountId}/balanceSet a paper account cash balance
resetPaperTradingAccount()POST .../accounts/{accountId}/resetReset a paper trading account
placePaperTradingOrder()POST .../accounts/{accountId}/ordersPlace a paper trading order
listPaperTradingOrders()GET .../accounts/{accountId}/ordersList paper trading orders
listPaperTradingPositions()GET .../accounts/{accountId}/positionsList paper trading positions
getPaperTradingPortfolio()GET .../accounts/{accountId}/portfolioGet a paper trading portfolio

Real-time

MethodHTTPReference
createWebSocket()WebSocket. Needs wsUrl in the client options. Runs the 5-minute book watchdog unless bookWatchdog: false. Server-side with apiKey, authenticates the handshake with x-app-api-key; pass webSocketImpl on runtimes without a global WebSocket. Resumes user events after reconnectsReal-Time Orderbook, Server connections
socket.subscribeAppEvents(cb)Every user event of the app, on an API-key connection. Returns an unsubscribe functionApp events
watchCatalog()catalog channel plus GET /catalog/changes catch-up on every (re)subscribe and interruption. Calls onChange once per newer entity state. Returns { stop(), lastChangedAt, resync(since), ready }. Needs wsUrl unless you pass socketCatalog Sync
socket.subscribeCatalog(filter, cb, { onSubscribed, onInterrupted })Live catalog_change frames only, no catch-up. onSubscribed fires on every confirmed (re)subscribe and onInterrupted on a catalog stream interruption: catch up over REST on both. Returns an unsubscribe functionCatalog feed

Utilities

MethodWhat it does
request()Calls any path with the client's headers. Retries once after a token refresh on 401
destroy()Releases browser resources. Safe to call more than once

Not in the public API reference

These methods exist in the SDK but call routes that are not part of the public API reference. They may change without notice. Do not build on them.

getOrders(), getUserHoldings(), getRpcToken(), getNewsFeedStatus(), getCorrelatedMarketsStatus(), recordDepositIntent(), syncManagedBalances(). syncManagedBalances() is not a public route. Do not call POST /execution/sync-balances.

Server module

@agg-build/sdk/server is for your backend only. It uses your app's x-app-api-key, which must never reach a browser.

import { AggAdminClient, verifyWebhook } from "@agg-build/sdk/server";

const admin = new AggAdminClient({
  baseUrl: "https://api.t.sufwankhalid.com",
  apiKey: process.env.AGG_APP_API_KEY!,
});

Webhooks and partner admin (AggAdminClient)

MethodHTTPReference
listUsers()GET /apps/{appId}/usersList users
getUser()GET /apps/{appId}/users/{userId}Get user
listOrders()GET /apps/{appId}/ordersList orders across your app
getAnalytics()GET /apps/{appId}/analyticsGet analytics
listMarketResolutionUsers()GET /apps/{appId}/market-resolutions/{venueMarketId}/usersUsers affected by a resolution
rotateWebhookSecret()POST /apps/{appId}/webhooks/{webhookId}/rotate-secretRotate webhook signing secret
replayWebhookDeliveries()POST /apps/{appId}/webhooks/{webhookId}/replayReplay failed deliveries

AggAdminClient also has request() for any other partner-admin route.

Helper functions

FunctionWhat it doesGuide
verifyWebhook()Checks a delivery's signature and timestamp. Throws if either is invalidVerifying webhook signatures
verifyWebhookAsync()Same as verifyWebhook(), for edge runtimes (Web Crypto)Verifying webhook signatures
parseWebhookEvent()Verifies the delivery, then returns it as a typed eventWebhook event reference
parseWebhookEventAsync()Same as parseWebhookEvent(), for edge runtimes (Web Crypto)Webhook event reference
signExternalId()Signs your internal user ID for external ID linkingExternal ID linking

On this page