Error while fetching positions

I am trying to fetch positions using my php code.
my many other requests are working fine both ‘GET’ and ‘POST’.

But while trying to fetch positions using GET request, i am unable to do so. instead i get the error saying “Signature Mismatch”. what could be the reason for this.

Below is my code.

$orderData = [];
	$dataString = json_encode($orderData);

	// Generate a signature
	$method = 'GET';
	$timestamp = time();
	$path = '/v2/positions/margined';
	$query_string = 'contract_types=call_options';
	$signaturePayload = $method . $timestamp . $path . $query_string . $dataString;
	$signature = hash_hmac('sha256', $signaturePayload, $secret_key);
	echo "<br/>Signature Payload: ".$signature;
	
	// Create headers
	$headers = [
		"Content-Type: application/json",
		"Accept: application/json",
		"api-key: $api_key",
		"signature: $signature",
		"timestamp: $timestamp"
	];
	
	// Initialize cURL
	$url = "https://api.india.delta.exchange/v2/positions/margined?contract_types=call_options";
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response instead of outputting
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_USERAGENT, 'MyCustomUserAgent');
	// Execute the request
	$response = curl_exec($ch);
	

I get below response

{"error":{"code":"Signature Mismatch","context":{"signature_data":"GET1735927557/v2/positions/margined?contract_types=call_options"}},"success":false}
1 Like

There are 2 issues in the code. Please fix them.

  1. $signaturePayload = $method . $timestamp . $path . “?” . $query_string . $dataString; (? was missing)
  2. This is a get request, so payload will be an empty string. $dataString = '';
1 Like

Thanks, problem is solved now.