From a67540fc959daac22c8d7abfa18de922e9367ecf Mon Sep 17 00:00:00 2001 From: YuWuKunCheng Date: Tue, 26 May 2026 11:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=94=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chan.py | 4 +- chanlun-py/Cargo.toml | 2 +- chanlun-py/build.sh | 10 ++ chanlun-py/bump_version.py | 74 +++++++++ chanlun-py/pyproject.toml | 2 +- chanlun-py/src/algorithm_py.rs | 120 +++++++++++++- chanlun-py/src/business_py.rs | 216 ++++++++++++++++++++++---- chanlun-py/src/config_py.rs | 34 ++++ chanlun-py/src/indicators_py.rs | 24 +++ chanlun-py/src/kline_py.rs | 24 +++ chanlun-py/src/lib.rs | 24 +++ chanlun-py/src/structure_py.rs | 131 +++++++++++++++- chanlun-py/src/types_py.rs | 24 +++ chanlun/src/algorithm/bi.rs | 24 +++ chanlun/src/algorithm/divergence.rs | 24 +++ chanlun/src/algorithm/hub.rs | 24 +++ chanlun/src/algorithm/mod.rs | 24 +++ chanlun/src/algorithm/segment.rs | 24 +++ chanlun/src/business/bsp.rs | 24 +++ chanlun/src/business/mod.rs | 24 +++ chanlun/src/business/multi_frame.rs | 55 +++++-- chanlun/src/business/observer.rs | 38 ++++- chanlun/src/business/synthesizer.rs | 24 +++ chanlun/src/config.rs | 24 +++ chanlun/src/indicators/kdj.rs | 24 +++ chanlun/src/indicators/macd.rs | 24 +++ chanlun/src/indicators/mod.rs | 24 +++ chanlun/src/indicators/rsi.rs | 24 +++ chanlun/src/kline/bar.rs | 24 +++ chanlun/src/kline/chan_kline.rs | 24 +++ chanlun/src/kline/mod.rs | 24 +++ chanlun/src/lib.rs | 24 +++ chanlun/src/main.rs | 26 ++++ chanlun/src/structure/dash_line.rs | 24 +++ chanlun/src/structure/feat_fractal.rs | 24 +++ chanlun/src/structure/fractal_obj.rs | 24 +++ chanlun/src/structure/mod.rs | 24 +++ chanlun/src/structure/segment_feat.rs | 24 +++ chanlun/src/types/bsp_type.rs | 24 +++ chanlun/src/types/direction.rs | 24 +++ chanlun/src/types/fractal.rs | 24 +++ chanlun/src/types/gap.rs | 24 +++ chanlun/src/types/mod.rs | 24 +++ chanlun/src/utils/datetime.rs | 24 +++ chanlun/src/utils/format.rs | 25 ++- chanlun/src/utils/mod.rs | 24 +++ 46 files changed, 1471 insertions(+), 58 deletions(-) create mode 100755 chanlun-py/bump_version.py diff --git a/chan.py b/chan.py index fc5f216..551e85c 100644 --- a/chan.py +++ b/chan.py @@ -212,6 +212,9 @@ class datetime(datetime): # 用于对齐C输出 def __repr__(self): return f"{int(self.timestamp())}" + def __int__(self) -> int: + return int(self.timestamp()) + def 转化为时间戳(ts: Union[str, datetime, int, float]) -> datetime: """ @@ -4178,7 +4181,6 @@ def 测试_周期合成(配置: 缠论配置, 配置组: Dict[int, 缠论配置] if __name__ == "__main__": - 当前配置 = 缠论配置.不推送() 当前配置.加载文件路径 = str(Path(__file__).parent / "btcusd-300-1761327300-1776327900.nb") 测试_读取数据(当前配置)().测试_保存数据() diff --git a/chanlun-py/Cargo.toml b/chanlun-py/Cargo.toml index cace846..e9bd549 100644 --- a/chanlun-py/Cargo.toml +++ b/chanlun-py/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chanlun-py" -version = "26.5.1" +version = "26.5.10" edition = "2021" description = "缠论技术分析库 — Rust 高性能 Python 绑定" authors = ["YuYuKunKun"] diff --git a/chanlun-py/build.sh b/chanlun-py/build.sh index cbada4d..e389da6 100755 --- a/chanlun-py/build.sh +++ b/chanlun-py/build.sh @@ -30,6 +30,7 @@ usage() { wheel 构建 wheel 包(release) publish 发布至 PyPI(需先配置 TWINE_ 环境变量或 .pypirc) clean 清理构建产物 + bump 版本号自增(年月.次 → 2605.X) check 检查 pyproject.toml 配置是否合法 PyPI 发布流程: @@ -56,7 +57,13 @@ cmd_release() { cargo build --release } +cmd_bump() { + green "[bump] 版本号自增..." + python3 "$PROJECT_DIR/bump_version.py" +} + cmd_install() { + cmd_bump green "[install] 构建 wheel 并安装..." maturin build --release 2>&1 | tail -3 local wheel=$(ls -t target/wheels/*.whl 2>/dev/null | head -1) @@ -102,6 +109,7 @@ cmd_sdist() { } cmd_wheel() { + cmd_bump green "[wheel] 构建 wheel 包..." maturin build --release yellow "构建产物在: target/wheels/" @@ -109,6 +117,7 @@ cmd_wheel() { } cmd_publish() { + cmd_bump yellow "发布前请确认:" yellow " 1. Cargo.toml 中 chanlun 依赖已切换为 crates.io 版本" yellow " 2. 版本号已更新 (pyproject.toml + Cargo.toml)" @@ -162,6 +171,7 @@ case "${1:-}" in wheel) cmd_wheel ;; publish) cmd_publish ;; clean) cmd_clean ;; + bump) cmd_bump ;; check) cmd_check ;; -h|--help|help) usage ;; *) red "未知命令: ${1:-}"; usage; exit 1 ;; diff --git a/chanlun-py/bump_version.py b/chanlun-py/bump_version.py new file mode 100755 index 0000000..c7d4a3e --- /dev/null +++ b/chanlun-py/bump_version.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""版本号自增 — pyproject.toml(2605.X) + Cargo.toml(26.5.X) + +规则: YYMM 匹配当前年月 → patch 自增; 不匹配 → 重置为 NEW_YYMM.1 +仅当版本号需要变化时才修改文件。 +""" + +import os +import re +import sys +from datetime import date + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +PYPROJECT = os.path.join(SCRIPT_DIR, "pyproject.toml") +CARGO_TOML = os.path.join(SCRIPT_DIR, "Cargo.toml") + + +def read_file(path: str) -> str: + with open(path, "r") as f: + return f.read() + + +def write_file(path: str, content: str) -> None: + with open(path, "w") as f: + f.write(content) + + +def main() -> None: + today = date.today() + new_yymm = today.strftime("%y%m") # 2605 + + # --- pyproject.toml --- + pyproject = read_file(PYPROJECT) + m = re.search(r'^version\s*=\s*"(\d{4})\.(\d+)"', pyproject, re.MULTILINE) + if not m: + print("ERROR: 无法从 pyproject.toml 解析版本号", file=sys.stderr) + sys.exit(1) + + old_yymm, old_patch = m.group(1), int(m.group(2)) + + if old_yymm == new_yymm: + new_patch = old_patch + 1 + else: + new_patch = 1 + + new_py_ver = f"{new_yymm}.{new_patch}" + if old_yymm == new_yymm and old_patch == new_patch: + print(f"版本号未变: {new_py_ver}") + return + + new_pyproject = re.sub( + r'^(version\s*=\s*)"\d{4}\.\d+"', + rf'\1"{new_py_ver}"', + pyproject, + flags=re.MULTILINE, + ) + write_file(PYPROJECT, new_pyproject) + print(f'pyproject.toml: {m.group(0).split("=")[1].strip()} → "{new_py_ver}"') + + # --- Cargo.toml --- + new_cargo_ver = f"{new_yymm[:2]}.{int(new_yymm[2:])}.{new_patch}" # 26.5.2 + cargo = read_file(CARGO_TOML) + new_cargo = re.sub( + r'^(version\s*=\s*)"\d+\.\d+\.\d+"', + rf'\1"{new_cargo_ver}"', + cargo, + flags=re.MULTILINE, + ) + write_file(CARGO_TOML, new_cargo) + print(f'Cargo.toml: → "{new_cargo_ver}"') + + +if __name__ == "__main__": + main() diff --git a/chanlun-py/pyproject.toml b/chanlun-py/pyproject.toml index af92c01..ef4b3e6 100644 --- a/chanlun-py/pyproject.toml +++ b/chanlun-py/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "chanlun" -version = "2605.1" +version = "2605.10" description = "缠论技术分析库 — Rust 高性能实现" readme = { file = "README.md", content-type = "text/markdown" } license = { file = "LICENSE", content-type = "text/plain" } diff --git a/chanlun-py/src/algorithm_py.rs b/chanlun-py/src/algorithm_py.rs index df2a370..7679592 100644 --- a/chanlun-py/src/algorithm_py.rs +++ b/chanlun-py/src/algorithm_py.rs @@ -1,7 +1,32 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::PyType; use std::rc::Rc; +use crate::business_py::观察者Py; use crate::config_py::缠论配置Py; use crate::kline_py::K线Py; use crate::structure_py::{分型Py, 虚线Py}; @@ -392,7 +417,44 @@ impl 笔Py { )) } - // 自检, 获取所有停顿位置, 是否背驰过 — deferred to Phase 7 (need observer) + #[classmethod] + fn 自检( + _cls: &Bound<'_, PyType>, + 筆: &Bound<'_, 虚线Py>, + 观察员: &Bound<'_, 观察者Py>, + ) -> bool { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::algorithm::bi::笔::自检(&筆.borrow().inner, &*obs_ref) + } + + #[classmethod] + fn 获取所有停顿位置( + _cls: &Bound<'_, PyType>, + 筆: &Bound<'_, 虚线Py>, + 观察员: &Bound<'_, 观察者Py>, + ) -> Vec<虚线Py> { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::algorithm::bi::笔::获取所有停顿位置(&筆.borrow().inner, &*obs_ref) + .into_iter() + .map(|d| 虚线Py { inner: Rc::new(d) }) + .collect() + } + + #[classmethod] + fn 是否背驰过( + _cls: &Bound<'_, PyType>, + 当前筆: &Bound<'_, 虚线Py>, + 观察员: &Bound<'_, 观察者Py>, + ) -> Vec<分型Py> { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::algorithm::bi::笔::是否背驰过(&当前筆.borrow().inner, &*obs_ref) + .into_iter() + .map(|f| 分型Py { inner: f }) + .collect() + } } // ========== 线段 ========== @@ -829,7 +891,50 @@ impl 线段Py { Ok(()) } - // 判断线段内部是否背驰, 段获取所有停顿位置, 是否背驰过 — deferred to Phase 7 (need observer) + #[classmethod] + fn 判断线段内部是否背驰( + _cls: &Bound<'_, PyType>, + 当前段: &Bound<'_, 虚线Py>, + 观察员: &Bound<'_, 观察者Py>, + ) -> bool { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::algorithm::segment::线段::判断线段内部是否背驰( + &当前段.borrow().inner, + &*obs_ref, + ) + } + + #[classmethod] + fn 段获取所有停顿位置( + _cls: &Bound<'_, PyType>, + 段: &Bound<'_, 虚线Py>, + 观察员: &Bound<'_, 观察者Py>, + ) -> Vec<虚线Py> { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::algorithm::segment::线段::段获取所有停顿位置( + &段.borrow().inner, + &*obs_ref, + ) + .into_iter() + .map(|d| 虚线Py { inner: Rc::new(d) }) + .collect() + } + + #[classmethod] + fn 是否背驰过( + _cls: &Bound<'_, PyType>, + 当前段: &Bound<'_, 虚线Py>, + 观察员: &Bound<'_, 观察者Py>, + ) -> Vec<分型Py> { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::algorithm::segment::线段::是否背驰过(&当前段.borrow().inner, &*obs_ref) + .into_iter() + .map(|f| 分型Py { inner: f }) + .collect() + } } // ========== 中枢 ========== @@ -872,6 +977,17 @@ impl 中枢Py { self.inner.级别 } + #[getter] + fn 基础序列(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for d in &self.inner.基础序列 { + list.append(虚线Py { + inner: Rc::clone(d), + })?; + } + Ok(list.into()) + } + #[getter] fn 第三买卖线(&self) -> Option<虚线Py> { self.inner.第三买卖线.as_ref().map(|d| 虚线Py { diff --git a/chanlun-py/src/business_py.rs b/chanlun-py/src/business_py.rs index 6a1e56b..a92a8a4 100644 --- a/chanlun-py/src/business_py.rs +++ b/chanlun-py/src/business_py.rs @@ -1,5 +1,30 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::PyType; +use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; @@ -281,71 +306,110 @@ impl 买卖点Py { #[pyclass(name = "观察者", subclass, unsendable)] pub struct 观察者Py { - pub(crate) inner: chanlun::business::observer::观察者, + pub(crate) inner: Option>>, +} + +impl 观察者Py { + pub(crate) fn obs(&self) -> std::cell::Ref<'_, chanlun::business::observer::观察者> { + self.inner + .as_ref() + .expect("观察者 尚未初始化,请通过 __init__(符号, 周期, 配置) 构造") + .borrow() + } + + pub(crate) fn obs_mut(&self) -> std::cell::RefMut<'_, chanlun::business::observer::观察者> { + self.inner + .as_ref() + .expect("观察者 尚未初始化,请通过 __init__(符号, 周期, 配置) 构造") + .borrow_mut() + } } #[pymethods] impl 观察者Py { + /// __new__ 只分配空壳,构造逻辑在 __init__ #[new] - #[pyo3(signature = (符号, 周期, 配置 = None))] + #[pyo3(signature = (*args, **kwargs))] fn new( + args: &Bound<'_, pyo3::types::PyTuple>, + kwargs: Option<&Bound<'_, pyo3::types::PyDict>>, + ) -> Self { + let _ = (args, kwargs); + Self { inner: None } + } + + /// __init__ 执行真正的构造。子类可重写并调用 super().__init__(符号, 周期, 配置) + #[pyo3(signature = (符号, 周期, 配置 = None))] + fn __init__( + &mut self, + py: Python<'_>, 符号: String, 周期: i64, 配置: Option<&Bound<'_, 缠论配置Py>>, - py: Python<'_>, - ) -> PyResult { + ) -> PyResult<()> { let config = match 配置 { Some(cfg) => cfg.borrow().to_rust_config(py)?, None => chanlun::config::缠论配置::default(), }; - Ok(Self { - inner: chanlun::business::observer::观察者::new(符号, 周期, config), - }) + self.inner = Some(chanlun::business::observer::观察者::new( + 符号, 周期, config, + )); + Ok(()) + } + + #[getter] + fn 观察员(slf: PyRef<'_, Self>) -> PyRef<'_, Self> { + slf } #[getter] fn 标识(&self) -> String { - self.inner.标识() + self.obs().标识() } #[getter] fn 当前K线(&self) -> Option { - self.inner.当前K线().map(|k| K线Py { + self.obs().当前K线().map(|k| K线Py { inner: (**k).clone(), }) } #[getter] fn 当前缠K(&self) -> Option<缠论K线Py> { - self.inner.当前缠K().map(|k| 缠论K线Py { + self.obs().当前缠K().map(|k| 缠论K线Py { inner: Rc::clone(k), }) } #[getter] fn 符号(&self) -> String { - self.inner.符号.clone() + self.obs().符号.clone() } #[getter] fn 周期(&self) -> i64 { - self.inner.周期 + self.obs().周期 + } + + #[getter] + fn 配置(&self) -> PyResult<缠论配置Py> { + 缠论配置Py::from_rust_config(&self.obs().配置) } fn 重置基础序列(&mut self) { - self.inner.重置基础序列(); + self.obs_mut().重置基础序列(); } fn 增加原始K线(&mut self, 普K: &Bound<'_, K线Py>) { - self.inner.增加原始K线(普K.borrow().inner.clone()); + self.obs_mut().增加原始K线(普K.borrow().inner.clone()); } fn 静态重新分析(&mut self) { - self.inner.静态重新分析(); + self.obs_mut().静态重新分析(); } fn 测试_保存数据(&self, root: Option<&str>) { - self.inner.测试_保存数据(root); + self.obs().测试_保存数据(root); } #[classmethod] @@ -360,7 +424,7 @@ impl 观察者Py { None => None, }; chanlun::business::observer::观察者::读取数据文件(文件路径, config) - .map(|inner| Self { inner }) + .map(|inner| Self { inner: Some(inner) }) .map_err(|e| pyo3::exceptions::PyValueError::new_err(e)) } @@ -369,7 +433,7 @@ impl 观察者Py { #[getter] fn 普通K线序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for k in &self.inner.普通K线序列 { + for k in &self.obs().普通K线序列 { list.append(K线Py { inner: (**k).clone(), })?; @@ -380,7 +444,7 @@ impl 观察者Py { #[getter] fn 缠论K线序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for k in &self.inner.缠论K线序列 { + for k in &self.obs().缠论K线序列 { list.append(缠论K线Py { inner: Rc::clone(k), })?; @@ -391,7 +455,7 @@ impl 观察者Py { #[getter] fn 分型序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for f in &self.inner.分型序列 { + for f in &self.obs().分型序列 { list.append(分型Py { inner: Rc::clone(f), })?; @@ -402,7 +466,7 @@ impl 观察者Py { #[getter] fn 笔序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for d in &self.inner.笔序列 { + for d in &self.obs().笔序列 { list.append(虚线Py { inner: Rc::clone(d), })?; @@ -413,7 +477,7 @@ impl 观察者Py { #[getter] fn 笔_中枢序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for h in &self.inner.笔_中枢序列 { + for h in &self.obs().笔_中枢序列 { list.append(中枢Py { inner: Rc::clone(h), })?; @@ -424,7 +488,7 @@ impl 观察者Py { #[getter] fn 线段序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for d in &self.inner.线段序列 { + for d in &self.obs().线段序列 { list.append(虚线Py { inner: Rc::clone(d), })?; @@ -435,7 +499,7 @@ impl 观察者Py { #[getter] fn 中枢序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for h in &self.inner.中枢序列 { + for h in &self.obs().中枢序列 { list.append(中枢Py { inner: Rc::clone(h), })?; @@ -446,7 +510,7 @@ impl 观察者Py { #[getter] fn 扩展线段序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for d in &self.inner.扩展线段序列 { + for d in &self.obs().扩展线段序列 { list.append(虚线Py { inner: Rc::clone(d), })?; @@ -457,7 +521,73 @@ impl 观察者Py { #[getter] fn 扩展中枢序列(&self, py: Python<'_>) -> PyResult> { let list = pyo3::types::PyList::empty(py); - for h in &self.inner.扩展中枢序列 { + for h in &self.obs().扩展中枢序列 { + list.append(中枢Py { + inner: Rc::clone(h), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 扩展线段序列_线段(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for d in &self.obs().扩展线段序列_线段 { + list.append(虚线Py { + inner: Rc::clone(d), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 扩展中枢序列_线段(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for h in &self.obs().扩展中枢序列_线段 { + list.append(中枢Py { + inner: Rc::clone(h), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 线段_线段序列(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for d in &self.obs().线段_线段序列 { + list.append(虚线Py { + inner: Rc::clone(d), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 线段_中枢序列(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for h in &self.obs().线段_中枢序列 { + list.append(中枢Py { + inner: Rc::clone(h), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 扩展线段序列_扩展线段(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for d in &self.obs().扩展线段序列_扩展线段 { + list.append(虚线Py { + inner: Rc::clone(d), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 扩展中枢序列_扩展线段(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for h in &self.obs().扩展中枢序列_扩展线段 { list.append(中枢Py { inner: Rc::clone(h), })?; @@ -494,6 +624,34 @@ impl K线合成器Py { .collect()) } + fn 投喂( + &mut self, + 时间戳: i64, + 开: f64, + 高: f64, + 低: f64, + 收: f64, + 量: f64, + ) -> Vec<(i64, K线Py)> { + let min_cycle = self.inner.周期组.iter().copied().min().unwrap_or(1); + let k = chanlun::kline::bar::K线::创建普K( + &self.inner.标识, + 时间戳, + 开, + 高, + 低, + 收, + 量, + 0, + min_cycle, + ); + let results = self.inner.投喂K线(k); + results + .into_iter() + .map(|(周期, k2)| (周期, K线Py { inner: k2 })) + .collect() + } + fn 获取当前K线(&self, 周期: i64) -> Option { self.inner .获取当前K线(周期) @@ -557,7 +715,11 @@ impl 立体分析器Py { self.inner.投喂K线(普K.borrow().inner.clone()); } - // 获取观察者 deferred — 观察者 doesn't implement Clone, needs core change + fn 获取观察者(&self, 周期: i64) -> Option<观察者Py> { + self.inner + .获取观察者(周期) + .map(|rc| 观察者Py { inner: Some(rc) }) + } fn 测试_保存数据(&self) { self.inner.测试_保存数据(); diff --git a/chanlun-py/src/config_py.rs b/chanlun-py/src/config_py.rs index e0f67fa..a5c26ad 100644 --- a/chanlun-py/src/config_py.rs +++ b/chanlun-py/src/config_py.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::{PyDict, PyType}; use std::collections::HashMap; @@ -52,6 +76,12 @@ impl 缠论配置Py { } } + fn __dir__(&self) -> Vec { + let mut names: Vec = self.fields.keys().cloned().collect(); + names.sort(); + names + } + fn __str__(&self) -> String { format!("缠论配置({} fields)", self.fields.len()) } @@ -179,6 +209,10 @@ impl 缠论配置Py { pub(crate) fn to_rust_config(&self, py: Python<'_>) -> PyResult { dict_to_rust_config(&self.fields) } + + pub(crate) fn from_rust_config(config: &chanlun::config::缠论配置) -> PyResult { + config_to_field_dict(config).map(|fields| Self { fields }) + } } fn config_to_field_dict( diff --git a/chanlun-py/src/indicators_py.rs b/chanlun-py/src/indicators_py.rs index c76cad3..7f409d2 100644 --- a/chanlun-py/src/indicators_py.rs +++ b/chanlun-py/src/indicators_py.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::PyType; diff --git a/chanlun-py/src/kline_py.rs b/chanlun-py/src/kline_py.rs index c1d9212..23626c3 100644 --- a/chanlun-py/src/kline_py.rs +++ b/chanlun-py/src/kline_py.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::{PyBytes, PyType}; use std::collections::HashMap; diff --git a/chanlun-py/src/lib.rs b/chanlun-py/src/lib.rs index 924012a..415bf1d 100644 --- a/chanlun-py/src/lib.rs +++ b/chanlun-py/src/lib.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; mod algorithm_py; diff --git a/chanlun-py/src/structure_py.rs b/chanlun-py/src/structure_py.rs index d12969c..1320856 100644 --- a/chanlun-py/src/structure_py.rs +++ b/chanlun-py/src/structure_py.rs @@ -1,8 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::PyType; use std::collections::HashMap; use std::rc::Rc; +use crate::algorithm_py::中枢Py; use crate::config_py::缠论配置Py; use crate::kline_py::{缠论K线Py, K线Py}; use crate::types_py::{分型结构Py, 相对方向Py, 缺口Py}; @@ -268,7 +293,38 @@ impl 虚线Py { Ok(list.into()) } - // 实_中枢序列 / 虚_中枢序列 / 合_中枢序列 — deferred to Phase 6 (中枢Py not yet available) + #[getter] + fn 实_中枢序列(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for h in &self.inner.实_中枢序列 { + list.append(中枢Py { + inner: Rc::clone(h), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 虚_中枢序列(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for h in &self.inner.虚_中枢序列 { + list.append(中枢Py { + inner: Rc::clone(h), + })?; + } + Ok(list.into()) + } + + #[getter] + fn 合_中枢序列(&self, py: Python<'_>) -> PyResult> { + let list = pyo3::types::PyList::empty(py); + for h in &self.inner.合_中枢序列 { + list.append(中枢Py { + inner: Rc::clone(h), + })?; + } + Ok(list.into()) + } // ---- 计算属性 ---- @@ -503,6 +559,68 @@ impl 虚线Py { chanlun::structure::dash_line::虚线::武之MACD极值(&rc_list, &实线.borrow().inner) } + #[classmethod] + fn 计算MACD柱子均值_阴( + _cls: &Bound<'_, PyType>, + 普K序列: Vec>, + 实线: &Bound<'_, Self>, + py: Python<'_>, + ) -> Option { + let rc_list: Vec> = 普K序列 + .iter() + .map(|k| Rc::new(k.bind(py).borrow().inner.clone())) + .collect(); + chanlun::structure::dash_line::虚线::计算MACD柱子均值_阴( + &rc_list, + &实线.borrow().inner, + ) + } + + #[classmethod] + fn 计算MACD柱子均值_阳( + _cls: &Bound<'_, PyType>, + 普K序列: Vec>, + 实线: &Bound<'_, Self>, + py: Python<'_>, + ) -> Option { + let rc_list: Vec> = 普K序列 + .iter() + .map(|k| Rc::new(k.bind(py).borrow().inner.clone())) + .collect(); + chanlun::structure::dash_line::虚线::计算MACD柱子均值_阳( + &rc_list, + &实线.borrow().inner, + ) + } + + #[classmethod] + fn 武之MACD均值_阴( + _cls: &Bound<'_, PyType>, + 普K序列: Vec>, + 实线: &Bound<'_, Self>, + py: Python<'_>, + ) -> bool { + let rc_list: Vec> = 普K序列 + .iter() + .map(|k| Rc::new(k.bind(py).borrow().inner.clone())) + .collect(); + chanlun::structure::dash_line::虚线::武之MACD均值_阴(&rc_list, &实线.borrow().inner) + } + + #[classmethod] + fn 武之MACD均值_阳( + _cls: &Bound<'_, PyType>, + 普K序列: Vec>, + 实线: &Bound<'_, Self>, + py: Python<'_>, + ) -> bool { + let rc_list: Vec> = 普K序列 + .iter() + .map(|k| Rc::new(k.bind(py).borrow().inner.clone())) + .collect(); + chanlun::structure::dash_line::虚线::武之MACD均值_阳(&rc_list, &实线.borrow().inner) + } + #[classmethod] fn 计算K线序列MACD趋向背驰( _cls: &Bound<'_, PyType>, @@ -562,7 +680,16 @@ impl 虚线Py { chanlun::structure::dash_line::虚线::统计MACD行为(&rc_list, 最大间隔, 最少交叉数) } - // 买卖意义 — deferred to Phase 7 (needs observer) + #[classmethod] + fn 买卖意义( + _cls: &Bound<'_, PyType>, + 实线: &Bound<'_, Self>, + 观察员: &Bound<'_, crate::business_py::观察者Py>, + ) -> (bool, String) { + let obs = 观察员.borrow(); + let obs_ref = obs.obs(); + chanlun::structure::dash_line::虚线::买卖意义(&实线.borrow().inner, &*obs_ref) + } } // ========== 线段特征 ========== diff --git a/chanlun-py/src/types_py.rs b/chanlun-py/src/types_py.rs index d874e74..ea60470 100644 --- a/chanlun-py/src/types_py.rs +++ b/chanlun-py/src/types_py.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use pyo3::prelude::*; use pyo3::types::PyType; diff --git a/chanlun/src/algorithm/bi.rs b/chanlun/src/algorithm/bi.rs index 5be9e28..120f6ab 100644 --- a/chanlun/src/algorithm/bi.rs +++ b/chanlun/src/algorithm/bi.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::business::observer::观察者; use crate::config::缠论配置; use crate::kline::bar::K线; diff --git a/chanlun/src/algorithm/divergence.rs b/chanlun/src/algorithm/divergence.rs index 383dca4..078308c 100644 --- a/chanlun/src/algorithm/divergence.rs +++ b/chanlun/src/algorithm/divergence.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::config::缠论配置; use crate::kline::bar::K线; use crate::structure::dash_line::虚线; diff --git a/chanlun/src/algorithm/hub.rs b/chanlun/src/algorithm/hub.rs index 87a670a..dd0e13a 100644 --- a/chanlun/src/algorithm/hub.rs +++ b/chanlun/src/algorithm/hub.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::structure::dash_line::虚线; use crate::structure::fractal_obj::分型; use crate::types::相对方向; diff --git a/chanlun/src/algorithm/mod.rs b/chanlun/src/algorithm/mod.rs index ce0b3de..d72f8bb 100644 --- a/chanlun/src/algorithm/mod.rs +++ b/chanlun/src/algorithm/mod.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod bi; pub mod divergence; pub mod hub; diff --git a/chanlun/src/algorithm/segment.rs b/chanlun/src/algorithm/segment.rs index 9df4c37..cfdcf27 100644 --- a/chanlun/src/algorithm/segment.rs +++ b/chanlun/src/algorithm/segment.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::algorithm::bi::笔; use crate::algorithm::hub::中枢; use crate::business::observer::观察者; diff --git a/chanlun/src/business/bsp.rs b/chanlun/src/business/bsp.rs index ca11643..929947f 100644 --- a/chanlun/src/business/bsp.rs +++ b/chanlun/src/business/bsp.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::kline::bar::K线; use crate::kline::chan_kline::缠论K线; use crate::structure::fractal_obj::分型; diff --git a/chanlun/src/business/mod.rs b/chanlun/src/business/mod.rs index e27f29c..01d03d7 100644 --- a/chanlun/src/business/mod.rs +++ b/chanlun/src/business/mod.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod bsp; pub mod multi_frame; pub mod observer; diff --git a/chanlun/src/business/multi_frame.rs b/chanlun/src/business/multi_frame.rs index 2f32d96..ccc31ec 100644 --- a/chanlun/src/business/multi_frame.rs +++ b/chanlun/src/business/multi_frame.rs @@ -1,8 +1,34 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::business::observer::观察者; use crate::business::synthesizer::K线合成器; use crate::config::缠论配置; use crate::kline::bar::K线; +use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; /// 立体分析器 — 多周期协调器 /// @@ -12,7 +38,7 @@ pub struct 立体分析器 { pub 周期组: Vec, 输入周期: i64, K线合成器: K线合成器, - 单体分析器: HashMap, + 单体分析器: HashMap>>, } impl 立体分析器 { @@ -69,20 +95,15 @@ impl 立体分析器 { // Dispatch on completion events (matching Python's __K线回调) for (周期, 完成K线) in 完成事件 { - if let Some(观察员) = self.单体分析器.get_mut(&周期) { - 观察员.增加原始K线(完成K线); + if let Some(观察员) = self.单体分析器.get(&周期) { + 观察员.borrow_mut().增加原始K线(完成K线); } } } /// 获取指定周期的观察者 - pub fn 获取观察者(&self, 周期: i64) -> Option<&观察者> { - self.单体分析器.get(&周期) - } - - /// 获取指定周期的观察者(可变) - pub fn 获取观察者_mut(&mut self, 周期: i64) -> Option<&mut 观察者> { - self.单体分析器.get_mut(&周期) + pub fn 获取观察者(&self, 周期: i64) -> Option>> { + self.单体分析器.get(&周期).cloned() } /// 测试_保存数据 — 多级别数据拆分保存 @@ -95,25 +116,23 @@ impl 立体分析器 { let 起始时间 = self .单体分析器 .get(&self.输入周期) - .and_then(|o| o.普通K线序列.first()) - .map(|k| k.时间戳) + .and_then(|o| o.borrow().普通K线序列.first().map(|k| k.时间戳)) .unwrap_or(0); let 结束时间 = self .单体分析器 .get(&self.输入周期) - .and_then(|o| o.普通K线序列.last()) - .map(|k| k.时间戳) + .and_then(|o| o.borrow().普通K线序列.last().map(|k| k.时间戳)) .unwrap_or(0); let 标识 = self .单体分析器 .get(&self.输入周期) - .map(|o| o.符号.clone()) + .map(|o| o.borrow().符号.clone()) .unwrap_or_default(); let 周期 = self .单体分析器 .get(&self.输入周期) - .map(|o| o.周期) + .map(|o| o.borrow().周期) .unwrap_or_default(); let 目录标识 = format!("RustM_{}:{}_{}_{}", 标识, 周期, 起始时间, 结束时间); @@ -126,7 +145,9 @@ impl 立体分析器 { for 周期 in &self.周期组 { if let Some(观察员) = self.单体分析器.get(周期) { - 观察员.测试_保存数据(Some(&保存路径.to_string_lossy())); + 观察员 + .borrow() + .测试_保存数据(Some(&保存路径.to_string_lossy())); } } diff --git a/chanlun/src/business/observer.rs b/chanlun/src/business/observer.rs index 8e85d44..46fa016 100644 --- a/chanlun/src/business/observer.rs +++ b/chanlun/src/business/observer.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::algorithm::bi::笔; use crate::algorithm::hub::中枢; use crate::algorithm::segment::线段; @@ -8,6 +32,7 @@ use crate::structure::dash_line::虚线; use crate::structure::fractal_obj::分型; use crate::types::相对方向; use crate::utils::datetime; +use std::cell::RefCell; use std::rc::Rc; /// 观察者 — 单周期分析器,持有所有层级序列,接收K线流式输入后逐层计算 @@ -50,7 +75,7 @@ pub struct 观察者 { } impl 观察者 { - pub fn new(符号: String, 周期: i64, 配置: 缠论配置) -> Self { + pub fn new(符号: String, 周期: i64, 配置: 缠论配置) -> Rc> { let 终止时间戳 = if 配置.手动终止 != "1970-01-01 00:00:00" && !配置.手动终止.is_empty() { datetime::转化为时间戳(&配置.手动终止) @@ -80,7 +105,7 @@ impl 观察者 { 终止时间戳, }; instance.配置.标识 = 符号; - instance + Rc::new(RefCell::new(instance)) } /// 标识 @@ -458,8 +483,9 @@ impl 观察者 { /// 读取数据文件 — 从 .nb 文件加载数据 pub fn 读取数据文件( - 文件路径: &str, 配置: Option<缠论配置> - ) -> Result { + 文件路径: &str, + 配置: Option<缠论配置>, + ) -> Result>, String> { let 配置 = 配置.unwrap_or_default(); // Parse filename: btcusd-300-1631772074-1632222374.nb @@ -477,14 +503,14 @@ impl 观察者 { .parse() .map_err(|e| format!("parse period: {}", e))?; - let mut 实例 = Self::new(符号, 周期, 配置); + let 实例 = Self::new(符号, 周期, 配置); let data = std::fs::read(文件路径).map_err(|e| format!("read file: {}", e))?; let size = 48; // 6 × 8 bytes (big-endian double) for i in 0..data.len() / size { let offset = i * size; if let Some(k线) = K线::from_bytes(&data[offset..offset + size], 周期, "nb") { - 实例.增加原始K线(k线); + 实例.borrow_mut().增加原始K线(k线); } } diff --git a/chanlun/src/business/synthesizer.rs b/chanlun/src/business/synthesizer.rs index 0a5f1f9..b77bb09 100644 --- a/chanlun/src/business/synthesizer.rs +++ b/chanlun/src/business/synthesizer.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::kline::bar::K线; use std::collections::HashMap; diff --git a/chanlun/src/config.rs b/chanlun/src/config.rs index cd61d0a..6551c40 100644 --- a/chanlun/src/config.rs +++ b/chanlun/src/config.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; fn is_infinite_f64(v: &f64) -> bool { diff --git a/chanlun/src/indicators/kdj.rs b/chanlun/src/indicators/kdj.rs index 7ae6e36..4f6cae0 100644 --- a/chanlun/src/indicators/kdj.rs +++ b/chanlun/src/indicators/kdj.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 随机指标 (KDJ) diff --git a/chanlun/src/indicators/macd.rs b/chanlun/src/indicators/macd.rs index de36b85..b10f4b9 100644 --- a/chanlun/src/indicators/macd.rs +++ b/chanlun/src/indicators/macd.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 平滑异同移动平均线 (MACD) diff --git a/chanlun/src/indicators/mod.rs b/chanlun/src/indicators/mod.rs index 2dcdd00..2597eb5 100644 --- a/chanlun/src/indicators/mod.rs +++ b/chanlun/src/indicators/mod.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod kdj; pub mod macd; pub mod rsi; diff --git a/chanlun/src/indicators/rsi.rs b/chanlun/src/indicators/rsi.rs index a65210c..b3a5c23 100644 --- a/chanlun/src/indicators/rsi.rs +++ b/chanlun/src/indicators/rsi.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 相对强弱指数 (RSI) diff --git a/chanlun/src/kline/bar.rs b/chanlun/src/kline/bar.rs index b17007b..c55fa2d 100644 --- a/chanlun/src/kline/bar.rs +++ b/chanlun/src/kline/bar.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::indicators::{平滑异同移动平均线, 相对强弱指数, 随机指标}; use crate::types::相对方向; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; diff --git a/chanlun/src/kline/chan_kline.rs b/chanlun/src/kline/chan_kline.rs index 7cad5d8..8b323dc 100644 --- a/chanlun/src/kline/chan_kline.rs +++ b/chanlun/src/kline/chan_kline.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::config::缠论配置; use crate::indicators::{ 平滑异同移动平均线, 相对强弱指数, 随机指标, K线取值 diff --git a/chanlun/src/kline/mod.rs b/chanlun/src/kline/mod.rs index 9b68892..d290bc1 100644 --- a/chanlun/src/kline/mod.rs +++ b/chanlun/src/kline/mod.rs @@ -1,2 +1,26 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod bar; pub mod chan_kline; diff --git a/chanlun/src/lib.rs b/chanlun/src/lib.rs index 731e928..b806bde 100644 --- a/chanlun/src/lib.rs +++ b/chanlun/src/lib.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #![allow(non_snake_case)] #![allow(non_camel_case_types)] diff --git a/chanlun/src/main.rs b/chanlun/src/main.rs index 5af9d46..90f7d2d 100644 --- a/chanlun/src/main.rs +++ b/chanlun/src/main.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use chanlun::business::multi_frame::立体分析器; use chanlun::business::observer::观察者; use chanlun::config::缠论配置; @@ -55,6 +79,7 @@ fn 测试_读取数据(文件路径: &str) { let 配置 = 缠论配置::default().不推送(); match 观察者::读取数据文件(文件路径, Some(配置)) { Ok(观察员) => { + let 观察员 = 观察员.borrow(); let 消耗用时 = 启动时间.elapsed(); println!( "测试_读取数据 耗时 {:.2?} 普K数量 {}", @@ -137,6 +162,7 @@ fn 测试_周期合成(文件路径: &str) { // Display stats per period for &p in &[周期, 周期 * 5, 周期 * 5 * 6] { if let Some(观察员) = 多级别分析.获取观察者(p) { + let 观察员 = 观察员.borrow(); println!( "周期<{}>: 缠K={}, 分型={}, 笔={}, 线段={}, 中枢={}", p, diff --git a/chanlun/src/structure/dash_line.rs b/chanlun/src/structure/dash_line.rs index c6af0c6..ac36ec3 100644 --- a/chanlun/src/structure/dash_line.rs +++ b/chanlun/src/structure/dash_line.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::algorithm::hub::中枢; use crate::config::缠论配置; use crate::kline::bar::K线; diff --git a/chanlun/src/structure/feat_fractal.rs b/chanlun/src/structure/feat_fractal.rs index e8cabc0..6a65634 100644 --- a/chanlun/src/structure/feat_fractal.rs +++ b/chanlun/src/structure/feat_fractal.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::structure::segment_feat::线段特征; use crate::types::分型结构; use std::rc::Rc; diff --git a/chanlun/src/structure/fractal_obj.rs b/chanlun/src/structure/fractal_obj.rs index 66f6b4a..a6a1783 100644 --- a/chanlun/src/structure/fractal_obj.rs +++ b/chanlun/src/structure/fractal_obj.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::kline::chan_kline::缠论K线; use crate::types::分型结构; use crate::types::相对方向; diff --git a/chanlun/src/structure/mod.rs b/chanlun/src/structure/mod.rs index 8ccac6b..c6b56b0 100644 --- a/chanlun/src/structure/mod.rs +++ b/chanlun/src/structure/mod.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod dash_line; pub mod feat_fractal; pub mod fractal_obj; diff --git a/chanlun/src/structure/segment_feat.rs b/chanlun/src/structure/segment_feat.rs index dd3ffb2..325ef87 100644 --- a/chanlun/src/structure/segment_feat.rs +++ b/chanlun/src/structure/segment_feat.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use crate::structure::dash_line::虚线; use crate::structure::feat_fractal::特征分型; use crate::structure::fractal_obj::分型; diff --git a/chanlun/src/types/bsp_type.rs b/chanlun/src/types/bsp_type.rs index f873f81..c1d3392 100644 --- a/chanlun/src/types/bsp_type.rs +++ b/chanlun/src/types/bsp_type.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 买卖点类型 —— 六类买卖点(一二三 + T1/T1P/T2/T2S/T3A/T3B) diff --git a/chanlun/src/types/direction.rs b/chanlun/src/types/direction.rs index 6087caf..8fc0bff 100644 --- a/chanlun/src/types/direction.rs +++ b/chanlun/src/types/direction.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 相对方向 —— K线之间的相对位置关系 diff --git a/chanlun/src/types/fractal.rs b/chanlun/src/types/fractal.rs index bee56ba..e419c47 100644 --- a/chanlun/src/types/fractal.rs +++ b/chanlun/src/types/fractal.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 分型结构 —— 三根K线构成的结构形态 diff --git a/chanlun/src/types/gap.rs b/chanlun/src/types/gap.rs index cef1fd0..295533f 100644 --- a/chanlun/src/types/gap.rs +++ b/chanlun/src/types/gap.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use serde::{Deserialize, Serialize}; /// 缺口 —— 两个价格区间之间的空隙 diff --git a/chanlun/src/types/mod.rs b/chanlun/src/types/mod.rs index a398ef1..c01614f 100644 --- a/chanlun/src/types/mod.rs +++ b/chanlun/src/types/mod.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod bsp_type; pub mod direction; pub mod fractal; diff --git a/chanlun/src/utils/datetime.rs b/chanlun/src/utils/datetime.rs index 7e0be6d..b88233e 100644 --- a/chanlun/src/utils/datetime.rs +++ b/chanlun/src/utils/datetime.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + use chrono::DateTime; /// 将多种类型统一转为时间戳 (Unix epoch 秒) diff --git a/chanlun/src/utils/format.rs b/chanlun/src/utils/format.rs index 07e2557..cafb651 100644 --- a/chanlun/src/utils/format.rs +++ b/chanlun/src/utils/format.rs @@ -1,4 +1,27 @@ -/// Format f64 with Python :g semantics — strip trailing zeros, no scientific notation for common values +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub fn format_f64_g(value: f64) -> String { if value.is_nan() { return "nan".to_string(); diff --git a/chanlun/src/utils/mod.rs b/chanlun/src/utils/mod.rs index 6070737..31ecfa1 100644 --- a/chanlun/src/utils/mod.rs +++ b/chanlun/src/utils/mod.rs @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2026 YuYuKunKun + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + pub mod datetime; pub mod format;