Crates.io | talib |
lib.rs | talib |
version | 0.1.0 |
source | src |
created_at | 2024-01-08 03:23:48.584716 |
updated_at | 2024-01-08 03:23:48.584716 |
description | Ta-Lib binding rust safe wrapper |
homepage | |
repository | https://github.com/Yvictor/polars_ta_extension |
max_upload_size | |
id | 1092170 |
size | 224,503 |
This is a safe Rust wrapper for the Ta-Lib (Technical Analysis Library)
cargo add talib
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();
}