hootnot / oanda-api-v20

OANDA REST-V20 API wrapper. Easy access to OANDA's REST v20 API with oandapyV20 package. Checkout the Jupyter notebooks!
MIT License
398 stars 107 forks source link

ContentDecodingError with InstrumentsCandles #193

Closed flowtrader2016 closed 1 year ago

flowtrader2016 commented 1 year ago

Hi,

I'm seeing intermittent issues with the response ContentDecodingError when using instruments.InstrumentsCandles. Appreciate any help.

Issue

Received response with content-encoding: gzip, but failed to decode it

To reproduce

event = { "ticker": "UK100_GBP", "granularity": "M15"}

granularity = event["granularity"]
ticker = event["ticker"]
  count = 500
  params = {
            "count": count,
            "granularity": granularity,
            "dailyAlignment": 0,
            "alignmentTimezone": "UTC",
        }
r = instruments.InstrumentsCandles(instrument=ticker, params=params)
oandaData = client.request(r)

stackTrace

{
  "errorMessage": "('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check'))",
  "errorType": "ContentDecodingError",
  "requestId": "fdc8726c-bbbe-4b50-beed-e2c198a4e54f",
  "stackTrace": [
    "  File \"/var/task/handler.py\", line 3662, in sls_getOandaData\n    oandaData = client.request(r)\n",
    "  File \"/var/task/oandapyV20/oandapyV20.py\", line 337, in request\n    response = self.__request(method, url,\n",
    "  File \"/var/task/oandapyV20/oandapyV20.py\", line 266, in __request\n    raise err\n",
    "  File \"/var/task/oandapyV20/oandapyV20.py\", line 262, in __request\n    response = func(url, stream=stream, headers=headers,\n",
    "  File \"/var/task/requests/sessions.py\", line 600, in get\n    return self.request(\"GET\", url, **kwargs)\n",
    "  File \"/var/task/requests/sessions.py\", line 587, in request\n    resp = self.send(prep, **send_kwargs)\n",
    "  File \"/var/task/requests/sessions.py\", line 745, in send\n    r.content\n",
    "  File \"/var/task/requests/models.py\", line 899, in content\n    self._content = b\"\".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b\"\"\n",
    "  File \"/var/task/requests/models.py\", line 820, in generate\n    raise ContentDecodingError(e)\n"
  ]
}

Thanks

hootnot commented 1 year ago

Look like you have an issue with the data, not with code.

I suggest you try:

For the record: I have things running 24/5 and have no issues fetching data for multiple pairs. Just added UK100_GBP...

 1) "20221005T07:15:00,True,7046.1,7046.9,7050.4,7051.2,7042.6,7043.4,7044.1,7044.9,68"
 2) "20221005T07:16:00,True,7043.7,7044.8,7047.1,7047.9,7039.9,7040.7,7042.4,7043.2,69"
 3) "20221005T07:17:00,True,7041.9,7042.7,7044.1,7044.9,7037.6,7038.4,7040.9,7041.7,60"
 4) "20221005T07:18:00,True,7040.4,7041.2,7046.6,7047.4,7039.7,7040.8,7045.4,7046.2,56"
 5) "20221005T07:19:00,True,7044.9,7045.7,7044.9,7045.7,7039.6,7040.4,7039.6,7040.4,56"
 6) "20221005T07:20:00,True,7039.1,7039.9,7043.9,7044.7,7034.9,7035.7,7035.4,7036.2,61"
 7) "20221005T07:21:00,True,7035.9,7036.7,7037.4,7038.2,7033.6,7034.4,7033.6,7034.4,43"
 8) "20221005T07:22:00,True,7034.1,7034.9,7035.9,7036.7,7031.4,7032.2,7031.9,7032.7,37"
 9) "20221005T07:23:00,True,7032.4,7033.2,7032.9,7033.7,7026.1,7026.9,7026.9,7027.7,42"
10) "20221005T07:24:00,True,7026.4,7027.2,7028.6,7029.4,7023.4,7024.2,7026.4,7027.2,39"
11) "20221005T07:25:00,True,7026.9,7027.7,7037.9,7038.7,7025.4,7026.2,7037.9,7038.7,45"
12) "20221005T07:26:00,False,7037.4,7038.2,7038.9,7039.7,7033.6,7034.4,7033.6,7034.4,54"

Conclusion: no issues

flowtrader2016 commented 1 year ago

Many thanks for the response.

The error was only for the UK100_GBP with M15 data and it is intermittent (currently ok but happened yesterday and today). I also run your code 24x5 with around 20 instruments and no other issues noted. Thanks for all you do! Is there a link to buy you a coffee?

hootnot commented 1 year ago

Not yet, working on it ;-)