Skip to main content

TradeHull client library for Delta Exchange India

Project description

Tradehull Delta Exchange

A Python client library for working with Delta Exchange India through a simple TradeHull-style interface.

It supports:

  • Login using API key and API secret
  • Historical OHLC candle data
  • Single and multiple symbol LTP
  • OHLC, quote, ask price, and bid price
  • ATM, ITM, and OTM option selection
  • Option chain and option-chain OHLC
  • Call-only and put-only option-chain views
  • Futures and options bracket orders
  • Closing all open orders and positions

Important: This package can place real live orders. Test every function carefully before using it with a live account.


Installation

pip install Tradehull-Delta-Exchange

Upgrade to the latest version:

pip install --upgrade Tradehull-Delta-Exchange

Required packages

The package uses:

  • aiohttp
  • pandas
  • requests
  • colorama (for the bold green login-success message)

The example file also uses rich for formatted printing:

pip install rich

Import and login

import Tradehull_Delta_Exchange as TDX

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"

tdx = TDX.login(api_key=api_key,api_secret=api_secret)

Keep API credentials private. Do not upload API keys or secrets to GitHub, PyPI, or any public file.


Market data

Historical chart data

btc_chart = tdx.get_chart(name="BTCUSD",timeframe="15minute",days=7)

print(btc_chart.tail())

Common timeframe values include:

minute
1minute
2minute
3minute
4minute
5minute
10minute
15minute
30minute
60minute
120minute
240minute
360minute
day
1day
week
1week

The returned value is a pandas DataFrame containing:

open
high
low
close
volume

The DataFrame index is the candle timestamp.


LTP of multiple symbols

ltp = tdx.get_ltp(names=["BTCUSD", "ETHUSD"])

btc_ltp = ltp["BTCUSD"]
eth_ltp = ltp["ETHUSD"]

print("BTC LTP:", btc_ltp)
print("ETH LTP:", eth_ltp)

LTP of one symbol

btc_ltp = tdx.get_ltp(names="BTCUSD")

print("BTC LTP:", btc_ltp)

OHLC of multiple symbols

ohlc = tdx.get_ohlc_data(names=["BTCUSD", "ETHUSD"])

btc_ohlc = ohlc["BTCUSD"]
eth_ohlc = ohlc["ETHUSD"]

print("BTC OHLC:", btc_ohlc)
print("ETH OHLC:", eth_ohlc)

For multiple symbols, each result contains:

{
	"open": 0.0,
	"high": 0.0,
	"low": 0.0,
	"close": 0.0,
}

OHLC of one symbol

open_, high, low, close = tdx.get_ohlc_data(names="BTCUSD")

print("OPEN :", open_)
print("HIGH :", high)
print("LOW  :", low)
print("CLOSE:", close)

Full quote of multiple symbols

quote = tdx.get_quote(names=["BTCUSD", "ETHUSD"])

btc_quote = quote["BTCUSD"]
eth_quote = quote["ETHUSD"]

print("BTC QUOTE:", btc_quote)
print("ETH QUOTE:", eth_quote)

Full quote of one symbol

btc_quote = tdx.get_quote(names="BTCUSD")

print("BTC QUOTE:", btc_quote)

Ask price

Multiple symbols

askprice = tdx.get_askprice(names=["BTCUSD", "ETHUSD"])

print("BTC ASK:", askprice["BTCUSD"])
print("ETH ASK:", askprice["ETHUSD"])

One symbol

btc_askprice = tdx.get_askprice(names="BTCUSD")

print("BTC ASK:", btc_askprice)

Bid price

Multiple symbols

bidprice = tdx.get_bidprice(names=["BTCUSD", "ETHUSD"])

print("BTC BID:", bidprice["BTCUSD"])
print("ETH BID:", bidprice["ETHUSD"])

One symbol

btc_bidprice = tdx.get_bidprice(
	names="BTCUSD"
)

print("BTC BID:", btc_bidprice)

Option selection

The get_option_name() function selects an option contract using:

  • symbolname: underlying name such as BTC
  • moneyness: strike distance from ATM
  • right: CE or PE
  • expiry: expiry index or expiry date

Moneyness meaning:

 0  = ATM
+1  = one strike OTM
+2  = two strikes OTM
-1  = one strike ITM
-2  = two strikes ITM

ATM call and put

atm_call_script = tdx.get_option_name(symbolname="BTC",moneyness=0,right="CE",expiry=0)

atm_put_script = tdx.get_option_name(symbolname="BTC",moneyness=0,right="PE",expiry=0)

print("BTC ATM CALL:", atm_call_script)
print("BTC ATM PUT :", atm_put_script)

OTM call and put

otm_call_script = tdx.get_option_name(symbolname="BTC",moneyness=1,right="CE",expiry=0)

otm_put_script = tdx.get_option_name(symbolname="BTC",moneyness=1,right="PE",expiry=0)

print("BTC OTM CALL:", otm_call_script)
print("BTC OTM PUT :", otm_put_script)

ITM call and put

itm_call_script = tdx.get_option_name(symbolname="BTC",moneyness=-1,right="CE",expiry=0)

itm_put_script = tdx.get_option_name(symbolname="BTC",moneyness=-1,right="PE",expiry=0)

print("BTC ITM CALL:", itm_call_script)
print("BTC ITM PUT :", itm_put_script)

Get ITM option using current LTP

btc_ltp = tdx.get_ltp("BTCUSD")

itm_call_script = tdx.get_itm_script(btc_ltp,"BTC",itm_level=1,script_type="CE",expiry=0)

print("ITM CALL SCRIPT:", itm_call_script)

For a put option:

itm_put_script = tdx.get_itm_script(btc_ltp,"BTC",itm_level=1,script_type="PE",expiry=0)

print("ITM PUT SCRIPT:", itm_put_script)

Option chain

Combined option chain

option_chain = tdx.get_option_chain(underlying="BTC",expiry_date=0,limit=20)

print(option_chain)

Parameters:

underlying  : BTC, ETH, SOL, etc.
expiry_date : 0 for nearest expiry, 1 for next expiry, or a supported date
limit       : number of strikes to include

Option chain with OHLC

option_chain_ohlc = tdx.get_option_chain_ohlc(underlying="BTC",expiry_date=0,limit=20)

print(option_chain_ohlc)

Call-only option chain

call_df = tdx.get_option_chain(underlying="BTC",expiry_date=0,limit=20,view="call")

print(call_df.tail())

Put-only option chain

put_df = tdx.get_option_chain(underlying="BTC",expiry_date=0,limit=20,view="put")

print(put_df.tail())

Live order placement

Live trading warning: The following functions can place real orders. Verify symbol, side, quantity, entry, target, and stop-loss before running them.


Place Market Order

Live order placement is disabled by default in the safe wrapper.

To place a real order, you must intentionally pass:

Example:

order = tdx.place_order(symbol="BTCUSD",side="buy",order_type="market_order",quantity=1,price=None)

print(order)

Futures bracket order

Example with a market entry:

result = tdx.place_bracket_order(symbol="BTCUSD",side="buy",quantity=1,entry_price=None,target_price=72000.0,sl_price=61000.0,sl_limit_price=60950.0,target_limit_price=72000.0)

print("Order ID:",result["order_id"],"| Status:",result["status"])

print("Full response:", result)

Use:

entry_price=None

for a market entry.

For a limit entry, pass a price:

entry_price=65000.0

Option bracket order using a direct option symbol

result = tdx.place_option_bracket_order(symbol="C-BTC-62800-060726",side="buy",quantity=1,entry_price=0.4,target_price=0.6,sl_price=0.2,sl_limit_price=0.2,target_limit_price=0.6)

print("Option Order ID:",result["order_id"],"| Status:",result["status"])

print("Full response:", result)

Select an ITM option and place its bracket order

