Skip to content
RealMarketAPI

market data api php

Live Price API for PHP: cURL and Guzzle Integration Guide

Retrieve live OHLC prices in PHP with plain cURL or Guzzle, including timeout handling and API key management.

Summary

Fetch live OHLC prices in PHP using cURL or Guzzle with retry-safe request patterns.

Runnable example

PHP cURL price request. Replace YOUR_KEY with your API key.

PHP cURL price request
<?php
$apiKey = 'YOUR_KEY';
$symbol = 'XAUUSD';
$url = "https://api.realmarketapi.com/api/v1/price"
     . "?ApiKey={$apiKey}&symbolCode={$symbol}&timeFrame=M1";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$body = curl_exec($ch);
curl_close($ch);

$candle = json_decode($body, true);
echo $candle['ClosePrice'];

Production notes

  • 01Set CURLOPT_TIMEOUT to avoid hanging requests in synchronous PHP-FPM workers.
  • 02Cache responses in APCu or Redis for repeated same-symbol reads within the same request cycle.
  • 03Validate the HTTP status code before json_decode to avoid silent null values on API errors.

Run this example with your own key

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