client-python icon indicating copy to clipboard operation
client-python copied to clipboard

stock list_aggs throw errors

Open investment-radar opened this issue 6 months ago • 1 comments

I am using version: 1.14.6

When calling client.list_aggs, now it's throw error: polygon.exceptions.BadResponse: {"status":"ERROR","request_id":"708a85cecad66756c956da798714ac63","error":"The parameter 'to' cannot be a time that occurs before 'from'"}

I didn't change my calling code. Even I used the example code: aggs = [] for a in client.list_aggs( "AAPL", 1, "day", "2023-01-09", "2023-02-10", adjusted="true", sort="desc", limit=2, ): aggs.append(a)

I still get same error: Request URL: https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2023-01-09/2023-02-10?adjusted=true&sort=desc&limit=2 Request Headers: {'Authorization': 'Bearer REDACTED', 'Accept-Encoding': 'gzip', 'User-Agent': 'Polygon.io PythonClient/1.14.6'} Response Headers: {'Date': 'Mon, 16 Jun 2025 12:26:53 GMT', 'Content-Type': 'application/json', 'Content-Length': '348', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'X-Polygon-Cluster-Name': 'polygon-ny5', 'X-Request-Id': '294c7b52f57a6ee48a895473ab336ca2', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains'}

polygon.exceptions.BadResponse: {"status":"ERROR","request_id":"708a85cecad66756c956da798714ac63","error":"The parameter 'to' cannot be a time that occurs before 'from'"}

investment-radar avatar Jun 16 '25 12:06 investment-radar

I set trace=True, and got this from the log: Request URL: https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2025-06-10/2025-06-16?adjusted=true&sort=desc&limit=2 And copy and request from the browser, I could get the correct response.

investment-radar avatar Jun 16 '25 12:06 investment-radar

Hey @investment-radar, do you mind trying this again? I tried to reproduce this and it seems to work. Here's what I see. Can you also say what plan you're on. I'll try it with those entitlements.

{
  "ticker": "AAPL",
  "queryCount": 2,
  "resultsCount": 2,
  "adjusted": true,
  "results": [
    {
      "v": 57388108,
      "vw": 150.4054,
      "o": 149.46,
      "c": 151.01,
      "h": 151.3401,
      "l": 149.22,
      "t": 1676005200000,
      "n": 443405
    },
    {
      "v": 55994243,
      "vw": 152.2769,
      "o": 153.775,
      "c": 150.87,
      "h": 154.33,
      "l": 150.42,
      "t": 1675918800000,
      "n": 471973
    }
  ],
  "status": "OK",
  "request_id": "2530ab020d35373f10cef17f1a4cace7",
  "count": 2,
  "next_url": "https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2023-01-09/1675918799999?cursor=bGltaXQ9MiZzb3J0PWRlc2M"
}

justinpolygon avatar Jun 23 '25 05:06 justinpolygon

I found the issue is when you set the limit less then 5, I still got the error. but set limit to 5, then it works. aggs = [] for a in client.list_aggs( "AAPL", 1, "day", "2023-01-09", "2023-02-10", adjusted="true", sort="desc", limit=5, ):

investment-radar avatar Jun 23 '25 09:06 investment-radar

Hey @investment-radar, I'm still not able to reproduce the issue. Do you mind contacting https://polygon.io/contact since they can look up your account and plans to see if their might be a restriction there. I've tried a bunch of different ways / dates but not seeing the same thing on my end. So, I suspect if might be the plan but support can look that up easily.

justinpolygon avatar Jun 23 '25 16:06 justinpolygon

Ok, thanks.

investment-radar avatar Jun 24 '25 06:06 investment-radar

Sorry, I could not be more helpful here.

justinpolygon avatar Jun 24 '25 06:06 justinpolygon