[Mod]round order volume to contract min_volume in AlgoEngine

This commit is contained in:
vn.py 2019-04-22 22:45:15 +08:00
parent 025efd06b7
commit 856749009b
3 changed files with 9 additions and 5 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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