btc_ltp = tdx.get_ltp("BTCUSD")

itm_call_script = tdx.get_itm_script(btc_ltp,"BTC",itm_level=1,script_type="CE",expiry=0)

result = tdx.place_option_bracket_order(symbol=itm_call_script,side="buy",quantity=1,entry_price=0.4,target_price=0.6,sl_price=0.2,sl_limit_price=0.2,target_limit_price=0.6)

print("ITM Option Order ID:",result["order_id"],"| Status:",result["status"])

print("Full response:", result)

Cancel Order

cancel_status = tdx.cancel_order(
    order_id=123456,
    product_id=27,
)

print(cancel_status)

Close all orders and positions

The following function acts as a kill switch:

result = tdx.close_all_orders()
print(result)

It attempts to:

  1. Cancel open orders
  2. Cancel bracket target and stop-loss orders
  3. Close running/open positions
  4. Verify whether positions are still visible

Use this function carefully. It can close every active position in the connected account.


Complete basic example

import Tradehull_Delta_Exchange as TDX
from rich import print

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"

tdx = TDX.login(
	api_key=api_key,
	api_secret=api_secret,
)

btc_chart = tdx.get_chart(
	name="BTCUSD",
	timeframe="15minute",
	days=7,
)
print(btc_chart.tail())

btc_ltp = tdx.get_ltp("BTCUSD")
print("BTC LTP:", btc_ltp)

open_, high, low, close = tdx.get_ohlc_data("BTCUSD")
print(
	f"OPEN: {open_} | HIGH: {high} | "
	f"LOW: {low} | CLOSE: {close}"
)

atm_call = tdx.get_option_name(
	symbolname="BTC",
	moneyness=0,
	right="CE",
	expiry=0,
)
print("BTC ATM CALL:", atm_call)

option_chain = tdx.get_option_chain(
	underlying="BTC",
	expiry_date=0,
	limit=20,
)
print(option_chain)

Closing the client

The returned client supports close():

tdx.close()

You can also use it as a context manager:

import Tradehull_Delta_Exchange as TDX

with TDX.login(
	api_key="YOUR_API_KEY",
	api_secret="YOUR_API_SECRET",
) as tdx:
	print(tdx.get_ltp("BTCUSD"))

Security recommendations

  • Never hard-code production credentials in public code.
  • Never upload API secrets to GitHub or PyPI.
  • Use environment variables for production deployments.
  • Test orders with the minimum permitted quantity.
  • Verify bracket-order prices against the current market.
  • Keep the kill-switch function available for emergency exits.

Example using environment variables:

import os
import Tradehull_Delta_Exchange as TDX

tdx = TDX.login(
	api_key=os.getenv("DELTA_API_KEY", ""),
	api_secret=os.getenv("DELTA_API_SECRET", ""),
)

Disclaimer

This software is provided for development and automation purposes. Trading involves financial risk. The package author is not responsible for trading losses, rejected orders, incorrect inputs, exchange downtime, API changes, connectivity problems, or unexpected broker behaviour.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradehull_delta_exchange-0.1.4.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tradehull_delta_exchange-0.1.4-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file tradehull_delta_exchange-0.1.4.tar.gz.

File metadata

File hashes

Hashes for tradehull_delta_exchange-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ad12e4cdc46e9222666557ff57d44d269de5f164e1a799153c360fe777e07bfe
MD5 4cd7aa30eabf59c960a275a5bf1a3a0a
BLAKE2b-256 25d0bcf86a5c7eb49f202bffa35744877939907edb9ab59098ab498823c7ccf7

See more details on using hashes here.

File details

Details for the file tradehull_delta_exchange-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for tradehull_delta_exchange-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b7cb49d24f7c16b0209e9b5c29a1753c999282872765c75cca408065212d7fbe
MD5 cc81f4afa291583e023d1f080b9caf78
BLAKE2b-256 a509481eb24e7be791e684465fb42324caef4fcd391c4e85e75d9fef5ffc24dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page