Fix KIS rate-limit classification and share limiter per app-key#11
Merged
smallfish06 merged 2 commits intomainfrom Apr 19, 2026
Merged
Fix KIS rate-limit classification and share limiter per app-key#11smallfish06 merged 2 commits intomainfrom
smallfish06 merged 2 commits intomainfrom
Conversation
- Extract KIS upstream error classification into internal/kis/error_mapping.go so the HTTP transport no longer hard-codes vendor-specific msg codes. KIS returns HTTP 500 with msg_cd=EGW00201 for per-second TPS overruns rather than HTTP 429; classify those as ErrRateLimitExceeded so the proxy surfaces 429 to callers instead of 502. - Add ratelimit.Shared(name, rps, burst, key) that returns one *Limiter per (name, key) pair. Bind kis.Client in SetCredentials so every Client that talks to the same KIS app-key cooperates on a single token bucket — previously each adapter instantiated its own 15 rps limiter, letting N adapters collectively exceed the upstream quota. - Move apiLimiter.Wait into doRequestOnce so the 401 refresh-and-retry path is also throttled. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
e7afb92 to
bac3698
Compare
- Introduced a new `DeleteToken(appKey string)` method in the `Manager` interface to allow token deletion. - Implemented `DeleteToken` across `filetoken.Manager`, `kis`, and `kiwoom` token managers. - Updated relevant tests to validate `DeleteToken` functionality.
smallfish06
commented
Apr 19, 2026
| } | ||
|
|
||
| func classifyUpstream(status int, body []byte) error { | ||
| switch parseMsgCode(body) { |
Owner
Author
There was a problem hiding this comment.
for further case, suppress lint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
msg_cd=EGW00201for per-second TPS overruns rather than HTTP 429 — we classified those asErrServerErrorand surfaced 502 to callers. Now inspected via a newinternal/kis/error_mapping.goand mapped toErrRateLimitExceeded→ 429.ratelimit.New(..., 15, 3)limiter, so N adapters talking to the same app-key collectively fired 15×N rps at KIS and tripped the upstream quota. Addedratelimit.Shared(name, rps, burst, key)and boundkis.Clientto it inSetCredentials, so every Client using the same app-key cooperates on a single token bucket.apiLimiter.WaitfromdoRequestintodoRequestOnceso the 401 refresh-and-retry path is also throttled.slog(separate commit).Test plan
go test ./... -count=1TestClassifyUpstreamcovers EGW00201 masked as 500, plain 429, generic 500, 4xx, non-JSON bodiesTestShared_sameKeyReturnsSameLimiter+TestShared_serializesIndependentCallersverify the registry and cooperative rate behaviorOut of scope
🤖 Generated with Claude Code