Skip to main content

OrcaClient

Struct OrcaClient 

Source
pub struct OrcaClient {
    pub solana: Solana,
    pub whirlpool_program_id: Pubkey,
    pub stable_swap_program_id: Pubkey,
}

Fields§

§solana: Solana§whirlpool_program_id: Pubkey§stable_swap_program_id: Pubkey

Implementations§

Source§

impl OrcaClient

Source

pub async fn get_token_balance( &self, owner: &Pubkey, mint: &Pubkey, ) -> OrcaResult<u64>

Get the balance of a specific token for a given owner and mint

§Params

owner - The public key of the token account owner mint - The public key of the token mint

§Example
use solana_sdk::pubkey;

let owner = pubkey!("OwnerPublicKeyHere");
let mint = pubkey!("MintPublicKeyHere");
let balance = client.get_token_balance(&owner, &mint).await?;
println!("Token balance: {}", balance);
Source

pub async fn get_all_token_balances( &self, owner: &Pubkey, ) -> OrcaResult<Vec<(Pubkey, u64)>>

Get balances for all tokens owned by a specific account

§Params

owner - The public key of the token account owner

§Example
use solana_sdk::pubkey;

let owner = pubkey!("OwnerPublicKeyHere");
let balances = client.get_all_token_balances(&owner).await?;
for (mint, balance) in balances {
    println!("Mint: {}, Balance: {}", mint, balance);
}
Source

pub async fn ensure_token_account( &self, keypair: &Keypair, mint: &Pubkey, ) -> OrcaResult<Pubkey>

Ensure a token account exists for the given keypair and mint Creates the account if it doesn’t exist

§Params

keypair - The keypair that owns the token account mint - The public key of the token mint

§Example
use solana_sdk::{pubkey, signer::keypair::Keypair};

let keypair = Keypair::new();
let mint = pubkey!("MintPublicKeyHere");
let token_account = client.ensure_token_account(&keypair, &mint).await?;
println!("Token account: {}", token_account);
Source

pub async fn create_associated_token_account( &self, keypair: &Keypair, mint: &Pubkey, ) -> OrcaResult<Pubkey>

Create an associated token account for the given keypair and mint

§Params

keypair - The keypair that will own the token account mint - The public key of the token mint

§Example
use solana_sdk::{pubkey, signer::keypair::Keypair};

let keypair = Keypair::new();
let mint = pubkey!("MintPublicKeyHere");
let token_account = client.create_associated_token_account(&keypair, &mint).await?;
println!("Created token account: {}", token_account);
Source

pub async fn get_token_supply(&self, mint: &Pubkey) -> OrcaResult<u64>

Get the total supply of a token mint

§Params

mint - The public key of the token mint

§Example
use solana_sdk::pubkey;

let mint = pubkey!("MintPublicKeyHere");
let supply = client.get_token_supply(&mint).await?;
println!("Token supply: {}", supply);
Source

pub fn decode_account_data( &self, ui_account_data: &UiAccountData, ) -> OrcaResult<Vec<u8>>

Decode account data from various encoding formats

§Params

ui_account_data - The UI account data to decode

Source§

impl OrcaClient

Source

pub async fn monitor_price_changes_production<F>( self: Arc<Self>, pool_address: &str, min_change_percent: f64, callback: F, ) -> OrcaResult<PriceMonitorHandle>
where F: Fn(PriceUpdate) + Send + Sync + 'static,

Monitors price changes for a given pool with production-ready error handling and configurable thresholds.

§Params

pool_address - The address of the liquidity pool to monitor min_change_percent - Minimum percentage change required to trigger callback callback - Function called when significant price change is detected

§Examples
use std::sync::Arc;
use orca_sdk::OrcaClient;

let client = Arc::new(OrcaClient::new().await?);
let pool_address = "POOL_ADDRESS_HERE";

let monitor_handle = client.monitor_price_changes_production(
    pool_address,
    1.0, // 1% minimum change
    |update| {
        println!("Price changed: {}%", update.change_percent);
        println!("Old price: {}, New price: {}", update.old_price, update.new_price);
    },
).await?;
Source§

impl OrcaClient

Source

pub async fn add_liquidity( &self, keypair: &Keypair, pool: &PoolInfo, token_a_amount: u64, token_b_amount: u64, lower_tick: i32, upper_tick: i32, config: Option<AddLiquidityConfig>, ) -> OrcaResult<Signature>

Adds liquidity to a concentrated liquidity pool within specified tick range

§Params

keypair - Keypair for transaction signing pool - Pool information token_a_amount - Amount of token A to deposit token_b_amount - Amount of token B to deposit
lower_tick - Lower tick boundary for position upper_tick - Upper tick boundary for position config - Optional configuration for slippage and iterations

§Example
use orca_rs::client::OrcaClient;
use solana_sdk::signature::Keypair;

let client = OrcaClient::new("https://api.mainnet-beta.solana.com");
let keypair = Keypair::new();
let pool_info = client.get_pool("whirlpool_address").await?;

let signature = client.add_liquidity(
    &keypair,
    &pool_info,
    1000000, // 1 token A
    2000000, // 2 token B  
    -1000,   // lower tick
    1000,    // upper tick
    None,    // use default config
).await?;
Source

pub async fn remove_liquidity( &self, keypair: &Keypair, position: &LiquidityPosition, ) -> OrcaResult<Signature>

Removes liquidity from a position and closes it

§Params

keypair - Keypair for transaction signing position - Liquidity position to remove

§Example
use orca_rs::client::OrcaClient;
use solana_sdk::signature::Keypair;

