Integrating a Trading Bot with Raydium SDK (Solana)

A trading bot in fast markets loses trades due to poor routes and retries. We set up Raydium integration turnkey: we build execution logic, add retries on failures, and control latency. The share of lost trades drops, and bot behavior under load becomes predictable.

Blockchain Development Services

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1376
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1350
  • B2B Advance company logo design
    B2B Advance company logo design
    798
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1089
  • AIDER company logo development
    AIDER company logo development
    1034
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1130

Why a trading bot loses trades on Raydium SDK

A trading bot on Raydium SDK loses trades not because of strategy, but at the execution stage: the signal fired, the transaction went out — and was not confirmed.

The cause is three bottlenecks that appear only in a live market: an outdated quote, confirmation failure, and an overflowing send queue. Individually, these are isolated cases; in sum, they are a systematic discrepancy between calculated and actual profitability.

At peak pool volatility, reserves manage to change between route calculation and transaction signing. The bot sends a swap at a price that no longer exists: the slippage limit triggers, and an execution error arrives instead of a trade.

The sharper the move, the more often the quote becomes outdated in the fractions of a second spent on assembly and signing.

The second failure point is confirmation. The transaction goes to the network but does not get into a block: the fee turned out to be below the current one, or a duplicate with the same counter was sent.

While the bot waits for confirmation, the send queue grows, and parallel attempts displace its own transactions.

The third is retries without analyzing the previous transaction. This produces double execution or a complete missed entry: one trade is confirmed twice, the second does not go through at all.

We break down how this is closed at the integration level: quote recalculation before signing, queue and fee priority management, idempotent retries, and explicit failure handling.

What changes after integration: routes, failures, delays

Integration changes not the interface, but what the bot actually sees at the input. Previously it sent an order and hoped that execution would match expectations; now the swap route is assembled from the current state of the pools, and price deviation is caught before sending. Let us break down the effect along two measurable lines.

Share of executed trades and slippage control

The bot builds a route using fresh reserves and sets an allowable slippage boundary in advance: a trade either goes through within these limits or is not sent at all. Orders that were executed at a price that was no longer on the market disappear from the sample.

The share of successfully executed orders grows, and instead of analyzing "why it slipped," there is a clear setting — how much price we are willing to give up on the route and at what deviation we simply abandon the entry.

Eliminated class of failures and recovery speed

The main eliminated class of failures is working from an outdated pool state: the route is assembled, by the time of sending the reserves have changed, and the order goes out in vain. Re-checking and rebuilding the route before sending close this scenario entirely.

If a node is unavailable or the pool changes sharply, the bot does not stop or hang — it rebuilds the route and returns to work within seconds, without a manual restart.

A benchmark for resilience is the public pools of Raydium: under a continuous stream of third-party arbitrage, they remain operational and return a consistent state. A bot that reads them directly and verifies data before a trade behaves just as predictably.

Connection options: comparing approaches and boundaries

A pool is not a single contract, but a bundle of a program, a state account, and token vaults. There are several ways to reach them, and the difference is not convenience, but how much control over the trade you keep for yourself and how much maintenance the team takes on.

The strategy dictates what to choose: whether you need your own route logic, whether time to block inclusion is critical, who is responsible for failures when slots are scarce, and how quickly you are ready to fix the integration after a pool program update.

Option When it fits Limitations
Direct pool program call Own routing strategy, full control over the set of instructions is needed Account parsing, fees, and output calculation are on your side
Wrapper with route aggregation Best price across several pools is needed without your own logic The route is chosen by an external service, influence over trade composition is limited
Your own pool state indexer Depth metrics, trade history, and event triggers are needed A separate circuit: nodes, storage, catch-up after a missed block

Direct pool program calls

Here swap instructions are assembled manually for a specific pool: you calculate how many tokens go in and what minimum to set on output. The pool fee and rounding are visible locally, so a discrepancy with the actual balance is caught before sending, not after.

The price for this is your own validation layer: a change in the account format breaks assembly, and the team bears full support for such an integration.

