diff --git a/rqalpha/data/base_data_source/storages.py b/rqalpha/data/base_data_source/storages.py index 56144971c..6091b5470 100644 --- a/rqalpha/data/base_data_source/storages.py +++ b/rqalpha/data/base_data_source/storages.py @@ -116,7 +116,7 @@ def get_tick_size(self, instrument): order_book_id = instrument.order_book_id underlying_symbol = instrument.underlying_symbol custom_info = self._custom_data.get(order_book_id) or self._custom_data.get(underlying_symbol) - info = self._default_data.get(order_book_id) or self._custom_data.get(underlying_symbol) + info = self._default_data.get(order_book_id) or self._default_data.get(underlying_symbol) if custom_info: info = copy(info) or {} info.update(custom_info) diff --git a/tests/outs/test_f_tick_size.pkl b/tests/outs/test_f_tick_size.pkl new file mode 100644 index 000000000..90db2675c Binary files /dev/null and b/tests/outs/test_f_tick_size.pkl differ diff --git a/tests/test_f_tick_size.py b/tests/test_f_tick_size.py new file mode 100644 index 000000000..0c130c71a --- /dev/null +++ b/tests/test_f_tick_size.py @@ -0,0 +1,67 @@ +from rqalpha.environment import Environment + +SLIPPAGE = 10 +price = 0 +futures_1 = "AG1702" # future_info.json 中存有该合约的数据 +futures_2 = "AG1612" # future_info.json 中不存在该合约的数据,需要通过 underlying_symbol 获取 + + +def init(context): + context.count = 0 + + subscribe_event(EVENT.TRADE, on_trade) + + +def on_trade(context, event): + + global price + trade = event.trade + order_book_id = trade.order_book_id + tick_size = Environment.get_instance().get_instrument(order_book_id).tick_size() + assert tick_size == 1.0 + assert trade.last_price == price + tick_size * SLIPPAGE + + +def before_trading(context): + pass + + +def handle_bar(context, bar_dict): + global price + context.count += 1 + if context.count == 1: + price = bar_dict[futures_1].close + buy_open(futures_1, 10) + elif context.count == 2: + price = bar_dict[futures_2].close + buy_open(futures_2, 10) + + +def after_trading(context): + pass + +__config__ = { + "base": { + "start_date": "2016-09-01", + "end_date": "2016-09-30", + "frequency": "1d", + "matching_type": "current_bar", + "accounts": { + "future": 1000000 + } + }, + "extra": { + "log_level": "error", + }, + "mod": { + "sys_progress": { + "enabled": True, + "show": True, + }, + "sys_simulation": { + "signal": True, + "slippage_model": "TickSizeSlippage", + "slippage": SLIPPAGE, + } + }, +} \ No newline at end of file