Polling vs webhooks: how should a trading bot refresh token risk?
For token risk updates in a trading bot, use events to trigger a fetch, then refresh the report before each order. Poll only a small watchlist to save calls.
Onchain Report Newsroom#30c2a44 min read
A trading bot should use events to trigger risk report fetches, then fetch again just before an order; timed polling suits only a handful of tokens.
Say you watch 20 Solana tokens and poll every 60 seconds. That makes 28,800 calls a day, using the formula tokens × (86,400 ÷ poll interval in seconds). Almost all return unchanged data. A rugcheck reviews a token for warning signs, and the rugcheck API is a concrete example of the report-fetch step because it lets the bot request a risk report after a trigger.
How should a bot choose between polling and event triggers?
Provider webhooks can cut calls and latency by notifying your bot when a risk update is ready. They require a public HTTPS endpoint, plus duplicate-safe handling: retries can deliver the same event more than once, so the bot needs to avoid processing it twice.
When the provider has no webhooks, Solana RPC websockets can act as the trigger. Subscribe with accountSubscribe to the token’s mint account and the liquidity pool account, then call rugcheck when either changes. Revoking Mint authority or Freeze authority, and removing pool liquidity, involves on-chain writes to those accounts. An account update can therefore trigger a rescan even when the risk API itself sends no notification.
Keep the event as a signal to fetch, not as the final risk result. The update may be duplicated or arrive before your bot has processed the latest report. Store the event safely, make handling idempotent, and fetch current data when processing it. Always fetch the report again immediately before placing an order; the last pushed result may already be stale.
Compare two bots that use the same 60-second interval and polling setup. One watches four tokens and makes 5,760 calls a day; the other watches 20 and makes 28,800. The watchlist size changes the call budget, so polling can be practical for a handful of tokens while event-triggered fetches suit a larger list. Choose by call volume, latency and build effort: poll a small list, and trigger fetches from events as it grows.
Wire the trigger to a fresh fetch, then add the order-time check. That gives the bot timely updates while keeping the final decision based on a current report.
Related questions
How often should a bot refresh a cached risk report?
A bot should refresh a cached report when a subscribed account changes, then fetch again just before an order. If it has no event source, set a polling interval that fits the watchlist and API call budget.
What should a bot do when a webhook is missed?
A bot should reconcile its cached report with a fresh fetch after a missed or delayed webhook. Keep retries and duplicate events safe, and use a periodic reconciliation fetch to catch gaps.
What else should a bot check around webhook risk updates?
How do I verify that a webhook really came from the provider?
Verify the provider’s signature or authentication method before accepting a webhook, and reject requests that fail validation. Keep the endpoint on HTTPS and follow the provider’s instructions for checking signatures.
What should a bot do with open positions when a danger flag appears?
A bot should route the new flag through its position risk process, then apply the configured response for that position. The flag is a reason to reassess; the response depends on the bot’s rules.
How do I stay under a risk API's rate limit during a launch rush?
A bot should queue event-triggered fetches, deduplicate repeated updates, and spread retries instead of sending them all at once. Reserve capacity for the fresh fetch required before an order.