Written small piece of Python Code to process trade log and paste as table in HTML. you will get expiry trade log faster and smoother hereafter

# import pandas library
import pandas as pd
import os
import glob
import ctypes # An included library with Python install.

# define trade log file name
tradelog_filename = “TradeLog.csv”
tradehtml_filename = “TradeLog.html”

# define account id to filer
account_id = your_id

# Remove the old file
if os.path.exists(tradelog_filename):
os.remove(tradelog_filename)

extension = ‘xls’
all_filenames = [i for i in glob.glob(‘*.{}’.format(extension))]

# Merge all trade log files
df = pd.concat( [ pd.read_excel(f) for f in all_filenames])

# Filter only specific user and completed status
df = df.loc[(df[‘AccountId’] == account_id) & (df[‘Status’] == “complete”)]

# Set ExchangeTimeStamp field as datetime format as per NEST & short by the same
df[‘ExchangeTimeStamp’] = pd.to_datetime(df[‘ExchangeTimeStamp’], format=’%d-%b-%Y %H:%M:%S’)
df = df.sort_values(by=”ExchangeTimeStamp”, ascending=False)

# List only the columes we are interested in and write to CVS
df = df[[‘Buy/Sell’, ‘Trading Symbol’, ‘Total Qty’, ‘Average Price’, ‘ExchangeTimeStamp’]]
df.to_csv(tradelog_filename, index=False )

trading_terminal_html_string = ”

Trading Terminal

\n\n\n

trading_log_html_string = ”

Trading Logs

df = pd.read_csv(tradelog_filename)
df_table_html_string = df.to_html()

Html_file = open(tradehtml_filename,”w”)
Html_file.write(trading_terminal_html_string)
Html_file.write(trading_log_html_string)
Html_file.write(df_table_html_string)
Html_file.close()

ctypes.windll.user32.MessageBoxW(0, “Post with TradeLog created in HTML.”, “TradeLog-Done”, 1)

Jegathesan Durairaj, a mathematician by qualification, an Ex-software professional and now a full time Risk Defined Option Writer. With his Open Book Strategies, he is the most known identity in twitter as itjegan, with huge followers. He had won Zerodha 60 Day Challenge – 10 Times round-the-clock. He is one of the prime Option Writing Trainer and tutored close to 1000 members till now.

He is the Mastermind of CapitalZone РActive Option Trading where Traders can avail Trading Chart with customised indicators, FNO tools and Payoff analysis. His keynote is to provide whole FNO deets to be handy for Traders in a sole place.

Now he is taking more heed on hedging portfolio in Option Writing where we might subject to more market risk. He is streamlining his strategies often and improving perpetually. At this time unfolding ways to measure good-quality Trend Following System.

Conducting workshop in all Metro Cities (Delhi, Mumbai, Bangalore, Chennai and Coimbatore) often based on queries from Traders.