Exemplo n.º 1
0
def test_context_load_statistic_error() -> None:
    settings = Setting()
    settings.STATISTIC = MagicMock  # type:ignore

    context = Context(settings)
    with pytest.raises(SettingError):
        context.load_statistic()
Exemplo n.º 2
0
def test_context_load_strategy_error() -> None:
    settings = Setting()
    settings.STRATEGY = MagicMock()  # type:ignore

    context = Context(settings)
    with pytest.raises(SettingError):
        context.load_strategy()
Exemplo n.º 3
0
def test_context_load_trade_counter_error() -> None:
    settings = Setting()
    settings.TRADE_COUNTER = MagicMock()  # type:ignore

    context = Context(settings)
    context.load_statistic()
    with pytest.raises(SettingError):
        context.load_trade_counter()
Exemplo n.º 4
0
def test_runner(tem_data_dir: str) -> None:
    settings = Setting()
    custom_settings = {
        "STRATEGY": TestStrategy,
        "START_TIME": utc_datetime(2018, 1, 1),
        "END_TIME": utc_datetime(2018, 2, 1),
        "RUN_TYPE": RUN_TYPE.BACKTEST,
        "FREQUENCY": "1m",
        "DATA_DIR": tem_data_dir,
        "EXCHANGE": {
            "bitmex": {
                'engine': 'monkq.exchange.bitmex',
                "IS_TEST": True,
                "API_KEY": '',
                "API_SECRET": '',
                "START_WALLET_BALANCE": 100000
            }
        },
        "REPORT_FILE": os.path.join(tem_data_dir, 'result.pkl')
    }

    settings.__dict__.update(custom_settings)
    with over_written_settings(settings, **custom_settings):
        runner = Runner(settings)

        runner.run()
Exemplo n.º 5
0
def test_settings_default_value() -> None:
    with tempfile.TemporaryDirectory() as temp:
        name = random_string(6)
        with change_default_module_settings('{}_settings'.format(name)):
            sys.path.insert(0, temp)
            setting = Setting()
            sys.path.pop(0)

            assert setting.FREQUENCY == FREQUENCY  # type:ignore
Exemplo n.º 6
0
def test_settings() -> None:
    with tempfile.TemporaryDirectory() as temp:
        name = random_string(6)
        with change_default_module_settings('{}_settings'.format(name)):
            with open(os.path.join(temp, '{}_settings.py'.format(name)),
                      'w') as f:
                f.write(setting_content)
            sys.path.insert(0, temp)
            setting = Setting()
            sys.path.pop(0)
            assert setting.A == 123  # type: ignore
            assert setting.B == 321  # type: ignore
Exemplo n.º 7
0
def test_context_load_default() -> None:
    with patch("monkq.exchange.bitmex.exchange.BitmexDataloader"):
        settings = Setting()
        context = Context(settings)

        context.setup_context()

        assert isinstance(context.strategy, BaseStrategy)
        assert isinstance(context.trade_counter, TradeCounter)
        assert isinstance(context.stat, Statistic)
        assert isinstance(context.accounts['bitmex_account'], FutureAccount)
        assert isinstance(context.exchanges['bitmex'], BitmexSimulateExchange)
Exemplo n.º 8
0
def test_context_custom_setting() -> None:
    with patch("monkq.exchange.bitmex.exchange.BitmexDataloader"):
        settings = Setting()
        settings.STRATEGY = TestStrategy  # type:ignore
        settings.TRADE_COUNTER = TestTradeCounter  # type:ignore
        settings.STATISTIC = TestStatistic  # type:ignore
        settings.ACCOUNTS[0]['ACCOUNT_MODEL'] = TestAccount  # type:ignore
        settings.EXCHANGES['bitmex']['ENGINE'] = TestExchange  # type:ignore

        context = Context(settings)
        context.setup_context()

        assert isinstance(context.strategy, TestStrategy)
        assert isinstance(context.trade_counter, TestTradeCounter)
        assert isinstance(context.stat, TestStatistic)
        assert isinstance(context.accounts, dict)
        assert isinstance(context.exchanges, dict)
Exemplo n.º 9
0
def settings() -> Generator[Setting, None, None]:
    yield Setting()