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)
Пример #2
0
def test_generate_signals_from_dataframe(config, broker, requests_mock):
    av_request_macd_ext(requests_mock, data="mock_macd_ext_hold.json")
    strategy = SimpleMACD(config, broker)
    data = strategy.fetch_datapoints(create_mock_market(broker))
    px = strategy.generate_signals_from_dataframe(data.dataframe)

    assert "positions" in px
    assert len(px) > 26
Пример #3
0
def test_get_trade_direction_from_signals(config, broker, requests_mock):
    av_request_macd_ext(requests_mock, data="mock_macd_ext_buy.json")
    strategy = SimpleMACD(config, broker)
    data = strategy.fetch_datapoints(create_mock_market(broker))
    dataframe = strategy.generate_signals_from_dataframe(data.dataframe)
    tradeDir = strategy.get_trade_direction_from_signals(dataframe)

    # BUY becasue the mock response loads the buy test json
    assert tradeDir == TradeDirection.BUY
Пример #4
0
def test_find_trade_signal_hold(config, broker, requests_mock):
    av_request_macd_ext(requests_mock, data="mock_macd_ext_hold.json")
    strategy = SimpleMACD(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 not None
    assert limit is None
    assert stop is None

    assert tradeDir == TradeDirection.NONE
Пример #5
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