|
@@ -651,8 +651,20 @@ Will trigger when {token} price moves {alarm['direction']} {target_price_str}
|
|
token = symbol.split('/')[0] if '/' in symbol else symbol.split(':')[0]
|
|
token = symbol.split('/')[0] if '/' in symbol else symbol.split(':')[0]
|
|
|
|
|
|
# Create a new trade lifecycle for this existing position
|
|
# Create a new trade lifecycle for this existing position
|
|
- side = 'buy' if size > 0 else 'sell'
|
|
|
|
- position_side = 'long' if size > 0 else 'short'
|
|
|
|
|
|
+ # Use the side field from exchange (more reliable than contracts sign)
|
|
|
|
+ exchange_side = position.get('side', '').lower()
|
|
|
|
+ if exchange_side == 'long':
|
|
|
|
+ side = 'buy'
|
|
|
|
+ position_side = 'long'
|
|
|
|
+ elif exchange_side == 'short':
|
|
|
|
+ side = 'sell'
|
|
|
|
+ position_side = 'short'
|
|
|
|
+ else:
|
|
|
|
+ # Fallback to contracts sign if side field missing
|
|
|
|
+ side = 'buy' if size > 0 else 'sell'
|
|
|
|
+ position_side = 'long' if size > 0 else 'short'
|
|
|
|
+ logger.warning(f"Using contracts sign fallback for {token}: size={size}, exchange_side='{exchange_side}'")
|
|
|
|
+
|
|
entry_price = float(position.get('entryPrice', 0))
|
|
entry_price = float(position.get('entryPrice', 0))
|
|
|
|
|
|
if entry_price > 0: # Valid position data
|
|
if entry_price > 0: # Valid position data
|