Skip to content

Commit

Permalink
feat: talib add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvictor committed Jan 8, 2024
1 parent 04e833e commit fe190a1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
8 changes: 7 additions & 1 deletion talib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
name = "talib"
version = "0.1.0"
edition = "2021"
description = "Ta-Lib binding rust safe wrapper"
keywords = ["Ta-Lib"]
readme = "README.md"
license = "MIT"
categories = ["api-bindings"]
repository = "https://github.com/Yvictor/polars_ta_extension"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
talib-sys = { path = "../talib-sys"}
talib-sys = { version = "0.1.0", path = "../talib-sys"}
54 changes: 54 additions & 0 deletions talib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# talib

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


## Installation
``` bash
cargo add talib
```

## Example
``` rust
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();
}

```




4 changes: 3 additions & 1 deletion talib/examples/rsi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use talib::common::TimePeriodKwargs;
use talib::common::{TimePeriodKwargs, ta_initialize, ta_shutdown};
use talib::momentum::ta_rsi;

fn main() {
let _ = ta_initialize();
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,
Expand All @@ -20,4 +21,5 @@ fn main() {
println!("Error: {:?}", e);
}
}
let _ = ta_shutdown();
}

0 comments on commit fe190a1

Please sign in to comment.