Skip to main content

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

Project description

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:

1.1.3

Installation

Install version 1.1.3 directly with one command:

pip install XTS-LAI==1.1.3

To always install the latest available version:

pip install XTS-LAI

TA-Lib is optional. The SDK includes built-in pandas/numpy implementations for RSI and ATR, so Windows users do not need Microsoft C++ Build Tools. To use native TA-Lib separately:

pip install "XTS-LAI[talib]"

To upgrade later:

pip install --upgrade XTS-LAI

Import and 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"
)

After successful login, all SDK functions are available through:

xts_lai

Market Data Functions

1. Historical Data

Fetch historical candle data for a trading symbol.

Function

get_historical_data(name, timeframe, interval)

Supported Timeframes

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

Example

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

get_ltp(name)

Example

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

get_ohlc_data(names)

Multiple Symbols

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

Single Symbol

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

get_stock_data(names)

Example

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

get_askprice(names)

Example

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

get_bidprice(names)

Example

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

get_quote(names)

Example

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

8. Get Open Interest

Fetch open interest values.

Function

open_interest_values(names)

Example

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

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

Multiplier Meaning

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

Example

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

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

Example

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

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

Available Flags

price
delta
delta2
theta
rho
vega
gamma
all_val

Example

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

get_expiry(name)

Example

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

13. ATM Strike Selection

Return ATM call and put option scripts.

Function

ATM_Strike_Selection(Underlying, Expiry)

Example

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

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

15. Get Lot Size

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

16. Get Freeze Quantity

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

17. Get Split Order Variables

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

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

19. Get Live PnL

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

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

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

Limit Order

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

Stop-Limit Order

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

Stop-Market Order

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

21. Get Order History

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

22. Get Executed Price

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

23. Order Report

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

24. Modify Order

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

xts_lai.cancel_order(order_id)

26. Cancel All Orders

order_details = xts_lai.cancel_all_orders()
print(order_details)

Indicator Functions

27. Calculate PCR

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

28. Calculate VWAP

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

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

30. Add SuperTrend

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

print(supertrend_data)

31. Calculate RSI

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

32. Calculate Moving Average

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

print(moving_average)

33. Calculate Linear Regression

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

print(linear_regression)

34. Calculate Indicators

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

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

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

37. Check Expiry Date

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

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

39. Get Combined Data

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

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

41. Send Telegram Alert

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

Complete Basic Usage

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.

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.1.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.1.3-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xts_lai-1.1.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.1.3.tar.gz
Algorithm Hash digest
SHA256 9e5ee5345c7126b1d39c3c793eea9380ad7f5a5e78ce13572ab3a8aaf5ff7251
MD5 545183e2aa41a214dfd78ccc89ba2521
BLAKE2b-256 f1871ed68981b4f70a3d4ce9f08c5015281d085243f937ef18fb8cde5e6cd3a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xts_lai-1.1.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.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2486ba99a228c78c4911283c045db59788b963a8d5722508eaf65dd2341ad8f8
MD5 590c2b18ca8fa4bd652aab222004a7a5
BLAKE2b-256 2a4396c3dec4c15aa83bff8beca7cf6c925ac7b33ee00af02f2b34fb38020e1e

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