Nouzan / exc

An abstraction layer for exchanges
MIT License
38 stars 14 forks source link

Sometimes `QueryLastCandles` takes a long time (2m 11s) #56

Closed rise0chen closed 1 year ago

rise0chen commented 1 year ago
impl<C, Req> Exchange<C, Req>
where
    Exc<C, Req>: ExcService<QueryLastCandles>,
{
    pub async fn get_price(&mut self, period: Period, num: usize) -> anyhow::Result<Vec<Decimal>> {
        let range = ..;
        let req = QueryLastCandles::new(&self.inst, period, range, num);
        let sub = (&mut self.public_exc).oneshot(req).await?;
        let data = sub.filter_map(|x| async { x.ok().map(|x|x.close) }).collect().await;
        Ok(data)
    }
}

Sometimes it takes a long time(2m 11s), but in most cases it only takes a short time(0.7s).

Do you know what causes it to take a long time?

Nouzan commented 1 year ago

What are the arguments you used within the above method?

rise0chen commented 1 year ago
let history = self.exchange.get_price(Period::minutes(UtcOffset::UTC, 1), 100).await.unwrap();
let price = self.exchange.get_price(Period::seconds(UtcOffset::UTC, 1), 1).await;

It may be caused by network fluctuations.

rise0chen commented 1 year ago

Can we set timeout for http?

Nouzan commented 1 year ago

You can set timeout at request level.

rise0chen commented 1 year ago

use tokio::time::timeout ?

Nouzan commented 1 year ago

Yes, or you can use TimeoutLayer if you are familiar with tower.