openfund-taker 1.0.17__py3-none-any.whl → 1.1.1__py3-none-any.whl

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-taker
3
- Version: 1.0.17
3
+ Version: 1.1.1
4
4
  Summary: Openfund-taker
5
5
  Requires-Python: >=3.9,<4.0
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,4 +1,4 @@
1
- taker/MultiAssetNewTradingBot.py,sha256=ZHQQslFi_BeewvkqkALP4Nop9un3JvUkjQR0pWgjhvk,35055
1
+ taker/MultiAssetNewTradingBot.py,sha256=L3XSiQFcKUTJLpgorsGhKn47b9ijIGFi457gmQS1CvI,37058
2
2
  taker/MultiAssetOldTradingBot.py,sha256=uBh_BxglvcbaHIsWHM7GI9Qa_QjzsxXaXJAAWEOMO5c,15315
3
3
  taker/ThreeLineTradingBot.py,sha256=oXIoQ8z9AzKzk0z13d0ufj2KGBOk5iHJTJNZQRDKA5U,20625
4
4
  taker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -9,7 +9,7 @@ taker/chua_ok_all.py,sha256=2XnZM6QdB3juSE1pqQIJyh2x1XuhlTlnBKNA3owlJ9E,15267
9
9
  taker/chua_ok_bot.py,sha256=9SW0ujhi6PfN4yR1JZ9NaA37HtnXJ2QAWUfW52NG68w,13109
10
10
  taker/config.py,sha256=YPxghO5i0vgRg9Cja8kGj9O7pgSbbtzOgf3RexqXXwY,1188
11
11
  taker/main.py,sha256=8cLWzEvQDeELbY5Av7JqkEyYbaNqSbAbVl1tQHXzU8s,1954
12
- openfund_taker-1.0.17.dist-info/METADATA,sha256=ocHhC9D7pvCW1Ciw_q4o2D0WMwZgsIsvgJ5b3YrVH08,7503
13
- openfund_taker-1.0.17.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
14
- openfund_taker-1.0.17.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
15
- openfund_taker-1.0.17.dist-info/RECORD,,
12
+ openfund_taker-1.1.1.dist-info/METADATA,sha256=mAwzF4dc7kT0CagE9RVnxr_TYntAFxaEVC3RwoY3kLE,7502
13
+ openfund_taker-1.1.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
14
+ openfund_taker-1.1.1.dist-info/entry_points.txt,sha256=a7mG8F7aOA5-Gk2vPWuAR4537faxaHUgM_jwIDBZoEc,50
15
+ openfund_taker-1.1.1.dist-info/RECORD,,
@@ -81,9 +81,9 @@ class MultiAssetNewTradingBot:
81
81
  payload = {"msg_type": "text", "content": {"text": message}}
82
82
  response = requests.post(self.feishu_webhook, json=payload, headers=headers)
83
83
  if response.status_code == 200:
84
- self.logger.info("飞书通知发送成功")
84
+ self.logger.debug("飞书通知发送成功")
85
85
  else:
86
- self.logger.error("飞书通知发送失败,状态码: %s", response.status_code)
86
+ self.logger.warn("飞书通知发送失败,状态码: %s", response.status_code)
87
87
  except Exception as e:
88
88
  self.logger.error("发送飞书通知时出现异常: %s", str(e))
89
89
 
@@ -180,6 +180,25 @@ class MultiAssetNewTradingBot:
180
180
 
181
181
  # 定义根据均线斜率判断 K 线方向的函数: 0 空 1 多 -1 平
182
182
 
183
+ def judge_range_diff(self,symbol,pair_config,prices:pd.Series) -> bool:
184
+ """
185
+ 计算价格列表中最后一个价格与第一个价格的差值。
186
+ Args:
187
+ prices: 价格列表。
188
+ Returns:
189
+ diff: 计算最高价列的最大值与最小值的差值
190
+
191
+ """
192
+ limit = int(pair_config.get('ema_range_limit', 1))
193
+ period = int(pair_config.get('ema_range_period', 3))
194
+ tick_size = self.get_tick_size(symbol)
195
+ if prices.empty:
196
+ return None
197
+
198
+ diff = prices.tail(period).max() - prices.tail(period).min()
199
+ self.logger.debug(f"{symbol}: 最高价列的最大值与最小值的差值 = {diff:.9f}")
200
+ return abs(diff) <= tick_size * limit
201
+
183
202
  # 定义根据均线斜率判断 K 线方向的函数: 0 空 1 多 -1 平
184
203
  def judge_k_line_direction(self, symbol, pair_config, ema: pd.Series, klines) -> int:
