第一版

This commit is contained in:
YuWuKunCheng
2026-05-25 02:16:35 +08:00
parent ff4e6ae570
commit f92eef11fb
37 changed files with 11615 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
use serde::{Deserialize, Serialize};
/// 买卖点类型 —— 六类买卖点(一二三 + T1/T1P/T2/T2S/T3A/T3B
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum {
#[serde(rename = "一买")]
,
#[serde(rename = "一卖")]
,
#[serde(rename = "二买")]
,
#[serde(rename = "二卖")]
,
#[serde(rename = "三买")]
,
#[serde(rename = "三卖")]
,
#[serde(rename = "T1买")]
T1买,
#[serde(rename = "T1卖")]
T1卖,
#[serde(rename = "T1P买")]
T1P买,
#[serde(rename = "T1P卖")]
T1P卖,
#[serde(rename = "T2买")]
T2买,
#[serde(rename = "T2卖")]
T2卖,
#[serde(rename = "T2S买")]
T2S买,
#[serde(rename = "T2S卖")]
T2S卖,
#[serde(rename = "T3A买")]
T3A买,
#[serde(rename = "T3A卖")]
T3A卖,
#[serde(rename = "T3B买")]
T3B买,
#[serde(rename = "T3B卖")]
T3B卖,
}
impl std::fmt::Display for {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self:: => write!(f, "一买"),
Self:: => write!(f, "一卖"),
Self:: => write!(f, "二买"),
Self:: => write!(f, "二卖"),
Self:: => write!(f, "三买"),
Self:: => write!(f, "三卖"),
Self::T1买 => write!(f, "T1买"),
Self::T1卖 => write!(f, "T1卖"),
Self::T1P买 => write!(f, "T1P买"),
Self::T1P卖 => write!(f, "T1P卖"),
Self::T2买 => write!(f, "T2买"),
Self::T2卖 => write!(f, "T2卖"),
Self::T2S买 => write!(f, "T2S买"),
Self::T2S卖 => write!(f, "T2S卖"),
Self::T3A买 => write!(f, "T3A买"),
Self::T3A卖 => write!(f, "T3A卖"),
Self::T3B买 => write!(f, "T3B买"),
Self::T3B卖 => write!(f, "T3B卖"),
}
}
}
impl {
pub fn (&self) -> bool {
matches!(
self,
Self::
| Self::
| Self::
| Self::T1买
| Self::T1P买
| Self::T2买
| Self::T2S买
| Self::T3A买
| Self::T3B买
)
}
pub fn (&self) -> bool {
matches!(
self,
Self::
| Self::
| Self::
| Self::T1卖
| Self::T1P卖
| Self::T2卖
| Self::T2S卖
| Self::T3A卖
| Self::T3B卖
)
}
}
+108
View File
@@ -0,0 +1,108 @@
use serde::{Deserialize, Serialize};
/// 相对方向 —— K线之间的相对位置关系
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum {
#[serde(rename = "交叠向上")]
,
#[serde(rename = "交叠向下")]
,
#[serde(rename = "向上缺口")]
,
#[serde(rename = "向下缺口")]
,
#[serde(rename = "衔接向上")]
,
#[serde(rename = "衔接向下")]
,
#[serde(rename = "顺序包含")]
,
#[serde(rename = "逆序包含")]
,
#[serde(rename = "相同包含")]
,
}
impl {
pub fn (&self) -> Self {
match self {
Self:: => Self::,
Self:: => Self::,
Self:: => Self::,
Self:: => Self::,
Self:: => Self::,
Self:: => Self::,
Self:: => Self::,
Self:: => Self::,
other => *other,
}
}
pub fn (&self) -> bool {
matches!(self, Self:: | Self:: | Self::)
}
pub fn (&self) -> bool {
matches!(self, Self:: | Self:: | Self::)
}
pub fn (&self) -> bool {
matches!(self, Self:: | Self:: | Self::)
}
pub fn (&self) -> bool {
matches!(self, Self:: | Self::)
}
pub fn (&self) -> bool {
matches!(self, Self:: | Self::)
}
/// 分析两个K线之间的相对方向
pub fn (: f64, : f64, : f64, : f64) -> Self {
if ( - ).abs() < f64::EPSILON && ( - ).abs() < f64::EPSILON {
return Self::;
}
if > && > {
if ( - ).abs() < f64::EPSILON {
return Self::;
}
if > {
return Self::;
}
return Self::;
}
if < && < {
if ( - ).abs() < f64::EPSILON {
return Self::;
}
if < {
return Self::;
}
return Self::;
}
if >= && <= {
return Self::;
}
if <= && >= {
return Self::;
}
panic!("无法识别的方向: 前({},{}), 后({},{})", , , , );
}
}
impl std::fmt::Display for {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self:: => write!(f, "相对方向.向上"),
Self:: => write!(f, "相对方向.向下"),
Self:: => write!(f, "相对方向.向上缺口"),
Self:: => write!(f, "相对方向.向下缺口"),
Self:: => write!(f, "相对方向.衔接向上"),
Self:: => write!(f, "相对方向.衔接向下"),
Self:: => write!(f, "相对方向.顺"),
Self:: => write!(f, "相对方向.逆"),
Self:: => write!(f, "相对方向.同"),
}
}
}
+109
View File
@@ -0,0 +1,109 @@
use serde::{Deserialize, Serialize};
/// 分型结构 —— 三根K线构成的结构形态
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum {
#[serde(rename = "三连向上")]
,
#[serde(rename = "三连向下")]
,
#[serde(rename = "顶分型")]
,
#[serde(rename = "底分型")]
,
#[serde(rename = "向右扩散")]
,
}
impl std::fmt::Display for {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self:: => write!(f, ""),
Self:: => write!(f, ""),
Self:: => write!(f, ""),
Self:: => write!(f, ""),
Self:: => write!(f, ""),
}
}
}
impl {
/// 分析三根K线构成的分型结构(泛型版本)
pub fn (
: &impl ,
: &impl ,
: &impl ,
: bool,
: bool,
) -> Option<Self> {
Self::_内部(.(), .(), .(), .(), .(), .(), , )
}
/// 分析三元素构成的分型结构(trait object 版本)
pub fn _对象(
: &dyn ,
: &dyn ,
: &dyn ,
: bool,
: bool,
) -> Option<Self> {
Self::_内部(.(), .(), .(), .(), .(), .(), , )
}
fn _内部(
: f64, : f64,
: f64, : f64,
: f64, : f64,
: bool,
: bool,
) -> Option<Self> {
use crate::types::direction::;
let = ::(, , , );
let = ::(, , , );
let = |d: | d.();
let = |d: | d.();
match (, ) {
// 顺序包含 — 忽视时可以绕过
(::, _) if ! => {
panic!("顺序包含: {:?} {:?}", , );
}
(_, ::) if ! => {
panic!("顺序包含: {:?} {:?}", , );
}
// 向上 + 向上 = 三连上
(a, b) if (a) && (b) => Some(Self::),
// 向上 + 向下 = 顶分型
(a, b) if (a) && (b) => Some(Self::),
// 向上 + 逆序包含 = 上
(a, ::) if (a) && => Some(Self::),
// 向下 + 向上 = 底分型
(a, b) if (a) && (b) => Some(Self::),
// 向下 + 向下 = 三连下
(a, b) if (a) && (b) => Some(Self::),
// 向下 + 逆序包含 = 下
(a, ::) if (a) && => Some(Self::),
// 逆序包含 + 向上 = 底
(::, a) if (a) && => Some(Self::),
// 逆序包含 + 向下 = 顶
(::, a) if (a) && => Some(Self::),
// 逆序包含 + 逆序包含 = 散
(::, ::) if => Some(Self::),
_ => {
eprintln!(
"无法识别的分型结构: 左中={:?}, 中右={:?}",
,
);
None
}
}
}
}
/// Trait for types that have 高 and 低 (used by 分型结构::分析)
pub trait {
fn (&self) -> f64;
fn (&self) -> f64;
}
+51
View File
@@ -0,0 +1,51 @@
use serde::{Deserialize, Serialize};
/// 缺口 —— 两个价格区间之间的空隙
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct {
pub : f64,
pub : f64,
}
impl {
pub fn new(: f64, : f64) -> Self {
assert!( > , "缺口高必须大于低: 高={高}, 低={低}");
Self { , }
}
/// 在 [起点, 终点] 区间内居中截取一个子区间
pub fn (: f64, : f64, : f64) -> Option<Self> {
let (, ) = if <= {
(, )
} else {
(, )
};
let = - ;
let = * ;
let = ( + ) / 2.0;
let = - ;
let = + ;
if > || < {
return None;
}
let = .max();
let = .min();
Some(Self::new(.max(), .min()))
}
}
impl std::fmt::Display for {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"缺口区间<{} <=> {}>",
crate::utils::format_f64_g(self.),
crate::utils::format_f64_g(self.)
)
}
}
+9
View File
@@ -0,0 +1,9 @@
pub mod bsp_type;
pub mod direction;
pub mod fractal;
pub mod gap;
pub use bsp_type::;
pub use direction::;
pub use fractal::;
pub use gap::;