How to Place FO order?

“response”: {
“req”: {
“method”: “POST”,
“url”: “https://api-v2.upstox.com/order/place”,
“data”: {
“quantity”: 15,
“product”: “I”,
“validity”: “DAY”,
“price”: 0
},
“headers”: {
“authorization”: “Bearer ”,
“api-version”: “2.0”,
“content-type”: “application/json”,
“accept”: “application/json”
}
},
“header”: {
“date”: “Mon, 11 Dec 2023 06:36:23 GMT”,
“content-type”: “application/json”,
“transfer-encoding”: “chunked”,
“connection”: “close”,
“vary”: “Origin, Access-Control-Request-Method, Access-Control-Request-Headers”,
“message”: “request failed”,
“requestid”: “cb146731-67ac-4fc7-b339-fa0cc3e6badb”,
“x-content-type-options”: “nosniff”,
“x-xss-protection”: “1; mode=block”,
“cache-control”: “no-cache, no-store, max-age=0, must-revalidate”,
“pragma”: “no-cache”,
“expires”: “0”,
“strict-transport-security”: “max-age=0; includeSubDomains”,
“x-frame-options”: “DENY”,
“cf-cache-status”: “DYNAMIC”,
“set-cookie”: [ my-cookie],
“server”: “cloudflare”,
“cf-ray”: “833bb686f85b1bd2-BOM”
},
“status”: 400,
“text”: “{"status":"error","errors":[{"errorCode":"UDAPI1026","message":"Instrument key is required","propertyPath":"instrumentKey","invalidValue":null,"error_code":"UDAPI1026","property_path":"instrumentKey","invalid_value":null},{"errorCode":"","message":"{post.order.transactionType.required}","propertyPath":"side","invalidValue":null,"error_code":"","property_path":"side","invalid_value":null},{"errorCode":"UDAPI1004","message":"Valid order type is required","propertyPath":"orderType","invalidValue":null,"error_code":"UDAPI1004","property_path":"orderType","invalid_value":null},{"errorCode":"","message":"{post.order.trigger_price.required}","propertyPath":"triggerPrice","invalidValue":null,"error_code":"","property_path":"triggerPrice","invalid_value":null}]}”
}

body data
{
“quantity”: 15,
“product”: “I”,
“validity”: “DAY”,
“price”: 0,
“instrument_token”: “NSE_FO|40807”,
“order_type”: “MARKET”,
“transaction_type”: “BUY”,
“disclosed_quantity”: 0,
“trigger_price”: 0,
“is_amo”: false
}

also the errorCode is not mentioned in Docs
ps. i have not tried Equity

Please locate the appropriate code for placing your order with the instrument_token NSE_FO|40807, according to your provided specifications of body.

import requests
import json

url = 'https://api.upstox.com/v2/order/place'

headers = {
    'Accept': 'application/json',
    'Api-Version': '2.0',
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {{your_access_token}}'
}

data = {
"quantity": 15,
"product": "I",
"validity": "DAY",
"price": 0,
"instrument_token": "NSE_FO|40807",
"order_type": "MARKET",
"transaction_type": "BUY",
"disclosed_quantity": 0,
"trigger_price": 0,
"is_amo": False
}


response = requests.request('POST', url, headers=headers, json=data)
json_formatted_str = json.dumps(response.json(), indent=2)

print(json_formatted_str)

Please be aware and reassured that the aforementioned code has been tested and is functioning properly.

There’s issue with upstox-nodejs-sdk

placing order does not work.

This above code works just fine.

Thanks for the information. We’ll review the upstox-node js-sdk and respond to you as soon as possible.

