use std::sync::Arc;
use digdigdig3::connector_manager::ExchangeHub;
use digdigdig3::core::types::{AccountType, ExchangeId, SymbolInput};
use crate::data::{BarPoint, TradePoint};
pub async fn trades_recent(
hub: &Arc<ExchangeHub>,
exchange: ExchangeId,
account: AccountType,
symbol: &str,
limit: usize,
) -> Vec<TradePoint> {
let Some(rest) = hub.rest(exchange) else { return Vec::new(); };
let limit = limit.min(1000).max(1) as u32;
let res = rest
.get_recent_trades(SymbolInput::Raw(symbol), Some(limit), account)
.await;
match res {
Ok(trades) => trades.iter().map(TradePoint::from_public).collect(),
Err(e) => {
tracing::debug!(?e, exchange = ?exchange, "rest backfill trades failed");
Vec::new()
}
}
}
pub async fn klines_recent(
hub: &Arc<ExchangeHub>,
exchange: ExchangeId,
account: AccountType,
symbol: &str,
interval: &str,
limit: usize,
) -> Vec<BarPoint> {
let Some(rest) = hub.rest(exchange) else { return Vec::new(); };
let limit = limit.min(1000).max(1) as u16;
let res = rest
.get_klines(
SymbolInput::Raw(symbol),
interval,
Some(limit),
account,
None,
)
.await;
match res {
Ok(bars) => bars.iter().map(BarPoint::from_kline).collect(),
Err(e) => {
tracing::debug!(?e, exchange = ?exchange, interval, "rest backfill klines failed");
Vec::new()
}
}
}