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

macro no-std indicator_macros

Abstractions for stream aggregation, we call them Indicator s

5 releases

0.4.4 Nov 29, 2023
0.4.3 Nov 26, 2023
0.4.2 Oct 30, 2023
0.4.1 Oct 9, 2023

#1231 in Procedural macros

Download history 85/week @ 2023-12-19 320/week @ 2023-12-26 317/week @ 2024-01-02 136/week @ 2024-01-09 895/week @ 2024-01-16 938/week @ 2024-01-23 38/week @ 2024-01-30 14/week @ 2024-02-06 177/week @ 2024-02-13 117/week @ 2024-02-20 34/week @ 2024-02-27 73/week @ 2024-03-05 24/week @ 2024-03-12 26/week @ 2024-03-19 6/week @ 2024-03-26 18/week @ 2024-04-02

81 downloads per month
Used in indicator

MIT license

36KB
762 lines

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

~3.5MB
~66K SLoC