Metadata-Version: 2.1
Name: XTS-LAI
Version: 1.0.2
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

Official **LET'S ALGOIT** Python SDK wrapper for XTS Interactive and Market Data APIs.

## Installation

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

## 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",
)
```

The returned `xts_lai` object provides access to market data, historical candles, indicators, option utilities, account details, order management, instrument validation, and Telegram alerts.

## Important safety notes

- Never publish API keys, API secrets, client IDs, PyPI tokens, or Telegram bot tokens.
- Keep `RUN_LIVE_ORDER_EXAMPLES = False` unless you intentionally want to place, modify, or cancel real orders.
- Test one section at a time with valid symbols and current expiry contracts.
- XTS login may require your current public IP address to be whitelisted by your broker or administrator.

## Complete SDK usage

The following reference includes usage examples for all public SDK functions.

```python
"""Complete XTS_LAI SDK usage reference.

IMPORTANT
---------
1. Replace all credential placeholders before running.
2. Keep RUN_LIVE_ORDER_EXAMPLES = False unless you intentionally want to
   place, modify, or cancel real orders.
3. Run one example section at a time while testing.
"""

from XTS_LAI import LetsAlgoIt
import pandas as pd


# ============================================================
# LOGIN
# ============================================================

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",
)

# Change these symbols according to your account and current contracts.
EQUITY_SYMBOL = "ACC-EQ"
INDEX_SYMBOL = "BANKNIFTY"
OPTION_SYMBOL = "BANKNIFTY_OPTION_SYMBOL"
EXPIRY_DATE = "YYYY-MM-DDTHH:MM:SS"

# Live order and Telegram examples remain disabled by default.
RUN_LIVE_ORDER_EXAMPLES = False
RUN_TELEGRAM_EXAMPLE = False


# ============================================================
# 1. LOGIN AGAIN, WHEN REQUIRED
# ============================================================
# login_call() is already called by login(). Use this only after logout/session
# expiry when you intentionally want to authenticate the same object again.
# xts_lai.login_call()


# ============================================================
# 2. PARAMETER VALIDATION
# ============================================================
parameter_types = {"ACC-EQ": str, 1: int}
xts_lai.check_if_parameter_is_correct(parameter_types)
print("Parameter validation completed")


# ============================================================
# 3. INSTRUMENT MASTER
# ============================================================
instrument_master = xts_lai.get_instrument_file()
print(instrument_master.head())


# ============================================================
# 4. HISTORICAL DATA
# ============================================================
historical_df = xts_lai.get_historical_data(
    EQUITY_SYMBOL,
    "5minute",
    xts_lai.intervals_dict["5minute"],
)
print(historical_df.tail())


# ============================================================
# 5. PUT/CALL RATIO
# ============================================================
# Replace these sample DataFrames with actual CE and PE historical data.
ce_data = pd.DataFrame({
    "date": pd.date_range("2026-01-01", periods=3, freq="5min"),
    "volume": [100, 120, 150],
})
pe_data = pd.DataFrame({
    "date": pd.date_range("2026-01-01", periods=3, freq="5min"),
    "volume": [110, 140, 135],
})
pcr_df = xts_lai.calculate_pcr(ce_data, pe_data)
print(pcr_df)


# ============================================================
# 6. VWAP
# ============================================================
if not historical_df.empty:
    vwap_df = xts_lai.calculate_vwap(historical_df.copy())
    print(vwap_df.tail())


# ============================================================
# 7. ATR SUPPORT DATA
# ============================================================
if not historical_df.empty:
    atr_df = xts_lai.atr(historical_df.copy(), period=14)
    print(atr_df.tail())


# ============================================================
# 8. SUPER TREND
# ============================================================
if not historical_df.empty:
    supertrend_df = xts_lai.add_super_trend(
        historical_df.copy(),
        period=10,
        multiplier=3,
        supertrendname="SuperTrend",
    )
    print(supertrend_df.tail())


# ============================================================
# 9. LIVE PNL
# ============================================================
# Current implementation reads positions from XTS. The two parameters are kept
# for compatibility with the SDK function signature.
live_pnl = xts_lai.get_pnl(complete_order={}, script_details={})
print("Live PnL:", live_pnl)


# ============================================================
# 10. FUTURE/SPOT DESCRIPTION
# ============================================================
spot_value = xts_lai.get_spot_value("CRUDEOIL", series="FUTCOM")
print("Spot/Future value:", spot_value)


# ============================================================
# 11. RSI
# ============================================================
if not historical_df.empty:
    rsi = xts_lai.calculate_rsi(historical_df["close"], rsi_length=14)
    print(rsi.tail())


# ============================================================
# 12. MOVING AVERAGE
# ============================================================
if not historical_df.empty:
    sma = xts_lai.calculate_ma(
        historical_df["close"],
        length=14,
        ma_type="SMA",
    )
    print(sma.tail())


# ============================================================
# 13. LINEAR REGRESSION
# ============================================================
if not historical_df.empty:
    linreg = xts_lai.calculate_linreg(historical_df["close"], length=14)
    print(linreg.tail())


# ============================================================
# 14. RSI TOPS AND BOTTOMS
# ============================================================
if not historical_df.empty:
    rsi_signal_df = historical_df.copy()
    rsi_signal_df["RSI"] = xts_lai.calculate_rsi(
        rsi_signal_df["close"],
        rsi_length=14,
    )
    rsi_signal_df = xts_lai.detect_rsi_tops_bottoms(rsi_signal_df)
    print(rsi_signal_df.tail())


# ============================================================
# 15. COMPLETE INDICATORS
# ============================================================
if not historical_df.empty:
    indicator_df = xts_lai.calculate_indicators(
        historical_df.copy(),
        rsi_length=14,
        ma_length=14,
        ma_type="SMA",
        linreg_length=36,
    )
    print(indicator_df.tail())


# ============================================================
# 16. AVAILABLE BALANCE
# ============================================================
balance = xts_lai.get_balance()
print("Available balance:", balance)


# ============================================================
# 17. EXPIRY DATES
# ============================================================
expiry_dates = xts_lai.get_expiry(INDEX_SYMBOL)
print("Expiry dates:", expiry_dates)


# ============================================================
# 18. CHECK EXPIRY DATE
# ============================================================
if expiry_dates:
    expiry_is_valid = xts_lai.check_expiry_date(INDEX_SYMBOL, expiry_dates[0])
    print("Expiry valid:", expiry_is_valid)


# ============================================================
# 19. LOT SIZE
# ============================================================
lot_size = xts_lai.get_lot_size(EQUITY_SYMBOL)
print("Lot size:", lot_size)


# ============================================================
# 20. FREEZE QUANTITY
# ============================================================
freeze_quantity = xts_lai.get_freeze_quantity(EQUITY_SYMBOL)
print("Freeze quantity:", freeze_quantity)


# ============================================================
# 21. SPLIT ORDER VARIABLES
# ============================================================
quantity, freeze_qty, split_count, remaining_qty = (
    xts_lai.get_split_order_variables(EQUITY_SYMBOL, lots=1)
)
print(
    "Quantity:", quantity,
    "Freeze:", freeze_qty,
    "Splits:", split_count,
    "Remaining:", remaining_qty,
)


# ============================================================
# 22. ATM STRIKE SELECTION
# ============================================================
if expiry_dates:
    ce_script, pe_script, atm_strike = xts_lai.ATM_Strike_Selection(
        INDEX_SYMBOL,
        expiry_dates[0],
    )
    print("ATM CE:", ce_script)
    print("ATM PE:", pe_script)
    print("ATM strike:", atm_strike)


# ============================================================
# 23. COMBINED OHLC DATA USING INSTRUMENT ID
# ============================================================
# Replace the ID and date strings with valid values.
# combined_df = xts_lai.get_combined_data(
#     instrument_id=12345,
#     start="Jul 01 2026 091500",
#     end="Jul 01 2026 153000",
# )
# print(combined_df.tail())


# ============================================================
# 24. BID AND ASK TOGETHER
# ============================================================
ask, bid = xts_lai.get_bid_ask(EQUITY_SYMBOL)
print("Ask:", ask, "Bid:", bid)


# ============================================================
# 25. RAW QUOTE RESPONSE
# ============================================================
raw_quote = xts_lai.get_data_for_single_script(EQUITY_SYMBOL)
print(raw_quote)


# ============================================================
# 26. LTP — SINGLE AND MULTIPLE SYMBOLS
# ============================================================
single_ltp = xts_lai.get_ltp(EQUITY_SYMBOL)
print("Single LTP:", single_ltp)

multiple_ltp = xts_lai.get_ltp(["ACC-EQ", "DMART-EQ"])
print("Multiple LTP:", multiple_ltp)


# ============================================================
# 27. STOCK DATA — LTP, OPEN, HIGH, LOW, CLOSE
# ============================================================
stock_data = xts_lai.get_stock_data(["ACC-EQ", "DMART-EQ"])
print(stock_data)


# ============================================================
# 28. OHLC — SINGLE AND MULTIPLE SYMBOLS
# ============================================================
open_price, high, low, close = xts_lai.get_ohlc_data(EQUITY_SYMBOL)
print("OHLC:", open_price, high, low, close)

multiple_ohlc = xts_lai.get_ohlc_data(["ACC-EQ", "DMART-EQ"])
print(multiple_ohlc)


# ============================================================
# 29. OPEN INTEREST
# ============================================================
open_interest = xts_lai.open_interest_values([OPTION_SYMBOL])
print("Open interest:", open_interest)


# ============================================================
# 30. ASK PRICE — SINGLE AND MULTIPLE SYMBOLS
# ============================================================
single_ask = xts_lai.get_askprice(EQUITY_SYMBOL)
print("Single ask:", single_ask)

multiple_ask = xts_lai.get_askprice(["ACC-EQ", "DMART-EQ"])
print("Multiple ask:", multiple_ask)


# ============================================================
# 31. BID PRICE — SINGLE AND MULTIPLE SYMBOLS
# ============================================================
single_bid = xts_lai.get_bidprice(EQUITY_SYMBOL)
print("Single bid:", single_bid)

multiple_bid = xts_lai.get_bidprice(["ACC-EQ", "DMART-EQ"])
print("Multiple bid:", multiple_bid)


# ============================================================
# 32. ATM / ITM / OTM STRIKE
# ============================================================
index_ltp = xts_lai.get_ltp(INDEX_SYMBOL)
atm_strike = xts_lai.get_atm_itm_otm_strike(
    index_ltp,
    INDEX_SYMBOL,
    multiplier=0,
    script_type="CE",
    expiry=0,
)
print("ATM strike:", atm_strike)


# ============================================================
# 33. ATM / ITM / OTM OPTION SCRIPT
# ============================================================
atm_option_script = xts_lai.get_atm_itm_otm_script(
    index_ltp,
    INDEX_SYMBOL,
    multiplier=0,
    script_type="CE",
    expiry=0,
)
print("ATM option script:", atm_option_script)


# ============================================================
# 34. OPTION GREEKS
# ============================================================
# Replace expiry and strike with current valid contract values.
# option_delta = xts_lai.get_option_greek(
#     strike=25000,
#     expiry_date=EXPIRY_DATE,
#     asset="NIFTY",
#     interest_rate=2,
#     flag="delta",
#     scrip_type="CE",
# )
# print("Option delta:", option_delta)


# ============================================================
# 35. ORDER PLACEMENT — LIVE ORDER
# ============================================================
order_id = None
if RUN_LIVE_ORDER_EXAMPLES:
    order_id = xts_lai.order_placement(
        tradingsymbol=EQUITY_SYMBOL,
        quantity=1,
        price=0,
        trigger_price=0,
        order_type="MARKET",
        transaction_type="BUY",
        trade_type="MIS",
    )
    print("Order ID:", order_id)


# ============================================================
# 36. ORDER HISTORY
# ============================================================
if RUN_LIVE_ORDER_EXAMPLES and order_id:
    order_status = xts_lai.get_orderhistory(order_id)
    print("Order status:", order_status)


# ============================================================
# 37. EXECUTED PRICE
# ============================================================
if RUN_LIVE_ORDER_EXAMPLES and order_id:
    executed_price = xts_lai.get_executed_price(order_id)
    print("Executed price:", executed_price)


# ============================================================
# 38. ORDER REPORT
# ============================================================
order_status_report, order_price_report = xts_lai.order_report()
print("Order status report:", order_status_report)
print("Order price report:", order_price_report)


# ============================================================
# 39. MODIFY ORDER — LIVE ORDER
# ============================================================
if RUN_LIVE_ORDER_EXAMPLES and order_id:
    modified_order_id = xts_lai.modify_order(
        appOrderID=order_id,
        modifiedOrderType="LIMIT",
        modifiedOrderQuantity=1,
        modifiedLimitPrice=2705,
        modifiedStopPrice=0,
        trade_type="MIS",
    )
    print("Modified order ID:", modified_order_id)


# ============================================================
# 40. CANCEL ORDER — LIVE ORDER
# ============================================================
if RUN_LIVE_ORDER_EXAMPLES and order_id:
    xts_lai.cancel_order(order_id)
    print("Order cancellation requested")


# ============================================================
# 41. CANCEL ALL ORDERS / CLOSE MIS POSITIONS — LIVE ACTION
# ============================================================
if RUN_LIVE_ORDER_EXAMPLES:
    cancelled_orders = xts_lai.cancel_all_orders()
    print("Cancelled orders:", cancelled_orders)


# ============================================================
# 42. CHECK VALID INSTRUMENT
# ============================================================
instrument_status = xts_lai.check_valid_instrument(INDEX_SYMBOL)
print(instrument_status)


# ============================================================
# 43. TELEGRAM ALERT
# ============================================================
if RUN_TELEGRAM_EXAMPLE:
    xts_lai.send_telegram_alert(
        message="XTS_LAI test alert",
        receiver_chat_id="YOUR_TELEGRAM_CHAT_ID",
        bot_token="YOUR_TELEGRAM_BOT_TOKEN",
    )
    print("Telegram alert requested")

```

## Package version

Current version: `1.0.2`

## Support

Website: https://letsalgoit.com
