pub struct Position {Show 19 fields
pub config: PositionConfig,
pub token_address: Pubkey,
pub pool: Arc<RwLock<dyn PoolTrait>>,
pub status: PositionStatus,
pub migrated: bool,
pub pool_address: Pubkey,
pub open_time: u64,
pub buy_confirmation_time: u64,
pub close_time: u64,
pub close_reason: PositionCloseReason,
pub sell_confirmation_time: u64,
pub entry_price_lp: u128,
pub exit_price_lp: u128,
pub tokens_purchased: u64,
pub wallet: Arc<Keypair>,
pub sol_token_a: bool,
pub stop_loss_price_lp: u128,
pub lowest_acceptable_price_lp: u128,
pub sell_amount_lp: u64,
}Expand description
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.
Fields§
§config: PositionConfig§token_address: Pubkey§pool: Arc<RwLock<dyn PoolTrait>>§status: PositionStatus§migrated: bool§pool_address: Pubkey§open_time: u64§buy_confirmation_time: u64§close_time: u64§close_reason: PositionCloseReason§sell_confirmation_time: u64§entry_price_lp: u128§exit_price_lp: u128§tokens_purchased: u64§wallet: Arc<Keypair>§sol_token_a: bool§stop_loss_price_lp: u128§lowest_acceptable_price_lp: u128§sell_amount_lp: u64Implementations§
Source§impl Position
impl Position
Sourcepub fn close_position(
position: Arc<Mutex<Position>>,
reason: PositionCloseReason,
position_manager: Arc<PositionManager>,
)
pub fn close_position( position: Arc<Mutex<Position>>, reason: PositionCloseReason, position_manager: Arc<PositionManager>, )
Close a position by creating and sending a sell transaction to the blockchain. Handles both stop-loss and hold-time closures. Creates a sell swap transaction and sends it via Jito bundles, retrying until confirmation is received.
Source§impl Position
impl Position
Sourcepub fn process_buy_tx_confirmation(
position: &mut Position,
position_arc: &Arc<Mutex<Position>>,
swap_tx: &SwapTx,
position_manager: &Arc<PositionManager>,
)
pub fn process_buy_tx_confirmation( position: &mut Position, position_arc: &Arc<Mutex<Position>>, swap_tx: &SwapTx, position_manager: &Arc<PositionManager>, )
Process confirmation of a buy transaction, transitioning position from Opening to Open. Records entry price, tokens purchased, and initializes stop-loss thresholds. Starts the hold-time task to automatically close the position after the configured hold duration.
Source§impl Position
impl Position
Sourcepub fn process_market_update(
position: &mut Position,
market_update: &MarketUpdate,
position_arc: &Arc<Mutex<Position>>,
position_manager: &Arc<PositionManager>,
)
pub fn process_market_update( position: &mut Position, market_update: &MarketUpdate, position_arc: &Arc<Mutex<Position>>, position_manager: &Arc<PositionManager>, )
Process a market update for an open position, checking stop-loss conditions. Implements trailing stop-loss by adjusting the stop-loss price upward as price increases. Closes the position if current price falls below the lowest acceptable price threshold.
Source§impl Position
impl Position
Sourcepub fn start(
position: Arc<Mutex<Position>>,
position_manager: Arc<PositionManager>,
)
pub fn start( position: Arc<Mutex<Position>>, position_manager: Arc<PositionManager>, )
Start a position by creating and sending a buy transaction to the blockchain. Validates position state, creates a buy swap transaction, sends it via Jito bundles, and sets up a timeout to close the position if confirmation doesn’t arrive within 5 seconds.
Source§impl Position
impl Position
Sourcepub fn start_hold_time_task(
position: Arc<Mutex<Position>>,
hold_time_ms: u32,
token_address: Pubkey,
position_manager: Arc<PositionManager>,
)
pub fn start_hold_time_task( position: Arc<Mutex<Position>>, hold_time_ms: u32, token_address: Pubkey, position_manager: Arc<PositionManager>, )
Start an async task that will close the position after the configured hold time expires. Waits for the specified hold time duration, then closes the position if it’s still open.
Source§impl Position
impl Position
Sourcepub fn process_sell_tx_confirmation(
position: &mut Position,
open_positions: &mut HashMap<Pubkey, Arc<Mutex<Position>>>,
swap_tx: &SwapTx,
)
pub fn process_sell_tx_confirmation( position: &mut Position, open_positions: &mut HashMap<Pubkey, Arc<Mutex<Position>>>, swap_tx: &SwapTx, )
Process confirmation of a sell transaction, finalizing the position. Records exit price, calculates PNL, marks position as Closed, and removes it from the open positions map.
Source§impl Position
impl Position
Sourcepub fn create_checked(
token_address: Pubkey,
sol_token_a: bool,
swap_tx: &SwapTx,
config: PositionConfig,
open_positions: &HashMap<Pubkey, Arc<Mutex<Position>>>,
position_manager: &Arc<PositionManager>,
) -> Option<Position>
pub fn create_checked( token_address: Pubkey, sol_token_a: bool, swap_tx: &SwapTx, config: PositionConfig, open_positions: &HashMap<Pubkey, Arc<Mutex<Position>>>, position_manager: &Arc<PositionManager>, ) -> Option<Position>
Create a new position after performing validation checks. Validates that: no duplicate position exists, token is legitimate, pool has sufficient liquidity, and buy amount doesn’t exceed wallet’s buy size. Caps buy size to 85-100% of wallet’s buy amount to avoid exact copy detection.
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
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