Can we place SL with Straddle strategy or How to place SL orders for two legs while executing Straddle

Hi Firstock Community

I’m trying to write python code for executing simple straddle with certain SL like 20% for each leg. Can any one help me on getting it in easier way. Currently i’m doing it in below steps:

  1. Execute the orders
  2. Get the order id’s from Order Book API
  3. Place SL orders for those order id’s

TIA

Hi Manjunath, this could be also achieved using WebSocket’s Subscribe Order Update and placing the order when you receive the Order ID through WebSocket’s and place SL order

from thefirstock.firstockModules import firstockWebSockets
from thefirstock.pyClient.websocket import WsClient
from thefirstock.pyClient.websocket.enums import MessageTopic


client = firstockWebSockets.webSocketLogin()
ws = client.ws


@ws.on_connect
def connected(client, message):
    if message.get('s') == 'OK':
        client.subscribe_order('userId')


@ws.on_message(MessageTopic.ORDER_FEED)
def msg_handler(client: WsClient, message: Any):
    print(message)
    """Logic for SL over here"""


ws.connect(uid='userId', actid='userId')
ws.run_forever()

The above give you the live update of the orders placed, next you can combine place order function with the above code and the message provides the following details

{ 't': 'om',
  'norenordno': '',
  'uid': '', 'actid': '',
  'exch': 'NSE',
  'tsym': 'TCS-EQ',
  'trantype': 'B',
  'qty': '1',
  'prc': '3101.10',
  'pcode': 'I',
  'remarks': '',
  'status': 'OPEN', 
  'reporttype': 'New', 
  'prctyp': 'LMT', 
  'ret': 'DAY', 
  'exchordid': '', 
  'dscqty': '0', 
  'exch_tm': ''
}

by running above code i’m not able to get/print the order update. Please find the below screenshot of code running in jupyter notebook. A’m i missing anything here, could you help me in this.

Hi Manjunath,
In the above WebSocket code, the order status will be update as and when the order is placed, so it won’t give you the previous order status, but will provide you the live order status as and when you have placed the order.

Once you start the WebSocket’s start placing the orders and you can see the updating of the status.