---
title: "Stock, Forex, and Crypto Market Data APIs | Twelve Data"
description: "Try Twelve Data financial APIs for free with instant access to stock, forex, cryptocurrency, and fundamental market data. Real time, historical, and EOD data."
canonical_url: "https://twelvedata.com/"
image: "https://twelvedata.com/assets/img/open_graph_logo.png"
---

# Financial Data that drives your success

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

[Start now](https://twelvedata.com/register) [Contact sales](https://twelvedata.com/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](https://twelvedata.com/stocks), [forex](https://twelvedata.com/forex), [cryptocurrency](https://twelvedata.com/cryptocurrency), [ETF](https://twelvedata.com/etf), [fundamentals](https://twelvedata.com/fundamentals), [various spreadsheets add-ins](https://twelvedata.com/spreadsheets), and everything in between.

We also help to build unique [solutions](https://twelvedata.com/expertise), [educate](https://twelvedata.com/education), [level-up the business](https://twelvedata.com/customers), and much more.

[Start with market data](https://twelvedata.com/market-data)

**Response example · /quote**

```json
{
  "symbol": "JPM",
  "name": "JPMorgan Chase & Co.",
  "exchange": "NYSE",
  "mic_code": "XNYS",
  "currency": "USD",
  "datetime": "2025-04-14",
  "timestamp": 1744637400,
  "open": "237.10001",
  "high": "239.78000",
  "low": "233.63000",
  "close": "234.72000",
  "volume": "13015700",
  "previous_close": "236.20000",
  "change": "-1.48000",
  "percent_change": "-0.62658584",
  "average_volume": "17879180",
  "is_market_open": false,
  "fifty_two_week": {
    "low": "179.20000",
    "high": "280.25",
    "low_change": "55.52000",
    "high_change": "-45.53000",
    "low_change_percent": "30.98215",
    "high_change_percent": "-16.24621",
    "range": "179.199997 - 280.250000"
  }
}
```

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](https://support.twelvedata.com/en/collections/2999522-api-guide) share easy to understand logic across all endpoints. WebSockets share the same structure, so you get 2 in 1.

[Read the docs](https://twelvedata.com/docs)

#### Tools for your stack

We provide you with SDKs for the most popular languages.

[See libraries](https://twelvedata.com/docs/introduction/libraries)

#### WebSocket

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

[Explore docs](https://twelvedata.com/docs/websocket/websocket-getting-started)

**API · Python**

```python
from twelvedata import TDClient

td = TDClient(apikey="YOUR_API_KEY_HERE")

ts = td.time_series(
    symbol="AAPL",
    interval="1min",
    outputsize=12,
)

print(ts.as_json())
```

**API · Go**

```go
package main

import (
   "encoding/json"
   "fmt"
   "io/ioutil"
   "log"
   "net/http"
)

const apiKey = "YOUR_API_KEY_HERE"

type TimeSeriesResponse struct {
   Status string `json:"status"`
   Message string `json:"message"`
   Meta struct {
      Symbol string `json:"symbol"`
      Interval string `json:"interval"`
   } `json:"meta"`
   Data []struct {
      Datetime string `json:"datetime"`
      Open string `json:"open"`
      High string `json:"high"`
      Low string `json:"low"`
      Close string `json:"close"`
      Volume string `json:"volume"`
   } `json:"values"`
}

func main() {
   symbol := "AAPL"
   interval := "1min"
   url := fmt.Sprintf("https://api.twelvedata.com/time_series?symbol=%s&interval=%s&apikey=%s", symbol, interval, apiKey)
   resp, err := http.Get(url)
   if err != nil {
      log.Fatal(err)
   } defer resp.Body.Close()
   body, err := ioutil.ReadAll(resp.Body)
   if err != nil {
      log.Fatal(err)
   }
   var response TimeSeriesResponse
   if err := json.Unmarshal(body, response); err != nil {
      log.Fatal(err)
   }
   if response.Status != "ok" {
      log.Fatalf("Error: %s\n", response.Message)
   }

   fmt.Printf("Time Series for symbol: %s\n", response.Meta.Symbol)
   for, data := range response.Data {
      fmt.Printf("Time: %s, Open: %s, High: %s, Low: %s, Close: %s, Volume: %s\n", data.Datetime, data.Open, data.High, data.Low, data.Close, data.Volume)
   }
}
```

**API · C++**

```cpp
#include <cjson/cJSON.h> // https://github.com/DaveGamble/cJSON
#include <curl/curl.h>
#include <iostream>
#include <memory>

const char* REQUEST_URL = "https://api.twelvedata.com/time_series?symbol=AAPL&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE";

// Take response data and write into the string
std::size_t write_callback(const char* data, std::size_t size, std::size_t count, std::string* out) {
    const std::size_t result = size * count;
    out->append(data, result);

    return result;
}

int main() {
    std::unique_ptr<std::string> responseData(new std::string());
    cJSON* json = nullptr;
    CURL* curl = curl_easy_init();

    curl_easy_setopt(curl, CURLOPT_URL, REQUEST_URL);
    curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, responseData.get());
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
    curl_easy_perform(curl);

    json = cJSON_Parse(responseData->c_str());
    cJSON* metaField = cJSON_GetObjectItem(json, "meta");
    cJSON* valuesField = cJSON_GetObjectItem(json, "values");
    cJSON* symbolField = cJSON_GetObjectItem(metaField, "symbol");
    cJSON* closeField = cJSON_GetObjectItem(cJSON_GetArrayItem(valuesField, 0), "close");

    std::cout << "Received symbol: " << cJSON_GetStringValue(symbolField) << ", ";
    std::cout << "close: " << cJSON_GetStringValue(closeField) << std::endl;

    cJSON_Delete(json);
    curl_easy_cleanup(curl);

    return 0;
}
```

**API · C#**

```csharp
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.Json;

namespace TwelveData
{
    public class TimeSeries
    {
        public Dictionary<string, string> meta { get; set; }
        public IList<Dictionary<string, string>> values { get; set; }
        public string status { get; set; }
    }

    class Prices
    {
        static void Main(string[] args)
        {
            using WebClient wc = new WebClient();
            var response = wc.DownloadString("https://api.twelvedata.com/time_series?symbol=AAPL&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE");
            var timeSeries = JsonSerializer.Deserialize<TimeSeries>(response);
            if (timeSeries.status == "ok")
            {
                Console.WriteLine("Received symbol: " + timeSeries.meta["symbol"] + ", close: " + timeSeries.values[0]["close"]);
            }
        }
    }
}
```

**API · Java**

```java
import org.json.simple.parser.JSONParser;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.Scanner;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    private static final String REQUEST_URL = "https://api.twelvedata.com/time_series?symbol=AAPL&interval=1min&outputsize=12&apikey=YOUR_API_KEY_HERE";

    public static void main(String[] args) throws Exception {
        URL requestURL = new URL(REQUEST_URL);
        HttpURLConnection connection = (HttpURLConnection)requestURL.openConnection();
        StringBuffer responseData = new StringBuffer();
        JSONParser parser = new JSONParser();

        connection.setRequestMethod("GET");
        connection.setRequestProperty("User-Agent", "twelve_java/1.0");
        connection.connect();

        if (connection.getResponseCode() != 200) {
            throw new RuntimeException("Request failed. Error: " + connection.getResponseMessage());
        }

        Scanner scanner = new Scanner(requestURL.openStream());
        while (scanner.hasNextLine()) {
            responseData.append(scanner.nextLine());
        }

        JSONObject json = (JSONObject) parser.parse(responseData.toString());
        JSONObject meta = (JSONObject) json.get("meta");
        JSONArray values = (JSONArray) json.get("values");

        connection.disconnect();
    }
}
```

**API · R**

```r
# install.packages("RcppSimdJson")

apikey <- "YOUR_API_KEY_HERE"
qry <- paste0(
        "https://api.twelvedata.com/time_series?",
        "symbol=AAPL&interval=1min&outputsize=12",
        "&apikey=", apikey)
res <- RcppSimdJson::fload(qry)
res
```

**WebSocket · Python**

```python
# pip install twelvedata[websocket]

from twelvedata import TDClient

def on_event(e):
    print(e)

td = TDClient(apikey="YOUR_API_KEY_HERE")
ws = td.websocket(symbols="AAPL", on_event=on_event)
ws.connect()
ws.keep_alive()
```

**WebSocket · Go**

```go
package main

import (
   "fmt"
   "log"
   "github.com/gorilla/websocket"
)

const websocketURL = "wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE"

func main() {
   conn, _, err := websocket.DefaultDialer.Dial(websocketURL, nil)
   if err != nil {
      log.Fatal("connect to WebSocket failed:", err)
   }
   defer conn.Close()

   subscribeMessage := `{"action": "subscribe", "params": {"symbols": "AAPL"}}`

   err = conn.WriteMessage(websocket.TextMessage, []byte(subscribeMessage))
   if err != nil {
      log.Fatal("message send failed:", err)
   }

   for {
      _, message, err := conn.ReadMessage()
      if err != nil {
         log.Fatal("message read failed:", err)
      }
      fmt.Printf("Received: %s\n", message)
   }
}
```

**WebSocket · C++**

```cpp
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>
#include <cjson/cJSON.h>

#include <iostream>
#include <iomanip>
#include <ctime>

namespace wlib = websocketpp::lib;
namespace ssl = boost::asio::ssl;

typedef websocketpp::client<websocketpp::config::asio_tls_client> wclient;
typedef wlib::shared_ptr<wlib::asio::ssl::context> context_ptr;

const char* ENDPOINT = "wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE";

const char* SUBSCRIBE_ACTION = "{"\
    "\"action\": \"subscribe\"," \
    "\"params\": {" \
        "\"symbols\": \"AAPL\"" \
    "}" \
"}";

int main() {
    wclient::connection_ptr connection;
    wlib::error_code error_code;
    wclient client;

    client.set_access_channels(websocketpp::log::alevel::all);
    client.clear_access_channels(websocketpp::log::alevel::frame_payload);
    client.set_error_channels(websocketpp::log::elevel::all);

    // Initialize Boost.ASIO
    client.init_asio();

    // Set TLS initialize handler
    client.set_tls_init_handler(wlib::bind([](auto* hostname, auto hdl) {
        context_ptr context = wlib::make_shared<ssl::context>(ssl::context::sslv23);
        context->set_verify_mode(ssl::verify_none);

        return context;
    }, ENDPOINT, websocketpp::lib::placeholders::_1));

    // Is called after the WebSocket handshake is complete
    client.set_open_handler([&client](auto hdl) {
        // Send subscribe action to stream
        client.send(hdl, SUBSCRIBE_ACTION, websocketpp::frame::opcode::text);
    });

    // Receive and handle messages from server
    client.set_message_handler([](auto hdl, wclient::message_ptr message) {
        cJSON* json = cJSON_Parse(message->get_payload().c_str());

        if (json == nullptr) {
            std::cout << "received invalid JSON: " << std::endl << message->get_payload() << std::endl;
            return;
        }

        // Get event type
        cJSON* eventTypeField = cJSON_GetObjectItem(json, "event");
        if (eventTypeField == nullptr) {
            std::cout << "unknown JSON structure" << std::endl;
            return;
        }

        // Extract string from event type
        const char* eventType = cJSON_GetStringValue(eventTypeField);
        if (strcmp(eventType, "subscribe-status") == 0) {
            cJSON* statusField = cJSON_GetObjectItem(json, "status");
            const char* status = cJSON_GetStringValue(statusField);

            if (strcmp(status, "ok") != 0) {
                std::cout << "Failed subscribe to stream" << std::endl;
                return;
            }

            cJSON* successField = cJSON_GetObjectItem(json, "success");
            cJSON* failsField = cJSON_GetObjectItem(json, "fails");

            // Iterate over the symbols that were successfully subscribed
            for (int idx = 0; idx < cJSON_GetArraySize(successField); idx++) {
                cJSON* item = cJSON_GetArrayItem(successField, idx);
                cJSON* symbolField = cJSON_GetObjectItem(item, "symbol");
                const char* symbol = cJSON_GetStringValue(symbolField);

                std::cout << "Success subscribed to `"<< symbol << "` " << "symbol." << std::endl;
            }

            // If we're unable to subscribe to some symbols
            for (int idx = 0; 0 < cJSON_GetArraySize(failsField); idx++) {
                cJSON* item = cJSON_GetArrayItem(failsField, idx);
                cJSON* symbolField = cJSON_GetObjectItem(item, "symbol");
                const char* symbol = cJSON_GetStringValue(symbolField);

                std::cout << "Failed to subscribe on `"<< symbol << "` " << "symbol." << std::endl;
            }

            return;
        }

        if (strcmp(eventType, "price") == 0) {
            cJSON* timestampField = cJSON_GetObjectItem(json, "timestamp");
            cJSON* currencyField = cJSON_GetObjectItem(json, "currency");
            cJSON* symbolField = cJSON_GetObjectItem(json, "symbol");
            cJSON* priceField = cJSON_GetObjectItem(json, "price");
            time_t time = timestampField->valueint;

            std::cout << "[" << std::put_time(gmtime(&time), "%I:%M:%S %p") << "]: ";
            std::cout << "The symbol `" << cJSON_GetStringValue(symbolField) << "` ";
            std::cout << "has changed price to " << priceField->valuedouble << " ";

            if (currencyField != nullptr) {
                std::cout << "(" << cJSON_GetStringValue(currencyField) << ")" << std::endl;
            } else {
                std::cout << std::endl;
            }

            return;
        }

        // Free memory of JSON structure
        cJSON_Delete(json);
    });

    // New connection to WebSocket endpoint
    connection = client.get_connection(ENDPOINT, error_code);
    if (error_code) {
        std::cout << "Failed connection. Message: " << error_code.message() << std::endl;
        return -1;
    }

    // Connect to websocket endpoint
    client.connect(connection);
    client.run();
}
```

**WebSocket · C#**

```csharp
using System;
using WebSocket4Net; //https://github.com/kerryjiang/WebSocket4Net

namespace TwelveData
{
    class TDWebSocket
    {
        WebSocket ws = new WebSocket("wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE");

        static void Main()
        {
            new TDWebSocket().Init();
        }

        public void Init()
        {
            ws.Opened += OnOpen;
            ws.Closed += OnClose;
            ws.Error += OnError;
            ws.MessageReceived += OnEvent;

            ws.Open();
            Console.ReadLine();
        }

        private void OnOpen(object sender, EventArgs e)
        {
            Console.WriteLine("TDWebSocket opened!");
            ws.Send("{\"action\": \"subscribe\", \"params\":{\"symbols\": \"AAPL\"}}");
        }

        private void OnClose(object sender, EventArgs e)
        {
            Console.WriteLine("TDWebSocket closed");
        }

        private void OnError(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
        {
            Console.WriteLine("TDWebSocket ERROR: " + e.Exception.Message);
        }

        private void OnEvent(object sender, MessageReceivedEventArgs e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
```

**WebSocket · Java**

```java
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.client.WebSocketClient;

import org.json.simple.parser.ParseException;
import org.json.simple.parser.JSONParser;
import org.json.simple.JSONObject;

import java.net.URI;

public class Main {
    private static final String ENDPOINT = "wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE";

    public static void main(String[] args) throws Exception {
        WebSocketClient client = new WebSocketClient(new URI(ENDPOINT)) {
            @Override
            public void onOpen(ServerHandshake handshake) {
                System.out.println("TDWebSocket opened!");
                send("{\"action\": \"subscribe\", \"params\":{\"symbols\": \"AAPL\"}}");
            }

            @Override
            public void onMessage(String message) {
                JSONParser parser = new JSONParser();
                try {
                    JSONObject json = (JSONObject) parser.parse(message);
                    System.out.println(json);
                } catch(ParseException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onClose(int status, String reason, boolean remote) {
                System.out.println("TDWebSocket closed.");
                this.close();
            }

            @Override
            public void onError(Exception e) {
                e.printStackTrace();
            }
        };

        client.connectBlocking();
    }
}
```

**WebSocket · R**

```r
# install.packages("websocket")

library(websocket)

ws <- WebSocket$new("wss://ws.twelvedata.com/v1/quotes/price?apikey=YOUR_API_KEY_HERE")
ws$onOpen(function(event) {
    cat("TDWebSocket opened!\n")
})
ws$onClose(function(event) {
    cat("TDWebSocket closed with code ", event$code,
        " and reason ", event$reason, "\n", sep = "")
})
ws$onError(function(event) {
    cat("TDWebSocket ERROR: ", event$message, "\n")
})
ws$onMessage(function(event) {
    cat("Received event:", event$data, "\n")
})

ws$send('{"action": "subscribe", "params":{"symbols": "AAPL"}}')
```

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.

700M+

API requests performed per day,
peaking 1M+ per minute.

250+

Exchanges are supported,
across the world.

82,000+

Different financial assets
and many more to come.

90+

Countries from where data
comes from.

Explore data

## All world market data

[Stocks — 190,000+ symbols](https://twelvedata.com/stocks)

[Forex — 1,300+ pairs](https://twelvedata.com/forex)

[Crypto — 1,900+ pairs](https://twelvedata.com/cryptocurrency)

[ETFs — 56,000+ symbols](https://twelvedata.com/etf)

[Commodities — 30+ symbols](https://twelvedata.com/commodities)

### Ready to get started?

Explore [Market Data](https://twelvedata.com/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](https://twelvedata.com/register) [Contact sales](https://twelvedata.com/contact/sales)

#### Simple pricing

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

**[Pricing](https://twelvedata.com/pricing.md)**

#### Begin with API

Integrate Twelve Data in as little as 5 minutes.

**[Docs](https://twelvedata.com/docs)**