use std::future::Future;
use std::pin::Pin;
use crate::OpenPxError;
#[derive(Debug)]
pub struct FetchResult {
pub markets: Vec<serde_json::Value>,
pub final_cursor: Option<String>,
pub total_fetched: usize,
}
pub type CheckpointCallback = Box<
dyn Fn(
&[serde_json::Value],
&str,
) -> Pin<Box<dyn Future<Output = Result<(), OpenPxError>> + Send>>
+ Send
+ Sync,
>;
#[allow(async_fn_in_trait)]
pub trait MarketFetcher: Send + Sync {
fn exchange_id(&self) -> &'static str;
async fn fetch_markets(&self) -> Result<Vec<serde_json::Value>, OpenPxError>;
async fn fetch_markets_with_checkpoints(
&self,
start_cursor: Option<String>,
checkpoint_interval: usize,
on_checkpoint: CheckpointCallback,
) -> Result<FetchResult, OpenPxError>;
fn extract_status(&self, raw: &serde_json::Value) -> String;
}