BlockSec Documents
  • 🚩About BlockSec
  • BlockSec Anti-MEV RPC
    • Bundle API
  • 🦅BlockSec Phalcon
    • Phalcon
    • Explorer
      • Quick Start
      • Debugger
      • Simulator
      • APIs
    • Security Incident List
  • 🕵️MetaSleuth
    • Overview
    • Phishing Attack
    • Avoid Being a Phishing Victim
  • Transaction Insights
    • Solana Swap Actions API
    • Transaction Simulation API
  • ⚒️MetaSuites
    • Overview
    • Fund Flow Graph
    • User Experience Enhancement
    • User-security Features
      • Approval Diagnosis
      • Address Labels and Compliance Score
    • Developer-Friendly Features
  • 🙌Community
    • Contacts
Powered by GitBook
On this page
  • Advantages
  • How to Use
  • Get supported protocols
  • Subscribe to DEX Swap Actions
  • Supported Protocols
  • Code Example
Export as PDF
  1. Transaction Insights

Solana Swap Actions API

Subscribe to DEX Swap Actions on Solana with One Single API

PreviousAvoid Being a Phishing VictimNextTransaction Simulation API

Last updated 24 days ago

Listening to Solana transactions and extracting swap actions is a challenging task for developers, as it requires a stable RPC connection and the ability to parse a transaction to understand the swap behavior across multiple DEX protocols. Furthermore, a single transaction can contain multiple swap actions from different DEX pools, adding to the complexity of the task.

BlockSec provides swap action APIs on Solana for developers. Users can subscribe to the WebSocket connection and receive detailed swap actions within a transaction. For example, users can subscribe to smart money accounts to track their swap actions and gain insights into their trading strategies.

Advantages

  • Real-Time Data Access: Enables real-time tracking of DEX swap actions, providing immediate updates through WebSocket connections.

  • Detailed Swap Information: Provides detailed data about individual DEX protocol actions, allowing for in-depth analysis of each swap.

  • Customizable Subscriptions: Users can subscribe to specific accounts and DEX protocols to tailor the data to their needs.

  • Support for Multiple DEX Protocols: , ensuring comprehensive data across different decentralized exchanges.

  • Easy Integration: Seamlessly integrates into user applications, allowing developers to easily track and analyze swap actions.

  • Scalable and Reliable: Built for scalability, ensuring stable data streams for high-volume applications.

How to Use

To use this API, you must to obtain an API key. After registering, log in to the dashboard to access your API key. The dashboard also shows the usage of the API.

Get supported protocols

Get a list of supported protocols.

GET https://api.blocksec.com/trade/api/v1/protocols

Response

{
  "code": 200,
  "data": {
    "protocols": [
      "jupiter_v6",
      "raydium_amm",
      "raydium_clmm",
      "raydium_cpmm",
      "raydium_launchpad",
      "pumpfun",
      "pumpfun_amm",
      "metaora",
      "metaora_dlmm",
      "metaora_damm_v2",
      ...
    ]
  }
}

Subscribe to DEX Swap Actions

Our API offers a WebSocket connection to subscribe to detailed DEX protocol actions for individual accounts. This means that whenever these accounts (signers) perform a swap in a DEX pool, the detailed information of the swap will be pushed to the WebSocket client.

WebSocket Endpoint

wss://api.blocksec.com/trade/solana?apiKey=API_KEY

Request

To subscribe to the WebSocket connection, you need to send the following data.

{
    "type": "SUBSCRIBE_SWAP",  
     "accounts": ["CyaE1VxvBrahnPWkqm5VsdCvyS2QmNht2UFrKJHga54o", 
     "EGTPP5dbJkoZRM1ahNM6fzYx1F2xSUcoUZ5WDrKKaMKy", 
     "C6GA4fZDTrxzqRh16F1XbGvYqodmgWT1JHCKHvKVnv8j"],
     "protocols": ["jupiter_v6",
            "raydium_clmm",
            "pumpfun", 
            "pumpfun_amm", 
            "raydium_amm"]
}
Name
Type
Description

type

String

Valid value: "SUBSCRIBE_SWAP" and "UNSUBSCRIBE_SWAP"

accounts

Array

The DEX actions of the accounts we want to listen to.

protocols

Array

The subscribed DEX protocols.

Response

For each subscribed account, if a DEX action occurs within the subscribed protocol, a message will be sent through the WebSocket connection. The following is an example of the response.

