Nouzan / exc

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

feat: add 24hr statistics for SubscribeTickers #64

Closed rise0chen closed 5 months ago

Nouzan commented 1 year ago

Why not just add MiniTicker for the 24-hour statistics and keep Ticker as it is now? Since we can calculate the 24-hour statistics just by using last.

Nouzan commented 1 year ago

It is fine for me to just add another kind of "Ticker".

rise0chen commented 1 year ago

Like this?

pub struct Ticker {
    /// Timestamp.
    #[serde(with = "time::serde::rfc3339")]
    pub ts: OffsetDateTime,
    /// Last traded price.
    pub last: Decimal,
    /// Last traded size.
    #[serde(default)]
    pub size: Decimal,
    /// Last traded side.
    #[serde(default)]
    pub buy: Option<bool>,
    /// Current best bid.
    #[serde(default)]
    pub bid: Option<Decimal>,
    /// The size of current best bid.
    #[serde(default)]
    pub bid_size: Option<Decimal>,
    /// Current best ask.
    #[serde(default)]
    pub ask: Option<Decimal>,
    /// The size of current best ask.
    #[serde(default)]
    pub ask_size: Option<Decimal>,
}

pub struct Statistics  {
    /// Timestamp.
    #[serde(with = "time::serde::rfc3339")]
    pub ts: OffsetDateTime,
    /// Last traded price.
    pub close: Decimal,
    /// Open price in the past 24 hours
    #[serde(default)]
    pub open: Decimal,
    /// Highest price in the past 24 hours
    #[serde(default)]
    pub high: Decimal,
    /// Lowest price in the past 24 hours
    #[serde(default)]
    pub low: Decimal,
    /// 24h trading volume.
    #[serde(default)]
    pub vol: Decimal,
}
Nouzan commented 1 year ago

Yes, I think that would be better.

rise0chen commented 1 year ago
let mut sub_ticker = self.ticker.subscribe_tickers(&self.inst).await?;
let mut sub_statistic = self.statistic.subscribe_statistics(&self.inst).await?;

sub_ticker will close, when subscribe_statistics, on okx.

Nouzan commented 1 year ago
let mut sub_ticker = self.ticker.subscribe_tickers(&self.inst).await?;
let mut sub_statistic = self.statistic.subscribe_statistics(&self.inst).await?;

sub_ticker will close, when subscribe_statistics, on okx.

Thank you for your work, I will check.

Nouzan commented 1 year ago
let mut sub_ticker = self.ticker.subscribe_tickers(&self.inst).await?;
let mut sub_statistic = self.statistic.subscribe_statistics(&self.inst).await?;

sub_ticker will close, when subscribe_statistics, on okx.

I can't reproduce. It just returned the "already subscribed" error as expected.

rise0chen commented 1 year ago

I can't reproduce. It just returned the "already subscribed" error as expected.

I can't reproduce, too. subscribe_statistics returned the "already subscribed" error, and sub_ticker not close.

Nouzan commented 5 months ago

Closing this PR as it's stale, but feel free to reopen it at any time.