diff --git a/main.py b/main.py index 8e09f61..0dd7b81 100644 --- a/main.py +++ b/main.py @@ -368,18 +368,23 @@ class MexcSpotTrade: order_type = order_type.upper() processed_kwargs = kwargs.copy() + # 记录未经过偏移的价格,以供LIMIT订单只有quoteOrderQty没有quantity的情况使用: + # 参数有price时直接使用,否则就为实时价格 + clean_price = processed_kwargs.get("price") + # 处理无price的情况,获取实时价格 if order_type in ["LIMIT", "LIMIT_MAKER"] and "price" not in processed_kwargs: current_price = self.market.get_price(symbol) if current_price is None: logger.error("无法获取实时价格,交易取消") return None + clean_price = current_price # 防止挂单不成交 if side == "BUY": - processed_kwargs["price"] = current_price * 1.01 # 买入加价0.5% + processed_kwargs["price"] = current_price * 1.01 # 买入加价1% elif side == "SELL": - processed_kwargs["price"] = current_price * 0.91 # 卖出减价0.5% - logger.info("使用调整0.5%%后价格作为限价: %f", processed_kwargs["price"]) + processed_kwargs["price"] = current_price * 0.99 # 卖出减价1% + logger.info("使用调整1%%后价格作为限价: %f", processed_kwargs["price"]) # 处理LIMIT订单只有quoteOrderQty没有quantity的情况 if ( @@ -390,12 +395,7 @@ class MexcSpotTrade: try: exchange_info = self.market.get_exchange_info(symbol) quote_amount = float(processed_kwargs["quoteOrderQty"]) - price = ( - float(current_price) - if not current_price is None - else float(processed_kwargs["price"]) - ) - quantity = quote_amount / price + quantity = quote_amount / clean_price base_asset_precision = int( exchange_info["symbols"][0]["baseAssetPrecision"] ) @@ -403,7 +403,7 @@ class MexcSpotTrade: exchange_info["symbols"][0]["quoteAmountPrecision"] ) processed_quantity = self._tool_calculate_quantity( - quantity, price, base_asset_precision, quote_amount_precision + quantity, clean_price, base_asset_precision, quote_amount_precision ) logger.info("根据quoteOrderQty计算quantity: %f", processed_quantity) processed_kwargs["quantity"] = str(processed_quantity)