SDKs overview

Twelve Data offers a range of Software Development Kits (SDKs) and community-contributed libraries designed to simplify interaction with its financial market data API. These SDKs encapsulate the complexities of HTTP requests, authentication, and data parsing, allowing developers to focus on integrating financial data into their applications rather than managing API communication protocols directly. The available SDKs support various programming languages, facilitating easier access to real-time and historical financial data across different development environments.

The primary function of these SDKs is to provide structured access to Twelve Data's extensive array of market data endpoints, which cover asset classes such as stocks, forex, cryptocurrencies, futures, and options, alongside fundamental company data. By using an SDK, developers can retrieve data points like real-time quotes, historical price series, corporate actions, and earnings reports through language-native function calls and data structures. This approach aims to reduce development time and potential errors associated with manual API integration.

Twelve Data's API is built on REST principles, utilizing JSON for data interchange, which is a common standard for web APIs. The SDKs translate these RESTful interactions into idiomatic code for each supported language, making the API more accessible to developers familiar with those ecosystems. For detailed information on the API endpoints and data models, developers can refer to the official Twelve Data API Reference.

Official SDKs by language

Twelve Data maintains official SDKs for several popular programming languages, ensuring direct support and compatibility with their API. These SDKs are developed and updated by Twelve Data to reflect API changes and best practices. The following table provides an overview of the official SDKs, their package names, typical installation commands, and general maturity status.

Language Package/Library Name Installation Command Maturity
JavaScript twelvedata npm install twelvedata or yarn add twelvedata Stable
Python twelvedata pip install twelvedata Stable
PHP twelvedata/php-sdk composer require twelvedata/php-sdk Stable
Ruby twelvedata-ruby gem install twelvedata-ruby Stable
Go github.com/twelvedata/twelvedata-go go get github.com/twelvedata/twelvedata-go Stable
C# TwelveData.Net dotnet add package TwelveData.Net Stable
Java com.twelvedata:twelvedata-java Maven: reference central repository; Gradle: implementation 'com.twelvedata:twelvedata-java:latest' Stable

Installation

Installing a Twelve Data SDK typically involves using the package manager specific to your programming language's ecosystem. The process is generally straightforward and follows standard conventions for library inclusion. Below are examples for Python and JavaScript, which are among the primary languages for which Twelve Data provides examples and support.

Python Installation

To install the Python SDK, use pip, the Python package installer. This command fetches the latest version of the twelvedata library from PyPI (Python Package Index).

pip install twelvedata

JavaScript Installation (Node.js/npm)

For JavaScript environments, such as Node.js projects, you can install the SDK using npm or yarn. This adds the twelvedata package to your project's dependencies.

npm install twelvedata
# or
yarn add twelvedata

Other Languages

For other supported languages like PHP, Ruby, Go, C#, and Java, the installation commands are listed in the Official SDKs by language table above. Each command utilizes the respective language's standard package manager (e.g., Composer for PHP, Bundler/RubyGems for Ruby, go get for Go, NuGet for C#, Maven/Gradle for Java) to integrate the SDK into your development environment. For detailed installation instructions and system requirements, consult the Twelve Data official documentation.

Quickstart example

The following examples demonstrate how to retrieve real-time stock data using the Python and JavaScript SDKs. These snippets illustrate basic API interaction, including initialization with an API key and making a data request. You will need a Twelve Data API key to execute these examples.

Python Quickstart

This Python example fetches the real-time price for Apple Inc. (AAPL) stock.

from twelvedata import TDClient
import os

# Initialize Twelve Data Client with your API key
# It's recommended to store your API key as an environment variable
# For example: export TD_API_KEY="YOUR_API_KEY"
td = TDClient(apikey=os.getenv("TD_API_KEY", "YOUR_API_KEY"))

# Get real-time quote for AAPL
ts = td.time_series(symbol="AAPL", interval="1min", outputsize=1)

# Execute the request and print the data
result = ts.as_json()
print(result)

# Example of getting multiple symbols
many_symbols = td.time_series(symbol="AAPL,MSFT,GOOG", interval="1day", outputsize=10)
print(many_symbols.as_json())

JavaScript Quickstart (Node.js)

This JavaScript example, intended for a Node.js environment, retrieves the real-time price for Microsoft Corporation (MSFT) stock.

const TwelveData = require("twelvedata");

// Initialize Twelve Data Client with your API key
// It's recommended to store your API key as an environment variable
// For example: process.env.TD_API_KEY = "YOUR_API_KEY";
const td = TwelveData({
  key: process.env.TD_API_KEY || "YOUR_API_KEY", // Replace with your actual API key or use environment variable
});

// Get real-time quote for MSFT
td.timeSeries({
  symbol: "MSFT",
  interval: "1min",
  outputsize: 1,
})
  .then((res) => {
    console.log("MSFT real-time data:", res.data);
  })
  .catch((err) => {
    console.error("Error fetching MSFT data:", err);
  });

// Example of getting multiple symbols
td.timeSeries({
    symbol: "AMZN,NVDA,TSLA",
    interval: "1day",
    outputsize: 5 // Get last 5 days
})
.then(res => {
    console.log("Multiple symbols data:", res.data);
})
.catch(err => {
    console.error("Error fetching multiple symbols data:", err);
});

Community libraries

In addition to the official SDKs, the Twelve Data ecosystem benefits from community-contributed libraries and wrappers. While not officially supported by Twelve Data, these projects can offer alternative implementations, specialized functionalities, or support for languages not covered by the official SDKs. Developers often create these libraries to address specific use cases, integrate with particular frameworks, or experiment with new language features. Before using a community library in a production environment, it is advisable to evaluate its maintenance status, documentation, and the reputation of its contributors.

To discover community-driven projects, developers typically search platforms like GitHub or package repositories for their preferred language. For instance, a search for twelvedata on GitHub might reveal various open-source projects. While the official documentation focuses on Twelve Data's own offerings, a broader search can uncover tools that extend functionality or provide integrations with other platforms. For example, developers building financial applications might integrate Twelve Data with other services for charting or advanced analytics, as explored in general financial API development contexts by resources like Google Charts documentation for financial visualizations.

As community projects are not formally endorsed, their stability, security, and feature parity with the latest API changes may vary. Developers should consult the project's repository for licensing information, issue trackers, and contribution guidelines. It is also recommended to review the source code for any security vulnerabilities or performance implications before deployment, especially when handling sensitive financial data or integrating into critical systems. The Twelve Data community forums or support channels may also provide insights into popular or recommended third-party integrations.