Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复获取tick_size为nan的问题 #861

Merged
merged 1 commit into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rqalpha/data/base_data_source/storages.py
Expand Up @@ -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)
Expand Down
Binary file added tests/outs/test_f_tick_size.pkl
Binary file not shown.
67 changes: 67 additions & 0 deletions 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,
}
},
}