Skip to content

Instantly share code, notes, and snippets.

@mgild
Created November 29, 2023 21:07
Show Gist options
  • Save mgild/67c8aadd3637c196ef605e4e1e9ef05e to your computer and use it in GitHub Desktop.
Save mgild/67c8aadd3637c196ef605e4e1e9ef05e to your computer and use it in GitHub Desktop.
let v: Vec<Pin<Box<dyn Future<Output = Result<Decimal, SbError>>>>> = vec![
Box::pin(switchboard_utils::exchanges::BitfinexApi::fetch_ticker("tETHUSD", None).map_ok(|x| x.last_price)),
Box::pin(switchboard_utils::exchanges::CoinbaseApi::fetch_ticker("ETH-USD", None).map_ok(|x| x.price)),
Box::pin(switchboard_utils::exchanges::HuobiApi::fetch_ticker("ethusdt", None).map_ok(|x| Decimal::from_f64(x.close).unwrap())),
Box::pin(switchboard_utils::exchanges::KrakenApi::fetch_ticker("ETHUSD", None).map_ok(|x| x.close[0]))
];
let eth_prices: Vec<Decimal> = join_all(v).await.into_iter().filter_map(|x| x.ok()).collect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment