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.india.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 India'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 India. 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., BTCUSD, ETHUSD)
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.
For traders developing algorithmic strategies, this endpoint is invaluable for discovering tradable instruments and understanding their specifications before placing orders.
# Simple example to fetch all products
response = requests.get('https://api.india.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.
You can also fetch tickers for multiple products simultaneously using the /v2/tickers endpoint with optional filtering by contract types.
Real-time market data is the lifeblood of any trading strategy, making this endpoint essential for both manual traders monitoring the market and automated systems making decisions based on current conditions.
# Example to fetch ticker for a specific symbol
symbol = "BTCUSD"
response = requests.get(f"https://api.india.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
This endpoint returns historical Open-High-Low-Close (OHLC) candlestick data with volume information. 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
The flexibility of timeframes makes this API suitable for various trading styles, from high-frequency trading using minute candles to long-term position trading using daily or weekly data.
For quantitative analysts and algo traders, this endpoint provides the raw material needed to identify patterns, calculate technical indicators, and develop predictive models.
# Basic example for fetching historical candles
params = {
'resolution': "1h",
'symbol': "BTCUSD",
'start': "1712745270", # Unix timestamp in seconds
'end': "1712831670"
}
response = requests.get("https://api.india.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.
For active traders, the ability to programmatically manage orders opens up possibilities for implementing complex strategies, such as grid trading, dollar-cost averaging, or automated stop management.
# Simplified example of order placement (authentication details omitted for brevity)
order_data = {
'product_id': 27, # BTCUSD
'size': 1,
'order_type': 'market_order',
'side': 'buy'
}
# Authentication and request handling would be required here
Authentication System
Delta India's API uses a robust signature-based authentication system to secure your trading activities. Here's how it works:
API Keys: You'll need to generate an API key and secret from your Delta India account.
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
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.
This authentication system ensures that only you can access your account and execute trades, even if your API key is somehow exposed.
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 India 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 India.
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!
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article