The task is to close filled orders that were opened today with the changed price.
# Cancel TP/SL
buyOrdersFilled = self.alpaca.list_orders(side="buy", status="filled")
for buyOrderFilled in buyOrdersFilled:
if today.strftime('%Y-%m-%d') == buyOrderFilled.submitted_at.strftime('%Y-%m-%d'):
filled_today_stock.append(buyOrderFilled.symbol)
for stock in filled_today_stock:
position = api.get_position(stock.symbol)
if position.unrealized_plpc >= self.take_profit_percent
api.cancel_order(stock.id)
time.sleep(1)
elif position.unrealized_plpc >= self.stop_loss_percent
api.cancel_order(stock.id)
time.sleep(1)
but there is a problem here, this code collects only the names of stocks, but there may be old ones in the list, how to get around this?