Download the PHP package robertgdev/ta-lib-hybrid without Composer
On this page you can find all versions of the php package robertgdev/ta-lib-hybrid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robertgdev/ta-lib-hybrid
More information about robertgdev/ta-lib-hybrid
Files in robertgdev/ta-lib-hybrid
Package ta-lib-hybrid
Short Description Hybrid TA-Lib wrapper: ext-ta-lib with pure PHP fallback
License MIT
Informations about the package ta-lib-hybrid
TaLibHybrid
A hybrid PHP wrapper for TA-Lib that provides 161 technical analysis indicator functions with automatic pass-through to the C extension when available, and a pure-PHP fallback when it's not.
Installation
The C extension is optional but recommended for performance:
Add to php.ini:
The library works without the extension — it will automatically fall back to the pure-PHP implementation.
Requirements
- PHP 8.3+
ext-ta_lib^1.0 (optional, recommended for 5-50x faster calculations)
Design
Goals
- Transparent dual-backend — When
ext-ta_libis loaded, all calls go through the C extension for maximum speed. When it's absent, the pure-PHP fallback delivers identical results. - Zero-disruption migration — Procedural
ta_*polyfill functions (ta_sma,ta_atr, etc.) andTA_*constants are defined only when the extension is not present, so existing code usingta_sma()works unchanged. - Consistent output format — Both backends return the same array structure: null-padded aligned arrays where leading positions (the lookback period) are
nulland actual values start at the correct offset. Multi-output indicators use lowercase string keys. - Full coverage — All 161 TA-Lib indicator functions are implemented, including
imiandmomwhich are missing from the C extension.
Architecture
Auto-detection: TaLibHybrid checks extension_loaded('ta_lib') on first call and selects the appropriate backend. You can override this with TaLibHybrid::setBackend().
Fallback delegation: ExtensionBackend delegates mom() and mama() to FallbackBackend because the C extension does not provide ta_mom, and ta_mama returns a broken flat array instead of the expected multi-output format.
Directory structure
Usage
OOP via static facade
Procedural polyfill
Works identically to the C extension's function signatures:
These functions are only defined when ext-ta_lib is not loaded, so they never conflict with the extension.
Backend selection
Direct backend instantiation
Output format
All indicator methods return arrays aligned with the input index. Values in the lookback period are null:
Multi-output indicators return an associative array of such arrays:
Indicator categories
| Category | Count | Examples |
|---|---|---|
| Overlap Studies | 18 | sma, ema, wma, dema, tema, bbands, kama, t3 |
| Momentum Indicators | 31 | rsi, macd, stoch, adx, cci, willr, mom, imi |
| Pattern Recognition | 61 | cdldoji, cdlengulfing, cdlhammer, cdlmorningstar |
| Statistic Functions | 9 | beta, correl, stddev, linearreg, tsf |
| Math Operators | 11 | add, sub, mult, div, sum, max, min |
| Math Transform | 15 | sin, cos, sqrt, exp, ln, ceil, floor |
| Volatility Indicators | 3 | atr, natr, trange |
| Cycle Indicators | 5 | ht_dcperiod, ht_dcphase, ht_sine |
| Volume Indicators | 3 | obv, ad, adosc |
| Price Transform | 5 | avgprice, medprice, typprice, wclprice |
Exceptions
Constants
When ext-ta_lib is loaded, it provides TA_MA_TYPE_SMA and similar constants. When it's not, Constants.php polyfills them all:
TA_MA_TYPE_*— Moving average types (0–8)TA_FUNC_UNST_*— Unstable period function IDs (0–24)TA_SUCCESS,TA_BAD_PARAM, … — Return codesTA_CANDLE_SETTING_*— Candle setting types (0–11)TA_RANGE_TYPE_*— Range types (0–2)TA_COMPATIBILITY_*— Compatibility modes (0–1)TA_REAL_MIN,TA_REAL_MAX,TA_INTEGER_MIN,TA_INTEGER_MAX
Each constant is guarded individually with if (!defined(...)), so they coexist correctly with the extension.
Testing
The package includes a Pest test suite with 213 tests and ~3000 assertions:
Test suites:
- Unit — Input validation, output format, value ranges, key names, all 61 pattern recognition functions
- Comparison — Cross-backend verification: Extension vs Fallback output for 60+ indicators within floating-point tolerance
License
MIT