bitmart优化完成
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
telegram/sign.db
BIN
telegram/sign.db
Binary file not shown.
@@ -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"
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
101
交易/weex_交易.py
101
交易/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(
|
||||
|
||||
Reference in New Issue
Block a user