Skip to content

Rate Limitation not reported #390

@kcphysics

Description

@kcphysics

Describe the bug
Rate Limitation is not correctly being detected and reported

To Reproduce
Run the snippet of code below multiple times until you hit your rate limit:

        API_KEY := os.Getenv("POLYGON_API_KEY")
	client := polygon.New(API_KEY)
	adjusted := true
	limit := 50000
	from := time.Now().AddDate(-2, 0, 0)
	to := time.Now()
	params := models.ListAggsParams{
		Ticker:     "AAPL",
		From:       models.Millis(from),
		To:         models.Millis(to),
		Limit:      &limit,
		Adjusted:   &adjusted,
		Timespan:   models.Day,
		Multiplier: 1,
	}
	iter := client.ListAggs(context.TODO(), &params, models.WithTrace(true))
	count := 0
	for iter.Next() {
		if iter.Err() != nil {
			log.Fatal(iter.Err())
		}
		count += 1
	}
	log.Printf("Found %d results", count)

Expected behavior
When rate limitation is reached, iter.Err contains an error stating that the rate limitation has been encountered

Screenshots
Output from the snipped above:
image

Additional context
I've tried this several different ways, but there's not "good" way to detect the rate limitation, and we cannot inspect the response inside of the Polygon.io client.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions