When i push order i am getting 403 error

Below is my C# code

        var url = "https://api-hft.upstox.com/v2/order/place";
        var accessToken = sAccTkn;

        var requestData = new
        {
            quantity = 1,
            product = "D",
            validity = "DAY",
            price = 0,
            tag = "string",
            instrument_token = "NSE_EQ|INE009A01021",
            order_type = "MARKET",
            transaction_type = "BUY",
            disclosed_quantity = 0,
            trigger_price = 0,
            is_amo = true,
        };

        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

        var jsonContent = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");

        try
        {
            var response = client.PostAsync(url, jsonContent).Result;
            var responseCode = (int)response.StatusCode;
            var responseBody = response.Content.ReadAsStringAsync();

            Console.WriteLine($"Response Code: {responseCode}");
            Console.WriteLine($"Response Body: {responseBody}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }

Could you assist with the corresponding curl request for this?

You can also try the curl request provided in the code sample on this page: Place Order | Upstox Developer API.

Hi Pradeep,

thank you for quick reply. i tried cURL code i am getting below error message.

I have tried same in python, below is my code and error. please help to fix it.

There are two issues with the above request:

Use the following line to make the request:

response = requests.request("POST", url, headers=headers, json=payload)

The price must be specified if you place a limit order in the payload.

2 Likes

Hi Pradeep,

thank you for help.

now i am able to place buy order and cancel the same order. i want to know hot create sell order for the same, do i need send order id ??

@taraanil, thereā€™s no need to include the order ID when creating a sell order. Simply use the place order API and set the transaction_type to SELL to place a sell order.

For further details, please refer to the Developer Documentation | Place Order.