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

no-std indicator

Abstractions for stream aggregation, we call them Indicator s

41 releases

0.4.4 Nov 29, 2023
0.4.2 Oct 30, 2023
0.4.0 Jun 5, 2023
0.4.0-rc.1 Nov 23, 2022
0.1.2 Nov 18, 2021

#267 in Rust patterns

Download history 668/week @ 2023-10-30 203/week @ 2023-11-06 351/week @ 2023-11-13 443/week @ 2023-11-20 462/week @ 2023-11-27 179/week @ 2023-12-04 503/week @ 2023-12-11 137/week @ 2023-12-18 460/week @ 2023-12-25 414/week @ 2024-01-01 445/week @ 2024-01-08 774/week @ 2024-01-15 1580/week @ 2024-01-22 294/week @ 2024-01-29 148/week @ 2024-02-05 427/week @ 2024-02-12

2,485 downloads per month
Used in 6 crates (2 directly)

MIT license

180KB
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.4"
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.7–2.1MB
~40K SLoC