@Tradehull_Imran sir need your help I am not able to get stock OI data
I need previous day and current day OI data i have tried so many times but getting an error could you please help and please fix this issue and guide me what code need to write
can you please provide me previous day OI data and current day OI data i can fetch the both the data please provide me correct code
can you please provide me full code so i can print the OI data please help.
Watchlist = [‘PAGEIND’, ‘CHAMBLFERT’, ‘BOSCHLTD’, ‘SHREECEM’, ‘ABBOTINDIA’, ‘DIXON’, ‘MARUTI’, ‘ULTRACEMCO’, ]
traded_watchlist = # Track traded stocks
active_position = None # Track active stock position
trade_info = {“options_name”: None, “qty”: None, “entry_price”: None, “sl”: None, “target”: None}
in_trading = False # Flag to indicate if the system is in an active trade
profit_target = 2000 # Profit target in INR
start_time = datetime.time(9, 18) # Time to start trading
end_time = datetime.time(23, 20) # Time to close positions
algo_end_time = datetime.time(23, 30) # Time to end the algo
Track the number of buys and sells
buy_count = 0
sell_count = 0
while True:
try:
current_time = datetime.datetime.now().time()
# Check if it's the time to start trading
if current_time >= start_time and current_time <= end_time and not in_trading:
for stock_name in watchlist: # Start iterating through the watchlist
if stock_name in traded_watchlist:
continue # Skip the stock if it has already been traded
time.sleep(2)
print(f"Scanning {stock_name}")
chart_5 = tsl.get_historical_data(tradingsymbol=stock_name, exchange='NSE', timeframe="5")
if chart_5.empty:
print(f"No data for {stock_name}")
continue
# Assuming the chart_5 contains data for previous and current prices
previous_close = chart_5['close'].iloc[-2] # Previous day's close price
current_ltp = chart_5['close'].iloc[-1] # Current day's last traded price
# Get previous and current volume data
previous_volume = chart_5['volume'].iloc[-2] # Previous day's volume
current_volume = chart_5['volume'].iloc[-1] # Current day's volume
# Fetch Open Interest (OI) data for the stock
previous_oi = tsl.get_open_interest(stock_name, date=datetime.datetime.now() - datetime.timedelta(days=1))
current_oi = tsl.get_open_interest(stock_name, date=datetime.datetime.now())
# Print the values of previous close, current LTP, and volumes for debugging
print(f"Stock: {stock_name} | Previous Close: {previous_close} | Current LTP: {current_ltp} | Previous Volume: {previous_volume} | Current Volume: {current_volume}")
print(f"Stock: {stock_name} | Previous OI: {previous_oi} | Current OI: {current_oi}")
# Calculate percentage change in price
price_change_percent = ((current_ltp - previous_close) / previous_close) * 100
# Calculate percentage change in volume
volume_change_percent = ((current_volume - previous_volume) / previous_volume) * 100
# Calculate OI percentage change
oi_change_percent = ((current_oi - previous_oi) / previous_oi) * 100
# Print price and volume change for debugging
print(f"Stock: {stock_name} | Price Change: {price_change_percent:.2f}% | Volume Change: {volume_change_percent:.2f}% | OI Change: {oi_change_percent:.2f}%")