-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpublic_data.rs
More file actions
57 lines (50 loc) · 2.26 KB
/
public_data.rs
File metadata and controls
57 lines (50 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use polymarket_rs::client::DataClient;
use polymarket_rs::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Create a DataClient for accessing position and portfolio data
let client = DataClient::new("https://data-api.polymarket.com");
// Example wallet address
let user_address = "0xe0368af7f5777989b927b7ad0d420562fee8616c";
// Get all positions for a user
println!("Fetching positions for user: {}...\n", user_address);
match client.get_positions(user_address).await {
Ok(positions) => {
println!("Found {} positions:", positions.len());
for (i, position) in positions.iter().enumerate() {
println!("\nPosition {}:", i + 1);
println!(" Market: {}", position.title);
println!(" Outcome: {}", position.outcome);
println!(" Size: {}", position.size);
println!(" Average Price: {}", position.avg_price);
println!(" Current Price: {}", position.cur_price);
println!(" Current Value: ${}", position.current_value);
println!(" Cash P&L: ${}", position.cash_pnl);
println!(" Percent P&L: {}%", position.percent_pnl);
println!(" Realized P&L: ${}", position.realized_pnl);
println!(" Redeemable: {}", position.redeemable);
println!(" End Date: {}", position.end_date);
// Only show first 5 positions to keep output manageable
if i >= 4 {
println!("\n... and {} more positions", positions.len() - 5);
break;
}
}
}
Err(e) => println!("Error fetching positions: {}", e),
}
// Get the total value of positions for a user
println!("Fetching position value for user: {}...\n", user_address);
match client.get_positions_value(user_address).await {
Ok(values) => {
println!("Position values:");
for value in values {
println!(" User: {}", value.user);
println!(" Total Value: ${}", value.value);
}
}
Err(e) => println!("Error fetching position value: {}", e),
}
println!("\nExample completed successfully!");
Ok(())
}