{
  "type": "SWAP",
  "data": {
    "signature": "4husz6dagdWSxFmmVYdyaZ6dvfRWRaCU5DthWwYxEQjX8rDwSwAqjKVWCELjniwKp36eYS3xdvepSBJKGcGgJVV1",
    "swap": {
      "user": "C6GA4fZDTrxzqRh16F1XbGvYqodmgWT1JHCKHvKVnv8j",
      "swaps": [
        {
          "protocol": "metaora",
          "address": "",
          "pool": {
            "market": "C729yEAn4cpTZf9fv8aii71avjsGCM6sKHMo3orhNE9n",
            "vault_in": "Fyt3uGVQRss4teveV2cNGjcp16C5aNdPYhxNjxVLaYva",
            "vault_out": "6oWCfmZG7whg5dxP9UyRynKRRMoaRQ2yh1aXabYoG3Dv"
          },
          "token_in": "So11111111111111111111111111111111111111112",
          "token_out": "",
          "amount_in": 632456442,
          "amount_out": 137366254421,
          "decimals_in": 9,
          "decimals_out": 6,
          "height": 2,
          "swaps": null
        },
        {
          "protocol": "pumpfun_amm",
          "address": "",
          "pool": {
            "market": "3F6ndV4bsDbcGzjc2myYAWLgKc4yjXEkvcPAWaMdjVjb",
            "vault_in": "v1KtuCqXFsBopdrNed51HpdSFY1Xb4MyLNS3c44ZYMp",
            "vault_out": "4Eqasnpi5YzWueyvhGp4Gfpu6PfUgbXBW4Hs5YprBF3A"
          },
          "token_in": "7APKDPK9KPXLdZH54GwT3q7PjMs1nwmFp8F3zV5Qpump",
          "token_out": "",
          "amount_in": 137366254421,
          "amount_out": 636917802,
          "decimals_in": 6,
          "decimals_out": 9,
          "height": 2,
          "swaps": null
        }
      ]
    }
  }
}

Field
Type
Description

type

String

Response type: Currently, the only expected value is "SWAP."

data.signature

String

The signature of the transaction.

data.swap.user

String

The user who signs the transaction.

data.swap.swaps

Array of swap

The swap actions involved in this transaction. Since multiple swap actions may occur within a single transaction, this is represented as an array.

The Swap structure

Field
Type
Description

protocol

String

The protocol of the swap.

address

String

The protocol's contract address.

pool.market

String

The DEX pool's address involved in this swap. (Optional)

pool.vault_in

String

The address of the vault that provides the input token for the swap. (Optional)

pool.vault_out

String

The address of the vault that receives the output token from the swap. (Optional)

token_in

String

The address of the input token in the swap.

token_out

String

The address of the output token in the swap.

amount_in

Integer

The amount of the input token in the swap.

amount_out

Integer

The amount of the output token in the swap.

decimals_in

Integer

The decimal of the input token in the swap.

decimals_out

Integer

The decimal of the output token in the swap.

height

Integer

The position of the swap instruction in the call stack, starting from 1.

Supported Protocols

The table lists the supported protocol (48 in total) and contact us (contract@blocksec.com) if you found some protocols are missing.

Protocol Name used in API
Address
Reference

jupiter_v6

JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4

perps

PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu

raydium_amm

675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8

raydium_clmm

CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK

raydium_cpmm

CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C

raydium_launchpad

LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj

pumpfun

6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P

pumpfun_amm

pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA

metaora

Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB

metaora_dlmm

LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo

metaora_damm_v2

cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG

lifinity_v2

2wT8Yq49kHgDzXuPxZSaeLaH1qbmGXtEyPy64bL7aD3c

orca_v1

DjVE6JNiYqPL2QXyCUUh8rNjHrbz9hXHNYt99MQ59qw1

orca_v2

9W959DqEETiGZocYWCQPaJ6sBmUzgfxXfqGeTEdp3aQP

whirlpool

whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc

flip

6LDad2GqEzvdCRA6DzTfqgRQGjFrQKndzdtRX6HEcTBf

saber

SSwpkEEcbUqx4vtoEByFjSkhKdCT862DNVb52nZg1UZ

saber_decimals

DecZY86MU5Gj7kppfUCEmd4LbXXuyZH1yHaP2NTqdiZB

zerofi

ZERor4xhbUycZ6gb9ntrhqscUcZmAbQDjEAtCf4hbZY

stabble_stable

swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ

stabble_weighted

swapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW

solfi

SoLFiHG9TfgtdUXUjWAxi3LtvYuFyDLVhBWxdMZxyCe

moonshot

MoonCVVNZFSYkqNXP6bxHLPL6QQJiMagDL3qcqUQTrG

invariant

HyaB3W9q6XdA5xwpU4XnSZV94htfmbmqJXZcEbRaJutt

phoenix

PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY

bonkswap

BSwp6bEBihVLdqJRKGgzjcGLHkcTuzmSo1TQkHepzH8p

fluxbeam

FLUXubRmkEi2q6K3Y9kBPg9248ggaZVsoSFhtJHSrm1X

crema

CLMM9tUoggJu2wagPkkqs9eFG4BWhVBZWkP1qv3Sp7tR

cropper

H8W3ctz92svYg6mkn1UtGfu2aQr2fnUFHM1RhScEtQDt

stepn

Dooar9JkhdZ7J3LHN3A7YCuoGRUggXhQaG4kijfLGU2j

1dex

DEXYosS6oEGvk8uCDayvwEZz4qEyDJRf9nFgYCaqPMTm

virtuals

5U3EU2ubXtK84QcRjWVmYt9RaDyA8gKxdUrPFXmZyaki

