feat: TA-Lib candlestick patterns — separating/kicking/ladder/mat-hold (part 6 of 9) (#138)

This commit is contained in:
kingchenc
2026-06-02 17:06:40 +02:00
committed by GitHub
parent e4ca9c3f8f
commit 04ae145126
19 changed files with 1274 additions and 39 deletions
+10
View File
@@ -265,6 +265,11 @@ from ._wickra import (
OnNeck,
InNeck,
Thrusting,
SeparatingLines,
Kicking,
KickingByLength,
LadderBottom,
MatHold,
# Microstructure: order book
OrderBookImbalanceTop1,
OrderBookImbalanceTopN,
@@ -557,6 +562,11 @@ __all__ = [
"OnNeck",
"InNeck",
"Thrusting",
"SeparatingLines",
"Kicking",
"KickingByLength",
"LadderBottom",
"MatHold",
# Microstructure: order book
"OrderBookImbalanceTop1",
"OrderBookImbalanceTopN",
+10
View File
@@ -11657,6 +11657,11 @@ candle_pattern_no_param!(PyHomingPigeon, wc::HomingPigeon, "HomingPigeon");
candle_pattern_no_param!(PyOnNeck, wc::OnNeck, "OnNeck");
candle_pattern_no_param!(PyInNeck, wc::InNeck, "InNeck");
candle_pattern_no_param!(PyThrusting, wc::Thrusting, "Thrusting");
candle_pattern_no_param!(PySeparatingLines, wc::SeparatingLines, "SeparatingLines");
candle_pattern_no_param!(PyKicking, wc::Kicking, "Kicking");
candle_pattern_no_param!(PyKickingByLength, wc::KickingByLength, "KickingByLength");
candle_pattern_no_param!(PyLadderBottom, wc::LadderBottom, "LadderBottom");
candle_pattern_no_param!(PyMatHold, wc::MatHold, "MatHold");
// ============================== Microstructure: Order Book ==============================
//
// Order-book indicators consume a depth snapshot rather than OHLCV. Streaming
@@ -14178,6 +14183,11 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyOnNeck>()?;
m.add_class::<PyInNeck>()?;
m.add_class::<PyThrusting>()?;
m.add_class::<PySeparatingLines>()?;
m.add_class::<PyKicking>()?;
m.add_class::<PyKickingByLength>()?;
m.add_class::<PyLadderBottom>()?;
m.add_class::<PyMatHold>()?;
// Microstructure: order book.
m.add_class::<PyOrderBookImbalanceTop1>()?;
m.add_class::<PyOrderBookImbalanceTopN>()?;
@@ -623,6 +623,26 @@ CANDLE_SCALAR = {
lambda: ta.Thrusting(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"SeparatingLines": (
lambda: ta.SeparatingLines(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"Kicking": (
lambda: ta.Kicking(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"KickingByLength": (
lambda: ta.KickingByLength(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"LadderBottom": (
lambda: ta.LadderBottom(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"MatHold": (
lambda: ta.MatHold(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
}
@@ -1835,6 +1855,42 @@ def test_thrusting_reference():
assert t.update((15.0, 15.1, 9.0, 10.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((7.0, 11.6, 6.9, 11.5, 1.0, 1)) == pytest.approx(-1.0)
def test_separating_lines_reference():
t = ta.SeparatingLines()
assert t.update((12.0, 12.1, 9.9, 10.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((12.0, 14.1, 12.0, 14.0, 1.0, 1)) == pytest.approx(1.0)
def test_kicking_reference():
t = ta.Kicking()
assert t.update((12.0, 12.0, 10.0, 10.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((14.0, 16.0, 14.0, 16.0, 1.0, 1)) == pytest.approx(1.0)
def test_kicking_by_length_reference():
t = ta.KickingByLength()
assert t.update((12.0, 12.0, 10.0, 10.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((14.0, 20.0, 14.0, 20.0, 1.0, 1)) == pytest.approx(1.0)
def test_ladder_bottom_reference():
t = ta.LadderBottom()
assert t.update((20.0, 20.1, 17.9, 18.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((18.0, 18.1, 15.9, 16.0, 1.0, 1)) == pytest.approx(0.0)
assert t.update((16.0, 16.1, 13.9, 14.0, 1.0, 2)) == pytest.approx(0.0)
assert t.update((14.0, 15.0, 12.4, 12.5, 1.0, 3)) == pytest.approx(0.0)
assert t.update((15.0, 17.1, 14.9, 17.0, 1.0, 4)) == pytest.approx(1.0)
def test_mat_hold_reference():
t = ta.MatHold()
assert t.update((10.0, 15.1, 9.9, 15.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((16.0, 16.1, 15.4, 15.5, 1.0, 1)) == pytest.approx(0.0)
assert t.update((15.5, 15.6, 14.9, 15.0, 1.0, 2)) == pytest.approx(0.0)
assert t.update((15.0, 15.1, 14.4, 14.5, 1.0, 3)) == pytest.approx(0.0)
assert t.update((14.5, 17.1, 14.4, 17.0, 1.0, 4)) == pytest.approx(1.0)
# --- Lifecycle ------------------------------------------------------------