Provide the entry time to the iron condor entry script in order to be explicit about the expected entry time of each trade
This commit is contained in:
parent
b5168bd92d
commit
9ce9067e5d
@ -13,7 +13,6 @@ from ibkr.order_action import BUY, SELL
|
||||
from options_chain import OptionsChain
|
||||
from option_type import OptionType
|
||||
from os import getenv
|
||||
from pytz import timezone
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@ -77,19 +76,19 @@ def monitor_spread_price(short_leg: OptionLeg, long_leg: OptionLeg, stop_price:
|
||||
market_data[leg] = leg_market_data
|
||||
leg_market_data.updateEvent += on_market_data_update
|
||||
|
||||
def enter_iron_condor():
|
||||
def enter_iron_condor(entry_time: datetime):
|
||||
logging.basicConfig(
|
||||
filename=f'iron_condor_{datetime.now().strftime("%H%M")}.log',
|
||||
filename=f'iron_condor_{entry_time.strftime("%H%M")}.log',
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s : %(levelname)s : %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
try:
|
||||
_enter_iron_condor()
|
||||
_enter_iron_condor(entry_time)
|
||||
except Exception as e:
|
||||
logging.error("Error: %s", traceback.format_exc())
|
||||
|
||||
def _enter_iron_condor():
|
||||
def _enter_iron_condor(entry_time: datetime):
|
||||
ibkr_host = getenv('IBKR_HOST')
|
||||
ibkr_port = getenv('IBKR_PORT')
|
||||
ibkr_client = Client(host = ibkr_host, port = ibkr_port)
|
||||
@ -168,15 +167,11 @@ def _enter_iron_condor():
|
||||
'Open': fill_price
|
||||
}
|
||||
|
||||
# Convert timezone and replace seconds and microseconds to facilitate joins with backtest table.
|
||||
now = datetime.now().astimezone(timezone('US/Eastern'))
|
||||
now = now.replace(second = 0, microsecond = 0, tzinfo = None)
|
||||
|
||||
trade_records.append({
|
||||
'Date': now.date(),
|
||||
'Date': datetime.now().date(),
|
||||
'Symbol': symbol,
|
||||
'Strategy': f'${credit_target:.2f} Iron Condor',
|
||||
'Entry Time': now,
|
||||
'Entry Time': entry_time.replace(tzinfo = None),
|
||||
'Exit Time': None,
|
||||
'Spreads': [call_spread_details, put_spread_details],
|
||||
'Profit': None
|
||||
|
@ -44,7 +44,7 @@ if __name__ == '__main__':
|
||||
# Prevent scheduling for times that have already elapsed.
|
||||
if schedule_time > now:
|
||||
print(f'Scheduling for {entry_time}.')
|
||||
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade)
|
||||
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade, schedule_time)
|
||||
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
|
Loading…
Reference in New Issue
Block a user