INNER CODE UNIT · Python

RTH_end

AlexShakaev/backtesting_and_algotrading_options_with_Interactive_Brokers_API · main.py:56

    RTH_end = RTH_start + timedelta(hours=6, minutes=15)  
    RTH_end = RTH_end.replace(tzinfo=ny)
    
    get_portfolio(client)    
          
    spy_filter = ExecutionFilter()
    spy_filter.symbol = 'SPY'
    spy_filter.secType = ['OPT', 'BAG']
    client.exec_df = client.exec_df[0:0]
    get_exec_info(client, spy_filter)    
    
    # check if we got existing position in spy
    spy_df = client.acc_df[(client.acc_df['Symbol'] == 'SPY') & (client.acc_df['SecType'] == 'OPT')]
    acc = client.acc_df
    trade_time = datetime.now(ny)
    if any(spy_df.loc[:, 'position']): 
        l = acc.loc[:, 'position'].loc[lambda x: x == 1].index
        long_con_id = int(acc.loc[l].ConID.values[0])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…