-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathget_reports_bulk.rs
More file actions
88 lines (77 loc) · 3.32 KB
/
get_reports_bulk.rs
File metadata and controls
88 lines (77 loc) · 3.32 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use chainlink_data_streams_report::feed_id::ID;
use chainlink_data_streams_report::report::{decode_full_report, v3::ReportDataV3};
use chainlink_data_streams_sdk::client::Client;
use chainlink_data_streams_sdk::config::Config;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let api_key = "YOUR_API_KEY_GOES_HERE";
let user_secret = "YOUR_USER_SECRET_GOES_HERE";
let rest_url = "https://api.testnet-dataengine.chain.link";
let ws_url = "wss://api.testnet-dataengine.chain.link/ws";
let eth_usd_feed_id =
ID::from_hex_str("0x000359843a543ee2fe414dc14c7e7920ef10f4372990b79d6361cdc0dd1ba782")
.unwrap();
let btc_usd_feed_id: ID =
ID::from_hex_str("0x00037da06d56d083fe599397a4769a042d63aa73dc4ef57709d31e9971a5b439")
.unwrap();
let feed_ids = vec![eth_usd_feed_id, btc_usd_feed_id];
let timestamp = 1732395909; // Example timestamp
// Initialize the configuration
let config = Config::new(
api_key.to_string(),
user_secret.to_string(),
rest_url.to_string(),
ws_url.to_string(),
)
.build()?;
// Initialize the client
let client = Client::new(config)?;
// Make a GET request to "/api/v1/reports/bulk?feedIDs={FeedID1},{FeedID2},...×tamp={timestamp}"
let response = client.get_reports_bulk(&feed_ids, timestamp).await?;
for (index, report) in response.iter().enumerate() {
println!("Report {}:", index);
println!("Feed ID: {}", report.feed_id.to_hex_string());
println!("Valid From Timestamp: {}", report.valid_from_timestamp);
println!("Observations Timestamp: {}", report.observations_timestamp);
// Uncomment to print the raw report data
// println!("Raw Report data: {}", report.full_report);
let full_report = hex::decode(&report.full_report[2..])?;
let (_report_context, report_blob) = decode_full_report(&full_report)?;
let report_data = ReportDataV3::decode(&report_blob)?;
println!("{:#?}", report_data);
}
// Prints:
//
// Report 0:
// Feed ID: 0x000359843a543ee2fe414dc14c7e7920ef10f4372990b79d6361cdc0dd1ba782
// Valid From Timestamp: 1732395909
// Observations Timestamp: 1732395909
// ReportDataV3 {
// feed_id: 0x000359843a543ee2fe414dc14c7e7920ef10f4372990b79d6361cdc0dd1ba782,
// valid_from_timestamp: 1732395909,
// observations_timestamp: 1732395909,
// native_fee: 29340742848900,
// link_fee: 5755723635476200,
// expires_at: 1732482309,
// benchmark_price: 3408230000000000000000,
// bid: 3408068208000000000000,
// ask: 3408391255216988000000,
// }
// Report 1:
// Feed ID: 0x00037da06d56d083fe599397a4769a042d63aa73dc4ef57709d31e9971a5b439
// Valid From Timestamp: 1732395909
// Observations Timestamp: 1732395909
// ReportDataV3 {
// feed_id: 0x00037da06d56d083fe599397a4769a042d63aa73dc4ef57709d31e9971a5b439,
// valid_from_timestamp: 1732395909,
// observations_timestamp: 1732395909,
// native_fee: 29343723231300,
// link_fee: 5755723635476200,
// expires_at: 1732482309,
// benchmark_price: 97731000145427245000000,
// bid: 97728886718324385000000,
// ask: 97736225246500000000000,
// }
Ok(())
}