Fast. Focused. Efficient.

Crypto Trading Sniper

Crypto Trading Sniper

Listen's. React's. Profit's.

Listen's. React's. Profit's.

High-Performance Execution with Golang

High-Performance Execution with Golang

High-Performance Execution with Golang

Golang was chosen for its concurrency and low-latency capabilities, ensuring the trading bot operates swiftly in a fast-paced crypto environment.

Golang was chosen for its concurrency and low-latency capabilities, ensuring the trading bot operates swiftly in a fast-paced crypto environment.

Golang was chosen for its concurrency and low-latency capabilities, ensuring the trading bot operates swiftly in a fast-paced crypto environment.

Real-Time Data with Websockets

Real-Time Data with Websockets

Real-Time Data with Websockets

Instant Updates from Pumpfun’s Liquidity Pool Text: Leveraged websocket connections to subscribe to token launch events, enabling the sniper bot to react the moment liquidity is added.

Instant Updates from Pumpfun’s Liquidity Pool Text: Leveraged websocket connections to subscribe to token launch events, enabling the sniper bot to react the moment liquidity is added.

Instant Updates from Pumpfun’s Liquidity Pool Text: Leveraged websocket connections to subscribe to token launch events, enabling the sniper bot to react the moment liquidity is added.

Logging Profits Post-Execution

Logging Profits Post-Execution

Logging Profits Post-Execution

After executing trades, the bot writes detailed logs to a text file, allowing analysis of trade decisions and performance of the profit-focused algorithm.

After executing trades, the bot writes detailed logs to a text file, allowing analysis of trade decisions and performance of the profit-focused algorithm.

After executing trades, the bot writes detailed logs to a text file, allowing analysis of trade decisions and performance of the profit-focused algorithm.

Smart Filtering for Token Selection

Smart Filtering for Token Selection

Smart Filtering for Token Selection

Implemented logic to filter incoming tokens based on volume, liquidity thresholds, and timing—ensuring the bot only snipes tokens with strong breakout potential.

Implemented logic to filter incoming tokens based on volume, liquidity thresholds, and timing—ensuring the bot only snipes tokens with strong breakout potential.

Implemented logic to filter incoming tokens based on volume, liquidity thresholds, and timing—ensuring the bot only snipes tokens with strong breakout potential.

Trading Bot

Trading Bot

Code

Execution

package main

import (
    "context"
    "encoding/json"
    "fmt"
    "log"
    "net/url"
    "os"
    "os/signal"
    "strings"
    "sync"
    "syscall"
    "time"

    "github.com/gorilla/websocket"
)

// TokenLaunchEvent represents a structured message received from the liquidity pool WebSocket
type TokenLaunchEvent struct {
    TokenName     string  `json:"token_name"`
    Liquidity     float64 `json:"liquidity"`
    LaunchTime    string  `json:"launch_time"`
    ContractAddr  string  `json:"contract_address"`
    CreatorWallet string  `json:"creator_wallet"`
}

// BotConfig defines strategy-level settings
type BotConfig struct {
    MinLiquidity       float64
    AllowedTokenPrefix []string
    TrustedCreators    []string
}

// TradeLogger handles writing trades to both console and file
type TradeLogger struct {
    file *os.File
    mu   sync.Mutex
}

// NewTradeLogger creates a logger with a file writer
func NewTradeLogger(filename string) (*TradeLogger, error) {
    file, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    if err != nil {
        return nil, err
    }
    return &TradeLogger{file: file}, nil
}

func (t *TradeLogger) Log(message string) {
    t.mu.Lock()
    defer t.mu.Unlock()

    logLine := fmt.Sprintf("[%s] %s\n", time.Now().Format(time.RFC3339), message)
    fmt.Print(logLine)
    t.file.WriteString(logLine)
}

func (t *TradeLogger) Close() {
    t.file.Close()
}

