wisespace-io / binance-rs

Rust Library for the Binance API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timeout Error on loop of fetching future trade data

ktjd123 opened this issue · 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.

Might be related with seanmonstar/reqwest#1215

Using below code works like charm (async reqwest)

    let start = SystemTime::now();
    while true {
        let client = reqwest::ClientBuilder::new()
            .timeout(Duration::from_secs(5))
            .tcp_keepalive(None)
            .build()
            .unwrap();
        let result = match client
            .get("https://fapi.binance.com/fapi/v1/trades?symbol=BTCBUSD")
            .send()
            .await
        {
            Ok(o) => o,
            Err(e) => {
                println!("{:?} :  {:?}", e.status(), e);
                continue;
            }
        };
        println!(
            "{} : {}, time duration is {}",
            result.status(),
            result.text().await.unwrap().len(),
            SystemTime::now().duration_since(start).unwrap().as_secs()
        );
    }