How to place bull/bear spread orders through API?

Hello,

From previous posts in the community I was able to find how we can place a single call or put option using API. But I want to place a bull spread or a straddle which requires placing multiple orders at once.

Can someone please help me on how to place multiple option orders in one? To implement option strategies.

Thank you, really appreciate any help

The Upstox API currently does not have the capability to place multiple orders simultaneously. I will forward this information to the product team for potential inclusion in future updates.

1 Like

Thank you Pradeep for prompt response. That feature will be really useful. Thank you.

1 Like

Hi Pradeep, any update on this?

@Prasad_G

We have recently launched our multi-order (basket order) feature, allowing you to place multiple orders simultaneously. This feature also includes an automatic slicing option. In a multi-order request, the system prioritizes the execution of all BUY orders first, followed by all SELL orders.

For more details, please refer to the Place Multi Order | Documentation.

1 Like

This will be processed as market order or limit order?
In both types, we may loose the spread between 2 legs, if more legs for butterfly or condor like strategy, we can not take position with confidence. I am trying to place orders with IOC type where if combined premium is equal to my input spread. Can anyone help me achieve this?

Thank you.

You can define market, limit, and other types of orders as per your requirements. The Multiple Order API is essentially an array of individual orders combined.

Based on your strategy, you must identify multiple orders at different strike prices with the desired configurations and bundle them using the Multiple Order API. To check your strategy’s margin and hedge, refer to the Margin API documentation at Margin Details | Upstox Developer API.

1 Like

order_url = “https://api-hft.upstox.com/v3/order/place

order_params_leg1 = {
“instrument_token”: instrument[0],
“quantity”: qty,
“order_type”: “MARKET”, # Order type
“transaction_type”: “SELL”,
“price”: 0, # Required for API even for market orders
“validity”: “DAY”,
“product”: “D”, # Replace ‘NRML’ with valid product value
“trigger_price”: 0 # Explicitly added
}

            order_params_leg2 = {
                "instrument_token": instrument[1],
                "quantity": qty,
                "order_type": "MARKET",
                "transaction_type": "BUY",
                "price": 0,
                "validity": "DAY",
                "product": "D",  # Replace 'NRML' with valid product value
                "trigger_price": 0
            }

response_leg1 = make_request(‘POST’, order_url, headers=headers, params=order_params_leg1)
response_leg2 = make_request(‘POST’, order_url, headers=headers, params=order_params_leg2)

Errors:
Leg 1 (Sell) order failed.
Error Response from API: {‘status’: ‘error’, ‘errors’: [{‘errorCode’: ‘UDAPI1026’, ‘message’: ‘Instrument key is required’, ‘propertyPath’: ‘instrumentKey’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1026’, ‘property_path’: ‘instrumentKey’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1006’, ‘message’: ‘Product is required’, ‘propertyPath’: ‘product’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1006’, ‘property_path’: ‘product’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1009’, ‘message’: ‘TransactionType is required’, ‘propertyPath’: ‘side’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1009’, ‘property_path’: ‘side’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1008’, ‘message’: ‘Price is required’, ‘propertyPath’: ‘price’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1008’, ‘property_path’: ‘price’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1007’, ‘message’: ‘Validity is required’, ‘propertyPath’: ‘validity’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1007’, ‘property_path’: ‘validity’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1004’, ‘message’: ‘Valid order type is required’, ‘propertyPath’: ‘orderType’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1004’, ‘property_path’: ‘orderType’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1036’, ‘message’: “The ‘‘trigger_price’’ is required”, ‘propertyPath’: ‘triggerPrice’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1036’, ‘property_path’: ‘triggerPrice’, ‘invalid_value’: None}]}
Error Code: UDAPI1026, Message: Instrument key is required
Error Code: UDAPI1006, Message: Product is required
Error Code: UDAPI1009, Message: TransactionType is required
Error Code: UDAPI1008, Message: Price is required
Error Code: UDAPI1007, Message: Validity is required
Error Code: UDAPI1004, Message: Valid order type is required
Error Code: UDAPI1036, Message: The ‘‘trigger_price’’ is required
Leg 2 (Buy) order failed.
Error Response from API: {‘status’: ‘error’, ‘errors’: [{‘errorCode’: ‘UDAPI1006’, ‘message’: ‘Product is required’, ‘propertyPath’: ‘product’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1006’, ‘property_path’: ‘product’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1007’, ‘message’: ‘Validity is required’, ‘propertyPath’: ‘validity’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1007’, ‘property_path’: ‘validity’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1036’, ‘message’: “The ‘‘trigger_price’’ is required”, ‘propertyPath’: ‘triggerPrice’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1036’, ‘property_path’: ‘triggerPrice’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1004’, ‘message’: ‘Valid order type is required’, ‘propertyPath’: ‘orderType’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1004’, ‘property_path’: ‘orderType’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1008’, ‘message’: ‘Price is required’, ‘propertyPath’: ‘price’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1008’, ‘property_path’: ‘price’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1026’, ‘message’: ‘Instrument key is required’, ‘propertyPath’: ‘instrumentKey’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1026’, ‘property_path’: ‘instrumentKey’, ‘invalid_value’: None}, {‘errorCode’: ‘UDAPI1009’, ‘message’: ‘TransactionType is required’, ‘propertyPath’: ‘side’, ‘invalidValue’: None, ‘error_code’: ‘UDAPI1009’, ‘property_path’: ‘side’, ‘invalid_value’: None}]}
Error Code: UDAPI1006, Message: Product is required
Error Code: UDAPI1007, Message: Validity is required
Error Code: UDAPI1036, Message: The ‘‘trigger_price’’ is required
Error Code: UDAPI1004, Message: Valid order type is required
Error Code: UDAPI1008, Message: Price is required
Error Code: UDAPI1026, Message: Instrument key is required
Error Code: UDAPI1009, Message: TransactionType is required

The above issue has been resolved.

Please check the above, I am not going to change the code from here. Awaiting for you help. Thank you.

1 Like

Thank you for updating.

1 Like