185
204
  """
@@ -194,19 +213,19 @@ class MultiAssetNewTradingBot:
194
213
  # 获取配置参数
195
214
  period = int(pair_config.get('ema_range_period', 3))
196
215
 
197
- ema_4_diff = ema.diff().tail(period)
216
+ ema_diff = ema.diff().tail(period)
198
217
 
199
218
  direction = None
200
- if all(ema_4_diff <= 0) :
219
+ if ema_diff.iloc[-1] < 0:
201
220
  # 下降趋势
202
221
  direction = 0
203
- elif all(ema_4_diff >= 0) :
222
+ elif ema_diff.iloc[-1] > 0:
204
223
  # 上升趋势
205
224
  direction = 1
206
225
  else:
207
226
  # 震荡趋势
208
227
  direction = -1
209
- self.logger.debug(f"{symbol}: K线极差={ema_4_diff.map('{:.9f}'.format).values} ,K线方向={direction}")
228
+ self.logger.debug(f"{symbol}: K线极差={ema_diff.map('{:.9f}'.format).values} ,K线方向={direction}")
210
229
  return direction
211
230
 
212
231
  def check_reverse_position(self,symbol,position,pair_config):
@@ -235,17 +254,32 @@ class MultiAssetNewTradingBot:
235
254
  is_apex = self.judge_ma_apex(symbol=symbol,pair_config=pair_config, fastklines=fastk,slowklines=slowk)
236
255
 
237
256
  kline_direction = self.judge_k_line_direction(symbol=symbol, pair_config=pair_config, ema=fastk, klines=klines)
257
+ # if_inner_range = self.judge_range_diff(symbol=symbol, pair_config=pair_config, prices=fastk)
238
258
 
239
- self.logger.debug(f"{symbol} cross={last_cross_direction},见顶={is_apex},持仓方向={side}")
240
- # 金叉逻辑 ,如果是金叉,且是周期顶部,且K线方向是空头,就清仓多单
259
+ self.logger.debug(f"{symbol} cross={last_cross_direction},两线收缩={is_apex},持仓方向={side} ,K线方向={kline_direction}")
260
+ order_stop_loss_pct = None
261
+ # 20250213 增加趋势顶部/底部判断
262
+ # 金叉逻辑 ,如果是金叉,且是周期顶部,且K线方向是空头,
241
263
  if last_cross_direction and last_cross_direction['cross'] == 1 and is_apex and side == 'long' and kline_direction == 0:
242
- self.logger.debug(f"{symbol} 金叉:{last_cross_direction['cross']},见顶={is_apex},持仓方向={side},开始清理多单!!")
243
- self.close_all_positions(symbol=symbol, position=position)
264
+ self.logger.debug(f"{symbol} 金叉:{last_cross_direction['cross']},两线收缩={is_apex},持仓方向={side} ,K线方向={kline_direction} ,开始清理多单!!")
265
+ # self.close_all_positions(symbol=symbol, position=position)
266
+ order_stop_loss_pct = self.stop_loss_pct / 2
267
+ self.logger.debug(f"{symbol} 全局止损阈值-修正后= {self.stop_loss_pct:.2f} -> {order_stop_loss_pct:.2f}%")
268
+
244
269
 
245
270
  # 死叉逻辑 ,如果是死叉,且是周期底部,且K线方向是多头,就清仓空单
246
- elif last_cross_direction and last_cross_direction['cross'] == 0 and is_apex and side == 'short' and kline_direction == 1:
247
- self.logger.debug(f"{symbol} 死叉:{last_cross_direction['cross']},见顶={is_apex},持仓方向={side},开始清理空单!!")
248
- self.close_all_positions(symbol=symbol, position=position)
271
+ if last_cross_direction and last_cross_direction['cross'] == 0 and is_apex and side == 'short' and kline_direction == 1:
272
+ self.logger.debug(f"{symbol} 死叉:{last_cross_direction['cross']},两线收缩={is_apex},持仓方向={side} ,K线方向={kline_direction} ,开始清理空单!!")
273
+ # self.close_all_positions(symbol=symbol, position=position)
274
+ order_stop_loss_pct = self.stop_loss_pct / 2
275
+ self.logger.debug(f"{symbol} 全局止损阈值-修正后= {self.stop_loss_pct:.2f} -> {order_stop_loss_pct:.2f}%")
276
+
277
+ # 根据情况 重新修正 止损
278
+ if order_stop_loss_pct is not None :
279
+ self.global_symbol_stop_loss_flag[symbol] = False
280
+ self.set_global_stop_loss(symbol=symbol,position=position,stop_loss_pct=order_stop_loss_pct)
281
+ else :
282
+ self.global_symbol_stop_loss_flag[symbol] = False
249
283
 
250
284
  except KeyboardInterrupt:
251
285
  self.logger.info("程序收到中断信号,开始退出...")
@@ -436,7 +470,7 @@ class MultiAssetNewTradingBot:
436
470
  self.logger.warning(f"!! {symbol} 设置止损单时重试次数用完仍未成功设置成功。 ")
437
471
  return False
438
472
 
439
- def set_global_stop_loss(self, symbol, position, side, stop_loss_algo):
473
+ def set_global_stop_loss(self, symbol, position, stop_loss_pct=None):
440
474
  """设置全局止损
