bitmart优化完成
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -423,6 +423,7 @@ class BitmartOneThirdStrategy:
|
|||||||
direction_str = "做多" if marketPriceLongOrder == 1 else "做空"
|
direction_str = "做多" if marketPriceLongOrder == 1 else "做空"
|
||||||
logger.info(f"执行{direction_str}操作,金额: {size}")
|
logger.info(f"执行{direction_str}操作,金额: {size}")
|
||||||
|
|
||||||
|
size = 25
|
||||||
try:
|
try:
|
||||||
if marketPriceLongOrder == -1:
|
if marketPriceLongOrder == -1:
|
||||||
self.click_safe('x://button[normalize-space(text()) ="市价"]')
|
self.click_safe('x://button[normalize-space(text()) ="市价"]')
|
||||||
@@ -510,6 +511,27 @@ class BitmartOneThirdStrategy:
|
|||||||
report_interval = 300 # 5分钟报告一次持仓
|
report_interval = 300 # 5分钟报告一次持仓
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
# 1. 打开浏览器
|
||||||
|
for i in range(5):
|
||||||
|
if self.openBrowser():
|
||||||
|
break
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
else:
|
||||||
|
self.ding("打开浏览器失败!", error=True)
|
||||||
|
return
|
||||||
|
logger.info("浏览器打开成功")
|
||||||
|
|
||||||
|
if self.close_extra_tabs_in_browser():
|
||||||
|
logger.info('关闭多余标签页成功')
|
||||||
|
else:
|
||||||
|
logger.info('关闭多余标签页失败')
|
||||||
|
|
||||||
|
self.page.get("https://derivatives.bitmart.com/zh-CN/futures/ETHUSDT")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
self.click_safe('x://button[normalize-space(text()) ="市价"]')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 获取K线数据
|
# 获取K线数据
|
||||||
kline_data = self.get_klines()
|
kline_data = self.get_klines()
|
||||||
@@ -560,10 +582,12 @@ class BitmartOneThirdStrategy:
|
|||||||
time.sleep(self.check_interval)
|
time.sleep(self.check_interval)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.info(f"{'='*50}")
|
logger.info(f"{'=' * 50}")
|
||||||
logger.info(f"🚨 检测到{direction}信号!触发价格: {trigger_price:.2f}")
|
logger.info(f"🚨 检测到{direction}信号!触发价格: {trigger_price:.2f}")
|
||||||
logger.info(f" 有效前一根[{prev_time}]: {prev_type} 实体={prev_body:.2f} O={valid_prev['open']:.2f} C={valid_prev['close']:.2f}")
|
logger.info(
|
||||||
logger.info(f" 当前K线: H={curr_kline['high']:.2f} L={curr_kline['low']:.2f} C={curr_kline['close']:.2f}")
|
f" 有效前一根[{prev_time}]: {prev_type} 实体={prev_body:.2f} O={valid_prev['open']:.2f} C={valid_prev['close']:.2f}")
|
||||||
|
logger.info(
|
||||||
|
f" 当前K线: H={curr_kline['high']:.2f} L={curr_kline['low']:.2f} C={curr_kline['close']:.2f}")
|
||||||
logger.info(f" 当前持仓: {self.start} (1=多, -1=空, 0=无)")
|
logger.info(f" 当前持仓: {self.start} (1=多, -1=空, 0=无)")
|
||||||
|
|
||||||
# ========== 执行交易逻辑 ==========
|
# ========== 执行交易逻辑 ==========
|
||||||
@@ -609,11 +633,12 @@ class BitmartOneThirdStrategy:
|
|||||||
self._send_position_message(curr_kline)
|
self._send_position_message(curr_kline)
|
||||||
last_report_time = time.time()
|
last_report_time = time.time()
|
||||||
|
|
||||||
logger.info(f"{'='*50}")
|
logger.info(f"{'=' * 50}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# 没有信号时,显示实时价格
|
# 没有信号时,显示实时价格
|
||||||
logger.debug(f"[{curr_time_str}] 现价: {curr['close']:.2f} H={curr['high']:.2f} L={curr['low']:.2f}")
|
logger.debug(
|
||||||
|
f"[{curr_time_str}] 现价: {curr['close']:.2f} H={curr['high']:.2f} L={curr['low']:.2f}")
|
||||||
|
|
||||||
# ========== 定时发送持仓信息 ==========
|
# ========== 定时发送持仓信息 ==========
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
@@ -629,6 +654,10 @@ class BitmartOneThirdStrategy:
|
|||||||
logger.error(f"主循环异常: {e}")
|
logger.error(f"主循环异常: {e}")
|
||||||
time.sleep(self.check_interval)
|
time.sleep(self.check_interval)
|
||||||
|
|
||||||
|
time.sleep(15)
|
||||||
|
self.page.close()
|
||||||
|
time.sleep(15)
|
||||||
|
|
||||||
def _send_position_message(self, latest_kline):
|
def _send_position_message(self, latest_kline):
|
||||||
"""发送持仓信息到钉钉"""
|
"""发送持仓信息到钉钉"""
|
||||||
current_price = float(latest_kline["close"])
|
current_price = float(latest_kline["close"])
|
||||||
@@ -638,7 +667,8 @@ class BitmartOneThirdStrategy:
|
|||||||
if self.start != 0:
|
if self.start != 0:
|
||||||
open_avg_price = float(self.open_avg_price) if self.open_avg_price else 0.0
|
open_avg_price = float(self.open_avg_price) if self.open_avg_price else 0.0
|
||||||
current_amount = float(self.current_amount) if self.current_amount else 0.0
|
current_amount = float(self.current_amount) if self.current_amount else 0.0
|
||||||
position_cross = float(self.position_cross) if hasattr(self, 'position_cross') and self.position_cross else 0.0
|
position_cross = float(self.position_cross) if hasattr(self,
|
||||||
|
'position_cross') and self.position_cross else 0.0
|
||||||
|
|
||||||
# 计算浮动盈亏
|
# 计算浮动盈亏
|
||||||
if self.start == 1: # 多头
|
if self.start == 1: # 多头
|
||||||
|
|||||||
Reference in New Issue
Block a user