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 requests(requests_mock):
    ig_request_login(requests_mock)
    ig_request_set_account(requests_mock)
    ig_request_market_info(requests_mock)
    ig_request_search_market(requests_mock)
    ig_request_watchlist(requests_mock, data="mock_watchlist_list.json")
    ig_request_watchlist(requests_mock, args="12345678", data="mock_watchlist.json")
def broker(requests_mock, config):
    ig_request_login(requests_mock)
    ig_request_set_account(requests_mock)
    ig_request_market_info(requests_mock)
    ig_request_search_market(requests_mock)
    ig_request_watchlist(requests_mock, data="mock_watchlist_list.json")
    ig_request_watchlist(requests_mock, args="12345678", data="mock_watchlist.json")
    return Broker(BrokerFactory(config))
Exemplo n.º 4
0
def test_get_watchlist_list(ig, requests_mock):
    ig_request_watchlist(requests_mock)
    data = ig.get_watchlist("")
    assert "watchlists" in data
    assert len(data["watchlists"]) == 5
    assert data["watchlists"][0]["id"] == "12345678"
    assert data["watchlists"][1]["id"] == "Popular Markets"
    assert data["watchlists"][2]["id"] == "Major Indices"
    assert data["watchlists"][3]["id"] == "6817448"
    assert data["watchlists"][4]["id"] == "Major Commodities"

    ig_request_watchlist(requests_mock, fail=True)
    data = ig.get_watchlist("")
    assert data is None

    ig_request_watchlist(requests_mock, data="mock_error.json")
    data = ig.get_watchlist("")
    assert data is None
Exemplo n.º 5
0
def test_get_watchlist_markets(ig, requests_mock):
    ig_request_market_info(requests_mock)
    ig_request_watchlist(requests_mock, data="mock_watchlist_list.json")
    ig_request_watchlist(requests_mock,
                         args="12345678",
                         data="mock_watchlist.json")

    data = ig.get_markets_from_watchlist("My Watchlist")
    assert isinstance(data, list)
    assert len(data) == 3
    assert isinstance(data[0], Market)

    data = ig.get_markets_from_watchlist("wrong_name")
    assert len(data) == 0

    ig_request_watchlist(requests_mock,
                         args="12345678",
                         data="mock_watchlist.json",
                         fail=True)
    data = ig.get_markets_from_watchlist("wrong_name")
    assert len(data) == 0
Exemplo n.º 6
0
def test_get_watchlist_markets(ig, requests_mock):
    ig_request_watchlist(requests_mock, data="mock_watchlist_list.json")
    ig_request_watchlist(requests_mock,
                         args="12345678",
                         data="mock_watchlist.json")

    data = ig.get_markets_from_watchlist("My Watchlist")
    assert isinstance(data, list)
    assert len(data) == 3
    assert data[0]["epic"] == "CS.D.BITCOIN.TODAY.IP"
    assert data[1]["epic"] == "IX.D.FTSE.DAILY.IP"
    assert data[2]["epic"] == "IX.D.DAX.DAILY.IP"

    data = ig.get_markets_from_watchlist("wrong_name")
    assert data is None

    ig_request_watchlist(requests_mock,
                         args="12345678",
                         data="mock_watchlist.json",
                         fail=True)
    data = ig.get_markets_from_watchlist("wrong_name")
    assert data is None