binance-rs icon indicating copy to clipboard operation
binance-rs copied to clipboard

Timeout Error on loop of fetching future trade data

Open ktjd123 opened this issue 1 year ago • 1 comments

Hi,

I'm having error with FutureMarket.get_trades.

below is reproduce code

    let start = SystemTime::now();
    let future_market = binance::futures::market::FuturesMarket::new(None, None);
    while true {
        match future_market.get_trades("BTCBUSD") {
            Ok(_) => {
                println!(
                    "FETCH DONE, Duration from start {}s",
                    SystemTime::now().duration_since(start).unwrap().as_secs()
                );
                std::thread::sleep(Duration::from_millis(100));
                continue;
            }
            Err(e) => {
                println!(
                    "{:?}, Duration from start {}s",
                    e,
                    SystemTime::now().duration_since(start).unwrap().as_secs()
                );
                std::thread::sleep(Duration::from_millis(100));
                continue;
            }
        }
    }

after about 20s ~ 50s from start, the function keep gives Timeout error, detailed error is

FETCH DONE, Duration from start 21s
FETCH DONE, Duration from start 21s
FETCH DONE, Duration from start 21s
FETCH DONE, Duration from start 21s
FETCH DONE, Duration from start 21s
FETCH DONE, Duration from start 21s
FETCH DONE, Duration from start 22s
Error(ReqError(reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("fapi.binance.com")), port: None, path: "/fapi/v1/trades", query: Some("symbol=BTCBUSD"), fragment: None }, source: TimedOut }), State { next_error: None, backtrace: InternalBacktrace }), Duration from start 52s
Error(ReqError(reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("fapi.binance.com")), port: None, path: "/fapi/v1/trades", query: Some("symbol=BTCBUSD"), fragment: None }, source: TimedOut }), State { next_error: None, backtrace: InternalBacktrace }), Duration from start 82s

If I restart the program the code succeeds to fetch again so it doesn't seem to be rate limit related problem.

Thank you, Appreciate your works.

ktjd123 avatar Dec 07 '22 18:12 ktjd123