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

How to avoid "Connection reset by peer" error? #144

Open
Polarchicken opened this issue Sep 7, 2024 · 0 comments
Open

How to avoid "Connection reset by peer" error? #144

Polarchicken opened this issue Sep 7, 2024 · 0 comments

Comments

@Polarchicken
Copy link

This may be a noob question.
When using sdks in other languages, I would typically instantiate a single client and use it to fetch all the data. This solves the problem entirely.
In this library, however, the methods are assigned to different structs. I tried to use instantiate a Client struct but that's in a private module.
The following code would log "Connection reset by peer" errors

#[tokio::main]
async fn main() {
    let list = get_list().await;
    fetch_books(&list).await;
    let _ = time::sleep(time::Duration::from_secs(60)).await;
}

async fn get_list() -> Vec<String> {
    let client: General = Binance::new(None, None);
    match client.exchange_info().await {
        Err(_) => panic!("List Fetch Failed, Aborting \n"),
        Ok(x) => x
            .symbols
            .into_iter()
            .filter(|y| y.quote_asset == "USDT" && y.status == "TRADING")
            .map(|z| z.symbol)
            .collect(),
    }
}

#[allow(dead_code)]
async fn fetch_books(list: &Vec<String>) {
    let client = Arc::new(Market::new(None, None));

    list.into_iter().for_each(|x| {
        let client_copy = Arc::clone(&client);
        let symbol = x.clone();
        task::spawn(async move {
            if let Err(e) = client_copy.get_depth(symbol).await {
                panic!("{e:?}");
            }
        });
    })
}
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