From 7ecdd92776e913b184529b38d92afdfc28196afe Mon Sep 17 00:00:00 2001 From: Administrator Date: Wed, 17 Dec 2025 17:42:46 +0800 Subject: [PATCH] =?UTF-8?q?bitmart=E4=BC=98=E5=8C=96=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- telegram/8619211027341.session | Bin 45056 -> 45056 bytes telegram/bot_session.session | Bin 40960 -> 40960 bytes telegram/sign.db | Bin 40960 -> 40960 bytes 交易/bitmart_api交易.py | 2 +- 交易/websea_交易.py | 40 ++++++++++--- 交易/weex_交易.py | 101 +++++++++++++++++++++++++++++---- 6 files changed, 123 insertions(+), 20 deletions(-) diff --git a/telegram/8619211027341.session b/telegram/8619211027341.session index 920d9188c031a92d32198407a56cb31e4edcbf61..e26a093931c123f3ec8ee5135a200f4c4f44100e 100644 GIT binary patch delta 64 zcmV-G0Kfl$-~xc)0+1U4%8?vH0m`vprELjrLE2EBz__aGlMZep0($?mGj7NP0($|o W{c@540(%0pk#r(E0($|IwXaKugc|w) delta 64 zcmZp8z|`=7X@WH4hKVxHj2kv4EY0Oibi5TXhyUPH|H*uL%1i~;n~n2MurL+aZT?#{ UiIJ(me)GfKFUVv9QUwJf0xS%y@vN4tf-KKjjJw7O)N?-EzWc*blt2`vVn`KnsKs$t>I+u`khQwk0&3iw_vZD%FD>h z5H*>#!JLUnW3o*{{p7t36PXz9Ob%$gp&~bZU*D^6py{#t>r`>zF?U6z#R sm7fYU*=Ms)lP4on)zr@QQQn+pH!~%HbwH_0q$WMr;g{jEWp7iRFeyMqEY)My9%kM!JUPeAD;! zy$WYzkmX>2NR}n#@lRWFX<-2ygFH~II329T++y={30ZbV!O5%&D$LvX;x-!^Nb^m0 z*Nf2@1s diff --git a/交易/bitmart_api交易.py b/交易/bitmart_api交易.py index 8e83d3c..bf3ab5c 100644 --- a/交易/bitmart_api交易.py +++ b/交易/bitmart_api交易.py @@ -346,8 +346,8 @@ class BitmartFuturesTransaction: msg = ( f"【BitMart {self.contract_symbol} 永续】\n" f"当前方向:{direction_str}\n" - f"开仓均价:{open_avg_price:.2f} USDT\n" f"当前现价:{current_price:.2f} USDT\n" + f"开仓均价:{open_avg_price:.2f} USDT\n" f"持仓量:{float(self.current_amount) / 1000} eth\n" f"浮动盈亏:{pnl_str}{rate_str}\n" f"账户可用余额:{self.balance:.2f} usdt" diff --git a/交易/websea_交易.py b/交易/websea_交易.py index 6df47d0..55fa7bf 100644 --- a/交易/websea_交易.py +++ b/交易/websea_交易.py @@ -278,6 +278,8 @@ class WeexTransaction: elif resp_data["result"][0]["type"] == 2: self.start = -1 + + self.resp_data = resp_data["result"][0] return True except: time.sleep(1) @@ -292,10 +294,10 @@ class WeexTransaction: def send_dingtalk_message(self, message_content, type=1): if type: - send_dingtalk_message(f"🔔websea:{self.get_now_time1()}" + message_content) + send_dingtalk_message(f"🔔websea:" + message_content) else: for i in range(15): - send_dingtalk_message(f"❌websea:{self.get_now_time1()}" + message_content) + send_dingtalk_message(f"❌websea:" + message_content) def action(self): # 获取比特端口 @@ -336,10 +338,10 @@ class WeexTransaction: self.pbar.n = current_minute - 30 self.pbar.refresh() - if current_minute not in [0, 1, 2, 3, 4, 5, 30, 31, 32, 33, 34, ]: # 判断是否是 新的30分钟了 - # if current_minute not in range(60): # 判断是否是 新的30分钟了 - time.sleep(10) - continue + # if current_minute not in [0, 1, 2, 3, 4, 5, 30, 31, 32, 33, 34, ]: # 判断是否是 新的30分钟了 + # # if current_minute not in range(60): # 判断是否是 新的30分钟了 + # time.sleep(10) + # continue if self.kline_3 and self.get_now_time() == self.kline_3["id"]: continue @@ -408,10 +410,32 @@ class WeexTransaction: return self.pbar.reset() # 重置进度条 + + # =============================================================================================== + # 提取并转换 + direction = "多" if int(self.resp_data['type']) == 2 else "空" + contracts = int(self.resp_data['number']) # 张数 + eth_amount = float(self.resp_data['numberConvert']) # ETH数量 + open_price = float(self.resp_data['openPriceAvg']) + current_price = float(self.resp_data['markPrice']) # 标记价格(更准确用于盈亏) + unrealized_pnl = float(self.resp_data['unProfitLoss']) + pnl_rate = float(self.resp_data['profitRate']) + available_balance = float(self.resp_data['accountAvailable']) + + # 钉钉消息示例 + msg = ( + f"【WebSea ETH-USDT 永续持仓】\n" + f"持仓方向:{direction}\n" + f"持仓张数:{contracts} 张\n" + f"持仓数量:{eth_amount:.3f} ETH\n" + f"开仓均价:{open_price:.2f} USDT\n" + f"标记现价:{current_price:.2f} USDT\n" + f"浮动盈亏:{unrealized_pnl:+.2f} USDT ({pnl_rate:+.2f}%)\n" + f"账户可用:{available_balance:.2f} USDT" + ) self.send_dingtalk_message( message_content= - f"目前有持仓:{"无" if self.start == 0 else ("多" if self.start == 1 else "空")}," - f"当前信号:{"无" if not self.direction else ("多" if self.direction == "long" else "空")}" + msg ) diff --git a/交易/weex_交易.py b/交易/weex_交易.py index 672a385..8efeb8f 100644 --- a/交易/weex_交易.py +++ b/交易/weex_交易.py @@ -61,13 +61,13 @@ class WeexTransaction: if type: send_dingtalk_message( - message_content=f"🔔weex:{self.get_now_time1()}," + message_content + message_content=f"🔔weex:" + message_content ) else: for i in range(15): send_dingtalk_message( - message_content=f"❌weex:{self.get_now_time1()}," + message_content + message_content=f"❌weex:" + message_content ) def openBrowser(self, ): # 直接指定ID打开窗口,也可以使用 createBrowser 方法返回的ID @@ -251,7 +251,7 @@ class WeexTransaction: ) - return response.json()["data"]["newContract"]["balanceList"][0]["accountRights"] + return response.json()["data"]["newContract"]["balanceList"][0]["available"] except: time.sleep(1) @@ -309,6 +309,7 @@ class WeexTransaction: else: self.start = 0 + self.datas = datas[0] return True except: time.sleep(1) @@ -352,10 +353,10 @@ class WeexTransaction: self.pbar.n = current_minute - 30 self.pbar.refresh() - if current_minute not in [0, 1, 2, 3, 4, 5, 30, 31, 32, 33, 34, 35]: # 判断是否是 新的30分钟了 - # if current_minute not in range(60): # 判断是否是 新的30分钟了 - time.sleep(10) - continue + # if current_minute not in [0, 1, 2, 3, 4, 5, 30, 31, 32, 33, 34, 35]: # 判断是否是 新的30分钟了 + # # if current_minute not in range(60): # 判断是否是 新的30分钟了 + # time.sleep(10) + # continue if self.kline_3 and self.get_now_time() == self.kline_3["id"]: continue @@ -429,12 +430,90 @@ class WeexTransaction: continue self.pbar.reset() # 重置进度条 - self.send_dingtalk_message( - message_content= - f"目前有持仓:{"无" if self.start == 0 else ("多" if self.start == 1 else "空")}," - f"当前信号:{"无" if not self.direction else ("多" if self.direction == "long" else "空")}" + + if self.get_position_status(): + logger.info("获取仓位信息成功!!!") + else: + logger.info("获取仓位信息失败!!!") + + self.send_dingtalk_message(message_content=f"获取仓位信息失败!!!", type=0) + continue + + num = self.get_num() + + # 持仓方向,开仓价格,现价,持仓量,盈亏,当前价值 + + # 1. 从 self.datas 中提取并转换关键数据 + # 假设 self.datas 是你贴的那个JSON字典(如果是个列表,取最新一笔) + data = self.datas + if isinstance(data, list) and data: + data = data[-1] # 如果是列表,取最新一笔成交 + + fill_size = float(self.datas['fillSize']) # 持仓量,单位:ETH + fill_value = float(self.datas['fillValue']) # 成交名义价值 USDT + open_avg_price = fill_value / fill_size # 开仓均价(本笔成交均价) + + position_side = self.datas['positionSide'] # "SHORT" 或 "LONG" + + # 2. 方向判断并设置 self.start(方便后续策略使用) + if position_side == 'SHORT': + direction = "空" + self.start = -1 + elif position_side == 'LONG': + direction = "多" + self.start = 1 + else: + direction = "无" + self.start = 0 + + # 3. 当前价格(从你的K线数据) + current_price = float(self.kline_3["close"]) + + # 4. 持仓量(假设当前持仓等于这笔成交量,如有加减仓后续可维护累计) + current_amount = fill_size # 单位:ETH + + # 5. 计算浮动盈亏(USDT) + if self.start == 1: # 多头 + unrealized_pnl = current_amount * (current_price - open_avg_price) + elif self.start == -1: # 空头 + unrealized_pnl = current_amount * (open_avg_price - current_price) + else: + unrealized_pnl = 0.0 + + # 6. 收益率 + 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 = "" + + pnl_str = f"{unrealized_pnl:+.2f} USDT" + + # 7. 当前持仓名义价值 + current_value = current_amount * current_price + + # 8. 持仓量显示 + amount_display = f"{current_amount:.3f} ETH" + + # 9. 组装消息(钉钉Markdown格式,更美观) + message_content = ( + "**【WEEX ETHUSDT 永续持仓监控】**\n\n" + f"**持仓方向**:{direction}\n" + f"**当前现价**:{current_price:.2f} USDT\n" + f"**开仓均价**:{open_avg_price:.2f} USDT\n" + f"**持仓数量**:{amount_display}\n" + f"**名义价值**:{current_value:.2f} USDT\n" + f"**浮动盈亏**:{pnl_str}{rate_str}\n" + f"**账户可用余额**:{float(num):.2f} USDT" ) + # 10. 发送钉钉消息 + self.send_dingtalk_message(message_content=message_content) + + if __name__ == '__main__': WeexTransaction(