// Kuvola Institutional Data API — Go starter (no published module; copy this file) package kuvola import ( "fmt" "io" "net/http" ) const BaseURL = "https://kuvola.ao" type Client struct { APIKey string HTTP *http.Client } func NewClient(apiKey string) *Client { return &Client{APIKey: apiKey, HTTP: &http.Client{}} } // v2ListMarkets returns the raw JSON body; response.pagination has totalPages. func (c *Client) V2ListMarkets() (string, error) { req, _ := http.NewRequest("GET", BaseURL+"/api/v2/markets", nil) req.Header.Set("Authorization", "Bearer "+c.APIKey) resp, err := c.HTTP.Do(req) if err != nil { return "", err } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) if resp.StatusCode == 429 { return "", fmt.Errorf("rate limited, reset: %s", resp.Header.Get("X-RateLimit-Reset")) } if resp.StatusCode >= 400 { return "", fmt.Errorf("kuvola API error %d: %s", resp.StatusCode, string(body)) } return string(body), nil } // Usage: client := kuvola.NewClient("kv_live_..."); data, err := client.V2ListMarkets()