Welcome to the exciting world of API Trading! If you're new here, you're probably eager to dive into the nuts and bolts of automated trading. This blog is tailored to help you get started with our APIs, ensuring you have all the tools you need to begin your trading journey on the right foot.

The Foundation:
 Base URL: https://api.delta.exchange

Before we dive into the APIs themselves, it's crucial to understand the foundation of all the API requests you'll be making. All your API requests will start with this URL, making it the gateway to programmatically accessing Delta Exchange Global's features. The API follows RESTful principles, making it intuitive and straightforward to use across different programming languages and platforms.


APIs at a Glance

To get you well-equipped for trading, we'll cover the following APIs:

  • Products API: Understand the markets and products available for trading.

  • Tickers API: Get real-time price updates of various trading pairs.

  • Historical Data API: Access historical trading data for backtesting and analysis.

  • Orders API: Learn how to execute and manage orders.

With these APIs, you'll have a comprehensive toolkit to start trading, analyze market trends, and make informed decisions. Let's explore each of these in detail.


1. Products API

The Products API serves as your gateway to understanding the trading landscape on Delta Exchange Global. It provides comprehensive information about all available trading instruments, including perpetual futures, options, and other derivatives.

Endpoint: /v2/products

This endpoint returns a wealth of information about each product, including:

  • Unique product identifiers

  • Trading symbols (e.g., BTCUSDT, ETHUSDT)

  • Detailed descriptions

  • Contract types (perpetual_futures, call_options, put_options)

  • Current state (live, expired, upcoming)

  • Tick sizes (minimum price movements)

  • Commission rates for makers and takers

  • Margin requirements

  • Position limits

You can also filter products by contract types or states using query parameters. For instance, if you're only interested in perpetual futures contracts, you can specify that in your request.

python

CopyEdit

# Simple example to fetch all products

import requests

response = requests.get('https://api.delta.exchange/v2/products')



2. Tickers API

The Tickers API is your window into the current market conditions. It provides real-time price information, allowing you to make informed trading decisions based on the latest market movements.

Endpoint: /v2/tickers/{symbol}

This powerful endpoint delivers comprehensive market data for a specific trading pair, including:

  • Latest closing price

  • 24-hour high and low prices

  • Mark price (used for funding and liquidation calculations)

  • Open interest (number of outstanding contracts)

  • Best bid and ask prices with their respective sizes

  • Trading volume

  • Price band limits (upper and lower boundaries)

For options contracts, the endpoint also provides "Greeks" (delta, gamma, theta, vega, rho), which are essential metrics for options traders to understand price sensitivity to various factors.

python

CopyEdit

# Example to fetch ticker for a specific symbol

import requests

symbol = "BTCUSDT"

response = requests.get(f"https://api.delta.exchange/v2/tickers/{symbol}")



3. Historical Data API

For developing and backtesting trading strategies, historical data is invaluable. The Historical Data API provides access to past market behavior, allowing you to test your strategies against real market conditions before deploying them with real capital.

Endpoint: /v2/history/candles

Key features include:

  • Multiple timeframe options (1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 1d, 7d, 30d, 1w, 2w)

  • Customizable date ranges via start and end timestamps

  • Support for regular price data, funding rates, mark prices, and open interest history

  • Up to 2000 candles per request

python

CopyEdit

# Basic example for fetching historical candles

import requests

params = {

    'resolution': "1h",

    'symbol': "BTCUSDT",

    'start': "1712745270",  # Unix timestamp in seconds

    'end':   "1712831670"

}

response = requests.get("https://api.delta.exchange/v2/history/candles", params=params)



4. Orders API

The Orders API is where trading strategies come to life. It allows you to place, modify, and cancel orders, as well as retrieve information about your current and past orders.

Endpoint: /v2/orders

This endpoint is the core of your trading activity, supporting:

  • Multiple order types (market, limit, stop-market, stop-limit)

  • Buy and sell directions

  • Size and price specifications

  • Reduce-only orders (which only close positions, not open new ones)

  • Custom client order IDs for tracking your orders

Authentication is required for this endpoint, as it interacts with your account and capital. The API uses a secure signature-based authentication system to ensure that only authorized requests can manage your orders.

python

CopyEdit

# Simplified example of order placement (authentication details omitted for brevity)

order_data = {

    'product_id': 139,  # BTCUSDT

    'size':       1,

    'order_type': 'market_order',

    'side':       'buy'

}

# Authentication and request handling would be required here



Authentication System

Delta Exchange Global's API uses a robust signature-based authentication system to secure your trading activities. Here's how it works:

  1. API Keys: You'll need to generate an API key and secret from your Delta Exchange Global account.

  2. Signature Generation: For each authenticated request, you must create a signature by:

    • Concatenating the HTTP method, timestamp, request path, query string, and request body

    • Creating an HMAC-SHA256 hash of this string using your API secret as the key

    • Converting the hash to a hexadecimal string

  3. Required Headers:

    • api-key: Your API key

    • signature: The generated signature

    • timestamp: The current Unix timestamp (in seconds)

    • User-Agent: Identifier for your client application

Security Considerations:

  • Signatures are valid for only 5 seconds to prevent replay attacks.

  • Never share your API secret or include it in client-side code.

  • Always make sure your IP is whitelisted.


Best Practices for API Trading

As you begin your API trading journey, keep these best practices in mind:

  • Error Handling: Implement robust error handling in your code to manage API failures, network issues, or unexpected responses.

  • Rate Limiting: Be mindful of API rate limits to avoid having your requests throttled or your access temporarily suspended.

  • Logging: Maintain detailed logs of all API interactions for troubleshooting and auditing purposes.

  • Testing Environment: Whenever possible, test new strategies or code changes in a controlled environment before deploying to production.

  • Monitoring: Set up monitoring for your trading systems to alert you of any issues or unexpected behaviors.

  • Risk Management: Implement proper risk management in your trading algorithms, including position sizing, stop-losses, and maximum drawdown limits.


Final Thoughts

You can embark on your automated trading journey with Delta Exchange Global by exploring these APIs. Each endpoint provides a building block to help you start trading programmatically. Dive in, experiment, and discover the power of automated trading with Delta Exchange Global.

The API documentation is your best friend as you develop your trading systems. It provides detailed information about all available endpoints, parameters, and response formats. Refer to it frequently as you build and refine your trading infrastructure.

Should you need any help or have further questions, don't hesitate to reach out to our support team. We're committed to helping you succeed in your trading endeavors.

Happy trading!