pub struct PositionManager {
pub open_positions: RwLock<HashMap<Pubkey, Arc<Mutex<Position>>>>,
pub wallet_configs: HashMap<Pubkey, PositionConfig>,
pub tx_monitor_receiver: Receiver<SwapTx>,
pub market_update_receiver: Receiver<MarketUpdate>,
pub new_pool_receiver: Receiver<Arc<RwLock<dyn PoolTrait>>>,
pub wallet: Arc<Keypair>,
pub central_context: Arc<CentralContext>,
pub execution_context: Arc<ExecutionContext>,
}Expand description
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.
Fields§
§open_positions: RwLock<HashMap<Pubkey, Arc<Mutex<Position>>>>§wallet_configs: HashMap<Pubkey, PositionConfig>§tx_monitor_receiver: Receiver<SwapTx>§market_update_receiver: Receiver<MarketUpdate>§new_pool_receiver: Receiver<Arc<RwLock<dyn PoolTrait>>>§wallet: Arc<Keypair>§central_context: Arc<CentralContext>§execution_context: Arc<ExecutionContext>Implementations§
Source§impl PositionManager
impl PositionManager
Sourcepub async fn market_update_loop(position_manager: Arc<PositionManager>)
pub async fn market_update_loop(position_manager: Arc<PositionManager>)
Monitor market price updates and trigger stop-loss checks for open positions. Receives market updates from broadcast channel and forwards them to open positions for stop-loss processing.
Source§impl PositionManager
impl PositionManager
Sourcepub async fn new_pool_loop(position_manager: Arc<PositionManager>)
pub async fn new_pool_loop(position_manager: Arc<PositionManager>)
Monitor new pool creations and handle Pumpfun bonding curve migrations. When a Pumpfun bonding curve completes and migrates to a Pumpswap pool, updates the position’s pool reference and lookup key to the new pool address.
Source§impl PositionManager
impl PositionManager
Sourcepub fn start(position_manager: &Arc<PositionManager>)
pub fn start(position_manager: &Arc<PositionManager>)
Start all async monitoring loops for the position manager. Spawns three separate async tasks: market update loop, transaction monitor loop, and new pool loop to handle different event streams concurrently.
Source§impl PositionManager
impl PositionManager
Sourcepub async fn tx_monitor_loop(position_manager: Arc<PositionManager>)
pub async fn tx_monitor_loop(position_manager: Arc<PositionManager>)
Monitor swap transactions and manage position lifecycle based on wallet activity. Processes swap transactions from broadcast channel, handling two cases: Our own wallet’s swaps: Confirms buy/sell transactions for existing positions and tracked wallets’ swaps: Opens new positions when they buy tokens
Auto Trait Implementations§
impl !Freeze for PositionManager
impl !RefUnwindSafe for PositionManager
impl Send for PositionManager
impl Sync for PositionManager
impl Unpin for PositionManager
impl !UnwindSafe for PositionManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request