Ready-made wrappers with route aggregation

Libraries at the level of Raydium SDK and external aggregators find the path between pools themselves and return a ready set of instructions. This is a fast start and less code to maintain: the provider takes on updating the data format.

The limitation is that you do not control which specific pool the trade goes through and depend on the availability of a third-party service.

Stages of integrating a trading bot with Raydium SDK

Integration of a trading bot with Raydium SDK almost never breaks at the "connect and trade" stage. Failures hide in execution routes, node limits, and transaction failure handling, and they show up on real trades.

We structure the integration stages so that each step removes its own class of failures before going live on the main account.

  1. Connection audit. We break down how the bot receives market data and sends transactions: which nodes are involved, whether there are backups, how keys are stored, what the request rate and retries are like. Most often the bottleneck is a single node without redundancy.
  2. Route scheme. We fix the pairs and pools through which trades will go: direct swap or via an intermediate asset, what liquidity depth there is, where the route loses on fees.
  3. Slippage protection. We set the allowable price deviation threshold, priority fee, and behavior on failure — retry along a new route or cancel. Otherwise, a rare trade eats up the result of a dozen successful ones.
  4. Test validation. First a run on historical data, then small volumes on the mainnet: we compare calculated execution with actual and correct discrepancies.
  5. Handover to maintenance. We provide the configuration, monitoring panel, failure notifications, and key rotation procedure, and fix the sequence of actions during node degradation.

Each stage is closed with an artifact: a scheme, configuration files, a run report. Any step can be revisited separately without rebuilding the bot entirely.

What we hand over: configurations, schemes, procedures

An integration cannot be considered delivered until the client's team can operate it without the author. Therefore, at the final stage we hand over not only code, but also a set of artifacts by which the circuit can be raised, configured, and rolled back on their own.

  • Connection configurations — node addresses, access rights, separation of test and production profiles, key rotation procedure.
  • Trade route scheme — from signal to signing and sending, with marked points where delay or failure is possible.
  • Limit rules — maximum position size, daily turnover, allowable slippage, auto-pause after a series of failed sends.
  • Integration documentation — methods, request formats, breakdown of node and pool error codes.
  • Update procedure — what changes and in what order when dependencies and program addresses are updated.
  • Rollback procedure — which switches return the previous state and who confirms the action.
  • Metrics and alerts — a set of indicators, trigger thresholds, notification channel, and responsible engineer.

Integration documentation

We describe not only the normal scenario, but also behavior during failure: which codes the node returns, what is considered a temporary error, where we repeat the request, and where we stop trading.

We verify the document on a live stand — the client's engineer goes through it independently, and we correct anything that turned out ambiguous.

Update procedure and rollback

Changes go through the test circuit: first a run on historical data and a small volume, then switching. Rollback is a known-in-advance sequence: restore the configuration, stop sending, restore the previous route. We record the time for the procedure and confirm it in drills.

What to do if the bot is already connected directly to the pool?

A direct connection to the pool is not a dead end: the bot's own contract does not change, only the execution layer changes. We raise the new route alongside in mirroring mode — it reads the same pool state and calculates quotes, but does not send orders yet. The discrepancy in prices and fees becomes visible before a real position is at risk.

Migration option When it fits Limitations
Parallel launch with decision mirroring Frequent trades, discrepancy statistics needed Both circuits work with one wallet — transaction sending synchronization is needed
Migration by pairs or strategies The bot trades several instruments independently Separate reporting is required for each circuit
One-time switch during a low-activity window One strategy with simple entry rules A pause is possible during the switch — fast rollback is needed

Backward compatibility rests on a configuration flag: the old path to the pool remains in the code and is enabled without rebuilding. The strategy interface does not change — the same signals, the same position format, so entry logic and risk limits carry over without edits.

Migration order: raise the mirror circuit, compare quote discrepancies, migrate one pair, record the result, and only then switch the rest.

A public benchmark for pauses is provided by Raydium materials: on liquid pairs, a downtime of a few seconds already affects slippage, so the goal is a transition without stopping trading, not a "quick" downtime window.

