Fix scale out for small positions and add exception handling to order placement
This commit is contained in:
1 parent
122f719b8d
commit
55f3e59d0b
2 files changed
+8
No files matched your search
@@ -55,6 +55,7 @@ class AlpacaClient:
|
||||
return self.api.get_position(symbol)
|
||||
|
||||
def place_order(self, symbol, side, notional, limit_price, limit_order_timeout):
|
||||
try:
|
||||
quote = self.get_latest_quote(symbol)
|
||||
if quote is None:
|
||||
return None
|
||||
@@ -93,3 +94,6 @@ class AlpacaClient:
|
||||
if status.status == "filled":
|
||||
return float(status.filled_avg_price)
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Order placement error: {e}")
|
||||
return None
|
||||
@@ -763,6 +763,10 @@ def scale_out_profit_taking(symbol, entry_price, current_price, stop_loss, posit
|
||||
position_state.target_1_hit = True
|
||||
logger.info(f"💰 Partial profit @ {profit_pct:.2f}% ({half_qty} shares)")
|
||||
debug_print(f"Partial profit taken: {half_qty} shares @ {profit_pct:.2f}%")
|
||||
else:
|
||||
position_state.target_1_hit = True
|
||||
logger.info(f"💰 Target 1 reached @ {profit_pct:.2f}% (position too small to scale)")
|
||||
debug_print(f"Position size {qty} too small for partial exit, holding for target 2")
|
||||
|
||||
if profit_pct >= target_2_pct:
|
||||
qty = current_position_qty(symbol)
|
||||
|
||||
Reference in new issue
Block a user