openfund-maker 2.1.10__tar.gz → 2.1.12__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openfund-maker
3
- Version: 2.1.10
3
+ Version: 2.1.12
4
4
  Summary: Openfund-maker.
5
5
  Requires-Python: >=3.9,<4.0
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openfund-maker"
3
- version = "2.1.10"
3
+ version = "2.1.12"
4
4
  description = "Openfund-maker."
5
5
  authors = []
6
6
  readme = "README.md"
@@ -44,7 +44,8 @@ class BestFVGStrategyMaker(SMCStrategyMaker):
44
44
  重置所有缓存
45
45
  """
46
46
  super().reset_all_cache(symbol)
47
- self.htf_last_CHoCH[symbol] = {}
47
+ if symbol in self.htf_last_CHoCH:
48
+ self.htf_last_CHoCH.pop(symbol)
48
49
 
49
50
  def process_pair(self,symbol,pair_config):
50
51
  self.logger.info("=" * 60)
@@ -59,11 +60,8 @@ class BestFVGStrategyMaker(SMCStrategyMaker):
59
60
  try:
60
61
  # 检查是否有持仓,有持仓不进行下单
61
62
  if self.check_position(symbol=symbol) :
62
- self.logger.info(f"{symbol} : 有持仓合约,不进行下单。")
63
- if symbol in self.place_order_prices:
64
- self.place_order_prices[symbol] = {}
65
- if symbol in self.htf_last_CHoCH:
66
- self.htf_last_CHoCH[symbol] = {}
63
+ self.reset_all_cache(symbol)
64
+ self.logger.info(f"{symbol} : 有持仓合约,不进行下单。")
67
65
  return
68
66
 
69
67
 
@@ -87,41 +85,42 @@ class BestFVGStrategyMaker(SMCStrategyMaker):
87
85
 
88
86
 
89
87
  # 初始化HTF趋势相关变量
90
- htf_side, htf_last_CHoCH_label = None, None
88
+ htf_side, htf_last_CHoCH_label, valid_htf_struct = None, None, None
91
89
  htf_struct = {"struct": "None"}
92
- # 检查是否有上一个CHoCH结构
90
+ # 获取上一个周期的CHoCH结构
93
91
  htf_last_CHoCH = self.htf_last_CHoCH.get(symbol,None)
94
- htf_struct = self.detect_struct(htf_df, prd=htf_prd, struct_key=htf_entry_struct) # HTF结构要严谨,prd周期要长一些
92
+ # 获取最新的CHoCH结构
93
+ htf_struct = self.detect_struct(htf_df, prd=htf_prd) # HTF结构要严谨,prd周期要长一些
95
94
 
96
- # 如果存在上一个CHoCH结构,更新趋势标签和方向
97
- if htf_last_CHoCH:
98
- htf_last_CHoCH_label = htf_last_CHoCH["struct"]
99
- # htf_side = htf_last_CHoCH["side"]
100
-
101
- # 优化: 只在没有新CHoCH结构时使用上一个结构
102
- if htf_struct["struct"] == "None":
103
- htf_struct = htf_last_CHoCH
104
- self.logger.debug(f"{symbol} : {htf} 使用之前 {htf_entry_struct} struct。{htf_struct['struct']} prd={htf_prd}。")
95
+ # 处理最新结构未形成的情况,使用上一个周期的结构
96
+ if htf_struct["struct"] == "None":
97
+ if htf_last_CHoCH:
98
+ htf_last_CHoCH_label = htf_last_CHoCH["struct"]
99
+ valid_htf_struct = htf_last_CHoCH
100
+ self.logger.debug(f"{symbol} : {htf} 使用之前 {htf_entry_struct} struct。{valid_htf_struct['struct']} prd={htf_prd}。")
105
101
  else:
106
- self.logger.debug(f"{symbol} : {htf} 形成新的 {htf_entry_struct} struct。{htf_struct['struct']} prd={htf_prd}。")
102
+ self.logger.debug(f"{symbol} : {htf} 未形成有效的 {htf_entry_struct} struct,不下单。")
103
+ return
104
+ else:
105
+ valid_htf_struct = htf_struct
106
+ self.logger.debug(f"{symbol} : {htf} 形成新的 {htf_entry_struct} struct。{valid_htf_struct['struct']} prd={htf_prd}。")
107
107
 
108
- # 检查是否已形成有效的CHoCH结构
109
- htf_struct_label = htf_struct["struct"]
110
- htf_side = htf_struct["side"]
111
- if htf_struct_label == "None" and not htf_last_CHoCH:
112
- self.logger.debug(f"{symbol} : {htf} is {htf_struct}, 未形成有效的 {htf_entry_struct} struct,不下单。")
108
+ # 检查是否已形成有效的结构
109
+ htf_struct_label = valid_htf_struct["struct"]
110
+ htf_side = valid_htf_struct["side"]
111
+ # if htf_struct_label == "None" and not htf_last_CHoCH:
112
+ # 20250417 优化: 最新的HTF_entry_struct结构要满足,才能下单。
113
+ if htf_entry_struct not in htf_struct_label :
114
+ # 如果是反转结构判断一下方向是否一致,不一致重置缓存。
115
+ if "CHoCH" in htf_struct_label and htf_last_CHoCH and htf_last_CHoCH["side"] != htf_side:
116
+ self.htf_last_CHoCH[symbol] = {}
117
+ self.logger.debug(f"{symbol} : {htf} is {htf_struct_label}, 未形成有效的 {htf_entry_struct} struct,不下单。")
113
118
  return
114
-
115
- # 更新最新的结构信息
116
- if ltf_entry_struct in htf_struct_label and htf_struct_label != htf_last_CHoCH_label:
117
- self.htf_last_CHoCH[symbol] = htf_struct
118
- htf_last_CHoCH = htf_struct
119
- htf_last_CHoCH_label = htf_struct_label
120
119
 
121
120
 
122
121
  # 1. HTF 判断struct趋势(CHoCH\SMS\BMS) ,HTF struct 看趋势,CTF 看FVG和OB的位置
123
- htf_pivot_high = htf_struct["pivot_high"]
124
- htf_pivot_low = htf_struct["pivot_low"]
122
+ htf_pivot_high = valid_htf_struct["pivot_high"]
123
+ htf_pivot_low = valid_htf_struct["pivot_low"]
125
124
  htf_mid_line = self.calculate_ce(symbol,htf_pivot_high,htf_pivot_low)
126
125
 
127
126
  # 2. HTF 获取最新的两个极值点,设置折价(discount)区和溢价(premium)区
@@ -137,11 +136,11 @@ class BestFVGStrategyMaker(SMCStrategyMaker):
137
136
  'ce': self.calculate_ce(symbol,htf_mid_line,htf_pivot_low)
138
137
  }
139
138
 
140
- self.logger.info(f"{symbol} : {htf} 趋势={htf_last_CHoCH_label}")
139
+ self.logger.info(f"{symbol} : {htf} 趋势={htf_last_CHoCH_label} 匹配 {htf_entry_struct} struct")
141
140
  self.logger.debug(f"{symbol} : {htf}\npivot_high={htf_pivot_high} pivot_low={htf_pivot_low} mid_line={htf_mid_line}\n溢价区={premium_box}\n折价区={discount_box}")
142
141
 
143
142
  # 3. find HTF FVG
144
- pivot_index = htf_struct["pivot_low_index"] if htf_side == "buy" else htf_struct["pivot_high_index"]
143
+ pivot_index = valid_htf_struct["pivot_low_index"] if htf_side == "buy" else valid_htf_struct["pivot_high_index"]
145
144
  # TODO 优化: 缓存FVG,不用每次都计算,且被平衡
146
145
  htf_fvg_boxes = self.find_fvg_boxes(htf_df,side=htf_side,threshold=htf_mid_line,check_balanced=False,pivot_index=pivot_index)
147
146
  if len(htf_fvg_boxes) == 0:
@@ -524,7 +524,8 @@ class SMCStrategyMaker(ThreeLineStrategyMaker):
524
524
  """_summary_
525
525
  重置所有缓存数据
526
526
  """
527
- self.place_order_prices[symbol] = {}
527
+ if symbol in self.place_order_prices:
528
+ self.place_order_prices.pop(symbol)
528
529
 
529
530
  def process_pair(self,symbol,pair_config):
530
531
  self.logger.info("=" * 60)