oxi-talib

Crates.iooxi-talib
lib.rsoxi-talib
version0.1.1
created_at2025-10-03 21:05:17.495354+00
updated_at2025-10-04 04:02:50.148872+00
descriptionA Rust library for candlestick pattern recognition.
homepage
repositoryhttps://github.com/sbooker/oxi-talib
max_upload_size
id1867197
size64,497
Sergey Knigin (sbooker)

documentation

README

oxi-talib

Русская версия

Crates.io Docs.rs CI

oxi-talib is a Rust library for candlestick pattern recognition.

Key Features

  • API: The interface uses standard Rust types (Vec, Result, Option).
  • Configurability: The parameters of the recognition algorithms can be modified.
  • Safety: The public API is 100% safe. All unsafe code required for C library interaction is encapsulated.

Installation

1. System Dependencies

The library depends on the C library TA-Lib, which must be installed on the system.

Linux / macOS Build from source:

sudo apt-get update && sudo apt-get install build-essential libclang-dev

Other Systems: Install the equivalent packages (e.g., base-devel and clang on Arch Linux, "Build Tools for Visual Studio" and LLVM on Windows, or Xcode Command Line Tools on macOS).

2. Dependency in Cargo.toml

[dependencies]
oxi-talib = "0.1.0"

Example Usage

use oxi_talib::{cdl, Pattern, SimpleCandle, Error};

fn main() -> Result<(), Error> {
    // 1. Data for analysis.
    let candles: Vec<SimpleCandle> = vec![
        SimpleCandle::try_new(100.0, 105.0, 106.0, 98.0)?,
        SimpleCandle::try_new(105.0, 102.0, 107.0, 101.0)?,
        // A candle corresponding to the "Hammer" pattern
        SimpleCandle::try_new(102.0, 103.0, 104.0, 95.0)?,
        SimpleCandle::try_new(103.0, 108.0, 109.0, 102.0)?,
    ];

    // 2. Perform the analysis for the "Hammer" pattern.
    let signals = cdl().pattern(Pattern::Hammer, &candles)?;

    // 3. Process the results.
    assert_eq!(signals.len(), candles.len());

    for (i, signal) in signals.iter().enumerate() {
        if let Some(s) = signal {
            println!(
                "Hammer pattern found at candle #{} with quality {}!",
                i, s.quality.value()
            );
        }
    }
    
    Ok(())
}

Advanced Usage

Implementing the Candle Trait

To work with your own data structures, you need to implement the Candle trait.

use oxi_talib::{Candle, Pattern, cdl};

#[derive(Clone)]
struct MyData {
    open_price: f64,
    high_price: f64,
    low_price: f64,
    close_price: f64,
}

impl Candle for MyData {
    type Price = f64;
    fn open(&self) -> Self::Price { self.open_price }
    fn high(&self) -> Self::Price { self.high_price }
    fn low(&self) -> Self::Price { self.low_price }
    fn close(&self) -> Self::Price { self.close_price }
}

let my_data: Vec<MyData> = // ...

let signals = cdl().pattern(Pattern::Doji, &my_data);

Configuration

Recognition parameters can be changed via the configure function. It should be called once at application startup in a single-threaded context.

use oxi_talib::cdl::engines::talib::engine::configure;
use oxi_talib::Settings;

// Executed once in the main function.
let mut settings = Settings::default();
settings.body_doji_factor = 0.2; // Example of changing a parameter

configure(settings).expect("Configuration should not be called more than once");

// All subsequent calls to `cdl()` will use these settings.

Roadmap

  • Stage 1: TA-Lib API Coverage

    • Add all remaining candlestick patterns (CDL).
    • Implement a module for technical indicators (SMA, EMA, RSI, MACD, etc.).
  • Stage 2: Native Rust Implementation

    • Gradually replace C function calls with equivalent Rust implementations. The goal is to eliminate the dependency on the system's C library.
  • Stage 3: Advanced Analysis

    • Implement a Quality (shape correctness) and Strength (contextual significance) scoring system after transitioning to a native implementation.

License

MIT License.

Commit count: 0

cargo fmt