pub struct PriceLevels { /* private fields */ }Expand description
Entry point for Titan’s pAMM price levels, structured like
crate::PropAmmRouter: a single client wrapping a default
PriceLevelsSource you can override.
PriceLevels::get_price_levelsreads the latest snapshot from the configured source (one-shot HTTP by default; pass aPriceLevelsWsSourceto stream).PriceLevels::get_quote/PriceLevels::get_quote_venueresolve a single size against Titan’s latest snapshot over HTTP JSON-RPC. They are HTTP-only — the stream pushes snapshots, not quotes — so they always go through an RPC source.
Implementations§
Source§impl PriceLevels
impl PriceLevels
Sourcepub fn new() -> Self
pub fn new() -> Self
Client with the default one-shot HTTP snapshot source.
Examples found in repository?
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // PriceLevels defaults to a one-shot HTTP snapshot source. Set
22 // PRICE_LEVELS_URL to point snapshots and quotes at a specific endpoint.
23 let prices = match std::env::var("PRICE_LEVELS_URL") {
24 Ok(url) => PriceLevels::with_source(Arc::new(PriceLevelsRpcSource::new(url))),
25 Err(_) => PriceLevels::new(),
26 };
27
28 // 1. Full snapshot: every pAMM's order book.
29 let snapshot = prices.get_price_levels().await?;
30 println!(
31 "snapshot @ block {} — {} pAMM(s)",
32 snapshot
33 .block_number
34 .map_or_else(|| "?".to_string(), |b| b.to_string()),
35 snapshot.pamms.len()
36 );
37
38 // Pick the first pAMM/pair that carries an order book to display.
39 let Some((pamm, pair)) = snapshot.pamms.iter().find_map(|entry| {
40 entry
41 .pairs
42 .iter()
43 .find(|pair| !pair.order_book.is_empty())
44 .map(|pair| (entry.pamm, pair))
45 }) else {
46 return Err("snapshot carried no order books".into());
47 };
48
49 println!(
50 "\n{} order book: {} -> {}",
51 venue_name(pamm),
52 token_symbol(pair.token_in),
53 token_symbol(pair.token_out),
54 );
55 for level in &pair.order_book {
56 println!(
57 " {} -> {} [{:?}]",
58 fmt(level.amount_in, pair.token_in),
59 fmt(level.amount_out, pair.token_out),
60 level.variant,
61 );
62 }
63
64 // 2. Quote helpers, for that pair and a mid-ladder size. `get_quote`
65 // returns the best across all pAMMs; `get_quote_venue` pins to one.
66 let size = pair.order_book[pair.order_book.len() / 2].amount_in;
67
68 let best = prices
69 .get_quote(pair.token_in, pair.token_out, size)
70 .await?;
71 println!(
72 "\nbest quote: {} -> {} via {}",
73 fmt(best.amount_in, best.token_in),
74 fmt(best.amount_out, best.token_out),
75 venue_name(best.pamm),
76 );
77
78 let pinned = prices
79 .get_quote_venue(pamm, pair.token_in, pair.token_out, size)
80 .await?;
81 println!(
82 "{} quote: {} -> {}",
83 venue_name(pamm),
84 fmt(pinned.amount_in, pinned.token_in),
85 fmt(pinned.amount_out, pinned.token_out),
86 );
87
88 Ok(())
89}Sourcepub fn with_source(source: Arc<dyn PriceLevelsSource>) -> Self
pub fn with_source(source: Arc<dyn PriceLevelsSource>) -> Self
Client with an explicit snapshot source. When source already speaks
HTTP (a PriceLevelsRpcSource), the quote helpers reuse it so a custom
endpoint covers both; otherwise quotes go to the default HTTP endpoint.
Examples found in repository?
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // PriceLevels defaults to a one-shot HTTP snapshot source. Set
22 // PRICE_LEVELS_URL to point snapshots and quotes at a specific endpoint.
23 let prices = match std::env::var("PRICE_LEVELS_URL") {
24 Ok(url) => PriceLevels::with_source(Arc::new(PriceLevelsRpcSource::new(url))),
25 Err(_) => PriceLevels::new(),
26 };
27
28 // 1. Full snapshot: every pAMM's order book.
29 let snapshot = prices.get_price_levels().await?;
30 println!(
31 "snapshot @ block {} — {} pAMM(s)",
32 snapshot
33 .block_number
34 .map_or_else(|| "?".to_string(), |b| b.to_string()),
35 snapshot.pamms.len()
36 );
37
38 // Pick the first pAMM/pair that carries an order book to display.
39 let Some((pamm, pair)) = snapshot.pamms.iter().find_map(|entry| {
40 entry
41 .pairs
42 .iter()
43 .find(|pair| !pair.order_book.is_empty())
44 .map(|pair| (entry.pamm, pair))
45 }) else {
46 return Err("snapshot carried no order books".into());
47 };
48
49 println!(
50 "\n{} order book: {} -> {}",
51 venue_name(pamm),
52 token_symbol(pair.token_in),
53 token_symbol(pair.token_out),
54 );
55 for level in &pair.order_book {
56 println!(
57 " {} -> {} [{:?}]",
58 fmt(level.amount_in, pair.token_in),
59 fmt(level.amount_out, pair.token_out),
60 level.variant,
61 );
62 }
63
64 // 2. Quote helpers, for that pair and a mid-ladder size. `get_quote`
65 // returns the best across all pAMMs; `get_quote_venue` pins to one.
66 let size = pair.order_book[pair.order_book.len() / 2].amount_in;
67
68 let best = prices
69 .get_quote(pair.token_in, pair.token_out, size)
70 .await?;
71 println!(
72 "\nbest quote: {} -> {} via {}",
73 fmt(best.amount_in, best.token_in),
74 fmt(best.amount_out, best.token_out),
75 venue_name(best.pamm),
76 );
77
78 let pinned = prices
79 .get_quote_venue(pamm, pair.token_in, pair.token_out, size)
80 .await?;
81 println!(
82 "{} quote: {} -> {}",
83 venue_name(pamm),
84 fmt(pinned.amount_in, pinned.token_in),
85 fmt(pinned.amount_out, pinned.token_out),
86 );
87
88 Ok(())
89}Sourcepub fn with_source_and_rpc_url(
source: Arc<dyn PriceLevelsSource>,
rpc_url: impl Into<String>,
) -> Self
pub fn with_source_and_rpc_url( source: Arc<dyn PriceLevelsSource>, rpc_url: impl Into<String>, ) -> Self
Client with an explicit snapshot source and a specific RPC URL for the
quote helpers. Use this when pairing a PriceLevelsWsSource with a
private or regional deployment so quotes go to the same host as the
stream. When source is a PriceLevelsRpcSource, rpc_url is
ignored and the source’s own URL is reused.
Sourcepub fn source(&self) -> &Arc<dyn PriceLevelsSource>
pub fn source(&self) -> &Arc<dyn PriceLevelsSource>
The snapshot source Self::get_price_levels pulls from.
Sourcepub async fn get_price_levels(&self) -> Result<Arc<PriceLevelsSnapshot>>
pub async fn get_price_levels(&self) -> Result<Arc<PriceLevelsSnapshot>>
Latest price-level snapshot from the configured source.
Examples found in repository?
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // PriceLevels defaults to a one-shot HTTP snapshot source. Set
22 // PRICE_LEVELS_URL to point snapshots and quotes at a specific endpoint.
23 let prices = match std::env::var("PRICE_LEVELS_URL") {
24 Ok(url) => PriceLevels::with_source(Arc::new(PriceLevelsRpcSource::new(url))),
25 Err(_) => PriceLevels::new(),
26 };
27
28 // 1. Full snapshot: every pAMM's order book.
29 let snapshot = prices.get_price_levels().await?;
30 println!(
31 "snapshot @ block {} — {} pAMM(s)",
32 snapshot
33 .block_number
34 .map_or_else(|| "?".to_string(), |b| b.to_string()),
35 snapshot.pamms.len()
36 );
37
38 // Pick the first pAMM/pair that carries an order book to display.
39 let Some((pamm, pair)) = snapshot.pamms.iter().find_map(|entry| {
40 entry
41 .pairs
42 .iter()
43 .find(|pair| !pair.order_book.is_empty())
44 .map(|pair| (entry.pamm, pair))
45 }) else {
46 return Err("snapshot carried no order books".into());
47 };
48
49 println!(
50 "\n{} order book: {} -> {}",
51 venue_name(pamm),
52 token_symbol(pair.token_in),
53 token_symbol(pair.token_out),
54 );
55 for level in &pair.order_book {
56 println!(
57 " {} -> {} [{:?}]",
58 fmt(level.amount_in, pair.token_in),
59 fmt(level.amount_out, pair.token_out),
60 level.variant,
61 );
62 }
63
64 // 2. Quote helpers, for that pair and a mid-ladder size. `get_quote`
65 // returns the best across all pAMMs; `get_quote_venue` pins to one.
66 let size = pair.order_book[pair.order_book.len() / 2].amount_in;
67
68 let best = prices
69 .get_quote(pair.token_in, pair.token_out, size)
70 .await?;
71 println!(
72 "\nbest quote: {} -> {} via {}",
73 fmt(best.amount_in, best.token_in),
74 fmt(best.amount_out, best.token_out),
75 venue_name(best.pamm),
76 );
77
78 let pinned = prices
79 .get_quote_venue(pamm, pair.token_in, pair.token_out, size)
80 .await?;
81 println!(
82 "{} quote: {} -> {}",
83 venue_name(pamm),
84 fmt(pinned.amount_in, pinned.token_in),
85 fmt(pinned.amount_out, pinned.token_out),
86 );
87
88 Ok(())
89}Sourcepub async fn get_quote(
&self,
token_in: Address,
token_out: Address,
amount_in: U256,
) -> Result<TitanQuote>
pub async fn get_quote( &self, token_in: Address, token_out: Address, amount_in: U256, ) -> Result<TitanQuote>
Best quote across all pAMMs for a size (titan_getPammQuote).
Examples found in repository?
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // PriceLevels defaults to a one-shot HTTP snapshot source. Set
22 // PRICE_LEVELS_URL to point snapshots and quotes at a specific endpoint.
23 let prices = match std::env::var("PRICE_LEVELS_URL") {
24 Ok(url) => PriceLevels::with_source(Arc::new(PriceLevelsRpcSource::new(url))),
25 Err(_) => PriceLevels::new(),
26 };
27
28 // 1. Full snapshot: every pAMM's order book.
29 let snapshot = prices.get_price_levels().await?;
30 println!(
31 "snapshot @ block {} — {} pAMM(s)",
32 snapshot
33 .block_number
34 .map_or_else(|| "?".to_string(), |b| b.to_string()),
35 snapshot.pamms.len()
36 );
37
38 // Pick the first pAMM/pair that carries an order book to display.
39 let Some((pamm, pair)) = snapshot.pamms.iter().find_map(|entry| {
40 entry
41 .pairs
42 .iter()
43 .find(|pair| !pair.order_book.is_empty())
44 .map(|pair| (entry.pamm, pair))
45 }) else {
46 return Err("snapshot carried no order books".into());
47 };
48
49 println!(
50 "\n{} order book: {} -> {}",
51 venue_name(pamm),
52 token_symbol(pair.token_in),
53 token_symbol(pair.token_out),
54 );
55 for level in &pair.order_book {
56 println!(
57 " {} -> {} [{:?}]",
58 fmt(level.amount_in, pair.token_in),
59 fmt(level.amount_out, pair.token_out),
60 level.variant,
61 );
62 }
63
64 // 2. Quote helpers, for that pair and a mid-ladder size. `get_quote`
65 // returns the best across all pAMMs; `get_quote_venue` pins to one.
66 let size = pair.order_book[pair.order_book.len() / 2].amount_in;
67
68 let best = prices
69 .get_quote(pair.token_in, pair.token_out, size)
70 .await?;
71 println!(
72 "\nbest quote: {} -> {} via {}",
73 fmt(best.amount_in, best.token_in),
74 fmt(best.amount_out, best.token_out),
75 venue_name(best.pamm),
76 );
77
78 let pinned = prices
79 .get_quote_venue(pamm, pair.token_in, pair.token_out, size)
80 .await?;
81 println!(
82 "{} quote: {} -> {}",
83 venue_name(pamm),
84 fmt(pinned.amount_in, pinned.token_in),
85 fmt(pinned.amount_out, pinned.token_out),
86 );
87
88 Ok(())
89}Sourcepub async fn get_quote_venue(
&self,
venue: Address,
token_in: Address,
token_out: Address,
amount_in: U256,
) -> Result<TitanQuote>
pub async fn get_quote_venue( &self, venue: Address, token_in: Address, token_out: Address, amount_in: U256, ) -> Result<TitanQuote>
Quote from a specific venue for a size (titan_getPammQuoteVenue).
Examples found in repository?
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21 // PriceLevels defaults to a one-shot HTTP snapshot source. Set
22 // PRICE_LEVELS_URL to point snapshots and quotes at a specific endpoint.
23 let prices = match std::env::var("PRICE_LEVELS_URL") {
24 Ok(url) => PriceLevels::with_source(Arc::new(PriceLevelsRpcSource::new(url))),
25 Err(_) => PriceLevels::new(),
26 };
27
28 // 1. Full snapshot: every pAMM's order book.
29 let snapshot = prices.get_price_levels().await?;
30 println!(
31 "snapshot @ block {} — {} pAMM(s)",
32 snapshot
33 .block_number
34 .map_or_else(|| "?".to_string(), |b| b.to_string()),
35 snapshot.pamms.len()
36 );
37
38 // Pick the first pAMM/pair that carries an order book to display.
39 let Some((pamm, pair)) = snapshot.pamms.iter().find_map(|entry| {
40 entry
41 .pairs
42 .iter()
43 .find(|pair| !pair.order_book.is_empty())
44 .map(|pair| (entry.pamm, pair))
45 }) else {
46 return Err("snapshot carried no order books".into());
47 };
48
49 println!(
50 "\n{} order book: {} -> {}",
51 venue_name(pamm),
52 token_symbol(pair.token_in),
53 token_symbol(pair.token_out),
54 );
55 for level in &pair.order_book {
56 println!(
57 " {} -> {} [{:?}]",
58 fmt(level.amount_in, pair.token_in),
59 fmt(level.amount_out, pair.token_out),
60 level.variant,
61 );
62 }
63
64 // 2. Quote helpers, for that pair and a mid-ladder size. `get_quote`
65 // returns the best across all pAMMs; `get_quote_venue` pins to one.
66 let size = pair.order_book[pair.order_book.len() / 2].amount_in;
67
68 let best = prices
69 .get_quote(pair.token_in, pair.token_out, size)
70 .await?;
71 println!(
72 "\nbest quote: {} -> {} via {}",
73 fmt(best.amount_in, best.token_in),
74 fmt(best.amount_out, best.token_out),
75 venue_name(best.pamm),
76 );
77
78 let pinned = prices
79 .get_quote_venue(pamm, pair.token_in, pair.token_out, size)
80 .await?;
81 println!(
82 "{} quote: {} -> {}",
83 venue_name(pamm),
84 fmt(pinned.amount_in, pinned.token_in),
85 fmt(pinned.amount_out, pinned.token_out),
86 );
87
88 Ok(())
89}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PriceLevels
impl !UnwindSafe for PriceLevels
impl Freeze for PriceLevels
impl Send for PriceLevels
impl Sync for PriceLevels
impl Unpin for PriceLevels
impl UnsafeUnpin for PriceLevels
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.