SDKs overview

StockData offers Software Development Kits (SDKs) and client libraries designed to facilitate interaction with its financial data API. These tools abstract the underlying HTTP requests and JSON parsing, allowing developers to integrate real-time and historical market data into their applications using familiar programming language constructs. The official SDKs cover several popular languages, providing a structured approach to accessing various data endpoints, including those for stocks, options, forex, and cryptocurrency data, as detailed in the StockData API documentation.

Using an SDK can streamline development by handling API key authentication, request formatting, and response parsing, reducing the boilerplate code required compared to making raw HTTP requests. This approach aims to accelerate the development of applications that require financial data, such as trading platforms, analytical tools, or portfolio management systems. The availability of SDKs across multiple languages supports a broad range of development environments and preferences.

Official SDKs by language

StockData provides official SDKs for several programming languages, each designed to offer a native-like experience for developers. These SDKs are maintained by StockData and are the recommended method for integrating the API into applications. Each SDK typically includes methods corresponding to the various API endpoints, allowing developers to fetch specific data types efficiently. The following table outlines the officially supported SDKs, their typical package names, and common installation commands.

Language Package/Module Name Installation Command Maturity
Python stockdata-sdk pip install stockdata-sdk Stable
Node.js @stockdata/node npm install @stockdata/node Stable
Go github.com/stockdata/go-sdk go get github.com/stockdata/go-sdk Stable
PHP stockdata/php-client composer require stockdata/php-client Stable
Ruby stockdata-ruby gem install stockdata-ruby Stable

These SDKs are designed to abstract the complexities of direct API interaction, such as handling API keys and constructing URL parameters. Developers can find detailed usage instructions and examples for each SDK within the StockData documentation portal, which includes specific guides for integrating different data types like real-time quotes, historical data, and options information.

Installation

The installation process for StockData SDKs typically follows the standard package management practices for each respective programming language. Below are detailed instructions for installing the official SDKs.

Python SDK Installation

The Python SDK can be installed using pip, the Python package installer. It is recommended to use a virtual environment to manage dependencies.

# Create a virtual environment (optional but recommended)
mkdir my_stock_project
cd my_stock_project
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`

# Install the StockData Python SDK
pip install stockdata-sdk

After installation, the SDK can be imported and used in Python scripts.

Node.js SDK Installation

The Node.js SDK is available via npm (Node Package Manager). Ensure you have Node.js and npm installed on your system.

# Initialize a new Node.js project (optional)
mkdir my-stock-app
cd my-stock-app
npm init -y

# Install the StockData Node.js SDK
npm install @stockdata/node

The SDK can then be required or imported into your JavaScript/TypeScript files.

Go SDK Installation

For Go projects, the SDK can be added using go get. Go modules are used for dependency management.

# Initialize a Go module (if not already done)
mkdir my-stock-go-app
cd my-stock-go-app
go mod init my-stock-go-app

# Install the StockData Go SDK
go get github.com/stockdata/go-sdk

The module will be added to your go.mod file and available for import.

PHP SDK Installation

The PHP SDK is managed via Composer, the dependency manager for PHP. Ensure Composer is installed globally or locally.

# Initialize a Composer project (if not already done)
mkdir my-stock-php-app
cd my-stock-php-app
composer init

# Install the StockData PHP SDK
composer require stockdata/php-client

Composer will generate an autoloader that needs to be included in your PHP script.

Ruby SDK Installation

The Ruby SDK is available as a Gem and can be installed using the gem command.

# Install the StockData Ruby Gem
gem install stockdata-ruby

For projects using Bundler, add gem 'stockdata-ruby' to your Gemfile and run bundle install.

Quickstart example

This section provides a quickstart example demonstrating how to fetch real-time stock quotes using the StockData API via its official SDKs. These examples focus on retrieving data for a specific symbol, such as Apple (AAPL), which is a common use case for market data APIs. You will need an API key from StockData, which can be obtained by signing up on their pricing page, including their free tier offering 500 API calls per day.

Python Quickstart

This Python example fetches the latest quote for AAPL.


from stockdata_sdk import StockDataClient
import os

# Replace 'YOUR_API_KEY' with your actual StockData API key
# It's recommended to use environment variables for API keys
api_key = os.environ.get("STOCKDATA_API_KEY", "YOUR_API_KEY")

client = StockDataClient(api_key)

try:
    # Fetch real-time quote for AAPL
    quote = client.get_quote(symbol="AAPL")
    if quote and quote.data:
        print(f"AAPL Real-time Quote:")
        print(f"  Price: {quote.data[0].price}")
        print(f"  Open: {quote.data[0].open}")
        print(f"  High: {quote.data[0].high}")
        print(f"  Low: {quote.data[0].low}")
        print(f"  Volume: {quote.data[0].volume}")
        print(f"  Timestamp: {quote.data[0].timestamp}")
    else:
        print("No data found for AAPL.")
except Exception as e:
    print(f"An error occurred: {e}")

Node.js Quickstart

This Node.js example uses the async/await pattern to fetch real-time stock data for AAPL.


const { StockDataClient } = require('@stockdata/node');

// Replace 'YOUR_API_KEY' with your actual StockData API key
// It's recommended to use environment variables for API keys
const apiKey = process.env.STOCKDATA_API_KEY || 'YOUR_API_KEY';

const client = new StockDataClient(apiKey);

async function getAAPLQuote() {
  try {
    const response = await client.getQuote('AAPL');
    if (response && response.data && response.data.length > 0) {
      const quote = response.data[0];
      console.log('AAPL Real-time Quote:');
      console.log(`  Price: ${quote.price}`);
      console.log(`  Open: ${quote.open}`);
      console.log(`  High: ${quote.high}`);
      console.log(`  Low: ${quote.low}`);
      console.log(`  Volume: ${quote.volume}`);
      console.log(`  Timestamp: ${quote.timestamp}`);
    } else {
      console.log('No data found for AAPL.');
    }
  } catch (error) {
    console.error(`An error occurred: ${error.message}`);
  }
}

getAAPLQuote();

These examples demonstrate the basic structure for initializing the client and making a request. For more complex queries, such as historical data, options chains, or forex rates, refer to the specific methods and parameters outlined in the official StockData API documentation. It is good practice to handle potential errors and implement retry mechanisms for production applications, as recommended by general API client library guidelines.

Community libraries

While StockData provides official SDKs for several major programming languages, the developer community may also contribute third-party libraries or wrappers. These community-driven projects can offer alternative interfaces, additional features, or support for languages not covered by official SDKs. Such libraries are typically found on platforms like GitHub or language-specific package repositories.

When considering a community library, it is important to evaluate its maintenance status, documentation, and active development. Factors such as the number of contributors, recent commits, and open issues can indicate the health and reliability of a project. Developers should verify that a community library correctly implements API authentication and error handling, and that it remains compatible with the latest version of the StockData API. Always refer to the official StockData API documentation for the definitive specification of endpoints and data structures, as community libraries may not always reflect the most current API changes immediately.

As of the current date, StockData's primary focus for client libraries is on its official SDKs, which are directly supported and maintained to ensure compatibility and performance. Developers are encouraged to check public repositories and forums for any community contributions that may emerge over time.