use ig_trading_api::streaming_api::StreamingApi;
use lightstreamer_client::item_update::ItemUpdate;
use lightstreamer_client::subscription::{Snapshot, Subscription, SubscriptionMode};
use lightstreamer_client::subscription_listener::SubscriptionListener;
use std::error::Error;
pub struct MySubscriptionListener {}
impl SubscriptionListener for MySubscriptionListener {
fn on_item_update(&mut self, update: ItemUpdate) {
println!(
"UPDATE {} {}",
update.get_value("stock_name").unwrap(),
update.get_value("last_price").unwrap()
);
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let mut my_subscription = Subscription::new(
SubscriptionMode::Merge,
Some(vec![
"MARKET:CS.D.BITCOIN.CFD.IP".to_string(), ]),
Some(vec![
"BID".to_string(),
"OFFER".to_string(),
"HIGH".to_string(),
"LOW".to_string(),
"MID_OPEN".to_string(),
"CHANGE".to_string(),
"CHANGE_PCT".to_string(),
"MARKET_DELAY".to_string(),
"MARKET_STATE".to_string(),
"UPDATE_TIME".to_string(),
]),
)?;
my_subscription.set_requested_snapshot(Some(Snapshot::Yes))?;
my_subscription.add_listener(Box::new(MySubscriptionListener {}));
let mut streaming_api = StreamingApi::new(vec![my_subscription]).await?;
streaming_api.connect().await;
Ok(())
}