bitmart优化完成

This commit is contained in:
Administrator
2025-12-17 18:10:48 +08:00
parent 7ecdd92776
commit 86b4616246
5 changed files with 159 additions and 120 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -154,6 +154,7 @@ class BitmartFuturesTransaction:
self.start = 1 if positions[0]['position_type'] == 1 else -1
self.open_avg_price = positions[0]['open_avg_price']
self.current_amount = positions[0]['current_amount']
self.position_cross = positions[0]["position_cross"]
return True
@@ -309,14 +310,17 @@ class BitmartFuturesTransaction:
self.pbar.reset()
# ===================================================================================================
size = self.calculate_size() # 获取可用余额
msg = None
current_price = float(kline_3["close"])
self.balance = self.get_available_balance()
if self.start:
if not self.get_position_status():
self.ding(error=True, msg="获取仓位信息失败!!!")
continue
# 持仓方向,开仓价格,现价,持仓量,盈亏,当前价值
# 1. 确保所有关键数据为 float 类型BitMart API 常返回字符串)
current_price = float(kline_3["close"])
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
@@ -348,10 +352,21 @@ class BitmartFuturesTransaction:
f"当前方向:{direction_str}\n"
f"当前现价:{current_price:.2f} USDT\n"
f"开仓均价:{open_avg_price:.2f} USDT\n"
f"持仓量:{float(self.current_amount) / 1000} eth\n"
f"持仓量(eht){float(self.current_amount) / 1000} eth\n"
f"持仓量(usdt){float(self.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"开仓均价:{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"
)
# 7. 发送钉钉消息
self.ding(msg=msg)

View File

@@ -412,6 +412,8 @@ class WeexTransaction:
self.pbar.reset() # 重置进度条
# ===============================================================================================
num = self.get_num()
if self.start:
# 提取并转换
direction = "" if int(self.resp_data['type']) == 2 else ""
contracts = int(self.resp_data['number']) # 张数
@@ -427,12 +429,20 @@ class WeexTransaction:
f"【WebSea ETH-USDT 永续持仓】\n"
f"持仓方向:{direction}\n"
f"持仓张数:{contracts}\n"
f"持仓数量:{eth_amount:.3f} ETH\n"
f"持仓数量(eth){eth_amount:.3f} ETH\n"
f"持仓数量(usdt){float(self.resp_data["numberConvertU"]) / 100:.3f} usdt\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"
)
else:
msg = (
f"【WebSea ETH-USDT 永续持仓】\n"
f"持仓方向:无\n"
f"账户可用:{float(num):.2f} USDT"
)
self.send_dingtalk_message(
message_content=
msg

View File

@@ -442,6 +442,9 @@ class WeexTransaction:
num = self.get_num()
# 持仓方向,开仓价格,现价,持仓量,盈亏,当前价值
message_content = None
current_price = float(self.kline_3["close"])
if self.start:
# 1. 从 self.datas 中提取并转换关键数据
# 假设 self.datas 是你贴的那个JSON字典如果是个列表取最新一笔
@@ -504,17 +507,28 @@ class WeexTransaction:
f"**持仓方向**{direction}\n"
f"**当前现价**{current_price:.2f} USDT\n"
f"**开仓均价**{open_avg_price:.2f} USDT\n"
f"**持仓数量**{amount_display}\n"
f"**持仓数量(eth)**{amount_display} eth\n"
f"**持仓数量(usdt)**{float(self.datas['fillValue']) / 100:.2f} usdt\n"
f"**名义价值**{current_value:.2f} USDT\n"
f"**浮动盈亏**{pnl_str}{rate_str}\n"
f"**账户可用余额**{float(num):.2f} USDT"
)
else:
message_content = (
"**【WEEX ETHUSDT 永续持仓监控】**\n\n"
f"**持仓方向**:无\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(
tge_id=146473,