openfund-core 1.0.7__tar.gz → 1.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openfund_core-1.0.7 → openfund_core-1.0.8}/PKG-INFO +1 -1
- {openfund_core-1.0.7 → openfund_core-1.0.8}/pyproject.toml +1 -1
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/SMCFVG.py +4 -4
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/SMCLiquidity.py +1 -4
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/SMCOrderBlock.py +4 -4
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/SMCPDArray.py +42 -8
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/SMCStruct.py +1 -1
- {openfund_core-1.0.7 → openfund_core-1.0.8}/README.md +0 -0
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/Exchange.py +0 -0
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/__init__.py +0 -0
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/main.py +0 -0
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/SMCBase.py +0 -0
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/smc/__init__.py +0 -0
- {openfund_core-1.0.7 → openfund_core-1.0.8}/src/core/utils/OPTools.py +0 -0
@@ -47,12 +47,12 @@ class SMCFVG(SMCStruct):
|
|
47
47
|
# 使用向量化操作替代apply,提高性能
|
48
48
|
if side == self.BUY_SIDE:
|
49
49
|
condition = df[self.HIGH_COL].shift(1) < df[self.LOW_COL].shift(-1)
|
50
|
-
side_value =
|
50
|
+
side_value = self.BULLISH_TREND
|
51
51
|
price_top = df[self.LOW_COL].shift(-1)
|
52
52
|
price_bot = df[self.HIGH_COL].shift(1)
|
53
53
|
else:
|
54
54
|
condition = df[self.LOW_COL].shift(1) > df[self.HIGH_COL].shift(-1)
|
55
|
-
side_value =
|
55
|
+
side_value = self.BEARISH_TREND
|
56
56
|
price_top = df[self.LOW_COL].shift(1)
|
57
57
|
price_bot = df[self.HIGH_COL].shift(-1)
|
58
58
|
|
@@ -64,9 +64,9 @@ class SMCFVG(SMCStruct):
|
|
64
64
|
df.loc[:, self.FVG_MID] = (df[self.FVG_TOP] + df[self.FVG_BOT]) / 2
|
65
65
|
|
66
66
|
fvg_df = df[
|
67
|
-
df[self.FVG_SIDE] ==
|
67
|
+
df[self.FVG_SIDE] == self.BULLISH_TREND
|
68
68
|
if side == self.BUY_SIDE
|
69
|
-
else df[self.FVG_SIDE] ==
|
69
|
+
else df[self.FVG_SIDE] == self.BEARISH_TREND
|
70
70
|
]
|
71
71
|
fvg_df = fvg_df.copy()
|
72
72
|
if check_balanced:
|
@@ -34,7 +34,7 @@ class SMCOrderBlock(SMCStruct):
|
|
34
34
|
symbol (_type_): _description_
|
35
35
|
data (pd.DataFrame): _description_
|
36
36
|
side (_type_): _description_ 如果是None, 则返回所有OB boxes(包括bullish和bearish)
|
37
|
-
|
37
|
+
start_index (int): _description_ 开始的位置
|
38
38
|
is_valid (bool): _description_ 找到有效的OB,没有被crossed
|
39
39
|
if_combine (bool): _description_ 是否合并OB
|
40
40
|
Returns:
|
@@ -63,8 +63,8 @@ class SMCOrderBlock(SMCStruct):
|
|
63
63
|
else any(df.loc[row.name + 1 :, self.HIGH_COL] >= row[self.OB_HIGH_COL]),
|
64
64
|
axis=1,
|
65
65
|
)
|
66
|
-
|
67
|
-
|
66
|
+
if is_valid :
|
67
|
+
ob_df = ob_df[~ob_df[self.OB_WAS_CROSSED]]
|
68
68
|
|
69
69
|
if if_combine:
|
70
70
|
# 合并OB
|
@@ -238,7 +238,7 @@ class SMCOrderBlock(SMCStruct):
|
|
238
238
|
# df.at[i, self.OB_START_TS_COL] = df.loc[index, self.TIMESTAMP_COL]
|
239
239
|
df.at[index, self.OB_ATR] = atr
|
240
240
|
|
241
|
-
def
|
241
|
+
def get_latest_OB(self, data, trend, start_index=-1):
|
242
242
|
"""
|
243
243
|
获取最新的Order Block
|
244
244
|
|
@@ -15,16 +15,15 @@ class SMCPDArray(SMCFVG,SMCOrderBlock):
|
|
15
15
|
self.logger = logging.getLogger(__name__)
|
16
16
|
|
17
17
|
def find_PDArrays(
|
18
|
-
self, struct: pd.DataFrame, side, start_index=-1
|
18
|
+
self, struct: pd.DataFrame, side, start_index=-1, check_balanced=True,
|
19
19
|
) -> pd.DataFrame:
|
20
20
|
"""_summary_
|
21
21
|
寻找PDArrays,包括Fair Value Gap (FVG)|Order Block (OB)|Breaker Block(BB)|Mitigation Block(BB)
|
22
22
|
Args:
|
23
23
|
data (pd.DataFrame): K线数据
|
24
24
|
side (_type_): 交易方向 'buy'|'sell'
|
25
|
-
threshold (_type_): 阈值价格,通常为溢价和折价区的CE
|
26
|
-
check_balanced (bool): 是否检查FVG是否被平衡过,默认为True
|
27
25
|
start_index (int): 开始查找索引的起点,默认为-1
|
26
|
+
check_balanced (bool): PD是否有效,默认为True。PD被crossed过,则是无效PD
|
28
27
|
|
29
28
|
Returns:
|
30
29
|
pd.DataFrame: _description_
|
@@ -37,11 +36,11 @@ class SMCPDArray(SMCFVG,SMCOrderBlock):
|
|
37
36
|
else struct.copy().iloc[max(0, start_index - 1) :]
|
38
37
|
)
|
39
38
|
|
40
|
-
df_FVGs = self.find_FVGs(df, side)
|
39
|
+
df_FVGs = self.find_FVGs(df, side, check_balanced, start_index)
|
41
40
|
# self.logger.info(f"fvgs:\n{df_FVGs[['timestamp', self.FVG_SIDE, self.FVG_TOP, self.FVG_BOT, self.FVG_WAS_BALANCED]]}")
|
42
41
|
|
43
42
|
|
44
|
-
df_OBs = self.find_OBs(df, side)
|
43
|
+
df_OBs = self.find_OBs(df, side, start_index, is_valid=check_balanced)
|
45
44
|
# self.logger.info("find_OBs:\n %s", df_OBs)
|
46
45
|
|
47
46
|
# 使用更简洁的方式重命名和合并时间戳列
|
@@ -67,9 +66,44 @@ class SMCPDArray(SMCFVG,SMCOrderBlock):
|
|
67
66
|
df_PDArrays.loc[:, self.PD_HIGH_COL] = df_PDArrays[[self.FVG_TOP, self.OB_HIGH_COL]].max(axis=1)
|
68
67
|
df_PDArrays.loc[:, self.PD_LOW_COL] = df_PDArrays[[self.FVG_BOT, self.OB_LOW_COL]].min(axis=1)
|
69
68
|
df_PDArrays.loc[:, self.PD_MID_COL] = (df_PDArrays[self.PD_HIGH_COL] + df_PDArrays[self.PD_LOW_COL]) / 2
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
|
73
70
|
|
74
71
|
return df_PDArrays
|
75
72
|
|
73
|
+
|
74
|
+
def get_latest_PDArray(self, df_PDArrays: pd.DataFrame, side, start_index=-1, check_balanced=True, mask:str=None) -> dict:
|
75
|
+
"""_summary_
|
76
|
+
过滤PDArrays,只保留指定方向的PDArrays
|
77
|
+
Args:
|
78
|
+
df_PDArrays (pd.DataFrame): _description_
|
79
|
+
mask (str): _description_
|
80
|
+
|
81
|
+
Returns:
|
82
|
+
pd.DataFrame: _description_
|
83
|
+
"""
|
84
|
+
|
85
|
+
# 检查数据中是否包含必要的列
|
86
|
+
df = df_PDArrays.copy()
|
87
|
+
check_columns = [self.STRUCT_COL]
|
88
|
+
try:
|
89
|
+
self.check_columns(df, check_columns)
|
90
|
+
except ValueError as e:
|
91
|
+
df = self.build_struct(df)
|
92
|
+
|
93
|
+
df = self.find_PDArrays(df, side, start_index, check_balanced)
|
94
|
+
|
95
|
+
if mask:
|
96
|
+
df = df[df[mask]]
|
97
|
+
|
98
|
+
if len(df) == 0:
|
99
|
+
self.logger.info("未找到PDArray.")
|
100
|
+
return None
|
101
|
+
else:
|
102
|
+
last_pd = df.iloc[-1]
|
103
|
+
return {
|
104
|
+
self.TIMESTAMP_COL: last_pd[self.TIMESTAMP_COL],
|
105
|
+
self.PD_TYPE_COL: last_pd[self.PD_TYPE_COL],
|
106
|
+
self.PD_HIGH_COL: last_pd[self.PD_HIGH_COL],
|
107
|
+
self.PD_LOW_COL: last_pd[self.PD_LOW_COL],
|
108
|
+
self.PD_MID_COL: last_pd[self.PD_MID_COL],
|
109
|
+
}
|
@@ -265,7 +265,7 @@ class SMCStruct(SMCBase):
|
|
265
265
|
df.at[i, self.STRUCT_HIGH_INDEX_COL] = structure[self.HIGH_START_COL]
|
266
266
|
df.at[i, self.STRUCT_LOW_INDEX_COL] = structure[self.LOW_START_COL]
|
267
267
|
|
268
|
-
def
|
268
|
+
def get_latest_struct(self, df):
|
269
269
|
"""
|
270
270
|
获取最新的结构
|
271
271
|
"""
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|