TSL Order Update होने पर भी पहला SL Modify/Cancel न होने की समस्या के समाधान हेतु अनुरोध
महोदय,
सविनय निवेदन है कि मैं SmartAPI (Angel One) का उपयोग करके एक Python-based Trading Script चला रहा हूँ।
मेरी Script Entry Order एवं Initial Stop Loss (SL-M) Order को सही प्रकार से place कर रही है।
परंतु समस्या यह आ रही है कि जब Trailing Stop Loss (TSL) Update होता है, तब भी पुराना SL Order Cancel या Modify नहीं हो रहा।
इसके परिणामस्वरूप Order Book में एक से अधिक SL-M Orders pending दिखाई दे रहे हैं, जो कि गलत execution का कारण बन सकता है।
समस्या के स्पष्ट विश्लेषण हेतु मैं निम्नलिखित संलग्न कर रहा हूँ:
• Order Book एवं TSL Update से संबंधित screenshots
• पूरी Python Trading Script (PDF format)
आपसे विनम्र अनुरोध है कि कृपया इस व्यवहार की गहन जाँच करें और यह स्पष्ट करें कि:
TSL Update के समय पुराने SL Order को Cancel/Modify करने की सही API approach क्या है
क्या SmartAPI में SL-M Orders के लिए कोई विशेष handling या limitation है
इस समस्या का recommended solution / best practice क्या रहेगा
आपके सहयोग एवं मार्गदर्शन के लिए मैं आभारी रहूँगा।
धन्यवाद।
सादर,
Diwakar Singh Kushwaha
```
====================== Order Placement (DUPLICATE SL-M FIX) ======================
def place_order(transaction_type, trigger_price=None, retries=3):
global obj, sl_order_id, current_tradingsymbol, current_symboltoken
if trigger_price is None:
base_params = {
"variety": "NORMAL",
"tradingsymbol": current_tradingsymbol,
"symboltoken": current_symboltoken,
"transactiontype": transaction_type,
"exchange": EXCHANGE,
"ordertype": "MARKET",
"producttype": PRODUCT_TYPE,
"duration": "DAY",
"price": "0",
"quantity": QUANTITY
}
else:
base_params = {
"variety": "STOPLOSS",
"tradingsymbol": current_tradingsymbol,
"symboltoken": current_symboltoken,
"transactiontype": transaction_type,
"exchange": EXCHANGE,
"ordertype": "STOPLOSS_MARKET",
"producttype": PRODUCT_TYPE,
"duration": "DAY",
"price": "0",
"triggerprice": str(trigger_price),
"quantity": QUANTITY
}
attempt = 0
while attempt < retries:
try:
# TSL Modify if sl_order_id exists
if trigger_price is not None and sl_order_id:
base_params["orderid"] = sl_order_id
response = obj.modifyOrder(base_params)
print(f"TSL MODIFIED → Trigger: {trigger_price:.2f} | Resp: {response}")
return response
# Place new order
response = obj.placeOrder(base_params)
print(f"{'ENTRY' if trigger_price is None else 'SL-M'} PLACED → {transaction_type} @ {trigger_price or 'MARKET'} | Resp: {response}")
if trigger_price is not None and isinstance(response, dict) and response.get('status') == True:
sl_order_id = response['data']['orderid']
print(f"SL Order ID Saved: {sl_order_id}")
return response
except Exception as e:
print(f"Order Error (Attempt {attempt+1}): {e}")
attempt += 1
time.sleep(1)
print("Order Failed after retries!")
return None
====================== Cancel SL ======================
def cancel_sl_order():
global sl_order_id
if sl_order_id:
try:
response = obj.cancelOrder(sl_order_id, "STOPLOSS")
print(f"Old SL Canceled | Resp: {response}")
sl_order_id = None
except Exception as e:
print(f"Cancel SL Error: {e}")