From 28003da75e6929821386a7ee39ec58c06ac2e9db Mon Sep 17 00:00:00 2001 From: 27942 Date: Tue, 6 Jan 2026 13:51:48 +0800 Subject: [PATCH] fewfef --- telegram/8619211027341.session | Bin 45056 -> 45056 bytes 交易/bitmart-趋势策略交易.py | 78 +++++++++++++++++++++++++++++++-- 交易/tools.py | 8 ++-- 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/telegram/8619211027341.session b/telegram/8619211027341.session index 66ec9d3ea7890e7d1549de6999d08a6e19f06feb..2225e318e50f75482bfa955b62a97d15f0f8942c 100644 GIT binary patch delta 72 zcmZp8z|`=7X@WH4jfpbOj5jtWEY0Qo;CL%sV?#>z#>sqn3hYUlF^l$#uHS5$ca()W bX3>Goe~TtE0vQK4Pb^Wi28m4Gy51WAaylR9 delta 72 zcmZp8z|`=7X@WH4wTUv$jMp|MEY0P7>v$`8>35y?{FC|e6xhQv{ifd(Y2Iv_ca(+M bZ~E=ce~TtE0vUHUPb^Wi28m4Gy51WAencP{ diff --git a/交易/bitmart-趋势策略交易.py b/交易/bitmart-趋势策略交易.py index 4765cd2..081ba48 100644 --- a/交易/bitmart-趋势策略交易.py +++ b/交易/bitmart-趋势策略交易.py @@ -9,6 +9,7 @@ from DrissionPage import ChromiumPage from DrissionPage import ChromiumOptions from bitmart.api_contract import APIContract +from 交易.tools import send_dingtalk_message class BitmartFuturesTransaction: @@ -66,7 +67,7 @@ class BitmartFuturesTransaction: return formatted # 最近3根: kline_1 (最老), kline_2, kline_3 (最新) except Exception as e: logger.error(f"获取K线异常: {e}") - self.ding(error=True, msg="获取K线异常") + self.ding(msg="获取K线异常", error=True) return None def get_current_price(self): @@ -112,6 +113,9 @@ class BitmartFuturesTransaction: positions = response['data'] if not positions: self.start = 0 + self.open_avg_price = None + self.current_amount = None + self.position_cross = None return True self.start = 1 if positions[0]['position_type'] == 1 else -1 self.open_avg_price = positions[0]['open_avg_price'] @@ -221,8 +225,16 @@ class BitmartFuturesTransaction: self.page.ele('x://*[@id="size_0"]').input(1) self.click_safe('x://span[normalize-space(text()) ="买入/做多"]') - def ding(self, text, error=False): - logger.info(text) + def ding(self, msg, error=False): + """统一消息格式""" + prefix = "❌bitmart:" if error else "🔔bitmart:" + if error: + logger.error(msg) + for i in range(10): + send_dingtalk_message(f"{prefix},{msg}") + else: + logger.info(msg) + send_dingtalk_message(f"{prefix},{msg}") def close_extra_tabs_in_browser(self): @@ -349,7 +361,7 @@ class BitmartFuturesTransaction: else: logger.info("获取仓位信息失败!!!") - self.send_dingtalk_message(message_content=f"获取仓位信息失败!!!", type=0) + self.ding(msg="获取仓位信息失败!!!", error=True) continue if self.start == 1: @@ -375,6 +387,64 @@ class BitmartFuturesTransaction: elif self.start == 0: self.开单(marketPriceLongOrder=-1, size=self.get_available_balance() * self.risk_percent) + # =================================================================================================== + # 发送持仓信息消息 + msg = None + current_price = float(self.kline_3["close"]) + balance = self.get_available_balance() + self.balance = balance if balance is not None else 0.0 + + if self.start: + # 持仓方向,开仓价格,现价,持仓量,盈亏,当前价值 + # 1. 确保所有关键数据为 float 类型(BitMart API 常返回字符串) + 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 + position_cross = float(self.position_cross) if hasattr(self, 'position_cross') and self.position_cross else 0.0 + + # 2. 计算浮动盈亏(USDT) + if self.start == 1: # 多头 + unrealized_pnl = current_amount * 0.001 * (current_price - open_avg_price) + elif self.start == -1: # 空头 + unrealized_pnl = current_amount * 0.001 * (open_avg_price - current_price) + else: # 无仓 + unrealized_pnl = 0.0 + + # 3. 计算收益率(可选,更直观) + if self.start != 0 and open_avg_price > 0: + if self.start == 1: + pnl_rate = (current_price - open_avg_price) / open_avg_price * 10000 + else: + pnl_rate = (open_avg_price - current_price) / open_avg_price * 10000 + rate_str = f" ({pnl_rate:+.2f}%)" + else: + rate_str = "" + + # 4. 格式化输出字符串 + direction_str = "空" if self.start == -1 else ("多" if self.start == 1 else "无") + pnl_str = f"{unrealized_pnl:+.2f} USDT" + + # 6. 最终消息 + msg = ( + f"【BitMart {self.contract_symbol} 永续】\n" + f"当前方向:{direction_str}\n" + f"当前现价:{current_price:.2f} USDT\n" + f"开仓均价:{open_avg_price:.2f} USDT\n" + f"持仓量(eht):{float(current_amount) / 1000} eth\n" + f"持仓量(usdt):{position_cross} usdt\n" + f"浮动盈亏:{pnl_str}{rate_str}\n" + f"账户可用余额:{self.balance:.2f} usdt" + ) + else: + msg = ( + f"【BitMart {self.contract_symbol} 永续】\n" + f"当前方向:无\n" + f"当前现价:{current_price:.2f} USDT\n" + f"账户可用余额:{self.balance:.2f} usdt" + ) + + # 7. 发送钉钉消息 + self.ding(msg=msg) + self.pbar.reset() # 重置进度条 diff --git a/交易/tools.py b/交易/tools.py index bf6110b..3950e2b 100644 --- a/交易/tools.py +++ b/交易/tools.py @@ -16,10 +16,10 @@ async def to_do_tg(message_content): PROXY = { 'proxy_type': "socks5", - 'addr': "202.155.144.102", - 'port': 31102, - 'username': "SyNuejCtrQ", - 'password': "MH8ioL7EXf" + 'addr': "199.168.137.123", + 'port': 12345, + 'username': "haha", + 'password': "haha" } try: