Skip to content

Commit

Permalink
update future_info config
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuizi7 committed Dec 5, 2018
1 parent 50e2345 commit 3d96c23
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions rqalpha/api/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from rqalpha.model.instrument import Instrument, SectorCode as sector_code, IndustryCode as industry_code
# noinspection PyUnresolvedReferences
from rqalpha.const import (EXECUTION_PHASE, EXC_TYPE, ORDER_STATUS, SIDE, POSITION_EFFECT, ORDER_TYPE, MATCHING_TYPE,
RUN_TYPE, POSITION_DIRECTION, COMMISSION_TYPE)
RUN_TYPE, POSITION_DIRECTION)
# noinspection PyUnresolvedReferences
from rqalpha.model.order import Order, MarketOrder, LimitOrder, OrderStyle
# noinspection PyUnresolvedReferences
Expand All @@ -65,7 +65,6 @@
'ORDER_TYPE',
'RUN_TYPE',
'MATCHING_TYPE',
'COMMISSION_TYPE',
'EVENT',
]

Expand Down
11 changes: 8 additions & 3 deletions rqalpha/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,16 @@ def parse_future_info(future_info):
):
new_info.setdefault(underlying_symbol, {})[field] = float(value)
elif field == "commission_type":
if not isinstance(value, COMMISSION_TYPE):
if isinstance(value, six.string_types) and value.upper() == "BY_MONEY":
new_info.setdefault(underlying_symbol, {})[field] = COMMISSION_TYPE.BY_MONEY
elif isinstance(value, six.string_types) and value.upper() == "BY_VOLUME":
new_info.setdefault(underlying_symbol, {})[field] = COMMISSION_TYPE.BY_VOLUME
elif isinstance(value, COMMISSION_TYPE):
new_info.setdefault(underlying_symbol, {})[field] = value
else:
raise RuntimeError(_(
"Invalid future info: commission_type must be an instance of COMMISSION_TYPE Enum"
"Invalid future info: commission_type is suppose to be BY_MONEY or BY_VOLUME"
))
new_info.setdefault(underlying_symbol, {})[field] = value
else:
raise RuntimeError(_("Invalid future info: field {} is not valid".format(field)))
return new_info
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def assert_almost_equal(first, second):
"SC": {
"close_commission_ratio": 0.0001,
"open_commission_ratio": 0.0002,
"commission_type": COMMISSION_TYPE.BY_MONEY,
"commission_type": "BY_MONEY",
}
}
}
Expand Down

0 comments on commit 3d96c23

Please sign in to comment.