441
475
 
442
476
  Args:
@@ -450,26 +484,31 @@ class MultiAssetNewTradingBot:
450
484
 
451
485
  return
452
486
  else :
453
- self.logger.debug(f"{symbol} - 是否设置过全局止损 {self.global_symbol_stop_loss_flag.get(symbol, False)} 策略订单: {stop_loss_algo}")
454
-
487
+ self.logger.debug(f"{symbol} - 是否设置过全局止损 {self.global_symbol_stop_loss_flag.get(symbol, False)} ")
488
+ if stop_loss_pct is None :
489
+ stop_loss_pct = self.stop_loss_pct
490
+
455
491
  # 根据持仓方向计算止损价格
492
+ side = position['side']
456
493
  if side == 'long':
457
- stop_loss_price = position['entryPrice'] * (1 - self.stop_loss_pct/100)
494
+ stop_loss_price = position['entryPrice'] * (1 - stop_loss_pct/100)
458
495
  elif side == 'short':
459
- stop_loss_price = position['entryPrice'] * (1 + self.stop_loss_pct/100)
496
+ stop_loss_price = position['entryPrice'] * (1 + stop_loss_pct/100)
497
+
498
+ order_price = float(self.round_price_to_tick(symbol, stop_loss_price))
460
499
 
461
500
  try:
462
501
  # 设置止损单
463
502
  if_success = self.set_stop_loss_take_profit(
464
503
  symbol=symbol,
465
504
  position=position,
466
- stop_loss_price=stop_loss_price
505
+ stop_loss_price=order_price
467
506
  )
468
507
  if if_success:
469
508
  # 设置全局止损标志
470
- self.logger.debug(f"{symbol} - {side} 设置全局止损价: {stop_loss_price}")
509
+ self.logger.debug(f"{symbol} - {side} 设置全局止损价: {order_price}")
471
510
  self.global_symbol_stop_loss_flag[symbol] = True
472
- self.global_symbol_take_profit_price[symbol] = stop_loss_price
511
+ self.global_symbol_take_profit_price[symbol] = order_price
473
512
 
474
513
  except Exception as e:
475
514
  error_msg = f"{symbol} - 设置止损时发生错误: {str(e)}"
@@ -669,9 +708,8 @@ class MultiAssetNewTradingBot:
669
708
  return
670
709
  else :
671
710
  self.logger.info(f"{symbol} 全局止损阈值: {self.stop_loss_pct:.2f}%")
672
- stop_loss_algo = position['info']['closeOrderAlgo']
673
- side = position['side']
674
- self.set_global_stop_loss(symbol, position, side, stop_loss_algo)
711
+
712
+ self.set_global_stop_loss(symbol, position)
675
713
 
676
714
  return
677
715
 
@@ -681,6 +719,7 @@ class MultiAssetNewTradingBot:
681
719
  abs(float(position['contracts'])) for position in self.fetch_positions()) # 初始总仓位大小
682
720
  while True:
683
721
  try:
722
+
684
723
  positions = self.fetch_positions()
685
724
  # 检查是否有仓位
686
725
  if not positions:
@@ -689,6 +728,7 @@ class MultiAssetNewTradingBot:
689
728
  self.reset_take_profie()
690
729
  time.sleep(1)
691
730
  continue
731
+ self.logger.info("+" * 60)
692
732
  # 检查仓位总规模变化
693
733
  current_position_size = sum(abs(float(position['contracts'])) for position in self.fetch_positions())
694
734
  if current_position_size > previous_position_size:
@@ -702,10 +742,11 @@ class MultiAssetNewTradingBot:
702
742
  for position in positions:
703
743
  symbol = position['symbol']
704
744
  self.check_total_profit(symbol, position)
705
- # 对有错误的仓位进行处理
745
+ time.sleep(0.1)
746
+ # 检查仓位和挂单是否有问题
706
747
  self.check_position(symbol, position)
707
748
 
708
-
749
+ self.logger.info("-" * 60)
709
750
  time.sleep(self.monitor_interval)
710
751
 
711
752
  except Exception as e: