RealMarketAPI
Docs

RealMarketAPI संदर्भ

सोना, फ़ॉरेक्स, क्रिप्टो और इंडेक्स के लिए OHLCV डेटा REST और WebSocket के माध्यम से.

REST बेस URL

https://api.realmarketapi.com

WebSocket बेस URL

wss://api.realmarketapi.com

प्रमाणीकरण

?apiKey=YOUR_KEY

Best Practices

Understanding when to use WebSocket versus REST is the single most impactful decision for your integration. WebSocket should be your default choice for any live data; REST is a fallback for specific, bounded queries.

Prefer WebSocket for all live price data

A single persistent WebSocket connection delivers every new candle the moment it closes — with zero polling overhead, zero extra rate-limit consumption, and lower latency than any HTTP request. If you find yourself polling /api/v1/price on a timer, switch to WebSocket instead.

WebSocket vs REST — quick decision guide
Use caseWebSocket ✓REST ✓
Live price ticker / chart✅ Ideal — server pushes every candle⚠️ Works, but wastes requests on polling
Trading signal engine✅ Near-zero latency per candle⚠️ Latency gap between polls
Real-time bid/ask spread✅ Updated with every frame❌ Not suitable
Historical back-fill on startup❌ Not designed for bulk history✅ Use /history with pagination
One-off price snapshot⚠️ Overhead to open a connection✅ Single GET is simpler
Backtesting / research queries❌ Not applicable✅ Use /history with date ranges
Available symbols lookup❌ Not applicable✅ Use GET /api/v1/symbol

❌ Anti-patterns to avoid

  • Polling /api/v1/price on a short timer — every poll burns a request from your plan quota and adds HTTP round-trip latency vs a push model.
  • Opening a new WebSocket per request — connect once per symbol/timeframe pair and keep the connection alive. Repeated open/close cycles exhaust rate limits.
  • No reconnect logic in production — networks drop. Always implement exponential back-off reconnection (see the reconnect pattern below).
  • Using WebSocket to fetch historical data — the WebSocket endpoint streams live candles only. Use /api/v1/history for past data, then switch to WS for live updates.

✅ Recommended integration pattern

  1. 1.On app start, call /api/v1/history to back-fill the initial candle series you need for charts or indicators.
  2. 2.Open a WebSocket connection for each symbol+timeframe pair you need to track live. Keep connections persistent.
  3. 3.Append each incoming WebSocket frame to your local candle series — no further REST calls needed for live data.
  4. 4.Implement exponential back-off reconnection so your app recovers automatically from transient network failures.
  5. 5.Reserve /api/v1/price only for one-off snapshots or server-side jobs that do not maintain a persistent connection.

Authentication

Every request must include your apiKey as a query parameter. Generate your key from the dashboard.

Query Parameter
NameTypeDescription
apiKey*stringYour secret API key. Passed as a query param on all REST and WebSocket connections.
Example authenticated request
GEThttps://api.realmarketapi.com/api/v1/price?apiKey=rm_live_XXXXXXXX&symbolCode=XAUUSD&timeFrame=M1

Timeframes

Pass one of the following values in the timeFrame query parameter. The value is case-sensitive.

M1

1 Minute

Ultra-short-term scalping & HFT

M5

5 Minutes

Short-term scalping & intraday signals

M15

15 Minutes

Intraday trend confirmation & entries

H1

1 Hour

Session-level trend & momentum

H4

4 Hours

Swing setups with reduced noise

D1

1 Day

Higher-timeframe trend & macro direction

Symbol Codes

Pass one of the following values in the symbolCode query parameter. All codes are uppercase.

Showing 13 of 13 symbols

Metals2 symbols
XAUUSDGold / US Dollar
XAGUSDSilver / US Dollar
Forex4 symbols
USDJPYUS Dollar / Yen
EURUSDEuro / US Dollar
GBPUSDBritish Pound / Dollar
USDVNDUS Dollar / Vietnamese Dong
Crypto3 symbols
BTCUSDBitcoin / US Dollar
ETHUSDEthereum / US Dollar
XRPUSDXRP / US Dollar
Commodities2 symbols
USOILUS Crude Oil (WTI)
UKOILBrent Crude Oil
Indices2 symbols
US500S&P 500 Index
US30Dow Jones 30 Index
GET

/api/v1/price

Returns the latest completed OHLCV candle for the requested symbol and timeframe.

💡Use WebSocket instead for continuous live data. Polling this endpoint on a timer wastes quota and adds latency. Open a WebSocket connection to receive every new candle automatically as it closes.
Query Parameters
NameTypeDescription
apiKey*stringYour API key.
symbolCode*stringMarket symbol. One of: XAUUSD, XAGUSD, USDJPY, EURUSD, GBPUSD, USDVND, BTCUSD, ETHUSD, XRPUSD, USOIL, UKOIL, US500, US30.
timeFrame*stringCandle interval. One of: M1, M5, M15, H1, H4, D1.

Request

GET /api/v1/price
GEThttps://api.realmarketapi.com/api/v1/price?apiKey=YOUR_API_KEY&symbolCode=XAUUSD&timeFrame=M1

Response — 200 OK

response.json
{
  "SymbolCode": "XAUUSD",
  "OpenPrice": 5168.43,
  "ClosePrice": 5174.00,
  "HighPrice": 5176.85,
  "LowPrice": 5165.20,
  "Bid": 5173.75,
  "Ask": 5174.25,
  "Volume": 1249.33,
  "OpenTime": "2026-03-08T09:20:00Z"
}
GET

/api/v1/history

Returns a paginated list of historical OHLCV candles for the requested symbol, timeframe, and date range.

🔒Historical data access requires an eligible plan. Calling this endpoint with a plan that does not include historical data will return error ERR_0010_NOT_SUPPORT_HISTORICAL. View plans to see which tiers include historical access.
Query Parameters
NameTypeDescription
apiKey*stringYour API key.
symbolCode*stringMarket symbol code (e.g. XAUUSD, BTCUSD).
timeFrame*stringCandle interval: M1 · M5 · M15 · H1 · H4 · D1.
startTime*ISO 8601Range start date-time, e.g. 2026-01-01T00:00:00Z.
endTime*ISO 8601Range end date-time, e.g. 2026-03-08T23:59:59Z.
pageNumberintegerPage number, 1-based. Defaults to 1.
pageSizeintegerNumber of candles per page. Max: 100. Defaults to 10.

Request

GET /api/v1/history
GEThttps://api.realmarketapi.com/api/v1/history?apiKey=YOUR_API_KEY&symbolCode=ETHUSD&timeFrame=H1&startTime=2026-02-08T00:00:00Z&endTime=2026-03-08T00:00:00Z&pageNumber=1&pageSize=10

Response — 200 OK

response.json
{
  "Data": [
    {
      "SymbolCode": "ETHUSD",
      "OpenPrice": 3120.22,
      "ClosePrice": 3138.44,
      "HighPrice": 3142.07,
      "LowPrice": 3115.13,
      "Bid": 3138.30,
      "Ask": 3138.58,
      "Volume": 432.58,
      "OpenTime": "2026-03-08T08:00:00Z"
    },
    {
      "SymbolCode": "ETHUSD",
      "OpenPrice": 3138.44,
      "ClosePrice": 3144.11,
      "HighPrice": 3150.90,
      "LowPrice": 3132.50,
      "Bid": 3143.97,
      "Ask": 3144.25,
      "Volume": 509.76,
      "OpenTime": "2026-03-08T09:00:00Z"
    }
  ],
  "TotalCount": 240,
  "CurrentPage": 1,
  "TotalPages": 24,
  "PageSize": 10
}
GET

/api/v1/candle

Returns the latest completed OHLCV candles (most recent first) for the requested symbol and timeframe. Useful for seeding a chart with recent bars on first load without needing a date range.

🔒Historical data access requires an eligible plan. Calling this endpoint with a plan that does not include historical data will return error ERR_0010_NOT_SUPPORT_HISTORICAL. View plans to see which tiers include historical access.
Query Parameters
NameTypeDescription
apiKey*stringYour API key.
symbolCode*stringMarket symbol code (e.g. XAUUSD, BTCUSD).
timeFrame*stringCandle interval: M1 · M5 · M15 · H1 · H4 · D1.
pageNumberintegerPage number, 1-based. Defaults to 1.
pageSizeintegerNumber of candles per page. Max: 50. Defaults to 10.

Request

GET /api/v1/candle
GEThttps://api.realmarketapi.com/api/v1/candle?apiKey=YOUR_API_KEY&symbolCode=XAUUSD&timeFrame=M1&pageNumber=1&pageSize=10

Response — 200 OK

response.json
{
  "Data": [
    {
      "SymbolCode": "XAUUSD",
      "OpenPrice": 5168.43,
      "ClosePrice": 5174.00,
      "HighPrice": 5176.85,
      "LowPrice": 5165.20,
      "Volume": 1249.33,
      "OpenTime": "2026-03-08T09:20:00Z"
    },
    {
      "SymbolCode": "XAUUSD",
      "OpenPrice": 5162.80,
      "ClosePrice": 5168.43,
      "HighPrice": 5169.75,
      "LowPrice": 5160.50,
      "Volume": 986.17,
      "OpenTime": "2026-03-08T09:19:00Z"
    }
  ],
  "TotalCount": 1440
}
Response Fields
FieldTypeDescription
DataarrayOrdered list of candles, most-recent first.
TotalCountintegerTotal number of available candles for the symbol / timeframe.
SymbolCodestringMarket symbol identifier (e.g. XAUUSD).
OpenPricenumberPrice at candle open.
ClosePricenumberPrice at candle close.
HighPricenumberHighest price during the candle period.
LowPricenumberLowest price during the candle period.
VolumenumberTraded volume during the candle period.
OpenTimeISO 8601UTC timestamp of the candle open.
GET

/api/v1/symbol

Returns the list of all available symbols your API key has access to.

Query Parameters
NameTypeDescription
apiKey*stringYour API key.

Request

GET /api/v1/symbol
GEThttps://api.realmarketapi.com/api/v1/symbol?apiKey=YOUR_API_KEY

Response — 200 OK

response.json
{
  "Data": [
    { "SymbolCode": "XAUUSD", "DisplayName": "Gold / US Dollar",   "MarketClass": "Metals"  },
    { "SymbolCode": "BTCUSD", "DisplayName": "Bitcoin / US Dollar","MarketClass": "Crypto"  },
    { "SymbolCode": "US500",  "DisplayName": "US 500 Index",        "MarketClass": "Indices" }
  ],
  "TotalCount": 12
}
GET

/api/v1/health

Returns the current health status of the API. No authentication required. Use this endpoint to verify connectivity or monitor API availability from your own infrastructure.

Public endpoint — no API key required. Safe to call from health checks, uptime monitors, or CI pipelines without consuming your plan quota.

Request

GET /api/v1/health
GEThttps://api.realmarketapi.com/api/v1/health

Response — 200 OK

response.json
{
  "Status": "Healthy",
  "Timestamp": "2026-03-07T15:05:05.846Z"
}
Response Fields
FieldTypeDescription
StatusstringAPI status. Either "Healthy" or "Unhealthy".
TimestampISO 8601UTC timestamp of the health check response.
WSS

/price

Opens a persistent WebSocket connection. The server pushes a new OHLCV frame after each completed candle. The connection URL follows the same parameter convention as the REST endpoints.

⚡ Recommended approach for live data

  • Zero polling overhead — candles are pushed to you the moment they close, no repeated HTTP calls.
  • Does not count against your requests/minute quota — the persistent connection is free to hold open; only the initial handshake counts.
  • Lower latency — avoid TCP setup, TLS negotiation, and HTTP framing on every update.
  • Identical response shape — the same OHLCV JSON you already know from REST, no extra parsing needed.
Connection Parameters
NameTypeDescription
apiKey*stringYour API key.
symbolCode*stringSymbol to subscribe to (e.g. XAUUSD, BTCUSD).
timeFrame*stringCandle interval: M1 · M5 · M15 · H1 · H4 · D1.

Connect

WebSocket URL
CONNECTwss://api.realmarketapi.com/price?apiKey=YOUR_API_KEY&symbolCode=XAUUSD&timeFrame=M1

Incoming frame (JSON)

message
{
  "SymbolCode": "XAUUSD",
  "OpenPrice": 5168.43,
  "ClosePrice": 5174.00,
  "HighPrice": 5176.85,
  "LowPrice": 5165.20,
  "Bid": 5173.75,
  "Ask": 5174.25,
  "Volume": 1249.33,
  "OpenTime": "2026-03-08T09:20:00Z"
}

JavaScript example

ws-example.js
// JavaScript — WebSocket (recommended for live data)
const ws = new WebSocket(
  "wss://api.realmarketapi.com/price?apiKey=YOUR_API_KEY&symbolCode=XAUUSD&timeFrame=M1"
)

ws.onopen    = () => console.log("[RealMarketAPI] Connected")
ws.onmessage = ({ data }) => {
  const candle = JSON.parse(data)
  console.log(candle.SymbolCode, candle.ClosePrice, candle.Bid, candle.Ask)
}
ws.onerror = (e) => console.error("[RealMarketAPI] WS error", e)
ws.onclose = ()  => console.log("[RealMarketAPI] Disconnected")

Python example

ws-example.py
# Python — WebSocket example (websockets library)
import asyncio, json, websockets

API_KEY   = "YOUR_API_KEY"
SYMBOL    = "XAUUSD"
TIMEFRAME = "M1"
URI = f"wss://api.realmarketapi.com/price?apiKey={API_KEY}&symbolCode={SYMBOL}&timeFrame={TIMEFRAME}"

async def stream():
    async for ws in websockets.connect(URI):          # auto-reconnect
        try:
            async for message in ws:
                candle = json.loads(message)
                print(candle["SymbolCode"], candle["ClosePrice"], candle["Bid"])
        except websockets.ConnectionClosed:
            print("Disconnected — retrying…")
            continue

asyncio.run(stream())

Multiple symbols

ws-multi-symbol.js
// JavaScript — Multiple symbols over separate connections
const subscriptions = [
  { symbol: "XAUUSD", timeFrame: "M1" },
  { symbol: "BTCUSD", timeFrame: "M5" },
  { symbol: "EURUSD", timeFrame: "H1" },
]

const connections = subscriptions.map(({ symbol, timeFrame }) => {
  const ws = new WebSocket(
    `wss://api.realmarketapi.com/price?apiKey=YOUR_API_KEY&symbolCode=${symbol}&timeFrame=${timeFrame}`
  )
  ws.onmessage = ({ data }) => handleCandle(JSON.parse(data))
  return ws
})

function handleCandle(candle) {
  // dispatch candle to your state / store
  console.log(candle.SymbolCode, candle.TimeFrame, candle.ClosePrice)
}

WebSocket — Reconnect Pattern

Network interruptions happen. A production integration must implement automatic reconnection with exponential back-off — otherwise a single dropped connection silently stops your live feed.

Back-off strategy: start at 1 s, double on each failure, cap at 30 s. Reset to 1 s on every successful onopen event. This prevents thundering-herd reconnects after a server restart.

JavaScript — auto-reconnect (production)

ws-reconnect.js
// JavaScript — Auto-reconnect pattern (production recommended)
const API_KEY    = "YOUR_API_KEY"
const SYMBOL     = "XAUUSD"
const TIMEFRAME  = "M1"
const WS_URL     = `wss://api.realmarketapi.com/price?apiKey=${API_KEY}&symbolCode=${SYMBOL}&timeFrame=${TIMEFRAME}`

let ws
let reconnectDelay = 1000  // start at 1 s, then back off

function connect() {
  ws = new WebSocket(WS_URL)

  ws.onopen = () => {
    console.log("Connected")
    reconnectDelay = 1000  // reset on successful connection
  }

  ws.onmessage = ({ data }) => {
    const candle = JSON.parse(data)
    // ─── handle incoming candle ────────────────────────────
    console.log(candle.SymbolCode, candle.ClosePrice)
  }

  ws.onclose = () => {
    console.warn(`Disconnected. Reconnecting in ${reconnectDelay}ms…`)
    setTimeout(connect, reconnectDelay)
    reconnectDelay = Math.min(reconnectDelay * 2, 30_000)  // cap at 30 s
  }

  ws.onerror = (e) => console.error("WS error", e)
}

connect()

OHLCV Response Fields

All candle objects (from /price, /history, and WebSocket) share the same shape.

FieldTypeDescription
SymbolCodestringMarket symbol identifier (e.g. XAUUSD).
OpenPricenumberPrice at the start of the candle period.
ClosePricenumberPrice at the end of the candle period.
HighPricenumberHighest traded price within the candle.
LowPricenumberLowest traded price within the candle.
BidnumberCurrent best bid price at the time of the candle close.
AsknumberCurrent best ask price at the time of the candle close.
VolumenumberTraded volume during the candle period.
OpenTimestringISO 8601 UTC timestamp marking the candle open.

Error Handling

All errors follow a consistent JSON shape. Check StatusCode and inspect Errors[] for field-level detail.

CodeStatusWhen it happens
400Bad RequestMissing or invalid query parameters.
401UnauthorizedAPI key missing or malformed.
403ForbiddenAPI key does not have access to this symbol or endpoint.
429Too Many RequestsRate limit exceeded for your plan.
500Internal Server ErrorUnexpected server error. Please retry.

Error response shape

error.json
{
  "StatusCode": 400,
  "Message": "Validation failed for query parameters.",
  "Errors": [
    {
      "PropertyName": "timeFrame",
      "ErrorCode": "ERR_0007_INVALID_TIME_FRAME",
      "ErrorMessage": "timeFrame must be one of M1, M5, M15, H1, H4, D1"
    },
    {
      "PropertyName": "symbolCode",
      "ErrorCode": "ERR_0008_SYMBOL_NOT_SUPPORTED",
      "ErrorMessage": "symbolCode BTCUSDT is not supported"
    }
  ],
  "TraceId": "00-7a8ab3af4fce34f3872a28ec7ca8f5e1-886d2e1bc76dc9a4-00"
}

Exception Codes

When a request fails, the Errors[] array contains one or more objects with a structured ErrorCode field. Use these codes for programmatic error handling.

HTTPError CodeDescription
404ERR_0001_DATA_NOT_FOUNDNo candle data found for the requested symbol and timeframe. The market may be closed or data is unavailable for the given period.
401ERR_0005_INVALID_API_KEYThe provided API key is missing, malformed, revoked, or does not match any active key in the system.
400ERR_0006_INVALID_TIME_RANGEThe startTime or endTime values are missing, in the wrong format, out of chronological order, or exceed the maximum allowed range for your plan.
400ERR_0007_INVALID_TIME_FRAMEThe timeFrame value is not one of the supported intervals. Accepted values: M1, M5, M15, H1, H4, D1.
403ERR_0008_SYMBOL_NOT_SUPPORTEDThe requested symbolCode is not supported on your current plan or does not exist in the system.
403ERR_0009_NOT_SUPPORT_WEBSOCKETYour current subscription plan does not include WebSocket access. Upgrade your plan to enable real-time streaming.
403ERR_0010_NOT_SUPPORT_HISTORICALYour current subscription plan does not include access to the historical data endpoint. Upgrade your plan to query historical candles.
403ERR_0012_EMAIL_NOT_VERIFIEDYour email address has not been verified. Verify your email from the dashboard before making API requests.