Skip to main content

LET'S ALGOIT Python SDK for XTS Interactive and Market Data APIs

Project description

XTS-LAI

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

Installation

pip install XTS-LAI

Login

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.

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

Complete SDK Usage

See XTS_codebase_usage.py for full examples.

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

xts_lai-1.0.3.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

xts_lai-1.0.3-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file xts_lai-1.0.3.tar.gz.

File metadata

  • Download URL: xts_lai-1.0.3.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for xts_lai-1.0.3.tar.gz
Algorithm Hash digest
SHA256 397d80f7a30ef9c18be5ef00f2f57f42a00efa8650a20e83e56e0ce87aa231e0
MD5 bfe2f6cdfe0d303bfa7d562dc9277827
BLAKE2b-256 d0ee5f65ee22f3725828708ae4a8866e55c4bdb8fa2d155bf7ff833358b40600

See more details on using hashes here.

File details

Details for the file xts_lai-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: xts_lai-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for xts_lai-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 83d436a3dd2aec11bcb5276c4e09927bb493000df235a4882af7f3661d2f2d8a
MD5 1e97828cbaca8b97fe8016bff9d1c6a7
BLAKE2b-256 fff7a88755eeb467e39865dd77c0c411590d8faf787326846c21137a7f776f66

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