func main() {
    // Configurable filters
    config := BotConfig{
        MinLiquidity:       1500,
        AllowedTokenPrefix: []string{"Pump", "Moon", "X"},
        TrustedCreators:    []string{"0x1234abcd...", "0xbeefdead..."},
    }

    logger, err := NewTradeLogger("trade_log.txt")
    if err != nil {
        log.Fatalf("Failed to create logger: %v", err)
    }
    defer logger.Close()

    ctx, cancel := context.WithCancel(context.Background())
    go listenForShutdown(cancel)

    connectToPumpfun(ctx, config, logger)
}

func listenForShutdown(cancelFunc context.CancelFunc) {
    c := make(chan os.Signal, 1)
    signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
    <-c
    fmt.Println("\nReceived shutdown signal. Exiting...")
    cancelFunc()
}

// connectToPumpfun handles WebSocket setup and token event stream
func connectToPumpfun(ctx context.Context, config BotConfig, logger *TradeLogger) {
    u := url.URL{Scheme: "wss", Host: "api.pumpfun.com", Path: "/liquidity-feed"}
    conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
    if err != nil {
        log.Fatalf("WebSocket connection failed: %v", err)
    }
    defer conn.Close()

    logger.Log("✅ Connected to Pumpfun WebSocket.")

    for {
        select {
        case <-ctx.Done():
            logger.Log("🛑 Shutting down WebSocket listener.")
            return
        default:
            _, message, err := conn.ReadMessage()
            if err != nil {
                logger.Log(fmt.Sprintf("⚠️ Read error: %v", err))
                continue
            }

            var event TokenLaunchEvent
            if err := json.Unmarshal(message, &event); err != nil {
                logger.Log(fmt.Sprintf("⚠️ JSON decode error: %v", err))
                continue
            }

            if shouldTrade(event, config) {
                logger.Log(fmt.Sprintf("🚀 Sniping token: %s (Liquidity: %.2f)", event.TokenName, event.Liquidity))
                executeTrade(event, logger)
            } else {
                logger.Log(fmt.Sprintf("❌ Skipped: %s (Liquidity: %.2f)", event.TokenName, event.Liquidity))
            }
        }
    }
}

// shouldTrade applies filtering rules to decide if a token is worth sniping
func shouldTrade(event TokenLaunchEvent, config BotConfig) bool {
    if event.Liquidity < config.MinLiquidity {
        return false
    }

    validPrefix := false
    for _, prefix := range config.AllowedTokenPrefix {
        if strings.HasPrefix(event.TokenName, prefix) {
            validPrefix = true
            break
        }
    }

    if !validPrefix {
        return false
    }

    for _, creator := range config.TrustedCreators {
        if strings.EqualFold(creator, event.CreatorWallet) {
            return true
        }
    }

    // If not from trusted creator, skip
    return false
}

