openfund-maker 1.0.6__py3-none-any.whl → 1.0.8__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.
@@ -288,7 +288,7 @@ class ThreeLineOrdergBot:
288
288
  'params': params
289
289
  }
290
290
  # 使用ccxt创建订单
291
- # self.logger.debug(f"Pre Order placed: {order} ")
291
+ self.logger.debug(f"Pre Order placed: {order} ")
292
292
  order_result = self.exchange.create_order(
293
293
  **order
294
294
  # symbol=symbol,
@@ -298,7 +298,7 @@ class ThreeLineOrdergBot:
298
298
  # price=float(adjusted_price),
299
299
  # params=params
300
300
  )
301
- self.logger.debug(f"{symbol} ++ Order placed rs : {order_result}")
301
+ # self.logger.debug(f"{symbol} ++ Order placed rs : {order_result}")
302
302
  except Exception as e:
303
303
  self.logger.error(f"{symbol} Failed to place order: {e}")
304
304
  self.logger.info(f"--------- ++ {symbol} Order placed done! --------")
@@ -359,8 +359,21 @@ class ThreeLineOrdergBot:
359
359
  'index': None
360
360
  }
361
361
 
362
-
363
- def calculate_price_diff(self,prices:pd.Series) -> float:
362
+ def judge_ma_apex(self,fastklines,slowklines) -> bool:
363
+ df = pd.DataFrame()
364
+ df['ema'] = fastklines
365
+ df['sma'] = slowklines
366
+ # 快线和慢线的差值
367
+ df['diff'] = df['ema']-df['sma']
368
+ # 计算斜率,【正】表示两线距离扩张,【负】表示两线距离收缩
369
+ df['slope'] = df['diff'].abs().diff().round(6)
370
+
371
+ #
372
+ return df['slope'].iloc[-1] < 0
373
+ # df['statu'] = df['slope']
374
+
375
+
376
+ def calculate_range_diff(self,prices:pd.Series) -> float:
364
377
  """
365
378
  计算价格列表中最后一个价格与第一个价格的差值。
366
379
  Args:
@@ -393,7 +406,7 @@ class ThreeLineOrdergBot:
393
406
  place_order_price = None
394
407
  # 计算止盈价格,用市场价格(取持仓期间历史最高)减去开仓价格的利润,再乘以不同阶段的止盈百分比。
395
408
 
396
- if side == 'long':
409
+ if side == 'buy':
397
410
  place_order_price = base_price * (1- amplitude_limit/100) - offset * tick_size
398
411
  else:
399
412
  place_order_price = base_price * (1 + amplitude_limit/100) + offset * tick_size
@@ -439,38 +452,36 @@ class ThreeLineOrdergBot:
439
452
  is_bullish_trend = True
440
453
  elif direction == 0:
441
454
  is_bearish_trend = True
442
- else:
443
- self.logger.info(f"{symbol} 当前是震荡(平)趋势,不执行挂单!!")
444
- return
445
-
455
+
456
+ # 结合金叉死叉判断是否是周期顶部和底部
457
+ is_apex = self.judge_ma_apex(fastklines=fastk,slowklines=slowk)
458
+ # 金叉死叉逻辑
446
459
  if last_cross_direction and last_cross_direction['cross'] == 1 : # 金叉
447
460
  self.logger.debug(f"{symbol} 金叉:{last_cross_direction},清理空单,挂多单!!")
448
461
  is_bearish_trend = False
462
+ if is_apex :
463
+ self.logger.debug(f"{symbol} 金叉:{last_cross_direction},周期见顶 {is_apex},不开单!!")
464
+ is_bullish_trend = False
465
+ return
449
466
  elif last_cross_direction and last_cross_direction['cross'] == 0 : # 死叉
450
467
  self.logger.debug(f"{symbol} 死叉:{last_cross_direction},清理多单,挂空单!!")
451
468
  is_bullish_trend = False
469
+ if is_apex :
470
+ self.logger.debug(f"{symbol} 死叉:{last_cross_direction},周期见顶 {is_apex},不开单!!")
471
+ is_bearish_trend = False
472
+ return
452
473
  else:
453
474
  self.logger.debug(f"{symbol} 当前没有金叉死叉,以快线趋势为准。!")
454
- return
475
+ return
476
+
477
+ if not is_bullish_trend and not is_bearish_trend :
478
+ self.logger.info(f"{symbol} 当前是震荡趋势(平),不挂单!!")
479
+ return
455
480
 
456
481
  '''
457
482
  取当前K线的前三根K线中最高/低的值作为止盈位。
458
483
  20250210 增加开单价格约束,下单时,三线如果价格振幅小(如0.32%内),那去找到0.32%外的那根。 振幅 amplitude_limit
459
484
  '''
460
- # 获取 K 线数据
461
- # ohlcv = self.exchange.fetch_ohlcv(symbol, '1m')
462
-
463
- # 取当前 K 线的前三根 K 线
464
- # previous_three_candles = ohlcv[-4:-1]
465
- # 提取每根 K 线的最高价
466
-
467
- # high_prices = [candle[2] for candle in previous_three_candles]
468
- # # 提取每根 K 线的最低价
469
- # low_prices = [candle[3] for candle in previous_three_candles]
470
- # # 找出最大值
471
- # max_high = max(high_prices)
472
- # # 找出最小值
473
- # min_low = min(low_prices)
474
485
 
475
486
  # 取当前 K 线的前三根 K 线
476
487
 
@@ -498,10 +509,11 @@ class ThreeLineOrdergBot:
498
509
  # 取最新K线的收盘价格
499
510
  close_price = klines[-1][4]
500
511
  self.logger.debug(f"-- {symbol} 最新K线 {klines[-1]}")
512
+
501
513
  if is_bullish_trend:
502
- diff = self.calculate_price_diff(prices=low_prices)
514
+ diff = self.calculate_range_diff(prices=low_prices)
503
515
  cur_amplitude_limit = diff / close_price * 100
504
- self.logger.info(f"{symbol} 当前为上升(多)趋势,允许挂多单,振幅{cur_amplitude_limit:.3f} hight/low {max(low_prices)}/{min(low_prices)} ++")
516
+ self.logger.info(f"{symbol} 当前为上升(多)趋势,允许挂多单,振幅{cur_amplitude_limit:.3f} hight/low {low_prices.max()}/{low_prices.min()} ++")
505
517
  # 振幅大于限制,直接下单,否则,根据振幅计算下单价格
506
518
  if cur_amplitude_limit >= amplitude_limit:
507
519
  self.place_order(symbol, min_low, long_amount_usdt, 'buy')
@@ -511,15 +523,14 @@ class ThreeLineOrdergBot:
511
523
 
512
524
 
513
525
  if is_bearish_trend:
514
- diff = self.calculate_price_diff(prices=high_prices)
526
+ diff = self.calculate_range_diff(prices=high_prices)
515
527
  cur_amplitude_limit = diff / close_price * 100
516
- self.logger.info(f"{symbol} 当前为下降(空)趋势,允许挂空单,振幅{cur_amplitude_limit:.3f} hight/low {max(high_prices)}/{min(high_prices)}--")
528
+ self.logger.info(f"{symbol} 当前为下降(空)趋势,允许挂空单,振幅{cur_amplitude_limit:.3f} hight/low {high_prices.max()}/{high_prices.min()}--")
517
529
  if cur_amplitude_limit >= amplitude_limit:
518
530
  self.place_order(symbol, max_high, short_amount_usdt, 'sell')
519
531
  else:
520
532
  entry_price = self.calculate_place_order_price(symbol,side='sell',base_price=max_high, amplitude_limit=amplitude_limit,offset=0)
521
- self.place_order(symbol, entry_price ,long_amount_usdt, 'sell')
522
-
533
+ self.place_order(symbol, entry_price ,long_amount_usdt, 'sell')
523
534
 
524
535
  except KeyboardInterrupt:
525
536
  self.logger.info("程序收到中断信号,开始退出...")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openfund-maker
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: Openfund-maker.
5
5
  Requires-Python: >=3.9,<4.0
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,4 +1,4 @@
1
- maker/ThreeLineOrderBot.py,sha256=xPiOJKAvIZ709lYSArWJJSbho-tYpH34unJaVSJY5fY,23276
1
+ maker/ThreeLineOrderBot.py,sha256=bqJj17SQw4XVGXtgDvY-uNCIG4NAwalRjWr5OT_SQG4,23838
2
2
  maker/WickReversalOrderBot.py,sha256=Oc6wChdWu39lfWh3NRHM8BqvaRIYDNZiDR6PDnE9XUM,17374
3
3
  maker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  maker/config.py,sha256=YPxghO5i0vgRg9Cja8kGj9O7pgSbbtzOgf3RexqXXwY,1188
@@ -7,7 +7,7 @@ maker/main_m.py,sha256=0PzDTnuBrxfpy5WDfsIHKAzZ_7pkuvuqqeWik0vpWio,15522
7
7
  maker/okxapi.py,sha256=_9G0U_o0ZC8NxaT6PqpiLgxBm9gPobC9PsFHZE1c5w0,553
8
8
  maker/zhen.py.bak,sha256=HNkrQbJts8G9umE9chEFsc0cLQApcM9KOVNMYPpkBXM,10918
9
9
  maker/zhen_2.py,sha256=4IaHVtTCMSlrLGSTZrWpW2q-f7HZsUNRkW_-5QgWv24,10509
10
- openfund_maker-1.0.6.dist-info/METADATA,sha256=dOXmSsHYvmhmNkpT29NdX45b8KZIc-vifuAof45l31E,1965
11
- openfund_maker-1.0.6.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
12
- openfund_maker-1.0.6.dist-info/entry_points.txt,sha256=gKMytICEKcMRFQDFkHZLnIpID7UQFoTIM_xcpiiV6Ns,50
13
- openfund_maker-1.0.6.dist-info/RECORD,,
10
+ openfund_maker-1.0.8.dist-info/METADATA,sha256=jlncVj8iDI2oWPC2YL6Ox30K71pOUP85HIhWSB9rAws,1965
11
+ openfund_maker-1.0.8.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
12
+ openfund_maker-1.0.8.dist-info/entry_points.txt,sha256=gKMytICEKcMRFQDFkHZLnIpID7UQFoTIM_xcpiiV6Ns,50
13
+ openfund_maker-1.0.8.dist-info/RECORD,,