api-pump.fun
  • General
    • Getting started
  • Reference
    • API Reference
      • Generate API Key
      • Balance
      • Token information
      • Get Quote
      • Bonding Curve
      • King of The Hill
      • Trade tokens
      • Trade tokens [local RPC]
      • Create token
  • Streams
    • Websocket subscription
Powered by GitBook
On this page
  • Available streams
  • Methods
  • Examples
  1. Streams

Websocket subscription

Streams are available with Websocket. Subscriptions are created using the RPC call subscribe with the stream (feed) name and subscription options set as parameters. Each stream has a different subscription name and can accept different subscription options. Please refer to the specific stream page for info

Available streams

NewPools New pools (tokens) creation

Trades New trades on pump.fun

Token New trades for specified token

Account New trades for specified account

Publications Publications tokens on Raydium

Methods

To subscribe to the stream, you need to specify the action "subscribe" and stream type.

subscribeNewPools New pools (tokens) creation

subscribeTrades New trades on pump.fun

subscribeToken New trades for specified token (to specify the token, fill the array params)

subscribeAccount New trades for specified account (to specify the account, fill the array params)

subscribePublications Publications tokens on Raydium

To unsubscribe from the stream, you need to specify the action "unsubscribe" and stream type.

unsubscribeNewPools New pools (tokens) creation

unsubscribeTrades New trades on pump.fun

unsubscribeToken New trades for specified token

unsubscribeAccount New trades for specified account

unsubscribePublications Publications tokens on Raydium

Examples

package main

import (
    "encoding/json"
    "log"
    "github.com/gorilla/websocket"
)

func main() {
    ws, _, err := websocket.DefaultDialer.Dial("wss://rpc.api-pump.fun/ws", nil)
    if err != nil {
        log.Fatal("Dial error:", err)
    }
    defer ws.Close()

    payload := map[string]interface{}{
        "method": "subscribeTrades",
        "params": []interface{}{},
    }
    if err := ws.WriteJSON(payload); err != nil {
        log.Println("WriteJSON error:", err)
        return
    }

    payload = map[string]interface{}{
        "method": "subscribeNewPools",
        "keys":   []interface{}{},
    }
    if err := ws.WriteJSON(payload); err != nil {
        log.Println("WriteJSON error:", err)
        return
    }

    payload = map[string]interface{}{
        "method": "subscribeToken",
        "params": []interface{}{"8LPjGAPtCywvo51UACHxDg3ygzbrm9qi2XxhB2Ropump"},
    }
    if err := ws.WriteJSON(payload); err != nil {
        log.Println("WriteJSON error:", err)
        return
    }

    for {
        _, message, err := ws.ReadMessage()
        if err != nil {
            log.Println("ReadMessage error:", err)
            return
        }
        var data map[string]interface{}
        if err := json.Unmarshal(message, &data); err != nil {
            log.Println("Unmarshal error:", err)
            return
        }
        log.Println(data)
    }
}
import WebSocket from 'ws';

const ws = new WebSocket('wss://rpc.api-pump.fun/ws');  

ws.on('open', function open() {

      // Subscribing to all pump.fun trades
      payload = {
          method: "subscribeTrades",
          params: []
        }
      ws.send(JSON.stringify(payload));

      // Subscribing to new pools
      payload = {
          method: "subscribeNewPools",
          params: []
        }
      ws.send(JSON.stringify(payload));

     // Subscribing to trades on specific mint
      payload = {
          method: "subscribeToken",
          params: ["8LPjGAPtCywvo51UACHxDg3ygzbrm9qi2XxhB2Ropump"]
        }
      ws.send(JSON.stringify(payload));
});

ws.on('message', function message(data) {
      console.log(JSON.parse(data));
});
import websocket
import json

def on_open(ws):
    payload = {
        "method": "subscribeTrades",
        "params": []
    }
    ws.send(json.dumps(payload))

    payload = {
        "method": "subscribeNewPools",
        "params": []
    }
    ws.send(json.dumps(payload))

    payload = {
        "method": "subscribeToken",
        "params": ["8LPjGAPtCywvo51UACHxDg3ygzbrm9qi2XxhB2Ropump"]
    }
    ws.send(json.dumps(payload))

def on_message(ws, message):
    data = json.loads(message)
    print(data)

def on_error(ws, error):
    print(error)

def on_close(ws, close_status_code, close_msg):
    print("Connection closed")

if __name__ == "__main__":
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("wss://rpc.api-pump.fun/ws",
                                on_open=on_open,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.run_forever()
PreviousStreams

Last updated 10 months ago