Skip to content

Commit b86ec83

Browse files
committed
update examples
1 parent d2049b1 commit b86ec83

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

examples/src/token.rs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use jup_ag_sdk::{JupiterClient, types::TokenPriceRequest};
1+
use jup_ag_sdk::{JupiterClient, client};
22

33
pub async fn token_balances() {
44
let client = JupiterClient::new("https://lite-api.jup.ag");
@@ -31,48 +31,22 @@ pub async fn token_price() {
3131
"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN".to_string(),
3232
];
3333

34-
let params = TokenPriceRequest::new(&token_mints);
35-
36-
let price = client
37-
.get_token_price(&params)
38-
.await
39-
.expect("Failed to get token price");
40-
41-
let sol_price = price
42-
.data
43-
.get(token_mints[0].as_str())
44-
.expect("SOL price not found");
45-
46-
println!("1 SOL price in USDC: {}", sol_price.price);
47-
48-
let jup_price = price
49-
.data
50-
.get(token_mints[1].as_str())
51-
.expect("Jup Token price not found");
52-
53-
println!("1 JUP price USDC: {}", jup_price.price);
54-
55-
let params = TokenPriceRequest::new(&token_mints)
56-
.with_vs_token("So11111111111111111111111111111111111111112");
57-
5834
let price = client
59-
.get_token_price(&params)
35+
.get_tokens_price(&token_mints)
6036
.await
6137
.expect("Failed to get token price");
6238

6339
let sol_price = price
64-
.data
6540
.get(token_mints[0].as_str())
6641
.expect("SOL price not found");
6742

68-
println!("1 SOL price in SOL: {}", sol_price.price);
43+
println!("1 SOL price in USDC: {}", sol_price.usd_price);
6944

7045
let jup_price = price
71-
.data
7246
.get(token_mints[1].as_str())
7347
.expect("Jup Token price not found");
7448

75-
println!("1 JUP price in SOL: {}", jup_price.price);
49+
println!("1 JUP price USDC: {}", jup_price.usd_price);
7650
}
7751

7852
pub async fn token_info() {
@@ -115,3 +89,18 @@ pub async fn get_tokens_from_tags() {
11589

11690
println!("mints: {}", mints.len())
11791
}
92+
93+
pub async fn get_trending_tokens() {
94+
let client = JupiterClient::new("https:://lite-api.jup.ag");
95+
96+
let tokens = client
97+
.get_tokens_by_category(
98+
jup_ag_sdk::types::Category::TopTrending,
99+
jup_ag_sdk::types::Interval::TwentyFourHours,
100+
Some(10),
101+
)
102+
.await
103+
.expect("failed to get trending tokens");
104+
105+
println!("trending tokens: {:?}", tokens.len());
106+
}

jup-ag-sdk/src/client/token_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl JupiterClient {
121121
/// .get_mints_by_category(Category::TopTrending, Interval::OneHour, None)
122122
/// .await.expect("failed to get tokens");
123123
/// ```
124-
pub async fn get_mints_by_category(
124+
pub async fn get_tokens_by_category(
125125
&self,
126126
category: Category,
127127
interval: Interval,

0 commit comments

Comments
 (0)