Global market indices JSON API

Real-time and historical data for indices works well for serving as a benchmark.

Start now Contact sales

Reliable data

Currency data is sourced from well established providers, that correspond to the institutional grade performance standards.

Real time & historical

All indices are available for real-time streaming and historical data across various time intervals.

Low latency

API data is updated every 1 minute, but in real-time streaming it updates tick by tick with latency of 170ms.

Ease of integration

Use the data in JSON, CSV formats, and WebSocket for real-time streaming, with direct connection or using our SDKs.

Global coverage

Indices as is

Access to all stock exchanges in the world, with a single API - sharing the same format for all data.

US

We support stock market data from all major US-based exchanges and their subsidiaries.

  • S&P 500 (GSPC)
  • Dow Jones Industrial Average (DJI)
  • NASDAQ Composite (IXIC)
  • Wilshire 5000 Total Market Index (W5000)
  • Russell 2000 (RUT)

Global

International stock market data is available at two different levels of access. The delay is displayed after the dash.

  • S&P/TSX Composite index (GSPTSE, Canada)
  • FTSE 100 (FTSE, United Kingdom)
  • Nifty 50 (NSE, India)
  • CAC 40 (FCHI, France)
  • EGX 30 Price Return Index (CASE30, Egypt)
  • Nikkei 225 (N225, Japan)
  • KOSPI Composite Index (KS11, Korea)
  • STI Index (STI, Singapore)
  • S&P/ASX 200 (AXJO, Australia)
  • ESTX 50 PR.EUR (STOXX50E, Europe)
Not all indices are displayed
Single platform

Developer-centric

Rapidly integrate indices data into your project with modern languages, from Python to Golang. Using Twelve Data's API means less code maintenance and more time towards building a great product.

  • Same request and response structure for all indexes
  • HTTP RESTful API supports JSON and CSV formats
  • Real-time indices streaming via WebSocket
  • World-class documentation with various SDKs
  • 99.95% SLA uptime
  1. from twelvedata import TDClient
  2.  
  3. td = TDClient(apikey="YOUR_API_KEY_HERE")
  4.  
  5. ts = td.time_series(
  6.     symbol="TSLA",
  7.     interval="1min",
  8.     outputsize=12,
  9. )
  10.  
  11. print(ts.as_json())
  12.  
  1. #include <cjson/cJSON.h> // https://github.com/DaveGamble/cJSON
  2. #include <curl/curl.h>
  3. #include <iostream>
  4. #include <memory>
  5.  
  6. const char* REQUEST_URL = "https://api.twelvedata.com/time_series?symbol=TSLA&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE";
  7.  
  8. // Take response data and write into the string
  9. std::size_t write_callback(const char* data, std::size_t size, std::size_t count, std::string* out) {
  10.     const std::size_t result = size * count;
  11.     out->append(data, result);
  12.  
  13.     return result;
  14. }
  15.  
  16. int main() {
  17.     std::unique_ptr<std::string> responseData(new std::string());
  18.     cJSON* json = nullptr;
  19.     CURL* curl = curl_easy_init();
  20.  
  21.     curl_easy_setopt(curl, CURLOPT_URL, REQUEST_URL);
  22.     curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
  23.     curl_easy_setopt(curl, CURLOPT_WRITEDATA, responseData.get());
  24.     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
  25.     curl_easy_perform(curl);
  26.  
  27.     json = cJSON_Parse(responseData->c_str());
  28.     cJSON* metaField = cJSON_GetObjectItem(json, "meta");
  29.     cJSON* valuesField = cJSON_GetObjectItem(json, "values");
  30.     cJSON* symbolField = cJSON_GetObjectItem(metaField, "symbol");
  31.     cJSON* closeField = cJSON_GetObjectItem(cJSON_GetArrayItem(valuesField, 0), "close");
  32.  
  33.     std::cout << "Received symbol: " << cJSON_GetStringValue(symbolField) << ", ";
  34.     std::cout << "close: " << cJSON_GetStringValue(closeField) << std::endl;
  35.  
  36.     cJSON_Delete(json);
  37.     curl_easy_cleanup(curl);
  38.  
  39.     return 0;
  40. }
  41.  
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.Text.Json;
  5.  
  6. namespace TwelveData
  7. {
  8.     public class TimeSeries
  9.     {
  10.         public Dictionary<string, string> meta { get; set; }
  11.         public IList<Dictionary<string, string>> values { get; set; }
  12.         public string status { get; set; }
  13.     }
  14.  
  15.     class Prices
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             using WebClient wc = new WebClient();
  20.             var response = wc.DownloadString("https://api.twelvedata.com/time_series?symbol=TSLA&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE");
  21.             var timeSeries = JsonSerializer.Deserialize<TimeSeries>(response);
  22.             if (timeSeries.status == "ok")
  23.             {
  24.                 Console.WriteLine("Received symbol: " + timeSeries.meta["symbol"] + ", close: " + timeSeries.values[0]["close"]);
  25.             }
  26.         }
  27.     }
  28. }
  29.  
  1. import org.json.simple.parser.JSONParser;
  2. import org.json.simple.JSONArray;
  3. import org.json.simple.JSONObject;
  4.  
  5. import java.util.Scanner;
  6. import java.net.HttpURLConnection;
  7. import java.net.URL;
  8.  
  9. public class Main {
  10.     private static final String REQUEST_URL = "https://api.twelvedata.com/time_series?symbol=TSLA&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE";
  11.  
  12.     public static void main(String[] args) throws Exception {
  13.         URL requestURL = new URL(REQUEST_URL);
  14.         HttpURLConnection connection = (HttpURLConnection)requestURL.openConnection();
  15.         StringBuffer responseData = new StringBuffer();
  16.         JSONParser parser = new JSONParser();
  17.  
  18.         connection.setRequestMethod("GET");
  19.         connection.setRequestProperty("User-Agent", "twelve_java/1.0");
  20.         connection.connect();
  21.  
  22.         if (connection.getResponseCode() != 200) {
  23.             throw new RuntimeException("Request failed. Error: " + connection.getResponseMessage());
  24.         }
  25.  
  26.         Scanner scanner = new Scanner(requestURL.openStream());
  27.         while (scanner.hasNextLine()) {
  28.             responseData.append(scanner.nextLine());
  29.         }
  30.  
  31.         JSONObject json = (JSONObject) parser.parse(responseData.toString());
  32.         JSONObject meta = (JSONObject) json.get("meta");
  33.         JSONArray values = (JSONArray) json.get("values");
  34.        
  35.         connection.disconnect();
  36.     }
  37. }
  38.  
  1. # install.packages(c("httr", "jsonlite", "dplyr"))
  2.  
  3. library(httr) ; library(jsonlite) ; library(dplyr)
  4.  
  5. url <- "https://api.twelvedata.com/time_series?symbol=TSLA&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE"
  6. request <- GET(url)
  7. response = content(request, as = "text", encoding = "UTF-8")
  8. df <- fromJSON(response, flatten = TRUE) %>% data.frame()
  9. df <- select(df,
  10.              datetime = values.datetime,
  11.              open = values.open,
  12.              high = values.high,
  13.              low = values.low,
  14.              close = values.close,
  15.              volume = values.volume)
  16.  
  1. # pip install twelvedata[websocket]
  2.  
  3. from twelvedata import TDClient
  4.  
  5. def on_event(e):
  6.     print(e)
  7.  
  8. td = TDClient(apikey="YOUR_API_KEY_HERE")
  9. ws = td.websocket(symbols="TSLA", on_event=on_event)
  10. ws.connect()
  11. ws.keep_alive()
  12.  
  1. #include <websocketpp/config/asio_client.hpp>
  2. #include <websocketpp/client.hpp>
  3. #include <cjson/cJSON.h>
  4.  
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <ctime>
  8.  
  9. namespace wlib = websocketpp::lib;
  10. namespace ssl = boost::asio::ssl;
  11.  
  12. typedef websocketpp::client<websocketpp::config::asio_tls_client> wclient;
  13. typedef wlib::shared_ptr<wlib::asio::ssl::context> context_ptr;
  14.  
  15. const char* ENDPOINT = "wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE";
  16.  
  17. const char* SUBSCRIBE_ACTION = "{"\
  18.     "\"action\": \"subscribe\"," \
  19.     "\"params\": {" \
  20.         "\"symbols\": \"TSLA\"" \
  21.     "}" \
  22. "}";
  23.  
  24. int main() {
  25.     wclient::connection_ptr connection;
  26.     wlib::error_code error_code;
  27.     wclient client;
  28.    
  29.     client.set_access_channels(websocketpp::log::alevel::all);
  30.     client.clear_access_channels(websocketpp::log::alevel::frame_payload);
  31.     client.set_error_channels(websocketpp::log::elevel::all);
  32.  
  33.     // Initialize Boost.ASIO
  34.     client.init_asio();
  35.  
  36.     // Set TLS initialize handler
  37.     client.set_tls_init_handler(wlib::bind([](auto* hostname, auto hdl) {
  38.         context_ptr context = wlib::make_shared<ssl::context>(ssl::context::sslv23);
  39.         context->set_verify_mode(ssl::verify_none);
  40.  
  41.         return context;
  42.     }, ENDPOINT, websocketpp::lib::placeholders::_1));
  43.  
  44.     // Is called after the WebSocket handshake is complete
  45.     client.set_open_handler([&client](auto hdl) {
  46.         // Send subscribe action to stream
  47.         client.send(hdl, SUBSCRIBE_ACTION, websocketpp::frame::opcode::text);
  48.     });
  49.  
  50.     // Receive and handle messages from server
  51.     client.set_message_handler([](auto hdl, wclient::message_ptr message) {
  52.         cJSON* json = cJSON_Parse(message->get_payload().c_str());
  53.  
  54.         if (json == nullptr) {
  55.             std::cout << "received invalid JSON: " << std::endl << message->get_payload() << std::endl;
  56.             return;
  57.         }
  58.  
  59.         // Get event type
  60.         cJSON* eventTypeField = cJSON_GetObjectItem(json, "event");
  61.         if (eventTypeField == nullptr) {
  62.             std::cout << "unknown JSON structure" << std::endl;
  63.             return;
  64.         }
  65.  
  66.         // Extract string from event type
  67.         const char* eventType = cJSON_GetStringValue(eventTypeField);
  68.         if (strcmp(eventType, "subscribe-status") == 0) {
  69.             cJSON* statusField = cJSON_GetObjectItem(json, "status");
  70.             const char* status = cJSON_GetStringValue(statusField);
  71.  
  72.             if (strcmp(status, "ok") != 0) {
  73.                 std::cout << "Failed subscribe to stream" << std::endl;
  74.                 return;
  75.             }
  76.  
  77.             cJSON* successField = cJSON_GetObjectItem(json, "success");
  78.             cJSON* failsField = cJSON_GetObjectItem(json, "fails");
  79.  
  80.             // Iterate over the symbols that were successfully subscribed
  81.             for (int idx = 0; idx < cJSON_GetArraySize(successField); idx++) {
  82.                 cJSON* item = cJSON_GetArrayItem(successField, idx);
  83.                 cJSON* symbolField = cJSON_GetObjectItem(item, "symbol");
  84.                 const char* symbol = cJSON_GetStringValue(symbolField);
  85.  
  86.                 std::cout << "Success subscribed to `"<< symbol << "` " << "symbol." << std::endl;
  87.             }
  88.  
  89.             // If we're unable to subscribe to some symbols
  90.             for (int idx = 0; 0 < cJSON_GetArraySize(failsField); idx++) {
  91.                 cJSON* item = cJSON_GetArrayItem(failsField, idx);
  92.                 cJSON* symbolField = cJSON_GetObjectItem(item, "symbol");
  93.                 const char* symbol = cJSON_GetStringValue(symbolField);
  94.  
  95.                 std::cout << "Failed to subscribe on `"<< symbol << "` " << "symbol." << std::endl;
  96.             }
  97.  
  98.             return;
  99.         }
  100.  
  101.         if (strcmp(eventType, "price") == 0) {
  102.             cJSON* timestampField = cJSON_GetObjectItem(json, "timestamp");
  103.             cJSON* currencyField = cJSON_GetObjectItem(json, "currency");
  104.             cJSON* symbolField = cJSON_GetObjectItem(json, "symbol");
  105.             cJSON* priceField = cJSON_GetObjectItem(json, "price");
  106.             time_t time = timestampField->valueint;
  107.  
  108.             std::cout << "[" << std::put_time(gmtime(&time), "%I:%M:%S %p") << "]: ";
  109.             std::cout << "The symbol `" << cJSON_GetStringValue(symbolField) << "` ";
  110.             std::cout << "has changed price to " << priceField->valuedouble << " ";
  111.            
  112.             if (currencyField != nullptr) {
  113.                 std::cout << "(" << cJSON_GetStringValue(currencyField) << ")" << std::endl;
  114.             } else {
  115.                 std::cout << std::endl;
  116.             }
  117.            
  118.             return;
  119.         }
  120.  
  121.         // Free memory of JSON structure
  122.         cJSON_Delete(json);
  123.     });
  124.  
  125.     // New connection to WebSocket endpoint
  126.     connection = client.get_connection(ENDPOINT, error_code);
  127.     if (error_code) {
  128.         std::cout << "Failed connection. Message: " << error_code.message() << std::endl;
  129.         return -1;
  130.     }
  131.  
  132.     // Connect to websocket endpoint
  133.     client.connect(connection);
  134.     client.run();
  135. }
  136.  
  1. using System;
  2. using WebSocket4Net; //https://github.com/kerryjiang/WebSocket4Net
  3.  
  4. namespace TwelveData
  5. {
  6.     class TDWebSocket
  7.     {
  8.         WebSocket ws = new WebSocket("wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE");
  9.  
  10.         static void Main()
  11.         {
  12.             new TDWebSocket().Init();
  13.         }
  14.  
  15.         public void Init()
  16.         {
  17.             ws.Opened += OnOpen;
  18.             ws.Closed += OnClose;
  19.             ws.Error += OnError;
  20.             ws.MessageReceived += OnEvent;
  21.  
  22.             ws.Open();
  23.             Console.ReadLine();
  24.         }
  25.  
  26.         private void OnOpen(object sender, EventArgs e)
  27.         {
  28.             Console.WriteLine("TDWebSocket opened!");
  29.             ws.Send("{\"action\": \"subscribe\", \"params\":{\"symbols\": \"TSLA\"}}");
  30.         }
  31.  
  32.         private void OnClose(object sender, EventArgs e)
  33.         {
  34.             Console.WriteLine("TDWebSocket closed");
  35.         }
  36.  
  37.         private void OnError(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
  38.         {
  39.             Console.WriteLine("TDWebSocket ERROR: " + e.Exception.Message);
  40.         }
  41.  
  42.         private void OnEvent(object sender, MessageReceivedEventArgs e)
  43.         {
  44.             Console.WriteLine(e.Message);
  45.         }
  46.     }
  47. }
  48.  
  1. import org.java_websocket.handshake.ServerHandshake;
  2. import org.java_websocket.client.WebSocketClient;
  3.  
  4. import org.json.simple.parser.ParseException;
  5. import org.json.simple.parser.JSONParser;
  6. import org.json.simple.JSONObject;
  7.  
  8. import java.net.URI;
  9.  
  10. public class Main {
  11.     private static final String ENDPOINT = "wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE";
  12.  
  13.     public static void main(String[] args) throws Exception {
  14.         WebSocketClient client = new WebSocketClient(new URI(ENDPOINT)) {
  15.             @Override
  16.             public void onOpen(ServerHandshake handshake) {
  17.                 System.out.println("TDWebSocket opened!");
  18.                 send("{\"action\": \"subscribe\", \"params\":{\"symbols\": \"TSLA\"}}");
  19.             }
  20.  
  21.             @Override
  22.             public void onMessage(String message) {
  23.                 JSONParser parser = new JSONParser();
  24.                 try {
  25.                     JSONObject json = (JSONObject) parser.parse(message);
  26.                     System.out.println(json);
  27.                 } catch(ParseException e) {
  28.                     e.printStackTrace();
  29.                 }
  30.             }
  31.  
  32.             @Override
  33.             public void onClose(int status, String reason, boolean remote) {
  34.                 System.out.println("TDWebSocket closed.");
  35.                 this.close();
  36.             }
  37.  
  38.             @Override
  39.             public void onError(Exception e) {
  40.                 e.printStackTrace();
  41.             }
  42.         };
  43.  
  44.         client.connectBlocking();
  45.     }
  46. }
  47.  
  1. # install.packages("websocket")
  2.  
  3. library(websocket)
  4.  
  5. ws <- WebSocket$new("wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_PRIME_API_KEY_HERE")
  6. ws$onOpen(function(event) {
  7.     cat("TDWebSocket opened!\n")
  8. })
  9. ws$onClose(function(event) {
  10.     cat("TDWebSocket closed with code ", event$code,
  11.         " and reason ", event$reason, "\n", sep = "")
  12. })
  13. ws$onError(function(event) {
  14.     cat("TDWebSocket ERROR: ", event$message, "\n")
  15. })
  16. ws$onMessage(function(event) {
  17.     cat("Received event:", event$data, "\n")
  18. })
  19.  
  20. ws$send('{"action": "subscribe", "params":{"symbols": "TSLA"}}')
  21.  
 
Strong backbone

Empower your project with market indices data

Search

Easily add a lookup of any symbol into your app with the most effective search in the industry.

Explore

Technical indicators

Do not waste time on manually listing all the indicators and stay always up to dated.

Explore

Single API Key

In addition to indices, access stock, forex, crypto, and more, with one 12Data subscription.

Explore

Charts

Use aggregated OHLCV bars with intraday, daily, weekly, and monthly intervals.

Explore

Institutional grade infrastructure. Designed to scale.

50,000,000+
Requests per day
2,000+
Pairs available
30,000+
Events per second

Curious, but not a developer?

We love our products and the way it empowers new stories.
We can help you to build projects of any difficulty, to deliver the highest quality.

Ready to get started? Get in touch or create an account.

Facilitate access to world indices and gain an advantage with Twelve Data.

Start now Contact sales

Simple pricing

Pay for what you need. No hidden or implicit fees.

Pricing

Begin with API

Integrate Twelve Data in as little as 5 minutes.

Docs