Metadata-Version: 2.1
Name: XTS-LAI
Version: 1.0.4
Summary: LET'S ALGOIT Python SDK for XTS Interactive and Market Data APIs
Author: LET'S ALGOIT Team
License: Proprietary
Project-URL: Homepage, https://letsalgoit.com
Project-URL: Documentation, https://letsalgoit.com
Keywords: XTS,trading,market-data,algorithmic-trading,LetsAlgoIt
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: Microsoft :: Windows
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: <3.13,>=3.8
Description-Content-Type: text/markdown
Requires-Dist: rich<15,>=13.7
Requires-Dist: requests<3,>=2.28
Requires-Dist: pandas<2.1,>=1.5; python_version == "3.8"
Requires-Dist: pandas<3,>=2.0; python_version >= "3.9"
Requires-Dist: numpy<1.25,>=1.23; python_version == "3.8"
Requires-Dist: numpy<3,>=1.24; python_version >= "3.9"
Requires-Dist: python-dateutil<3,>=2.8
Requires-Dist: six<2,>=1.16
Requires-Dist: mibian>=0.1.3
Requires-Dist: TA-Lib>=0.4.28
Requires-Dist: openpyxl<4,>=3.0

# XTS-LAI

A simple Python SDK by **LET'S ALGOIT** for working with XTS Interactive and Market Data APIs.

The package provides easy methods for:

- XTS login
- Historical candle data
- LTP and OHLC data
- Bid and ask prices
- ATM, ITM and OTM strike calculation
- Option Greeks and indicators
- Account information
- Order placement and management
- Expiry information
- Instrument validation
- Telegram alerts

---

## Version

Current version:

```text
1.0.4
```

---

## Installation

Install the latest version:

```bash
pip install XTS-LAI
```

Install version `1.0.4`:

```bash
pip install XTS-LAI==1.0.4
```

Upgrade the package:

```bash
pip install --upgrade XTS-LAI
```

---

## Import and Login

```python
from XTS_LAI import LetsAlgoIt

xts_lai = login(
    interactive_api_key="YOUR_INTERACTIVE_API_KEY",
    interactive_api_secret="YOUR_INTERACTIVE_API_SECRET",
    market_api_key="YOUR_MARKET_API_KEY",
    market_api_secret="YOUR_MARKET_API_SECRET",
    clientID="YOUR_CLIENT_ID"
)
```

After successful login, all SDK functions are available through:

```python
xts_lai
```

---

# Market Data Functions

## 1. Historical Data

Fetch historical candle data for a trading symbol.

### Function

```python
get_historical_data(name, timeframe, interval)
```

### Supported Timeframes

```text
minute
2minute
3minute
4minute
5minute
10minute
15minute
30minute
60minute
day
```

### Example

```python
acc_df = xts_lai.get_historical_data(
    "ACC-EQ",
    "5minute",
    xts_lai.intervals_dict["5minute"]
)

print(acc_df)
```

---

## 2. Get LTP

Fetch the last traded price of a symbol.

### Function

```python
get_ltp(name)
```

### Example

```python
acc_ltp = xts_lai.get_ltp("ACC-EQ")
print(f"ACC LTP: {acc_ltp}")
```

---

## 3. Get OHLC Data

Fetch open, high, low and close values.

### Function

```python
get_ohlc_data(names)
```

### Multiple Symbols

```python
ohlc = xts_lai.get_ohlc_data(["ACC-EQ", "DMART-EQ"])
print(ohlc)
```

### Single Symbol

```python
open_price, high, low, close = xts_lai.get_ohlc_data("ACC-EQ")

print(f"OPEN: {open_price}")
print(f"HIGH: {high}")
print(f"LOW: {low}")
print(f"CLOSE: {close}")
```

---

## 4. Get Stock Data

Fetch LTP, open, high, low and close for multiple symbols.

### Function

```python
get_stock_data(names)
```

### Example

```python
stock_data = xts_lai.get_stock_data(["ACC-EQ", "DMART-EQ"])
print(stock_data)
```

---

## 5. Get Ask Price

Fetch the ask price of one or multiple symbols.

### Function

```python
get_askprice(names)
```

### Example

```python
askprice = xts_lai.get_askprice(["ACC-EQ"])
acc_askprice = askprice["ACC-EQ"]
print(f"ACC ASK PRICE: {acc_askprice}")
```

---

## 6. Get Bid Price

Fetch the bid price of one or multiple symbols.

### Function

```python
get_bidprice(names)
```

### Example

```python
bidprice = xts_lai.get_bidprice(["ACC-EQ"])
acc_bidprice = bidprice["ACC-EQ"]
print(f"ACC BID PRICE: {acc_bidprice}")
```

---

## 7. Get Quote

Fetch complete quote information.

### Function

```python
get_quote(names)
```

### Example

```python
quote = xts_lai.get_quote(["ACC-EQ"])
print(quote)
```

---

## 8. Get Open Interest

Fetch open interest values.

### Function

```python
open_interest_values(names)
```

### Example

```python
open_interest = xts_lai.open_interest_values(["BANKNIFTY"])
print(open_interest)
```

---

# Option Functions

## 9. Get ATM, ITM or OTM Strike

Calculate the strike price using LTP, option type and multiplier.

### Function

```python
get_atm_itm_otm_strike(ltp, underlying, multiplier, script_type, expiry)
```

### Multiplier Meaning

```text
0   = ATM
1   = First OTM
2   = Second OTM
-1  = First ITM
-2  = Second ITM
```

### Example

```python
acc_ltp = xts_lai.get_ltp("ACC-EQ")

itm_strike = xts_lai.get_atm_itm_otm_strike(
    acc_ltp,
    "ACC-EQ",
    -1,
    "CE",
    0
)

print(f"ITM STRIKE: {itm_strike}")
```

---

## 10. Get ATM, ITM or OTM Option Script

Return the complete option trading symbol.

### Function

```python
get_atm_itm_otm_script(ltp, underlying, multiplier, script_type, expiry)
```

### Example

```python
option_script = xts_lai.get_atm_itm_otm_script(
    acc_ltp,
    "ACC-EQ",
    0,
    "CE",
    0
)

print(f"OPTION SCRIPT: {option_script}")
```

---

## 11. Get Option Greeks

Calculate option price and Greek values.

### Function

```python
get_option_greek(strike, expiry_date, asset, interest_rate, flag, scrip_type)
```

### Available Flags

```text
price
delta
delta2
theta
rho
vega
gamma
all_val
```

### Example

```python
delta = xts_lai.get_option_greek(
    22100,
    "2026-07-30T15:30:00",
    "NIFTY",
    2,
    "delta",
    "CE"
)

print(f"NIFTY DELTA: {delta}")
```

---

## 12. Get Expiry Dates

Return all available expiry dates for an underlying.

### Function

```python
get_expiry(name)
```

### Example

```python
expiry_dates = xts_lai.get_expiry("BANKNIFTY")
print(expiry_dates)
```

---

## 13. ATM Strike Selection

Return ATM call and put option scripts.

### Function

```python
ATM_Strike_Selection(Underlying, Expiry)
```

### Example

```python
expiry_dates = xts_lai.get_expiry("NIFTY")

ce_script, pe_script, strike = xts_lai.ATM_Strike_Selection(
    "NIFTY",
    expiry_dates[0]
)

print(f"CE SCRIPT: {ce_script}")
print(f"PE SCRIPT: {pe_script}")
print(f"ATM STRIKE: {strike}")
```

---

# Instrument Functions

## 14. Check Valid Instrument

```python
result = xts_lai.check_valid_instrument("BANKNIFTY")
print(result)
```

## 15. Get Lot Size

```python
lot_size = xts_lai.get_lot_size("NIFTY26JUL25000CE")
print(f"LOT SIZE: {lot_size}")
```

## 16. Get Freeze Quantity

```python
freeze_quantity = xts_lai.get_freeze_quantity("NIFTY26JUL25000CE")
print(f"FREEZE QUANTITY: {freeze_quantity}")
```

## 17. Get Split Order Variables

```python
quantity, freeze_quantity, split_count, remaining_quantity = (
    xts_lai.get_split_order_variables("NIFTY26JUL25000CE", 10)
)

print(f"TOTAL QUANTITY: {quantity}")
print(f"FREEZE QUANTITY: {freeze_quantity}")
print(f"SPLIT COUNT: {split_count}")
print(f"REMAINING QUANTITY: {remaining_quantity}")
```

---

# Account Functions

## 18. Get Balance

```python
balance = xts_lai.get_balance()
print(f"AVAILABLE BALANCE: {balance}")
```

## 19. Get Live PnL

```python
live_pnl = xts_lai.get_pnl(complete_order={}, script_details={})
print(f"LIVE PNL: {live_pnl}")
```

---

# Order Functions

> **Warning:** The following functions may place, modify or cancel live orders. Verify all parameters before running them.

## 20. Place Order

### Market Order

```python
order_id = xts_lai.order_placement(
    "ACC-EQ",
    1,
    0,
    0,
    "MARKET",
    "BUY",
    "MIS"
)

print(f"ORDER ID: {order_id}")
```

### Limit Order

```python
order_id = xts_lai.order_placement(
    "ACC-EQ", 1, 2700, 0, "LIMIT", "BUY", "MIS"
)
```

### Stop-Limit Order

```python
order_id = xts_lai.order_placement(
    "ACC-EQ", 1, 2704, 2700, "STOPLIMIT", "BUY", "MIS"
)
```

### Stop-Market Order

```python
order_id = xts_lai.order_placement(
    "ACC-EQ", 1, 0, 2700, "STOPMARKET", "BUY", "MIS"
)
```

## 21. Get Order History

```python
status = xts_lai.get_orderhistory(order_id)
print(f"ORDER STATUS: {status}")
```

## 22. Get Executed Price

```python
executed_price = xts_lai.get_executed_price(order_id)
print(f"EXECUTED PRICE: {executed_price}")
```

## 23. Order Report

```python
order_status, order_price = xts_lai.order_report()
print(order_status)
print(order_price)
```

## 24. Modify Order

```python
modified_order_id = xts_lai.modify_order(
    order_id,
    "LIMIT",
    1,
    2705,
    0,
    "MIS"
)

print(f"MODIFIED ORDER ID: {modified_order_id}")
```

## 25. Cancel Order

```python
xts_lai.cancel_order(order_id)
```

## 26. Cancel All Orders

```python
order_details = xts_lai.cancel_all_orders()
print(order_details)
```

---

# Indicator Functions

## 27. Calculate PCR

```python
pcr_data = xts_lai.calculate_pcr(call_data, put_data)
print(pcr_data)
```

## 28. Calculate VWAP

```python
historical_data = xts_lai.get_historical_data("ACC-EQ", "5minute", 5)
vwap_data = xts_lai.calculate_vwap(historical_data)
print(vwap_data)
```

## 29. Calculate ATR

```python
atr_data = xts_lai.atr(historical_data, 14)
print(atr_data)
```

## 30. Add SuperTrend

```python
supertrend_data = xts_lai.add_super_trend(
    historical_data,
    10,
    3,
    "SuperTrend"
)

print(supertrend_data)
```

## 31. Calculate RSI

```python
rsi = xts_lai.calculate_rsi(historical_data["close"], 14)
print(rsi)
```

## 32. Calculate Moving Average

```python
moving_average = xts_lai.calculate_ma(
    historical_data["close"],
    20,
    "EMA"
)

print(moving_average)
```

## 33. Calculate Linear Regression

```python
linear_regression = xts_lai.calculate_linreg(
    historical_data["close"],
    36
)

print(linear_regression)
```

## 34. Calculate Indicators

```python
indicator_data = xts_lai.calculate_indicators(
    historical_data,
    rsi_length=14,
    ma_length=14,
    ma_type="SMA",
    linreg_length=36
)

print(indicator_data)
```

## 35. Detect RSI Tops and Bottoms

```python
result = xts_lai.detect_rsi_tops_bottoms(
    indicator_data,
    rsi_col="RSI",
    upper_band=70,
    lower_band=30,
    prd=10,
    min_bars=5,
    max_dis=100
)

print(result)
```

---

# Additional Functions

## 36. Get Spot Value

```python
spot_value = xts_lai.get_spot_value("CRUDEOIL", "FUTCOM")
print(spot_value)
```

## 37. Check Expiry Date

```python
expiry_dates = xts_lai.get_expiry("NIFTY")
is_available = xts_lai.check_expiry_date("NIFTY", expiry_dates[0])
print(is_available)
```

## 38. Get Bid and Ask

```python
ask, bid = xts_lai.get_bid_ask("ACC-EQ")
print(f"ASK: {ask}")
print(f"BID: {bid}")
```

## 39. Get Combined Data

```python
combined_data = xts_lai.get_combined_data(
    instrument_id=12345,
    start="Jul 01 2026 091500",
    end="Jul 16 2026 153000"
)

print(combined_data)
```

## 40. Get Raw Script Data

```python
raw_data = xts_lai.get_data_for_single_script(["ACC-EQ"])
print(raw_data)
```

## 41. Send Telegram Alert

```python
xts_lai.send_telegram_alert(
    message="XTS-LAI alert",
    receiver_chat_id="YOUR_CHAT_ID",
    bot_token="YOUR_BOT_TOKEN"
)
```

---

# Complete Basic Usage

```python
from XTS_LAI import LetsAlgoIt

xts_lai = login(
    interactive_api_key="YOUR_INTERACTIVE_API_KEY",
    interactive_api_secret="YOUR_INTERACTIVE_API_SECRET",
    market_api_key="YOUR_MARKET_API_KEY",
    market_api_secret="YOUR_MARKET_API_SECRET",
    clientID="YOUR_CLIENT_ID"
)

acc_df = xts_lai.get_historical_data(
    "ACC-EQ",
    "5minute",
    xts_lai.intervals_dict["5minute"]
)
print(acc_df)

acc_ltp = xts_lai.get_ltp("ACC-EQ")
print(f"ACC LTP: {acc_ltp}")

ohlc = xts_lai.get_ohlc_data(["ACC-EQ"])
print(ohlc)

askprice = xts_lai.get_askprice(["ACC-EQ"])
print(askprice)

bidprice = xts_lai.get_bidprice(["ACC-EQ"])
print(bidprice)

expiry_dates = xts_lai.get_expiry("BANKNIFTY")
print(expiry_dates)

is_valid = xts_lai.check_valid_instrument("BANKNIFTY")
print(is_valid)
```

---

# Important Notes

- Valid XTS API credentials are required.
- Your public IP may need to be added to the XTS trusted-IP list.
- Interactive API credentials are required for order functions.
- Market Data credentials are required for LTP, OHLC and historical-data functions.
- Check all order parameters before sending live orders.
- Never place API credentials directly inside publicly shared source code.

---

# About LET'S ALGOIT

**XTS-LAI** is maintained by **LET'S ALGOIT** to provide a simple Python interface for XTS trading and market-data operations.