token_swap

SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8

sanctum

5ocnV1qiCgaQR8Jb8xWnVbApfaygJ8tNoZfgPwsgx9kx

sanctum_router

stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq

obric_v2

obriQD1zbpyLz95G5n7nJe6a4DPjpFwa5XYPoNm113y

saros

SSwapUtytfBdBn1b9NUGG6foMVPtcWgpRU32HToDUZr

guac

Gswppe6ERWKpUTXvRPfXdzHhiCyJvLadVvXGfdpBqcE1

aldrin

AMM55ShdkoGRB5jVYPjWziwk8m5MpwyDgsMWHaMSQWH6

aldrin_v2

CURVGoZn8zycx6FXwwevgBTB2gVvdbGTEpvMJDbgs2t4

openbook_v2

opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb

dexlab

DSwpgjMvXhtGn6BsbqmacdBZyfLj6jSWf3HJpdJtmg6N

helium

treaf4wWBBty3fHdyBpo35Mz84M8k3heKXmjmi9vFt5

penguin

PSwapMdSai8tjrEXcxFeQth87xC4rRsa4VA5mhGhXkP

token_mill

JoeaRXgtME3jAoz5WuFXGEndfv4NPH9nBxsLq44hk9J

solayer

endoLNCKTqDn8gSVnN2hDdpgACUPWHZTwoYnnMybpAT

marcopolo

9tKE7Mbmj4mxDjWatikzGAtkoWosiiZX9y6J4Hfm2R8H

daofun

5jnapfrAN47UYkLkEf7HnprPPBCQLvkYWGZDeKkaP5hv

mercurial

MERLuDFBMmsHnsBPZw2sDQZHvXFMwp8EdjudcU2HKky

Code Example

The following shows a Python example of using the API.

import websockets
import asyncio
from websockets_proxy import Proxy, proxy_connect
import json

accounts = ["CyaE1VxvBrahnPWkqm5VsdCvyS2QmNht2UFrKJHga54o", 
     "EGTPP5dbJkoZRM1ahNM6fzYx1F2xSUcoUZ5WDrKKaMKy", 
     "C6GA4fZDTrxzqRh16F1XbGvYqodmgWT1JHCKHvKVnv8j"]

protocols = ["jupiter_v6",
            "raydium_clmm",
            "pumpfun", 
            "pumpfun_amm", 
            "raydium_amm", 
            "raydium_cpmm",
            "whirlpool",
            "lifinity_v2",
            "metaora",
            "metaora_dlmm"]

send_data = {
    "type": "SUBSCRIBE_SWAP",  
     "accounts": accounts,
     "protocols": protocols
}

# without socks proxy
async def subscribe_to_websocket_no_proxy():
    # change the API_KEY to your own
    uri = "wss://api.blocksec.com/trade/solana?apiKey=API_KEY"
    try:
        async with websockets.connect(uri) as websocket:
            await websocket.send(json.dumps(send_data))  # Send initial subscription message
            print ("connected!")
            while True:
                message = await websocket.recv()
                print(f"Received message: {message}")
    except Exception as e:
        print(f"Connection error: {e}")

# with socks proxy
async def subscribe_to_websocket_proxy():
    # change to your own socks proxy
    proxy = Proxy.from_url('socks5://127.0.0.1:1086')
    # change the API_KEY to your own
    uri = "wss://api.blocksec.com/trade/solana?apiKey=API_KEY"
    try:
        async with proxy_connect(uri, proxy=proxy) as websocket:
            await websocket.send(json.dumps(send_data))  # Send initial subscription message
            print ("connected!")
            while True:
                message = await websocket.recv()
                print(f"Received message: {message}")
    except Exception as e:
        print(f"Connection error: {e}")

if __name__ == "__main__":
    # asyncio.run(subscribe_to_websocket_proxy())
    asyncio.run(subscribe_to_websocket_no_proxy())

https://jup.ag/
https://jup.ag/
https://raydium.io/
https://raydium.io/
https://raydium.io/
https://raydium.io/
https://pump.fun/
https://pump.fun/
https://www.meteora.ag/
https://www.meteora.ag/
https://www.meteora.ag/
https://lifinity.io/
https://www.orca.so/
https://www.orca.so/
https://www.orca.so/
https://app.saber.so/swap
https://app.saber.so/swap
http://stabble.org/
http://stabble.org/
https://moonshot.money/
https://invariant.app/
https://www.phoenix.trade/
https://www.bonkswap.io/
https://fluxbeam.xyz/
https://www.crema.finance/
https://app.cropper.finance/
https://www.stepn.com/
https://onedex.app/
https://app.virtuals.io/
https://app.sanctum.so/
https://app.sanctum.so/
https://dex.saros.xyz/
https://guac.gg/
https://www.openbook.ag/
https://www.dexlab.space/
https://www.helium.com/
https://png.fi/
https://solayer.org/
https://www.daos.fun/
https://www.meteora.ag/
register an account
Covers more than 45 DEX protocols