// executeTrade simulates the execution of a token snipe
func executeTrade(event TokenLaunchEvent, logger *TradeLogger) {
    logger.Log(fmt.Sprintf("✅ Executed simulated trade for %s at %s", event.TokenName, event.ContractAddr))

    // Simulated: you would integrate here with an on-chain trading SDK like 0x, Uniswap, or a custom smart contract call
    // Example placeholder: tradeAPI.PlaceOrder(event.ContractAddr, ...)

    // Simulated delay

Code

Execution

package main

import (
    "context"
    "encoding/json"
    "fmt"
    "log"
    "net/url"
    "os"
    "os/signal"
    "strings"
    "sync"
    "syscall"
    "time"

    "github.com/gorilla/websocket"
)

// TokenLaunchEvent represents a structured message received from the liquidity pool WebSocket
type TokenLaunchEvent struct {
    TokenName     string  `json:"token_name"`
    Liquidity     float64 `json:"liquidity"`
    LaunchTime    string  `json:"launch_time"`
    ContractAddr  string  `json:"contract_address"`
    CreatorWallet string  `json:"creator_wallet"`
}

// BotConfig defines strategy-level settings
type BotConfig struct {
    MinLiquidity       float64
    AllowedTokenPrefix []string
    TrustedCreators    []string
}

// TradeLogger handles writing trades to both console and file
type TradeLogger struct {
    file *os.File
    mu   sync.Mutex
}

// NewTradeLogger creates a logger with a file writer
func NewTradeLogger(filename string) (*TradeLogger, error) {
    file, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    if err != nil {
        return nil, err
    }
    return &TradeLogger{file: file}, nil
}

func (t *TradeLogger) Log(message string) {
    t.mu.Lock()
    defer t.mu.Unlock()

    logLine := fmt.Sprintf("[%s] %s\n", time.Now().Format(time.RFC3339), message)
    fmt.Print(logLine)
    t.file.WriteString(logLine)
}

func (t *TradeLogger) Close() {
    t.file.Close()
}

func main() {
    // Configurable filters
    config := BotConfig{
        MinLiquidity:       1500,
        AllowedTokenPrefix: []string{"Pump", "Moon", "X"},
        TrustedCreators:    []string{"0x1234abcd...", "0xbeefdead..."},
    }

    logger, err := NewTradeLogger("trade_log.txt")
    if err != nil {
        log.Fatalf("Failed to create logger: %v", err)
    }
    defer logger.Close()

    ctx, cancel := context.WithCancel(context.Background())
    go listenForShutdown(cancel)

    connectToPumpfun(ctx, config, logger)
}

func listenForShutdown(cancelFunc context.CancelFunc) {
    c := make(chan os.Signal, 1)
    signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
    <-c
    fmt.Println("\nReceived shutdown signal. Exiting...")
    cancelFunc()
}

// connectToPumpfun handles WebSocket setup and token event stream
func connectToPumpfun(ctx context.Context, config BotConfig, logger *TradeLogger) {
    u := url.URL{Scheme: "wss", Host: "api.pumpfun.com", Path: "/liquidity-feed"}
    conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
    if err != nil {
        log.Fatalf("WebSocket connection failed: %v", err)
    }
    defer conn.Close()

    logger.Log("✅ Connected to Pumpfun WebSocket.")

    for {
        select {
        case <-ctx.Done():
            logger.Log("🛑 Shutting down WebSocket listener.")
            return
        default:
            _, message, err := conn.ReadMessage()
            if err != nil {
                logger.Log(fmt.Sprintf("⚠️ Read error: %v", err))
                continue
            }

            var event TokenLaunchEvent
            if err := json.Unmarshal(message, &event); err != nil {
                logger.Log(fmt.Sprintf("⚠️ JSON decode error: %v", err))
                continue
            }

            if shouldTrade(event, config) {
                logger.Log(fmt.Sprintf("🚀 Sniping token: %s (Liquidity: %.2f)", event.TokenName, event.Liquidity))
                executeTrade(event, logger)
            } else {
                logger.Log(fmt.Sprintf("❌ Skipped: %s (Liquidity: %.2f)", event.TokenName, event.Liquidity))
            }
        }
    }
}

// shouldTrade applies filtering rules to decide if a token is worth sniping
func shouldTrade(event TokenLaunchEvent, config BotConfig) bool {
    if event.Liquidity < config.MinLiquidity {
        return false
    }

    validPrefix := false
    for _, prefix := range config.AllowedTokenPrefix {
        if strings.HasPrefix(event.TokenName, prefix) {
            validPrefix = true
            break
        }
    }

    if !validPrefix {
        return false
    }

    for _, creator := range config.TrustedCreators {
        if strings.EqualFold(creator, event.CreatorWallet) {
            return true
        }
    }

    // If not from trusted creator, skip
    return false
}

// executeTrade simulates the execution of a token snipe
func executeTrade(event TokenLaunchEvent, logger *TradeLogger) {
    logger.Log(fmt.Sprintf("✅ Executed simulated trade for %s at %s", event.TokenName, event.ContractAddr))

    // Simulated: you would integrate here with an on-chain trading SDK like 0x, Uniswap, or a custom smart contract call
    // Example placeholder: tradeAPI.PlaceOrder(event.ContractAddr, ...)

    // Simulated delay