From f86cce3af05a06c39b6c88091449cdd6dde6bd99 Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Thu, 17 Jul 2025 22:29:30 +0800 Subject: [PATCH] feat(place_order): a 0.5% price impact in `LIMIT` orders to guarantee filling --- main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8f52744..2ffa8a0 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ import logging import os import time import json +from pathlib import Path from datetime import datetime, date from typing import Dict, Any, Optional, Tuple, List @@ -306,8 +307,12 @@ class MexcSpotTrade: if current_price is None: logger.error("无法获取实时价格,交易取消") return None - processed_kwargs["price"] = current_price - logger.info("使用实时价格作为限价: %f", current_price) + # 防止挂单不成交 + if side == "BUY": + processed_kwargs["price"] = current_price * 1.01 # 买入加价0.5% + elif side == "SELL": + processed_kwargs["price"] = current_price * 0.91 # 卖出减价0.5% + logger.info("使用调整0.5%%后价格作为限价: %f", processed_kwargs["price"]) # 处理LIMIT订单只有quoteOrderQty没有quantity的情况 if (