Crate copy_trading

Source
Expand description

§Solana Copy Trading Library

Live execution system for copying trades from high-performing Solana wallets.

This library provides the core components for a copy trading system that:

  • Monitors swap transactions from tracked wallets
  • Automatically opens positions when tracked wallets buy tokens
  • Manages position lifecycle (opening, monitoring, closing)
  • Implements stop-loss and hold-time strategies
  • Executes trades via Jito bundles for fast settlement

§Architecture

  • PositionManager: Central coordinator that monitors swap transactions, market updates, and new pool creations. Manages multiple positions simultaneously.
  • Position: Represents a single copy trading position with state management and lifecycle handling.
  • PositionConfig: Configuration for each tracked wallet defining buy amounts, hold times, stop-loss settings.

§Position Lifecycle

  1. Created: Position created when a tracked wallet buys a token
  2. Opening: Buy transaction sent to blockchain via Jito
  3. Open: Position actively monitored for stop-loss triggers and hold time expiration
  4. Closing: Sell transaction sent to blockchain
  5. Closed: Position finalized and removed from active tracking

LOTS OF FUNCTIONS UNDER IMPLEMENTATIONS OF POSITION AND POSITION MANAGER ARE DOCUMENTED IN THE CODE.

Structs§

Position
Represents a single copy trading position tracking a token purchase from a monitored wallet. Contains all state for a position including entry/exit prices, timestamps, stop-loss settings, and lifecycle status. Positions are managed through a state machine with transitions: Created -> Opening -> Open -> Closing -> Closed.
PositionConfig
Configuration for copy trading a specific wallet, defining position sizing and risk management. Each tracked wallet has its own configuration specifying buy amounts, hold times, stop-loss thresholds, and slippage tolerances.
PositionManager
Central coordinator for managing copy trading positions and monitoring wallet activity. Monitors swap transactions, market updates, and new pool creations, automatically opening and closing positions based on tracked wallet behavior. It maintains active positions and wallet configurations for copy trading.

Enums§

PositionCloseReason
Reason why a position was closed.
PositionStatus
Represents the current lifecycle state of a position. Positions transition through these states: Created -> Opening -> Open -> Closing -> Closed.

Functions§

set_wallet_configs_from_pl_df
Set wallet configurations from a Polars DataFrame. Clears existing wallet configs and loads new configurations from a DataFrame containing wallet addresses and their position configuration parameters.