We’ve just launched a new portal to help you explore stocks, crypto, ETFs, and more data

Financial Data that drives your success

Access stocks, forex and other financial assets from anywhere at any time.

Start now Contact sales
Single platform

APIs, WebSocket, SDKs
unified for all financial data

We bring everything together that is required to build a successful trading system, fintech product, and empower your research. Twelve Data’s products include stock, forex, cryptocurrency, ETF, fundamentals, various spreadsheets add-ins, and everything in between.

We also help to build unique solutions, educate, level-up the business, and much more.

Start with market data
  1. {
  2.   "symbol": "JPM",
  3.   "name": "JPMorgan Chase & Co",
  4.   "exchange": "NYSE",
  5.   "currency": "USD",
  6.   "datetime": "2021-03-26",
  7.   "open": "154.30",
  8.   "high": "155.28",
  9.   "low": "152.92",
  10.   "close": "153.00",
  11.   "volume": "9,283,955",
  12.   "previous_close": "152.55",
  13.   "change": "0.45",
  14.   "average_volume": "18,613,062
  15. }
  16.  
 
Designed for developers

The most powerful
and easy-to-use APIs

We understand how tedious it is to think about different formats and integration barriers. Our APIs share easy to understand logic across all endpoints. WebSockets share the same structure, so you get 2 in 1.

Read the docs

Tools for your stack

We provide you with SDKs for the most popular languages.

See libraries

WebSocket

Connect to a real time stream of ultra low latency data.

Explore docs
  1. from twelvedata import TDClient
  2.  
  3. td = TDClient(apikey="YOUR_API_KEY_HERE")
  4.  
  5. ts = td.time_series(
  6.     symbol="AAPL",
  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=AAPL&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=AAPL&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=AAPL&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("RcppSimdJson")
  2.  
  3. apikey <- "YOUR_API_KEY_HERE"
  4. qry <- paste0(
  5.         "https://api.twelvedata.com/time_series?",
  6.         "symbol=AAPL&interval=1min&outputsize=12",
  7.         "&apikey=", apikey)
  8. res <- RcppSimdJson::fload(qry)
  9. res
  10.  
  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="AAPL", 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\": \"AAPL\"" \
  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\": \"AAPL\"}}");
  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\": \"AAPL\"}}");
  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_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": "AAPL"}}')
  21.  
 
Why Twelve Data

A technology-first approach together
with exceptional service.

Data coverage

We support around 100 000 symbols across a different range of assets available from all over the world.

Fast moving

Every day, from year to year we release hundreds of new features to make sure that you stay ahead of the industry.

Reliability

Our system has 99.95% SLA. Twelve Data tends to raise the standards for quality and uptime to the next level.

Latency

Real time data streaming via WebSockets has ultra low latency at only ~170 ms on average for all instruments.

Think globally

More than data provider

For those individuals and companies who want to challenge the world, Twelve Data makes it possible to achieve their goals. Our decentalized team is located across the world and helps to make next big step.

700М+

API requests performed per day,
peaking 1,000,000 per minute.

250+

Exchanges are supported,
across the world.

80k+

Different financial assets
and many more to come.

90+

Countries from where data
comes from.

Explore data

All world market data

Stock, crypto, forex, ETF, and other symbols Search through 100K+ symbols

Ready to get started?

Explore Market Data, or create an account and start working with the data. You can also leave us a note and we will prepare custom plan for your needs.

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