Skip to content
RealMarketAPI

ohlcv api golang

OHLCV API for Go: Concurrent Requests with net/http

Fetch OHLCV candles in Go using net/http with timeouts, concurrent symbol fetches, and struct-based JSON parsing.

Summary

Use Go's standard library to fetch and parse OHLCV candles with proper timeout and concurrency patterns.

Runnable example

Go net/http price request. Replace YOUR_KEY with your API key.

Go net/http price request
package main

import (
    "encoding/json"
    "fmt"
    "net/http"
    "time"
)

func main() {
    client := &http.Client{Timeout: 10 * time.Second}
    url := "https://api.realmarketapi.com/api/v1/price" +
           "?ApiKey=YOUR_KEY&symbolCode=XAUUSD&timeFrame=M1"
    resp, _ := client.Get(url)
    defer resp.Body.Close()
    var result map[string]any
    json.NewDecoder(resp.Body).Decode(&result)
    fmt.Println(result["ClosePrice"])
}

Production notes

  • 01Always set a Timeout on http.Client to prevent goroutine leaks in high-throughput services.
  • 02Use sync.WaitGroup and a buffered channel to fan out multi-symbol fetches concurrently.
  • 03Define typed structs for the response payload to catch schema drift at compile time.

Run this example with your own key

Create a free account, then try the request in the playground before wiring it into production.