For any queries, email us at
[email protected]
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.
Base URL: https://cdn.india.deltaex.org
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.
To get you well-equipped for trading, we’ll cover the following APIs:
With these APIs, you’ll have a comprehensive toolkit to start trading, analyze market trends, and make informed decisions.
The Products API lets you explore available trading pairs and market information on Delta India. Here’s how you can fetch details about available products:
import requests # Fetch products response = requests.get('https://cdn.india.deltaex.org/v2/products') products = response.json()
# Example response [{'id': 1, 'symbol': 'BTCUSD', 'name': 'Bitcoin vs USD'}, ...]
To get real-time price information of trading pairs, use the Tickers API:
import requests # Fetch ticker information for a specific symbol symbol = "BTCUSD" # Example symbol response = requests.get("https://cdn.india.deltaex.org/v2/tickers" + f"/{symbol}") ticker_info = response.json() print(ticker_info)
# Example output {'result': {'close': 64905.5, 'contract_type': 'perpetual_futures', 'description': 'Bitcoin Perpetual', 'funding_rate': '0.01',...
For backtesting strategies or analyzing market trends, accessing historical data is vital. Here’s a quick way to fetch historical OHLC (Open, High, Low, Close) data:
import requests params = { 'resolution': "1m", 'symbol': "BTCUSD", 'start': "1712745270", 'end': "1712746220" } response = requests.get("https://cdn.india.deltaex.org/v2/history/candles", params=params) historical_data = response.json() print(historical_data)
# Example output [{'close': 68777, 'high': 68792.5, 'low': 68777, 'open': 68792.5, 'time': 1712746080, 'volume': 163}, ...]
Managing orders is crucial for trading, and with the Orders API, you can place, retrieve, and cancel orders programmatically.
import hashlib import hmac import json import time import requests api_key = 'your-api-key' api_secret = 'your-api-secret' # Create the signature def generate_signature(method, endpoint, payload): timestamp = str(int(time.time())) signature_data = method + timestamp + endpoint + payload message = bytes(signature_data, 'utf-8') secret = bytes(api_secret, 'utf-8') hash = hmac.new(secret, message, hashlib.sha256) return hash.hexdigest(), timestamp # Prepare the order data order_data = { 'product_id': 27, # Product ID for BTCUSD is 27 'size': 1, 'order_type': 'market_order', 'side': 'buy' } body = json.dumps(order_data, separators=(',', ':')) method = 'POST' endpoint = '/v2/orders' signature, timestamp = generate_signature(method, endpoint, body) # Add the API key and signature to the request headers headers = { 'api-key': api_key, 'signature': signature, 'timestamp': timestamp, 'Content-Type': 'application/json' } response = requests.post('https://cdn.india.deltaex.org/v2/orders', headers=headers, data=body) order_response = response.json() print(order_response)
# Example output {'result': {'id': 38089090, 'state': 'closed', 'side': 'buy', ...}, 'success': True}
Final Thoughts
You can embark on your automated trading journey with Delta India by exploring these APIs. Each snippet provided here is a building block to help you start trading programmatically. Dive in, experiment, and discover the power of automated trading with Delta India. Should you need any help or have further questions, don’t hesitate to reach out.
Happy trading!
Stay Connected With News, Updates And More