Details of my order are below :
Phone Num used : 9742xxx894
Gtt Order Details :
TIME: 12-12-2025 10:11:28
Strike: 26000
Condition Met & Momentum DOWN
Entry: 95.0
SL: 83.0
Tgt: 131.0
GID: GTT-C25121200056671
Trade Count:1
Used gtt order placement using below python def
Python code below:
def place_gtt_order_new1(access_token, instrument_token, quantity, entry_price, sl_price, target_price,
trailing_gap=6.0, product=“I”):
url = "https://api.upstox.com/v3/order/gtt/place"
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}"
}
# --- 1. Basic Input Validation ---
if sl_price <= 0 or target_price <= 0 or entry_price <= 0:
print(" Invalid prices (must be > 0)")
return None
print(f"Input validation:")
print(f" Entry: {entry_price}, SL: {sl_price}, Target: {target_price}, Trailing: {trailing_gap}")
# --- 2. Upstox Trailing Stop Loss Constraint Check (CRITICAL) ---
# Upstox requires trailing_gap >= 10% of the difference between LTP and SL price.
price_difference = abs(entry_price - sl_price)
min_trailing_gap = 0.10 * price_difference
if trailing_gap < min_trailing_gap:
print(f"CONSTRAINT VIOLATION: trailing_gap ({trailing_gap:.2f}) is too low.")
print(f" Minimum required trailing_gap is {min_trailing_gap:.2f} (10% of |LTP - SL|).")
print(" The TSL might be ignored or the order may fail.")
# Option: Use the minimum required gap instead of the user-provided one
trailing_gap = min_trailing_gap
print(f" Adjusting trailing_gap to minimum: {trailing_gap:.2f}")
# --- 3. Construct Order Rules ---
rules = [
{
"strategy": "ENTRY",
"trigger_type": "ABOVE",
"trigger_price": float(entry_price)
},
{
"strategy": "TARGET",
"trigger_type": "IMMEDIATE",
"trigger_price": float(target_price)
},
{
"strategy": "STOPLOSS",
"trigger_type": "IMMEDIATE",
"trigger_price": float(sl_price),
"trailing_gap": float(trailing_gap) # This is where the validated/adjusted gap is used
}
]
data = {
"type": "MULTIPLE",
"quantity": int(quantity),
"product": product,
"instrument_token": instrument_token,
"transaction_type": "BUY", # Adjust as needed (e.g., "SELL" for short positions)
"rules": rules
}
# --- 4. API Call and Error Handling ---
try:
response = requests.post(url, json=data, headers=headers)
response.raise_for_status()
result = response.json()
if result.get("status") == "success":
gtt_id = result["data"]["gtt_order_ids"][0]
print(f"GTT Order Placed: {gtt_id}")
return gtt_id
else:
print(f" GTT Failed: {result.get('errors', result)}")
return None
except requests.exceptions.RequestException as e:
print(f"API Error: {e}")
if hasattr(e.response, 'text'):
print(f"Response Body: {e.response.text}")
return None
except Exception as e:
print(f" Unexpected Error: {e}")
return None
After this def got executed my gtt order got placed successfully for PE with entry price 95, sl: 83, trailing gap of 6.0, strike 26000PE price went to 115 from 95, but the trailing sl was constant at 83, it should have moved to 109, but it did not move. I am losing lot of handful of profits because of this. Please see the screenshot below taken in my mobile after successful gtt order placement. It doesn’t print any api error. I have to manually cancel it to save my profits
Please fix this issue asap, or let me know the required time to fix so that I can stop my trading_bot to stop executing on daily basis.