let client = OrcaClient::new("https://api.mainnet-beta.solana.com");
let keypair = Keypair::new();
let positions = client.get_liquidity_positions(&keypair.pubkey()).await?;

if let Some(position) = positions.first() {
    let signature = client.remove_liquidity(&keypair, position).await?;
}
Source

pub async fn get_liquidity_positions( &self, owner: &Pubkey, ) -> OrcaResult<Vec<LiquidityPosition>>

Retrieves all liquidity positions for a given owner

§Params

owner - Public key of the position owner

§Example
use orca_rs::client::OrcaClient;
use solana_sdk::pubkey::Pubkey;

let client = OrcaClient::new("https://api.mainnet-beta.solana.com");
let owner = Pubkey::new_unique();
let positions = client.get_liquidity_positions(&owner).await?;

for position in positions {
    println!("Position: {} LP tokens", position.lp_token_amount);
}
Source§

impl OrcaClient

Source

pub async fn monitor_pool_health( &self, pool_address: &str, ) -> OrcaResult<PoolHealth>

Monitors the health of a liquidity pool by analyzing key metrics.

§Params

pool_address - The address of the pool to monitor

§Returns

Returns a PoolHealth struct containing liquidity, volume, fee growth, and health score

§Example
use orca_client::OrcaClient;

tokio_test::block_on(async {
let client = OrcaClient::new();
let pool_health = client.monitor_pool_health("POOL_ADDRESS_HERE").await.unwrap();
println!("Pool health score: {}", pool_health.health_score);
});
Source§

impl OrcaClient

Source

pub async fn get_pool_state_onchain( &self, pool_address: &str, ) -> OrcaResult<PoolInfo>

Fetches pool state from on-chain data

§Example
let pool_info = client.get_pool_state_onchain("address").await?;
println!("Pool liquidity: {}", pool_info.liquidity);
Source

pub async fn find_pools_by_token_onchain_optimized( &self, token_mint: &str, ) -> OrcaResult<Vec<String>>

Optimized method to find pools containing a specific token

§Example
let pools = client.find_pools_by_token_onchain_optimized("So11111111111111111111111111111111111111112").await?;
println!("Found {} pools", pools.len());
Source

pub async fn find_pools_by_token_onchain( &self, token_mint: &str, ) -> OrcaResult<Vec<String>>

Source

pub async fn get_quote_from_pool( &self, input_mint: &str, output_mint: &str, input_amount: u64, slippage: f64, ) -> OrcaResult<QuoteResult>

Gets a quote for swapping between two tokens

§Example
let quote = client.get_quote_from_pool(
    "So11111111111111111111111111111111111111112",
    "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    1000000,
    0.5
).await?;
println!("Output amount: {}", quote.output_amount);
Source

pub async fn derive_price_from_pool_state( &self, pool: &PoolInfo, base_mint: &str, ) -> OrcaResult<f64>

Source

pub async fn get_pools_by_token_onchain( &self, token_mint: &str, ) -> OrcaResult<Vec<String>>

Gets all pools containing a specific token from on-chain data

Source§

impl OrcaClient

Source

pub async fn get_token_price_from_pool( &self, base_mint: &str, quote_mint: &str, ) -> OrcaResult<f64>

Get token price from a liquidity pool

§Arguments

base_mint - Base token mint address quote_mint - Quote token mint address

§Example
let price = client.get_token_price_from_pool(
    "So11111111111111111111111111111111111111112", // SOL
    "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"  // USDC
).await?;
println!("SOL/USDC price: {}", price);
Source

pub async fn get_price_history_from_chain( &self, pool_address: &str, limit: usize, ) -> OrcaResult<Vec<PriceData>>

Get price history from on-chain transactions

§Arguments

pool_address - Pool address to get history for limit - Maximum number of price points to return

§Example
let price_history = client.get_price_history_from_chain(
    "whirlpool_address_here",
    100
).await?;
for data in price_history {
    println!("Time: {}, Price: {}", data.timestamp, data.price);
}
Source

pub async fn calculate_moving_average_from_chain( &self, pool_address: &str, period: usize, ) -> OrcaResult<f64>

Calculate moving average price from on-chain data

§Arguments

pool_address - Pool address to calculate MA for period - Number of periods for moving average

§Example
let ma_20 = client.calculate_moving_average_from_chain(
    "whirlpool_address_here",
    20
).await?;
println!("20-period moving average: {}", ma_20);
Source

pub async fn get_kline_data_production( &self, pool_address: &str, timeframe_minutes: u32, limit: usize, ) -> OrcaResult<Vec<Kline>>

Source§

impl OrcaClient

Source

pub async fn swap( &self, keypair: &Keypair, input_mint: &str, output_mint: &str, amount: u64, config: Option<TradeConfig>, ) -> OrcaResult<Signature>

Executes a token swap between specified input and output mints

§Arguments

keypair - Keypair for signing the transaction input_mint - Mint address of the input token output_mint - Mint address of the output token amount - Amount of input tokens to swap config - Optional trade configuration parameters

§Returns

Transaction signature if successful

§Examples
use orca_sdk::client::OrcaClient;
use solana_sdk::signature::Keypair;

let client = OrcaClient::new();
let keypair = Keypair::new();
let input_mint = "So11111111111111111111111111111111111111112";
let output_mint = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
let amount = 1_000_000; // 1 SOL

let signature = client.swap(&keypair, input_mint, output_mint, amount, None).await?;
println!("Swap completed with signature: {}", signature);
Source§

impl OrcaClient

Source

pub fn new() -> Result<Self, OrcaError>

Source

pub fn get_associated_token_address( &self, wallet: &Pubkey, mint: &Pubkey, ) -> Pubkey

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> 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: Sized + 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: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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