-
Notifications
You must be signed in to change notification settings - Fork 0
feat(web): frontend overhaul — rebrand, UX fixes, data upgrades, glossary #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package polygon | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestListActiveTickersRespectsFreeTierRateLimit(t *testing.T) { | ||
| var firstRequestAt time.Time | ||
| var serverURL string | ||
|
|
||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
|
|
||
| switch r.URL.Query().Get("cursor") { | ||
| case "": | ||
| firstRequestAt = time.Now() | ||
| _, _ = fmt.Fprintf(w, `{"results":[{"ticker":"AAA","name":"Alpha","primary_exchange":"XNAS","type":"CS","active":true}],"next_url":"%s/v3/reference/tickers?cursor=page-2"}`, | ||
| serverURL, | ||
| ) | ||
| case "page-2": | ||
| if time.Since(firstRequestAt) < 11*time.Second { | ||
| w.WriteHeader(http.StatusTooManyRequests) | ||
| _, _ = w.Write([]byte(`{"status":"ERROR","request_id":"req-rate","error":"rate limit exceeded"}`)) | ||
| return | ||
| } | ||
| _, _ = w.Write([]byte(`{"results":[{"ticker":"BBB","name":"Beta","primary_exchange":"XNYS","type":"CS","active":true}]}`)) | ||
|
Comment on lines
+12
to
+31
|
||
| default: | ||
| w.WriteHeader(http.StatusBadRequest) | ||
| } | ||
| })) | ||
| defer server.Close() | ||
| serverURL = server.URL | ||
|
|
||
| client := NewClient("test-key", discardLogger()) | ||
| client.baseURL = server.URL | ||
|
|
||
| tickers, err := client.ListActiveTickers(context.Background(), "stocks", "CS") | ||
| if err != nil { | ||
| t.Fatalf("ListActiveTickers() error = %v", err) | ||
| } | ||
| if len(tickers) != 2 { | ||
| t.Fatalf("ListActiveTickers() count = %d, want 2", len(tickers)) | ||
| } | ||
| if tickers[0].Ticker != "AAA" || tickers[1].Ticker != "BBB" { | ||
| t.Fatalf("ListActiveTickers() tickers = %#v, want AAA then BBB", tickers) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 12s hard-coded pause on every paginated request makes ListActiveTickers potentially very slow for large universes and is not easily testable/configurable (e.g., for paid tiers or different limits). Consider using a configurable rate limiter/delay on the Client (or an injected limiter/clock) so production can still respect free-tier limits while keeping tests fast and allowing other tiers to override the pacing.