pub(crate) fn crawl_snapshot(
    exchange: &str,
    market_type: MarketType,
    msg_type: MessageType, // L2Snapshot or L3Snapshot
    symbols: Option<&[String]>,
    on_msg: Arc<Mutex<dyn FnMut(Message) + 'static + Send>>,
    interval: Option<u64>,
    duration: Option<u64>,
) {
    let interval = Duration::from_secs(interval.unwrap_or(60));
    let now = Instant::now();
    loop {
        let loop_start = Instant::now();

        let is_empty = match symbols {
            Some(list) => {
                if list.is_empty() {
                    true
                } else {
                    check_args(exchange, market_type, &list);
                    false
                }
            }
            None => true,
        };

        let real_symbols = if is_empty {
            fetch_symbols_retry(exchange, market_type)
        } else {
            symbols.unwrap().to_vec()
        };

        for symbol in real_symbols.iter() {
            let resp = match msg_type {
                MessageType::L2Snapshot => fetch_l2_snapshot(exchange, market_type, symbol),
                MessageType::L3Snapshot => fetch_l3_snapshot(exchange, market_type, symbol),
                _ => panic!("msg_type must be L2Snapshot or L3Snapshot"),
            };
            match resp {
                Ok(msg) => {
                    let message = Message::new(exchange.to_string(), market_type, msg_type, msg);
                    (on_msg.lock().unwrap())(message);
                }
                Err(err) => error!("{} {} {}, error: {}", exchange, market_type, symbol, err),
            }
        }

        if let Some(seconds) = duration {
            if now.elapsed() > Duration::from_secs(seconds) {
                break;
            }
        }
        if loop_start.elapsed() < interval {
            std::thread::sleep(interval - loop_start.elapsed());
        }
    }
}
/// Crawl leve2 or level3 orderbook snapshots through RESTful APIs.
Crawl leve2 or level3 orderbook snapshots through RESTful APIs.
Crawl leve2 or level3 orderbook snapshots through RESTful APIs .
pub(crate) fn crawl_snapshot(
    exchange: &str,
    market_type: MarketType,
    msg_type: MessageType, // L2Snapshot or L3Snapshot
    symbols: Option<&[String]>,
    on_msg: Arc<Mutex<dyn FnMut(Message) + 'static + Send>>,
    interval: Option<u64>,
    duration: Option<u64>,
) {
    let interval = Duration::from_secs(interval.unwrap_or(60));
    let now = Instant::now();
    loop {
        let loop_start = Instant::now();
        let is_empty = match symbols {
            Some(list) => {
                if list.is_empty() {
                    true
                } else {
                    check_args(exchange, market_type, &list);
                    false
                }
            }
            None => true,
        };
        let real_symbols = if is_empty {
            fetch_symbols_retry(exchange, market_type)
        } else {
            symbols.unwrap().to_vec()
        };
        for symbol in real_symbols.iter() {
            let resp = match msg_type {
                MessageType::L2Snapshot => fetch_l2_snapshot(exchange, market_type, symbol),
                MessageType::L3Snapshot => fetch_l3_snapshot(exchange, market_type, symbol),
                _ => panic!("msg_type must be L2Snapshot or L3Snapshot"),
            };
            match resp {
                Ok(msg) => {
                    let message = Message::new(exchange.to_string(), market_type, msg_type, msg);
                    (on_msg.lock().unwrap())(message);
                }
                Err(err) => error!("{} {} {}, error: {}", exchange, market_type, symbol, err),
            }
        }
        if let Some(seconds) = duration {
            if now.elapsed() > Duration::from_secs(seconds) {
                break;
            }
        }
        if loop_start.elapsed() < interval {
            std::thread::sleep(interval - loop_start.elapsed());
        }
    }
}
pub ( crate ) fn crawl_snapshot ( exchange : & str , market_type : MarketType , msg_type : MessageType , // L2Snapshot or L3Snapshot symbols : Option < & [ String ] > , on_msg : Arc < Mutex < dyn FnMut ( Message ) + ' static + Send > > , interval : Option < u64 > , duration : Option < u64 > , ) { let interval = Duration :: from_secs ( interval . unwrap_or ( 60 ) ) ; let now = Instant :: now ( ) ; loop { let loop_start = Instant :: now ( ) ; let is_empty = match symbols { Some ( list ) => { if list . is_empty ( ) { true } else { check_args ( exchange , market_type , & list ) ; false } } None => true , } ; let real_symbols = if is_empty { fetch_symbols_retry ( exchange , market_type ) } else { symbols . unwrap ( ) . to_vec ( ) } ; for symbol in real_symbols . iter ( ) { let resp = match msg_type { MessageType :: L2Snapshot => fetch_l2_snapshot ( exchange , market_type , symbol ) , MessageType :: L3Snapshot => fetch_l3_snapshot ( exchange , market_type , symbol ) , _ => panic ! ( " " ) , } ; match resp { Ok ( msg ) => { let message = Message :: new ( exchange . to_string ( ) , market_type , msg_type , msg ) ; ( on_msg . lock ( ) . unwrap ( ) ) ( message ) ; } Err ( err ) => error ! ( " " exchange market_type symbol err ) , } } if let Some ( seconds ) = duration { if now . elapsed ( ) > Duration :: from_secs ( seconds ) { break ; } } if loop_start . elapsed ( ) < interval { std :: thread :: sleep ( interval - loop_start . elapsed ( ) ) ; } } }
Crawl leve2 or level3 orderbook snapshots through RESTful APIs.
Crawl leve2 or level3 orderbook snapshots through RESTful APIs .
exchange
&str
market_type
MarketType
msg_type
MessageType
symbols
Option<&[String]>
on_msg
Arc<Mutex<dyn FnMut(Message) + 'static + Send>>
interval
Option<u64>
duration
Option<u64>