def mock_http_calls(requests_mock):
    ig_request_login(requests_mock)
    ig_request_set_account(requests_mock)
    ig_request_account_details(requests_mock)
    ig_request_open_positions(requests_mock)
    ig_request_market_info(requests_mock)
    ig_request_search_market(requests_mock)
    ig_request_prices(requests_mock)
    ig_request_trade(requests_mock)
    ig_request_confirm_trade(requests_mock)
    ig_request_navigate_market(requests_mock)
    ig_request_navigate_market(requests_mock,
                               args="668394",
                               data="mock_navigate_markets_markets.json")
    ig_request_navigate_market(requests_mock,
                               args="77976799",
                               data="mock_navigate_markets_markets.json")
    ig_request_navigate_market(requests_mock,
                               args="89291253",
                               data="mock_navigate_markets_markets.json")
    ig_request_watchlist(requests_mock)
    ig_request_watchlist(requests_mock,
                         args="12345678",
                         data="mock_watchlist.json")
    av_request_prices(requests_mock)
    av_request_macd_ext(requests_mock)
def test_find_trade_signal_sell(config, broker, requests_mock):
    av_request_prices(requests_mock, data="av_daily_boll_bands_sell.json")
    strategy = SimpleBollingerBands(config, broker)
    # Create a mock market data from the json file
    market = create_mock_market(broker)
    data = strategy.fetch_datapoints(market)
    tradeDir, limit, stop = strategy.find_trade_signal(market, data)

    assert tradeDir is TradeDirection.NONE
    assert limit is None
    assert stop is None
def test_find_trade_signal_buy(config, broker, requests_mock):
    av_request_prices(requests_mock, data="av_daily_boll_bands_buy.json")
    strategy = SimpleBollingerBands(config, broker)
    # Create a mock market data from the json file
    market = create_mock_market(broker)
    # Call function to test
    data = strategy.fetch_datapoints(market)
    tradeDir, limit, stop = strategy.find_trade_signal(market, data)

    assert tradeDir is not None
    assert limit is not None
    assert stop is not None

    assert tradeDir == TradeDirection.BUY
    assert (
        limit == market.offer + market.offer *
        config.config["strategies"]["simple_boll_bands"]["limit_perc"] / 100)
    assert (
        stop == market.bid - market.bid *
        config.config["strategies"]["simple_boll_bands"]["stop_perc"] / 100)
Exemplo n.º 4
0
def test_backtest(config, broker, requests_mock):
    av_request_macd_ext(requests_mock, data="mock_macd_ext_buy.json")
    av_request_prices(requests_mock)

    strategy = SimpleMACD(config, broker)

    # Create a mock market data from the json file
    market = create_mock_market(broker, requests_mock)

    result = strategy.backtest(
        market,
        dt.strptime("2018-01-01", "%Y-%m-%d"),
        dt.strptime("2018-06-01", "%Y-%m-%d"),
    )

    assert "balance" in result
    assert result["balance"] is not None
    assert result["balance"] == 997.9299999999998
    assert "trades" in result
    assert len(result["trades"]) == 8