INNER CODE UNIT · Python
spread_price
AlexShakaev/backtesting_and_algotrading_options_with_Interactive_Brokers_API · main.py:160
spread_price = get_spread_price(client, bag_con)*100
pnl = np.abs(spread_price) >= premium *1.5
if pnl or (bocd.cp_detected and client.data['c'].iloc[-1] < client.data['c'].iloc[-3]) or (current_time - trade_time) / pd.Timedelta(5, "d") > 5:
if client.entered:
print('Selling spread')
client.reqAccountUpdates(True, "")
client.reqGlobalCancel()
lmt_price = get_spread_price(client, bag_con)
order_id = get_order_id(client)
print(f'Placing order with lmt price {lmt_price}')
place_order(client, order_id, bag_con, lmt_price, "SELL")
time.sleep(10)
while not client.filled and (client.con_ids['short_leg'] in client.acc_df.loc[:,'ConID'].values
and (not
(int(client.acc_df[client.acc_df['ConID'] == client.con_ids['short_leg']].loc[:,'position'].values[0]) == 0))):