Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout Error on loop of fetching future trade data #194

Open
ktjd123 opened this issue Dec 7, 2022 · 1 comment
Open

Timeout Error on loop of fetching future trade data #194

ktjd123 opened this issue Dec 7, 2022 · 1 comment

Comments

@ktjd123
Copy link
Contributor

ktjd123 commented Dec 7, 2022

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
Copy link
Contributor Author

ktjd123 commented Dec 7, 2022

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()
        );
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant