openfund-maker 1.1.0__tar.gz → 1.1.2__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: 1.1.0
3
+ Version: 1.1.2
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 = "1.1.0"
3
+ version = "1.1.2"
4
4
  description = "Openfund-maker."
5
5
  authors = []
6
6
  readme = "README.md"
@@ -245,19 +245,19 @@ class ThreeLineOrdergBot:
245
245
 
246
246
  # precision= self.get_precision_length(symbol)
247
247
 
248
- ema_4_diff = ema.diff().tail(period)
248
+ ema_diff = ema.diff().tail(period)
249
249
 
250
250
  direction = None
251
- if all(ema_4_diff <= 0) :
251
+ if ema_diff.iloc[-1] < 0:
252
252
  # 下降趋势
253
253
  direction = 0
254
- elif all(ema_4_diff >= 0) :
254
+ elif ema_diff.iloc[-1] > 0 :
255
255
  # 上升趋势
256
256
  direction = 1
257
257
  else:
258
258
  # 震荡趋势
259
259
  direction = -1
260
- self.logger.debug(f"{symbol}: K线极差={ema_4_diff.map('{:.9f}'.format).values} ,K线方向={direction}")
260
+ self.logger.debug(f"{symbol}: K线极差={ema_diff.map('{:.9f}'.format).values} ,K线方向={direction}")
261
261
  return direction
262
262
 
263
263
  def judge_ema_direction(self, symbol, pair_config, ema: pd.Series) -> int:
@@ -326,10 +326,15 @@ class ThreeLineOrdergBot:
326
326
  'index': last_death
327
327
  }
328
328
 
329
- def judge_ma_apex(self,symbol,pair_config, fastklines,slowklines) -> bool:
329
+ def judge_ma_apex(self,symbol,pair_config,cross_index, fastklines,slowklines) -> bool:
330
330
  period = int(pair_config.get('ema_range_period', 3))
331
331
  precision= self.get_precision_length(symbol)
332
332
 
333
+ # 获取交叉点的索引,从交叉点之后进行判断
334
+ index = 0
335
+ if cross_index is not None:
336
+ index = cross_index
337
+
333
338
  df = pd.DataFrame({
334
339
  'ema': fastklines,
335
340
  'sma': slowklines
@@ -337,17 +342,21 @@ class ThreeLineOrdergBot:
337
342
  # 快线和慢线的差值
338
343
  # 将ema和sma转换为tick_size精度
339
344
  # df['diff'] = df['ema'].apply(lambda x: float(self.round_price_to_tick(x, tick_size))) - df['sma'].apply(lambda x: float(self.round_price_to_tick(x, tick_size)))
340
- df['diff'] = df['ema'].round(precision)-df['sma'].round(precision)
345
+ df['diff'] = df['ema'].tail(period*2).round(precision)-df['sma'].tail(period*2).round(precision)
341
346
  df['ema_diff'] = df['ema'] - df['ema'].shift(1)
342
347
  df['sma_diff'] = df['sma'] - df['sma'].shift(1)
343
348
  # 计算斜率,【正】表示两线距离扩张,【负】表示两线距离收缩
344
349
  df['slope'] = df['diff'].abs().diff().round(4)
345
350
 
346
- self.logger.debug(f"{symbol}: slopes = \n{df[['ema','ema_diff','sma','sma_diff','diff','slope']].iloc[-6:-1]} ")
347
-
348
- # 两条线的距离是扩张状态还是收缩状态 true 是收缩 flase 是扩张
349
- is_expanding_or_contracting = all(df['slope'].tail(period) <= 0 ) and any(df['slope'].tail(period) < 0)
351
+ self.logger.debug(f"{symbol}: ma apex slopes = \n"
352
+ f"{df[['ema','ema_diff','sma','sma_diff','diff','slope']].iloc[-1-period:-1]} ")
353
+ # 筛选出索引大于等于特定索引值的 slope 列元素
354
+ filtered_slope = df['slope'][df.index >= index]
350
355
 
356
+ # 两条线的距离是扩张状态还是收缩状态 true 是收缩 flase 是扩张
357
+ is_expanding_or_contracting = all(filtered_slope.tail(period) <= 0 ) and \
358
+ any(filtered_slope.tail(period) < 0)
359
+
351
360
  return is_expanding_or_contracting
352
361
 
353
362
  def judge_range_diff(self,symbol,pair_config,prices:pd.Series) -> bool:
@@ -480,6 +489,7 @@ class ThreeLineOrdergBot:
480
489
  self.logger.error(f"{symbol} 取消订单失败: {str(e)}")
481
490
 
482
491
  def process_pair(self,symbol,pair_config):
492
+ self.logger.info("=" * 60)
483
493
  # 检查是否有持仓,有持仓不进行下单
484
494
  if self.check_position(symbol=symbol) :
485
495
  self.logger.info(f"{symbol} 有持仓合约,不进行下单。")
@@ -510,7 +520,7 @@ class ThreeLineOrdergBot:
510
520
 
511
521
  # 最新交叉方向
512
522
  last_cross_direction = self.exchange.safe_dict(self.cross_directions,symbol,None)
513
-
523
+ cross_index = self.exchange.safe_dict(last_cross_direction,'index',None)
514
524
 
515
525
  # 判断趋势:多头趋势或空头趋势
516
526
  direction = self.judge_k_line_direction(symbol=symbol, pair_config=pair_config,ema=fastk,klines=klines)
@@ -520,43 +530,48 @@ class ThreeLineOrdergBot:
520
530
  is_bearish_trend = True
521
531
 
522
532
  # 结合金叉死叉判断是否是周期顶部和底部
523
- is_apex = self.judge_ma_apex(symbol=symbol,pair_config=pair_config, fastklines=fastk,slowklines=slowk)
524
533
  ema_direction = self.judge_ema_direction(symbol=symbol, pair_config=pair_config,ema=fastk)
525
- if_inner_range = self.judge_range_diff(symbol=symbol, pair_config=pair_config, prices=fastk)
534
+ is_apex = self.judge_ma_apex(symbol=symbol,pair_config=pair_config,cross_index=cross_index, fastklines=fastk,slowklines=slowk)
535
+ # if_inner_range = self.judge_range_diff(symbol=symbol, pair_config=pair_config, prices=fastk)
526
536
  # 金叉死叉逻辑
527
537
  if last_cross_direction and last_cross_direction['cross'] == 1 : # 金叉
528
- self.logger.debug(f"{symbol} 金叉:{last_cross_direction},清理空单,挂多单!!")
529
- is_bearish_trend = False
530
538
  # 强校验下单条件
531
- if is_apex or ema_direction == -1 or if_inner_range:
532
- self.logger.debug(f"{symbol} 强校验 - 死叉:{last_cross_direction},两线收缩={is_apex} ,ema_平={ema_direction},均线振幅={if_inner_range} ,不开单!!")
539
+ # if is_apex or ema_direction == -1 or if_inner_range:
540
+ # self.logger.debug(f"{symbol} 强校验 - 金叉:{last_cross_direction},两线收缩={is_apex} ,ema_平={ema_direction},均线振幅={if_inner_range} ,不开单!!")
533
541
  # 弱校验下单条件
534
- # if is_apex or ema_direction == -1:
535
- # self.logger.debug(f"{symbol} 金叉:{last_cross_direction},两线收缩={is_apex} ,ema_平={ema_direction},不开单!!")
542
+ if is_apex or ema_direction == -1:
543
+ self.logger.debug(f"{symbol} :金叉={last_cross_direction['cross']},两线收缩={is_apex} ,快线方向(平:-1)={ema_direction},不挂单!!")
536
544
  is_bullish_trend = False
545
+ is_bearish_trend = False
546
+ else :
547
+ self.logger.debug(f"{symbol} :金叉={last_cross_direction['cross']},两线收缩={is_apex} ,快线方向(平:-1)={ema_direction}, 清理空单,挂多单!!")
548
+ is_bearish_trend = False
537
549
 
538
550
  elif last_cross_direction and last_cross_direction['cross'] == 0 : # 死叉
539
- self.logger.debug(f"{symbol} 死叉:{last_cross_direction},清理多单,挂空单!!")
540
- is_bullish_trend = False
551
+
541
552
  # 强校验下单条件
542
- if is_apex or ema_direction == -1 or if_inner_range :
543
- self.logger.debug(f"{symbol} 强校验 - 死叉:{last_cross_direction},两线收缩={is_apex} ,ema_平={ema_direction},均线振幅={if_inner_range} ,不开单!!")
553
+ # if is_apex or ema_direction == -1 or if_inner_range :
554
+ # self.logger.debug(f"{symbol} 强校验 - 死叉:{last_cross_direction},两线收缩={is_apex} ,ema_平={ema_direction},均线振幅={if_inner_range} ,不开单!!")
544
555
  # 弱校验下单条件
545
- # if is_apex or ema_direction == -1:
546
- # self.logger.debug(f"{symbol} 死叉:{last_cross_direction},两线收缩={is_apex} ,ema_平={ema_direction},不开单!!")
556
+ if is_apex or ema_direction == -1:
557
+ self.logger.debug(f"{symbol} :死叉={last_cross_direction['cross']},两线收缩={is_apex} ,快线方向(平:-1)={ema_direction},不挂单!!")
547
558
  is_bearish_trend = False
559
+ is_bullish_trend = False
560
+ else :
561
+ self.logger.debug(f"{symbol} :死叉={last_cross_direction['cross']},两线收缩={is_apex} ,快线方向(平:-1)={ema_direction},清理多单,挂空单!!")
562
+ is_bullish_trend = False
548
563
 
549
564
  else:
550
- self.logger.debug(f"{symbol} 当前没有金叉死叉,以快线趋势为准。!")
565
+ self.logger.warning(f"{symbol} :当前没有金叉死叉,以K线趋势为准。")
551
566
 
552
567
 
553
- if (not is_bullish_trend and not is_bearish_trend) or direction == -1 :
554
- self.logger.info(f"{symbol} 当前是震荡趋势(平),不挂单!!direction={direction}")
568
+ if (not is_bullish_trend and not is_bearish_trend) :
569
+ self.logger.info(f"{symbol} :当前是震荡趋势(平),不挂单!! 死叉={last_cross_direction['cross']},两线收缩={is_apex} ,快线方向(平:-1)={ema_direction}")
555
570
  return
556
571
 
557
572
  '''
558
573
  取当前K线的前三根K线中最高/低的值作为止盈位。
559
- 20250210 增加开单价格约束,下单时,三线如果价格振幅小(如0.32%内),那去找到0.32%外的那根。 振幅 amplitude_limit
574
+ 20250210 增加开单价格约束,下单时,三线如果价格振幅小(如0.32%内),那去找到0.32%外的那根。 振幅 amplitude_limit
560
575
  '''
561
576
 
562
577
  # 取当前 K 线的前三根 K 线
@@ -614,7 +629,7 @@ class ThreeLineOrdergBot:
614
629
  self.logger.error(error_message,exc_info=True)
615
630
  traceback.print_exc()
616
631
  self.send_feishu_notification(error_message)
617
-
632
+ self.logger.info("=" * 60)
618
633
  def monitor_klines(self):
619
634
  symbols = list(self.trading_pairs_config.keys()) # 获取所有币对的ID
620
635
  batch_size = 5 # 每批处理的数量
File without changes