$MARKET_URL = "https://api.upstox.com/v2/feed/market-data-feed/authorize";
$BEARER_TOKEN = [YOUR ACCESS TOKEN];
$curl = curl_init();
$headers = [
'Accept: application/json',
'Authorization: Bearer '.$BEARER_TOKEN
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $MARKET_URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($curl);
// echo $response;
$wsUrlResponse = $response;
echo $wsUrlResponse ;
if ($wsUrlResponse === null) {
echo "Error getting WebSocket URL\n";
return;
}
$wsUrlData = json_decode($response, true);
$wsUrl = $wsUrlData['data']['authorizedRedirectUri'];
// echo "authorizedRedirectUri ".$wsUrl;
// Initialize cURL for WebSocket connection
$ch = curl_init($wsUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Ignore SSL certificate verification
// Send subscription message
$subscriptionMessage = json_encode([
"guid" => "someguid",
"method" => "sub",
"data" => [
"mode" => "full",
"instrumentKeys" => ["NSE_INDEX|Nifty Bank","NSE_INDEX|Nifty 50"]
]
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $subscriptionMessage);
// Perform WebSocket handshake
$response = curl_exec($ch);
echo "response".$response;
// Read messages from WebSocket
while ($message = curl_exec($ch)) {
echo "Received message: " . $message . "\n";
}
// Close cURL handle
curl_close($ch);
I got authorizedRedirectUri from api response then how i can get websocket connection and data from authorizedRedirectUri (any sample code in curl php)