Metadata-Version: 2.1
Name: Tradehull-Delta-Exchange
Version: 0.1.3
Summary: TradeHull client library for Delta Exchange India
Author: TradeHull
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: aiohttp>=3.9
Requires-Dist: pandas>=2.0
Requires-Dist: requests>=2.31

# 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

```bash
pip install Tradehull-Delta-Exchange
```

Upgrade to the latest version:

```bash
pip install --upgrade Tradehull-Delta-Exchange
```

---

## Required packages

The package uses:

- `aiohttp`
- `pandas`
- `requests`

The example file also uses `rich` for formatted printing:

```bash
pip install rich
```

---

## Import and login

```python
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

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

print(btc_chart.tail())
```

Common timeframe values include:

```text
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:

```text
open
high
low
close
volume
```

The DataFrame index is the candle timestamp.

---

## LTP of multiple symbols

```python
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

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

print("BTC LTP:", btc_ltp)
```

---

## OHLC of multiple symbols

```python
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:

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

---

## OHLC of one symbol

```python
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

```python
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

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

print("BTC QUOTE:", btc_quote)
```

---

## Ask price

### Multiple symbols

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

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

### One symbol

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

print("BTC ASK:", btc_askprice)
```

---

## Bid price

### Multiple symbols

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

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

### One symbol

```python
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:

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

---

## ATM call and put

```python
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

```python
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

```python
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

```python
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:

```python
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

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

print(option_chain)
```

Parameters:

```text
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

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

print(option_chain_ohlc)
```

---

## Call-only option chain

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

print(call_df.tail())
```

---

## Put-only option chain

```python
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:

```python
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:

```python
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:

```text
entry_price=None
```

for a market entry.

For a limit entry, pass a price:

```python
entry_price=65000.0
```

---

## Option bracket order using a direct option symbol

```python
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

```python
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

```python

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:

```python
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

```python
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()`:

```python
tdx.close()
```

You can also use it as a context manager:

```python
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:

```python
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.