We design rollback in advance: positions live in the wallet, not inside the layer, so returning to a direct connection is a flag change and restart, without closing trades. If the quote discrepancy exceeds a set threshold, automation returns the old route by itself.

Case study: arbitrage bot, metrics before and after rework

The task came from a team that traded through Raydium pools. The bot sent transactions on a timer without checking the actual pool state: as soon as liquidity in one of them disappeared, some sends came back with an error.

The on-call person analyzed each such case manually — that is exactly what caused the main downtime.

State before the work

The share of executed trades held at around 61%, and one successful trade accounted for 6-8 repeated sends. The retry logic lived in a loop without a shared queue, so during a spike in failures the bot duplicated already sent transactions and inflated the load on the node.

A pool failure or node restart stopped trading for 4-6 minutes: until the operator restarted the process and manually checked balances, the bot stayed silent.

After delivery

Sending was moved to a subscription for pool state changes, and retries into a queue with a trade key: a duplicate is discarded rather than sent a second time.

Confirmation checking and error parsing became automatic, with a configurable number of attempts and a log for each trade.

The share of executed trades grew to 94%, repeated sends dropped to 1-2 per trade, and recovery after a pool failure takes 20-30 seconds without human involvement.

We separately put the failure rate, queue depth, and time to confirmation into monitoring — pool degradation is visible before it stops trading.

Technical concerns before starting integration

Integration of a trading bot with Raydium SDK begins with answers to the five most frequently asked questions. Below is how the system behaves during sharp price movements, connection loss, how the actual trade price is verified, and how access is transferred.

Will the bot react in time during a sharp price movement?

We keep several independent quote sources and check their freshness before sending an order. If the price leaves the specified corridor, the order is not sent — the pre-selected policy triggers: pause, cancel, or wait for a pullback.

The bot runs around the clock — what happens during a connection loss?

The process runs as a service with auto-restart, and trade state is stored separately and restored after a failure. When the connection is lost, outdated orders are not sent later: the system reconciles positions with the exchange and continues from the current state.

How can we be sure the execution price matches the expected one?

Before sending, we calculate the expected price taking fees and slippage into account; after, we compare it with the actual price from the exchange response.

Discrepancies are written to the log with context, so it is clear where the result is lost: in calculation, delay, or liquidity.

Will we have to rewrite the logic if we change the strategy?

Signal calculation, risk rules, and execution are separated, so a new strategy connects as a separate module. Validation, logging, and error protection remain and work with it without rework.

How are access rights and keys transferred?

Keys are transferred over a secure channel and stored encrypted; they do not get into the repository. We grant minimal rights — trading without withdrawal of funds; when work is completed, access is revoked and changed.

Let us discuss the task: we will return with an estimate, plan, and scheme

We start work with an analysis of the task, not with code: we need to understand what the bot does on the market, which pairs and volumes interest it, and how it behaves during a sharp price movement.

The architecture depends on the answers — where to store position state, whether to keep keys on the bot side, and how to recover after a connection loss with a network node.

To return with an estimate of the work and an integration plan, we need the minimum from the client:

  • Access to Raydium SDK: a read-only key and a node address for the test circuit;
  • Description of trading logic: pairs, entry and exit conditions, slippage and fee limits;
  • Current code or its absence — what we reuse and what we write from scratch;
  • Environment: where the bot will run, what requirements there are for monitoring and failure alerts;
  • The person responsible for acceptance and the procedure for approving edits on your side;
  • Constraints: jurisdiction, logging requirements, who owns the keys and how we rotate them.

The work order is as follows: logic analysis, an integration plan broken into stages, a prototype on a test wallet, a run on historical data, launch with a limited volume, and scaling to production limits.

Each stage ends with a demonstration and a rollback point — you can return one step back without losing what has already been done.

In response, we send an estimate by stage, an integration plan with timelines and dependencies, a component interaction scheme, and a list of risks with how we close them. Describe the task — we will return with an estimate and a plan.