ig-python / trading-ig

A lightweight Python wrapper for the IG Markets API
https://trading-ig.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
308 stars 196 forks source link

Invalid session token, triggering refresh... #319

Closed b-y-f closed 6 months ago

b-y-f commented 6 months ago

Need to use this


Tring to get 1 year data, but always fail, If use shorter period seems ok.

history = ig_service.fetch_historical_prices_by_epic(
    epic="CS.D.BITCOIN.CFD.IP",
    resolution="30Min", 
    start_date="2023-01-01",
    end_date="2023-12-31",
    wait=20
)

And the output

---------------------------------------------------------------------------
ApiExceededException                      Traceback (most recent call last)
Cell In[5], line 1
----> 1 history = ig_service.fetch_historical_prices_by_epic(
      2     epic="CS.D.BITCOIN.CFD.IP",
      3     resolution="30Min",
      4     start_date="2023-01-01",
      5     end_date="2023-12-31",
      6 )
      7 history['prices']

File ~/miniconda3/envs/trade/lib/python3.10/site-packages/trading_ig/rest.py:1783, in IGService.fetch_historical_prices_by_epic(self, epic, resolution, start_date, end_date, numpoints, pagesize, session, format, wait)
   1781 while more_results:
   1782     params["pageNumber"] = pagenumber
-> 1783     response = self._req(action, endpoint, params, session, version)
   1784     data = self.parse_response(response.text)
   1785     prices.extend(data["prices"])

File ~/miniconda3/envs/trade/lib/python3.10/site-packages/trading_ig/rest.py:379, in IGService._req(self, action, endpoint, params, session, version, check)
    375     result = self._retryer.__call__(
    376         self._request, action, endpoint, params, session, version, check
    377     )
    378 else:
--> 379     result = self._request(action, endpoint, params, session, version, check)
    381 return result
...
--> 400     raise ApiExceededException()
    401 if token_invalid(response.text):
    402     logger.warning("Invalid session token, triggering refresh...")

ApiExceededException: