1

i hv got multiple error massage while going to resampling live streaming data to 15M time frame, if i remove we remove resampling code, the programing working fine.

import time,os,datetime,math                                                                                                                
import xlwings as xw
from time import sleep
import logging
from alice_blue import *
import pandas as pd
import datetime
import pdb  
from pandas.io.json import json_normalize
############################################################################

logging.basicConfig(level=logging.DEBUG)

access_token = open('access_token.txt','r').read().strip()

alice = AliceBlue(username='username', password='password', access_token=access_token, master_contracts_to_download=['NFO'])
#############################################################################
token = 0                                                                                                                                       
ltp = 0
open_price=0
high_price=0
low_price=0
close_price=0
t_stamp=0
row_no =2

socket_opened = False
def event_handler_quote_update(message):
    # print(f"quote update {message}")
    global row_no
    global token
    global ltp
    global open_price
    global high_price
    global close_price
    global low_price
    global t_stamp
    
    token = message['token']
    ltp =   message['ltp']
    open_price = message['open']
    high_price = message['high']
    low_price = message['low']
    close_price = message['close']
    t_stamp = message['exchange_time_stamp']
    
####################################################################################
    wb = xw.Book('TickData.xlsx')        
    sht = wb.sheets['Sheet1']
    sht.range('A' + str(row_no)).value = token                                                      
    sht.range('B' + str(row_no)).value = datetime.datetime.fromtimestamp(int(t_stamp)).strftime('%Y-%m-%d %H:%M:%S')  
    sht.range('C' + str(row_no)).value = ltp                                                        
    sht.range('D' + str(row_no)).value = open_price                                                 
    sht.range('E' + str(row_no)).value = high_price                                                 
    sht.range('F' + str(row_no)).value = low_price                                                  
    sht.range('G' + str(row_no)).value = close_price                                                

    row_no = row_no + 1 
    # print(token, t_stamp, ltp, open_price, high_price, low_price, close_price)
    
####################################################################################    
def open_callback():
    global socket_opened
    socket_opened = True

alice.start_websocket(subscribe_callback=event_handler_quote_update,
                      socket_open_callback=open_callback,
                      run_in_background=True)
while(socket_opened==False):
    pass
    
df=pd.read_excel('TickData.xlsx', names=['token','t_stamp','ltp','open_price','high_price','low_price','close_price'], index_col=1, parse_dates=True)     
df=pd.DataFrame(df)
data=df['ltp'].resample('1min').ohlc()                                                                                                                  
print(data)
data.to_excel('a.xlsx')


alice.subscribe(alice.get_instrument_by_symbol('NFO', 'BANKNIFTY SEP FUT'), LiveFeedType.MARKET_DATA)

sleep(0.200)

# print(token, t_stamp, open_price, high_price, low_price, close_price)
sleep(4000)
####################################################################################

i have requested to create a OHLC resampling on every 15M complated and basic of live data received.

Further can we do the same in one excel and/or without saving data to any csv/xls.

thanks for advance & sorry for my coding skills.

Anchal2804
  • 11
  • 1

0 Answers0