#stream #no-std #stream-processing #aggregation

no-std indicator

Abstractions for stream aggregation, we call them Indicator s

33 releases

Uses new Rust 2021

0.4.0-rc.1 Nov 23, 2022
0.3.4 Dec 7, 2022
0.3.0 Oct 10, 2022
0.3.0-alpha.5 May 23, 2022
0.1.2 Nov 18, 2021

#181 in Rust patterns

Download history 330/week @ 2022-08-15 272/week @ 2022-08-22 425/week @ 2022-08-29 353/week @ 2022-09-05 297/week @ 2022-09-12 489/week @ 2022-09-19 589/week @ 2022-09-26 88/week @ 2022-10-03 272/week @ 2022-10-10 313/week @ 2022-10-17 243/week @ 2022-10-24 374/week @ 2022-10-31 143/week @ 2022-11-07 77/week @ 2022-11-14 120/week @ 2022-11-21 612/week @ 2022-11-28

1,026 downloads per month
Used in 4 crates (via exc-core)

MIT license

125KB
3.5K SLoC

Indicator

Abstractions for stream aggregation, we call them Indicator s.

Crates.io MIT licensed Build Status

API Docs

Example

Add indicator as a dependency of your project.

[dependencies]
indicator = "0.3"
rust_decimal = "1.17.0"
rust_decimal_macros = "1.17.0"
time = { version = "0.3", default-features = false, features = ["macros"] }

And then, you can try these codes.

use arrayvec::ArrayVec;
use indicator::*;
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
use time::macros::{datetime, offset};

/// Return an indicator that calculate `hl2` and `ohlc4` simultaneously.
fn hl2_ohlc4(period: Period) -> impl Operator<TickValue<Decimal>, Output = (Decimal, Decimal)> {
    tumbling(
        period,
        |_w: &ArrayVec<[Decimal; 4], 0>, y: &mut Option<[Decimal; 4]>, x| match y {
            Some(ohlc) => {
                ohlc[1] = ohlc[1].max(x);
                ohlc[2] = ohlc[2].min(x);
                ohlc[3] = x;
                *ohlc
            }
            None => {
                let ohlc = [x; 4];
                *y = Some(ohlc);
                ohlc
            }
        },
    )
    .then(facet_t(
        map_t(|ohlc: [Decimal; 4]| (ohlc[1] + ohlc[2]) / dec!(2)),
        map_t(|ohlc: [Decimal; 4]| (ohlc[0] + ohlc[1] + ohlc[2] + ohlc[3]) / dec!(4)),
    ))
    .map(|v| v.value)
}

Dependencies

~0.5–1.3MB
~26K SLoC