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: PubkeyImplementations§
Source§impl OrcaClient
impl OrcaClient
Sourcepub async fn get_token_balance(
&self,
owner: &Pubkey,
mint: &Pubkey,
) -> OrcaResult<u64>
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);Sourcepub async fn get_all_token_balances(
&self,
owner: &Pubkey,
) -> OrcaResult<Vec<(Pubkey, u64)>>
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);
}Sourcepub async fn ensure_token_account(
&self,
keypair: &Keypair,
mint: &Pubkey,
) -> OrcaResult<Pubkey>
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);Sourcepub async fn create_associated_token_account(
&self,
keypair: &Keypair,
mint: &Pubkey,
) -> OrcaResult<Pubkey>
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);Sourcepub async fn get_token_supply(&self, mint: &Pubkey) -> OrcaResult<u64>
pub async fn get_token_supply(&self, mint: &Pubkey) -> OrcaResult<u64>
Sourcepub fn decode_account_data(
&self,
ui_account_data: &UiAccountData,
) -> OrcaResult<Vec<u8>>
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
impl OrcaClient
Sourcepub async fn monitor_price_changes_production<F>(
self: Arc<Self>,
pool_address: &str,
min_change_percent: f64,
callback: F,
) -> OrcaResult<PriceMonitorHandle>
pub async fn monitor_price_changes_production<F>( self: Arc<Self>, pool_address: &str, min_change_percent: f64, callback: F, ) -> OrcaResult<PriceMonitorHandle>
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
impl OrcaClient
Sourcepub 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>
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?;Sourcepub async fn remove_liquidity(
&self,
keypair: &Keypair,
position: &LiquidityPosition,
) -> OrcaResult<Signature>
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?;
}Sourcepub async fn get_liquidity_positions(
&self,
owner: &Pubkey,
) -> OrcaResult<Vec<LiquidityPosition>>
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
impl OrcaClient
Sourcepub async fn monitor_pool_health(
&self,
pool_address: &str,
) -> OrcaResult<PoolHealth>
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
impl OrcaClient
Sourcepub async fn get_pool_state_onchain(
&self,
pool_address: &str,
) -> OrcaResult<PoolInfo>
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);Sourcepub async fn find_pools_by_token_onchain_optimized(
&self,
token_mint: &str,
) -> OrcaResult<Vec<String>>
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());pub async fn find_pools_by_token_onchain( &self, token_mint: &str, ) -> OrcaResult<Vec<String>>
Sourcepub async fn get_quote_from_pool(
&self,
input_mint: &str,
output_mint: &str,
input_amount: u64,
slippage: f64,
) -> OrcaResult<QuoteResult>
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);pub async fn derive_price_from_pool_state( &self, pool: &PoolInfo, base_mint: &str, ) -> OrcaResult<f64>
Sourcepub async fn get_pools_by_token_onchain(
&self,
token_mint: &str,
) -> OrcaResult<Vec<String>>
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
impl OrcaClient
Sourcepub async fn get_token_price_from_pool(
&self,
base_mint: &str,
quote_mint: &str,
) -> OrcaResult<f64>
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);Sourcepub async fn get_price_history_from_chain(
&self,
pool_address: &str,
limit: usize,
) -> OrcaResult<Vec<PriceData>>
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);
}Sourcepub async fn calculate_moving_average_from_chain(
&self,
pool_address: &str,
period: usize,
) -> OrcaResult<f64>
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);pub async fn get_kline_data_production( &self, pool_address: &str, timeframe_minutes: u32, limit: usize, ) -> OrcaResult<Vec<Kline>>
Source§impl OrcaClient
impl OrcaClient
Sourcepub async fn swap(
&self,
keypair: &Keypair,
input_mint: &str,
output_mint: &str,
amount: u64,
config: Option<TradeConfig>,
) -> OrcaResult<Signature>
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);Auto Trait Implementations§
impl !RefUnwindSafe for OrcaClient
impl !UnwindSafe for OrcaClient
impl Freeze for OrcaClient
impl Send for OrcaClient
impl Sync for OrcaClient
impl Unpin for OrcaClient
impl UnsafeUnpin for OrcaClient
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 more