|
|
@@ -98,7 +98,9 @@ data_lock = threading.Lock()
|
|
|
|
|
|
def calculate_percentage_diff(price_a, price_b):
|
|
|
if price_a is not None and price_b is not None and isinstance(price_a, decimal.Decimal) and isinstance(price_b, decimal.Decimal) and price_b != 0:
|
|
|
- return (price_a - price_b) / price_b
|
|
|
+ rst = (price_a - price_b) / price_b
|
|
|
+ rst = rst.quantize(decimal.Decimal('1e-4'), rounding=decimal.ROUND_DOWN)
|
|
|
+ return rst
|
|
|
return None
|
|
|
|
|
|
def send_arb_msg(profit, data):
|
|
|
@@ -110,50 +112,50 @@ def send_arb_msg(profit, data):
|
|
|
human_in_base = atomic_in_base / (10 ** in_dec)
|
|
|
human_out_target = atomic_out_target / (10 ** out_dec)
|
|
|
|
|
|
- # arbitrage_data = {
|
|
|
- # "tx": tx,
|
|
|
- # "profit": str(profit),
|
|
|
- # "profitLimit": str(PROFIT_LIMIT),
|
|
|
- # "symbol": MEXC_TARGET_PAIR_USDT,
|
|
|
- # "fromToken": IN_TOKEN_ADDRESS,
|
|
|
- # "fromTokenAmountHuman": str(human_in_base),
|
|
|
- # "fromTokenDecimal": IN_TOKEN_DECIMALS,
|
|
|
- # "toToken": OUT_TOKEN_ADDRESS,
|
|
|
- # "toTokenAmountHuman": str(human_out_target)
|
|
|
- # }
|
|
|
-
|
|
|
- # """
|
|
|
- # 向 arb_executor 服务提交套利处理请求。
|
|
|
- # """
|
|
|
- # print(f"正在提交套利数据到 {ARB_EXECUTOR_URL}")
|
|
|
-
|
|
|
- # try:
|
|
|
- # # 发送 POST 请求
|
|
|
- # response = requests.post(ARB_EXECUTOR_URL, json=arbitrage_data)
|
|
|
-
|
|
|
- # # 检查响应状态码
|
|
|
- # if response.status_code == 201:
|
|
|
- # print("\n请求成功! 套利流程已启动。")
|
|
|
- # elif response.status_code == 200:
|
|
|
- # print("\n请求接收成功,但未达到利润阈值,未启动套利流程。")
|
|
|
- # elif response.status_code == 400:
|
|
|
- # print("\n请求失败! 无效的请求数据。")
|
|
|
- # else:
|
|
|
- # print(f"\n请求失败! 状态码: {response.status_code}")
|
|
|
-
|
|
|
- # # 打印响应体
|
|
|
- # try:
|
|
|
- # print("响应体:")
|
|
|
- # print(json.dumps(response.json(), indent=4))
|
|
|
- # except json.JSONDecodeError:
|
|
|
- # print("响应体不是有效的 JSON:")
|
|
|
- # print(response.text)
|
|
|
-
|
|
|
- # except requests.exceptions.ConnectionError as e:
|
|
|
- # print(f"\n连接错误: 无法连接到 {ARB_EXECUTOR_URL}。请确保 arb_executor.py 正在运行。")
|
|
|
- # print(f"错误详情: {e}")
|
|
|
- # except Exception as e:
|
|
|
- # print(f"\n发送请求时发生未知错误: {e}")
|
|
|
+ """
|
|
|
+ 向 arb_executor 服务提交套利处理请求。
|
|
|
+ """
|
|
|
+ arbitrage_data = {
|
|
|
+ "tx": tx,
|
|
|
+ "profit": str(profit),
|
|
|
+ "profitLimit": str(PROFIT_LIMIT),
|
|
|
+ "symbol": MEXC_TARGET_PAIR_USDT,
|
|
|
+ "fromToken": IN_TOKEN_ADDRESS,
|
|
|
+ "fromTokenAmountHuman": str(human_in_base),
|
|
|
+ "fromTokenDecimal": IN_TOKEN_DECIMALS,
|
|
|
+ "toToken": OUT_TOKEN_ADDRESS,
|
|
|
+ "toTokenAmountHuman": str(human_out_target)
|
|
|
+ }
|
|
|
+
|
|
|
+ print(f"正在提交套利数据到 {ARB_EXECUTOR_URL}")
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 发送 POST 请求
|
|
|
+ response = requests.post(ARB_EXECUTOR_URL, json=arbitrage_data)
|
|
|
+
|
|
|
+ # 检查响应状态码
|
|
|
+ if response.status_code == 201:
|
|
|
+ print("\n请求成功! 套利流程已启动。")
|
|
|
+ elif response.status_code == 200:
|
|
|
+ print("\n请求接收成功,但未达到利润阈值,未启动套利流程。")
|
|
|
+ elif response.status_code == 400:
|
|
|
+ print("\n请求失败! 无效的请求数据。")
|
|
|
+ else:
|
|
|
+ print(f"\n请求失败! 状态码: {response.status_code}")
|
|
|
+
|
|
|
+ # 打印响应体
|
|
|
+ try:
|
|
|
+ print("响应体:")
|
|
|
+ print(json.dumps(response.json(), indent=4))
|
|
|
+ except json.JSONDecodeError:
|
|
|
+ print("响应体不是有效的 JSON:")
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
+ except requests.exceptions.ConnectionError as e:
|
|
|
+ print(f"\n连接错误: 无法连接到 {ARB_EXECUTOR_URL}。请确保 arb_executor.py 正在运行。")
|
|
|
+ print(f"错误详情: {e}")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"\n发送请求时发生未知错误: {e}")
|
|
|
|
|
|
logging.info(f"套利消息已发送, {profit}, {human_in_base}, {human_out_target}")
|
|
|
pass
|