from datetime import date, time, datetime, timedelta
import math
from nsepy.derivatives import get_expiry_date
from nse_fno import *
import os
import sys
# -------------------- begin declaration section ------------------
# days between entry and exit
symbol = "BANKNIFTY"
lot_size = 40
# ------------------- end of declaration section --------------------
if len(sys.argv) < 4:
exit
arg_mon = str(sys.argv[1])
arg_day = str(sys.argv[2])
arg_fun = str(sys.argv[3])
beg_date = date(2016,int(arg_mon),int(arg_day))
beg_time = datetime.combine(beg_date, time())
month_expiry = get_expiry_date(beg_time.year, beg_time.month)
leg_beg_time = next_working_day(beg_time)
weekly_expiry = next_weekly_expiry(leg_beg_time)
if len(sys.argv) == 5:
base_strike = int(sys.argv[4])
else:
future = future_price(symbol, leg_beg_time, leg_beg_time, month_expiry, csvname="future")
base_strike = (math.trunc(future / 100)) * 100
if arg_fun == "bc":
monthly = option_price(symbol, beg_time, base_strike, month_expiry, str_trans_type="BUY :", str_option="CE", csvname="monthly")
monthly *= lot_size
write_to_csv([beg_date,"BUY", "CE", base_strike,monthly])
if arg_fun == "sc":
monthly = option_price(symbol, beg_time, base_strike, month_expiry, str_trans_type="SELL:", str_option="CE", csvname="monthly")
monthly *= lot_size
write_to_csv([beg_date,"SELL", "CE", base_strike,monthly])
if arg_fun == "bp":
monthly = option_price(symbol, beg_time, base_strike, month_expiry, str_trans_type="BUY :", str_option="PE", csvname="monthly")
monthly *= lot_size
write_to_csv([beg_date,"BUY" ,"PE", base_strike,monthly])
if arg_fun == "sp":
monthly = option_price(symbol, beg_time, base_strike, month_expiry, str_trans_type="SELL:", str_option="PE", csvname="monthly")
monthly *= lot_size
write_to_csv([beg_date,"SELL", "PE", base_strike,monthly])