Here I tried to buy an instrument in derivatives but its return error without any explanation.
Here is my sample code:
$headers = array(
'Content-Type: application/json',
'x-jwt-token: ' . $this->jwt_token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.upstox.com/v2/order/place");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
Its returns:
{"status":"error","errors":[]}
Value of $data in request as below:
{"txn_type":"BUY","tag":"string","product":"D","instrument_token":"NSE_FO|60331","quantity":"50","validity":"DAY","order_type":"MARKET","price":"0","trigger_price":"","is_amo":false}
Ketan
March 23, 2024, 5:24am
2
Please take note of the following:
Our authentication method utilizes bearer tokens rather than JWT tokens.
When specifying transaction details in the data, use transaction_type
instead of txn_type
to indicate whether it is a buy or sell order.
Here is a working example for your reference.
<?php
$headers = [
'Content-Type: application/json',
'Authorization: Bearer {your_access_token}',
];
$data = [
'quantity' => 50,
'product' => 'D',
'validity' => 'DAY',
'price' => 0,
'tag' => 'string',
'instrument_token' => 'NSE_FO|60331',
'order_type' => 'MARKET',
'transaction_type' => 'BUY',
'disclosed_quantity' => 0,
'trigger_price' => 0,
'is_amo' => true,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.upstox.com/v2/order/place");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
?>
Please check out our Example Codes , where we have covered all variations of orders and other API calls.
I hope the above information is helpful.
Now I’m getting this error that trigger price required where I’m placing a market order. How I set Trigger price for market order?
Ketan
March 26, 2024, 6:00am
4
Set the Trigger price as 0
for market buy order