Struct Position

Source
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: u64

Implementations§

Source§

impl Position

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more