Skip to content

Commit

Permalink
move matcher to simulation mod
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWang committed Feb 22, 2017
1 parent 816f51f commit 79ffa51
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions rqalpha/api/api_future.py
Expand Up @@ -21,9 +21,8 @@

from __future__ import division
import six
from collections import Iterable

from .api_base import assure_order_book_id, decorate_api_exc, instruments
from .api_base import decorate_api_exc, instruments
from ..execution_context import ExecutionContext
from ..model.order import Order, MarketOrder, LimitOrder, OrderStyle
from ..const import EXECUTION_PHASE, SIDE, POSITION_EFFECT, ORDER_TYPE
Expand All @@ -32,7 +31,6 @@
from ..utils.logger import user_log
from ..utils.i18n import gettext as _
from ..utils.arg_checker import apply_rules, verify_that
from ..environment import Environment


__all__ = [
Expand Down
Expand Up @@ -16,14 +16,14 @@

from collections import defaultdict

from ..utils.i18n import gettext as _
from ..const import ORDER_TYPE, SIDE, BAR_STATUS
from ..model.trade import Trade
from ..environment import Environment
from ..events import Events
from ...utils.i18n import gettext as _
from ...const import ORDER_TYPE, SIDE, BAR_STATUS
from ...model.trade import Trade
from ...environment import Environment
from ...events import Events


class DefaultMatcher(object):
class Matcher(object):
def __init__(self,
deal_price_decider,
bar_limit=True,
Expand Down
5 changes: 3 additions & 2 deletions rqalpha/mod/simulation/mod.py
Expand Up @@ -14,14 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from rqalpha.interface import AbstractMod
from rqalpha.events import Events
from .simulation_broker import SimulationBroker
from .simulation_event_source import SimulationEventSource


class SimulationMod(AbstractMod):
def __init__(self):
self._env = None

def start_up(self, env, mod_config):
self._env = env
self._env.set_broker(SimulationBroker(self._env))
Expand Down
6 changes: 3 additions & 3 deletions rqalpha/mod/simulation/simulation_broker.py
Expand Up @@ -16,7 +16,6 @@

import jsonpickle

from rqalpha.core.default_matcher import DefaultMatcher
from rqalpha.interface import AbstractBroker, Persistable
from rqalpha.utils import get_account_type
from rqalpha.utils.i18n import gettext as _
Expand All @@ -27,6 +26,7 @@
from rqalpha.environment import Environment
from .stock_account import StockAccount
from .future_account import FutureAccount
from .matcher import Matcher


def init_accounts(env):
Expand Down Expand Up @@ -55,10 +55,10 @@ class SimulationBroker(AbstractBroker, Persistable):
def __init__(self, env):
self._env = env
if env.config.base.matching_type == MATCHING_TYPE.CURRENT_BAR_CLOSE:
self._matcher = DefaultMatcher(lambda bar: bar.close, env.config.validator.bar_limit)
self._matcher = Matcher(lambda bar: bar.close, env.config.validator.bar_limit)
self._match_immediately = True
else:
self._matcher = DefaultMatcher(lambda bar: bar.open, env.config.validator.bar_limit)
self._matcher = Matcher(lambda bar: bar.open, env.config.validator.bar_limit)
self._match_immediately = False

self._accounts = None
Expand Down
1 change: 1 addition & 0 deletions tests/outs/time.csv
Expand Up @@ -2,3 +2,4 @@ date_time,time_spend
2017-02-22 11:19:09.672697,25.548931
2017-02-22 11:21:49.141829,24.767031
2017-02-22 11:27:18.907992,26.539639
2017-02-22 11:37:34.984080,25.417706

0 comments on commit 79ffa51

Please sign in to comment.