FIXED CODE
mapToPlaceOrderRequest(data) {
let obj = {};
if (data) {
if (data.hasOwnProperty(‘quantity’)) obj.quantity = _ApiClient.ApiClient.convertToType(data[‘quantity’], ‘Number’);
if (data.hasOwnProperty(‘product’)) obj.product = _ApiClient.ApiClient.convertToType(data[‘product’], ‘String’);
if (data.hasOwnProperty(‘validity’)) obj.validity = _ApiClient.ApiClient.convertToType(data[‘validity’], ‘String’);
if (data.hasOwnProperty(‘price’)) obj.price = _ApiClient.ApiClient.convertToType(data[‘price’], ‘Number’);
if (data.hasOwnProperty(‘tag’)) obj.tag = _ApiClient.ApiClient.convertToType(data[‘tag’], ‘String’);
if (data.hasOwnProperty(‘instrument_token’)) obj.instrument_token = _ApiClient.ApiClient.convertToType(data[‘instrument_token’], ‘String’);
if (data.hasOwnProperty(‘order_type’)) obj.order_type = _ApiClient.ApiClient.convertToType(data[‘order_type’], ‘String’);
if (data.hasOwnProperty(‘transaction_type’)) obj.transaction_type = _ApiClient.ApiClient.convertToType(data[‘transaction_type’], ‘String’);
if (data.hasOwnProperty(‘disclosed_quantity’)) obj.disclosed_quantity = _ApiClient.ApiClient.convertToType(data[‘disclosed_quantity’], ‘Number’);
if (data.hasOwnProperty(‘trigger_price’)) obj.trigger_price = _ApiClient.ApiClient.convertToType(data[‘trigger_price’], ‘Number’);
if (data.hasOwnProperty(‘is_amo’)) obj.is_amo = _ApiClient.ApiClient.convertToType(data[‘is_amo’], ‘Boolean’);
}
return obj;
}

ORIGINAL CODE
mapToPlaceOrderRequest(data) {
let obj = {};
if (data) {
if (data.hasOwnProperty(‘quantity’)) obj.quantity = _ApiClient.ApiClient.convertToType(data[‘quantity’], ‘Number’);
if (data.hasOwnProperty(‘product’)) obj.product = _ApiClient.ApiClient.convertToType(data[‘product’], ‘String’);
if (data.hasOwnProperty(‘validity’)) obj.validity = _ApiClient.ApiClient.convertToType(data[‘validity’], ‘String’);
if (data.hasOwnProperty(‘price’)) obj.price = _ApiClient.ApiClient.convertToType(data[‘price’], ‘Number’);
if (data.hasOwnProperty(‘tag’)) obj.tag = _ApiClient.ApiClient.convertToType(data[‘tag’], ‘String’);
if (data.hasOwnProperty(‘instrumentToken’)) obj.instrument_token = _ApiClient.ApiClient.convertToType(data[‘instrumentToken’], ‘String’);
if (data.hasOwnProperty(‘orderType’)) obj.order_type = _ApiClient.ApiClient.convertToType(data[‘orderType’], ‘String’);
if (data.hasOwnProperty(‘transactionType’)) obj.transaction_type = _ApiClient.ApiClient.convertToType(data[‘transactionType’], ‘String’);
if (data.hasOwnProperty(‘disclosedQuantity’)) obj.disclosed_quantity = _ApiClient.ApiClient.convertToType(data[‘disclosedQuantity’], ‘Number’);
if (data.hasOwnProperty(‘triggerPrice’)) obj.trigger_price = _ApiClient.ApiClient.convertToType(data[‘triggerPrice’], ‘Number’);
if (data.hasOwnProperty(‘isAmo’)) obj.is_amo = _ApiClient.ApiClient.convertToType(data[‘isAmo’], ‘Boolean’);
}
return obj;
}

// upstox-js-sdk/dist/api/OrderApi.js

Thanks for pointing out. We will examine the information provided and respond to you shortly

@Savio_Silveira

I tested placing an order using the nodejs SDK for the scenario you described, and it functioned perfectly. Below is a sample code snippet that accomplishes this:

apiInstance = new UpstoxClient.OrderApi();
body = new UpstoxClient.PlaceOrderRequest(); // PlaceOrderRequest |
body.quantity = 1;
body.product = UpstoxClient.PlaceOrderRequest.ProductEnum.I;
body.validity = UpstoxClient.PlaceOrderRequest.ValidityEnum.DAY;
body.price = 0;
body.tag = "NODE-SDK-TEST";
body.instrumentToken = data.instrumentKey;
body.orderType = UpstoxClient.PlaceOrderRequest.OrderTypeEnum.MARKET;
body.transactionType = UpstoxClient.PlaceOrderRequest.TransactionTypeEnum.BUY;
body.disclosedQuantity = 0;
body.triggerPrice = 0;
body.isAmo = false;

apiInstance.placeOrder(body, data.apiVersion, (error, data, response) => {
  if (error) {
    console.error("PLACE ORDER FAILURE");
  } else {
    console.log("API called successfully. Returned data: " + JSON.stringify(data));
  }
});

Ensure you construct the payload as a PlaceOrderRequest object for it to work correctly with the SDK.

Give it a try and let me know how it goes.

Thanks!

Thx.

But I have fixed the issue long back

1 Like