mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-12 07:16:56 +08:00
robustness: shared HTTP client, HTTP status checks, abort controller, streaming perf
- web.go: reuse shared binanceClient with connection pooling instead of per-request client - sentinel.go: check HTTP status code before parsing Binance ticker response - brain.go: check HTTP status codes in news scan and market brief APIs - brain.go: add cleanStaleSignals() to prevent unbounded sync.Map growth - scheduler.go: periodically clean expired pending trades - AgentChatPage.tsx: add AbortController to cancel in-flight requests - AgentChatPage.tsx: check response.ok before parsing JSON - AgentChatPage.tsx: batch word streaming (~40 frames max) to reduce re-renders - AgentChatPage.tsx: handle AbortError gracefully (remove orphan bot message)
This commit is contained in:
14
agent/web.go
14
agent/web.go
@@ -17,6 +17,17 @@ var validSymbolRe = regexp.MustCompile(`^[A-Za-z0-9\-_]{1,20}$`)
|
||||
// validIntervalRe matches only valid kline intervals (e.g. 1m, 5m, 1h, 4h, 1d, 1w).
|
||||
var validIntervalRe = regexp.MustCompile(`^[0-9]{1,2}[mhHdDwWM]$`)
|
||||
|
||||
// binanceClient is a shared HTTP client for proxying Binance API requests.
|
||||
// Reused across requests to benefit from connection pooling.
|
||||
var binanceClient = &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 20,
|
||||
MaxIdleConnsPerHost: 10,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
// WebHandler provides HTTP endpoints for the NOFXi agent.
|
||||
type WebHandler struct {
|
||||
agent *Agent
|
||||
@@ -105,8 +116,7 @@ func (w *WebHandler) HandleTicker(rw http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func proxyBinance(rw http.ResponseWriter, url string) {
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
resp, err := client.Get(url)
|
||||
resp, err := binanceClient.Get(url)
|
||||
if err != nil {
|
||||
writeJSON(rw, 502, map[string]string{"error": "upstream request failed"})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user