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}");
}
}