diff --git a/vnpy/app/algo_trading/engine.py b/vnpy/app/algo_trading/engine.py index 8607cc71..9429e06a 100644 --- a/vnpy/app/algo_trading/engine.py +++ b/vnpy/app/algo_trading/engine.py @@ -5,7 +5,7 @@ from vnpy.trader.event import ( EVENT_TICK, EVENT_TIMER, EVENT_ORDER, EVENT_TRADE) from vnpy.trader.constant import (Direction, Offset, OrderType) from vnpy.trader.object import (SubscribeRequest, OrderRequest) -from vnpy.trader.utility import load_json, save_json +from vnpy.trader.utility import load_json, save_json, round_to from .template import AlgoTemplate @@ -162,6 +162,10 @@ class AlgoEngine(BaseEngine): self.write_log(f'委托下单失败,找不到合约:{vt_symbol}', algo) return + volume = round_to(volume, contract.min_volume) + if not volume: + return "" + req = OrderRequest( symbol=contract.symbol, exchange=contract.exchange, diff --git a/vnpy/app/cta_strategy/backtesting.py b/vnpy/app/cta_strategy/backtesting.py index d439f4b2..fdeff439 100644 --- a/vnpy/app/cta_strategy/backtesting.py +++ b/vnpy/app/cta_strategy/backtesting.py @@ -14,7 +14,7 @@ from vnpy.trader.constant import (Direction, Offset, Exchange, Interval, Status) from vnpy.trader.database import database_manager from vnpy.trader.object import OrderData, TradeData, BarData, TickData -from vnpy.trader.utility import round_to_pricetick +from vnpy.trader.utility import round_to from .base import ( BacktestingMode, @@ -726,7 +726,7 @@ class BacktestingEngine: lock: bool ): """""" - price = round_to_pricetick(price, self.pricetick) + price = round_to(price, self.pricetick) if stop: vt_orderid = self.send_stop_order(direction, offset, price, volume) else: diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index 60a33485..ef245503 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -101,11 +101,11 @@ def save_json(filename: str, data: dict): json.dump(data, f, indent=4) -def round_to_pricetick(price: float, pricetick: float): +def round_to(value: float, target: float): """ Round price to price tick value. """ - rounded = round(price / pricetick, 0) * pricetick + rounded = int(round(value / target)) * target return rounded