Skip to content

Commit

Permalink
Merge pull request #391 from AngusWG/new_master
Browse files Browse the repository at this point in the history
Fix get_trade_price exception in future(tick).
  • Loading branch information
Cuizi7 committed Nov 6, 2018
2 parents 386bcea + a43f1c6 commit 4ee2e23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions rqalpha/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def install(params):
* 必须以 `rqalpha-mod-` 来开头,比如 `rqalpha-mod-xxx-yyy`
* 对应import的库名必须要 `rqalpha_mod_` 来开头,并且需要和包名后半部分一致,但是 `-` 需要替换为 `_`, 比如 `rqalpha_mod_xxx_yyy`
"""
mod_name = _detect_package_name_from_dir()
mod_name = _detect_package_name_from_dir(params)
mod_name = mod_name.replace("-", "_").replace("rqalpha_mod_", "")
mod_list.append(mod_name)

Expand Down Expand Up @@ -380,8 +380,8 @@ def disable(params):
locals()[cmd](params)


def _detect_package_name_from_dir():
setup_path = os.path.join(os.path.abspath('.'), 'setup.py')
def _detect_package_name_from_dir(params):
setup_path = os.path.join(os.path.abspath(params[-1]), 'setup.py')
if not os.path.exists(setup_path):
return None
return os.path.split(os.path.dirname(setup_path))[1]
Expand Down
17 changes: 10 additions & 7 deletions rqalpha/mod/rqalpha_mod_sys_simulation/slippage.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ def __init__(self, rate=0.):
def get_trade_price(self, order, price):
side = order.side
temp_price = price + price * self.rate * (1 if side == SIDE.BUY else -1)
temp_bar = Environment.get_instance().bar_dict[order.order_book_id]
limit_up, limit_down = temp_bar.limit_up, temp_bar.limit_down
try:
temp_bar = Environment.get_instance().bar_dict[order.order_book_id]
limit_up, limit_down = temp_bar.limit_up, temp_bar.limit_down

if is_valid_price(limit_up):
temp_price = min(temp_price, limit_up)
if is_valid_price(limit_up):
temp_price = min(temp_price, limit_up)

if is_valid_price(limit_down):
temp_price = max(temp_price, limit_down)

if is_valid_price(limit_down):
temp_price = max(temp_price, limit_down)
except KeyError:
# tick中没有涨跌停价
pass
return temp_price


Expand Down

0 comments on commit 4ee2e23

Please sign in to comment.