1 unstable release

0.1.0 Jan 8, 2024

#88 in Finance

Download history 4/week @ 2024-01-03 3/week @ 2024-02-14 11/week @ 2024-02-21 6/week @ 2024-02-28 4/week @ 2024-03-27 39/week @ 2024-04-03 9/week @ 2024-04-10

52 downloads per month

MIT license

400KB
13K SLoC

talib

Ta-Lib Safe Wrapper for Rust

This is a safe Rust wrapper for the Ta-Lib (Technical Analysis Library)

Installation

cargo add talib

Example

use talib::common::{TimePeriodKwargs, ta_initialize, ta_shutdown};
use talib::momentum::ta_rsi;

fn main() {
    // Initialize Ta-Lib
    let _ = ta_initialize();

    // Sample close prices
    let close_prices: Vec<f64> = vec![
        1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
        1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
        1.086670, 1.086630,
    ];

    // Specify the RSI calculation parameters
    let kwargs = TimePeriodKwargs { timeperiod: 5 };

    // Calculate RSI
    let res = ta_rsi(close_prices.as_ptr(), close_prices.len(), &kwargs);

    // Process the result
    match res {
        Ok(rsi_values) => {
            for (index, value) in rsi_values.iter().enumerate() {
                println!("RSI at index {}: {}", index, value);
            }
        }
        Err(e) => {
            println!("Error: {:?}", e);
        }
    }

    // Shutdown Ta-Lib
    let _ = ta_shutdown();
}

Dependencies

~0.4–8MB
~167K SLoC