diff --git a/tests/test_integration.py b/tests/test_integration.py index 954065b..46b9a2d 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -163,8 +163,8 @@ def test_fetch_account_activity_by_period(self, ig_service: IGService): assert isinstance(response, pd.DataFrame) def test_fetch_account_activity_by_date(self, ig_service: IGService): - to_date = datetime.now() - from_date = to_date - timedelta(days=7) + to_date = datetime.now() - timedelta(days=30) + from_date = to_date - timedelta(days=60) response = ig_service.fetch_account_activity_by_date(from_date, to_date) assert isinstance(response, pd.DataFrame) @@ -174,23 +174,23 @@ def test_fetch_account_activity_v2_span(self, ig_service: IGService): assert isinstance(response, pd.DataFrame) def test_fetch_account_activity_v2_dates(self, ig_service): - to_date = datetime(2021, 7, 31) - from_date = to_date - timedelta(days=7) + to_date = datetime.now() - timedelta(days=30) + from_date = to_date - timedelta(days=60) response = ig_service.fetch_account_activity_v2( from_date=from_date, to_date=to_date ) assert isinstance(response, pd.DataFrame) def test_fetch_account_activity_from(self, ig_service: IGService): - to_date = datetime.now() - timedelta(days=3) - from_date = to_date - timedelta(days=7) + to_date = datetime.now() - timedelta(days=30) + from_date = to_date - timedelta(days=60) response = ig_service.fetch_account_activity(from_date=from_date) assert isinstance(response, pd.DataFrame) assert response.shape[1] == 9 def test_fetch_account_activity_from_to(self, ig_service: IGService): - to_date = datetime(2023, 7, 18) - from_date = to_date - timedelta(days=7) + to_date = datetime.now() - timedelta(days=30) + from_date = to_date - timedelta(days=60) response = ig_service.fetch_account_activity( from_date=from_date, to_date=to_date ) @@ -198,8 +198,8 @@ def test_fetch_account_activity_from_to(self, ig_service: IGService): assert response.shape[1] == 9 def test_fetch_account_activity_detailed(self, ig_service): - to_date = datetime(2023, 7, 18) - from_date = to_date - timedelta(days=7) + to_date = datetime.now() - timedelta(days=30) + from_date = to_date - timedelta(days=60) response = ig_service.fetch_account_activity( from_date=from_date, to_date=to_date, detailed=True ) @@ -208,7 +208,7 @@ def test_fetch_account_activity_detailed(self, ig_service): def test_fetch_account_activity_old(self, ig_service: IGService): from_date = datetime(1970, 1, 1) - to_date = from_date + timedelta(days=7) + to_date = from_date + timedelta(days=60) response = ig_service.fetch_account_activity( from_date=from_date, to_date=to_date ) @@ -216,8 +216,8 @@ def test_fetch_account_activity_old(self, ig_service: IGService): assert response.shape[0] == 0 def test_fetch_account_activity_fiql(self, ig_service: IGService): - to_date = datetime(2023, 7, 18) - from_date = to_date - timedelta(days=30) + to_date = datetime.now() - timedelta(days=30) + from_date = to_date - timedelta(days=60) response = ig_service.fetch_account_activity( from_date=from_date, to_date=to_date, fiql_filter="channel==PUBLIC_WEB_API" ) @@ -461,6 +461,11 @@ def test_search_markets(self, ig_service: IGService): response = ig_service.search_markets(search_term) assert isinstance(response, pd.DataFrame) + def test_search_markets_v2(self, ig_service: IGService): + epics = "CS.D.GBPUSD.TODAY.IP" + response = ig_service.search_markets_v2(epics) + assert isinstance(response, pd.DataFrame) + def test_fetch_historical_prices_by_epic_and_numpoints(self, ig_service: IGService): response = ig_service.fetch_historical_prices_by_epic_and_num_points( "CS.D.EURUSD.MINI.IP", "h", 4 diff --git a/trading_ig/rest.py b/trading_ig/rest.py index 4e3c620..aaf1236 100644 --- a/trading_ig/rest.py +++ b/trading_ig/rest.py @@ -1569,6 +1569,19 @@ def search_markets(self, search_term, session=None): data = pd.DataFrame(data["markets"]) return data + def search_markets_v2(self, epics, session=None): + """Returns all markets matching the epics""" + self.non_trading_rate_limit_pause_or_pass() + version = "2" + endpoint = "/markets" + params = {"epics": epics} + action = "read" + response = self._req(action, endpoint, params, session, version) + data = self.parse_response(response.text) + if self.return_dataframe: + data = pd.DataFrame(data["marketDetails"]) + return data + def format_prices(self, prices, version, flag_calc_spread=False): """ Format prices data as a DataFrame with hierarchical columns