Exemplo n.º 1
0
def test_get_open_positions(ig, requests_mock):
    ig_request_open_positions(requests_mock)

    positions = ig.get_open_positions()

    assert positions is not None
    assert "positions" in positions
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)
Exemplo n.º 3
0
def test_get_open_positions(ig, requests_mock):
    ig_request_open_positions(requests_mock)

    positions = ig.get_open_positions()

    assert positions is not None
    assert isinstance(positions, list)
    assert len(positions) > 0
    assert isinstance(positions[0], Position)
Exemplo n.º 4
0
def test_close_all_positions_fail(ig, requests_mock):
    ig_request_open_positions(requests_mock)
    ig_request_trade(requests_mock, fail=True)
    ig_request_confirm_trade(requests_mock)

    result = ig.close_all_positions()
    assert result == False

    ig_request_open_positions(requests_mock)
    ig_request_trade(requests_mock)
    ig_request_confirm_trade(
        requests_mock,
        data={
            "dealId": "123456789",
            "dealStatus": "FAIL",
            "reason": "FAIL"
        },
    )

    result = ig.close_all_positions()
    assert result == False
Exemplo n.º 5
0
def test_close_all_positions(ig, requests_mock):
    ig_request_open_positions(requests_mock)
    ig_request_trade(requests_mock)
    ig_request_confirm_trade(requests_mock)
    result = ig.close_all_positions()
    assert result
Exemplo n.º 6
0
def test_get_open_positions_fail(ig, requests_mock):
    ig_request_open_positions(requests_mock, fail=True)
    with pytest.raises(RuntimeError) as e:
        positions = ig.get_open_positions()
Exemplo n.º 7
0
def test_get_open_positions_fail(ig, requests_mock):
    ig_request_open_positions(requests_mock, fail=True)
    positions = ig.get_open_positions()

    assert positions is None