Web socket not working

when I use websocket.php t show me all data(u can check in response.php file) but when I try same in my websocket .php file it always show me

  1. websocket not connect
  2. url not found
  3. PS E:\xampp\htdocs\traidsocket> php websocket_test.php
    :arrows_counterclockwise: Connecting to: wss://api.upstox.com/live/marketdata?token=eyJ0eXAiOiJKV1QiLCJrZXlfaWQiOiJza192MS4wIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiIzQUNXTDYiLCJqdGkiOiI2N2JjMDQyMzVjZjZiMDJhNGU0YjVlMGIiLCJpc011bHRpQ2xpZW50IjpmYWxzZSwiaWF0IjoxNzQwMzc1MDc1LCJpc3MiOiJ1ZGFwaS1nYXRld2F5LXNlcnZpY2UiLCJleHAiOjE3NDA0MzQ0MDB9.Y517rk0kQ7DftNp36n7SEBtVbgDKpjIMV32dPGDpUQs
    :white_check_mark: Connected to Upstox WebSocket
    :x: WebSocket Error: Connection to ‘wss://api.upstox.com/live/marketdata?token=eyJ0eXAiOiJKV1QiLCJrZXlfaWQiOiJza192MS4wIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiIzQUNXTDYiLCJqdGkiOiI2N2J
    jMDQyMzVjZjZiMDJhNGU0YjVlMGIiLCJpc011bHRpQ2xpZW50IjpmYWxzZSwiaWF0IjoxNzQwMzc1MDc1LCJpc3MiOiJ1ZGFwaS1nYXRld2F5LXNlcnZpY2UiLCJleHAiOjE3NDA0MzQ0MDB9.Y517rk0kQ7DftNp36n7SEBtVbgDKpjIMV32dPGDpUQs’ failed: Server sent invalid upgrade response: HTTP/1.1 299 Successful
    Date: Mon, 24 Feb 2025 06:58:45 GMT
    Content-Type: application/json
    Content-Length: 129
    Connection: keep-alive
    Access-Control-Allow-Origin: https://pro.upstox.com
    Access-Control-Allow-Credentials: true
    Access-Control-Allow-Headers: *
    Set-Cookie: __cf_bm=_bDJC0dpBQps3oi64fz3arqDydLdU6RmfiOvKuOZgfI-1740380325-1.0.1.1-62MzJsIkCz6Rw8Xj6zxnNMfGNv4qTkFEeApixLvcDY0dacNW45eU47INXpEPAGqV; path=/; expires=Mon, 24-Feb-25 07:28:45 GMT; domain=.upstox.com; HttpOnly; Secure; SameSite=None
    Strict-Transport-Security: max-age=0; includeSubDomains
    Set-Cookie: _cfuvid=YkG3U_ZrzX.o4r0xe4U.cEoUNMRD…FimsA3d_R4A2M-1740380325371-0.0.1.1-604800000; path=/; domain=.upstox.com; HttpOnly; Secure; SameSite=None
    Server: cloudflare
    CF-RAY: 916d919af92346ec-BOM
    alt-svc: h3=“:443”; ma=86400

I changed so may
$wsUrl = “wss://api.upstox.com/live/marketdata?token=$accessToken”;

wsurl as per document but still I’m unable to get data from live market throw socket can u tell me and update this code where I made mistake

<?php require 'vendor/autoload.php'; use WebSocket\Client; $accessToken = "eyJ0eXAiOiJKV1QiLCJrZXlfaWQiOiJza192MS4wIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiIzQUNXTDYiLCJqdGkiOiI2N2JjMDQyMzVjZjZiMDJhNGU0YjVlMGIiLCJpc011bHRpQ2xpZW50IjpmYWxzZSwiaWF0IjoxNzQwMzc1MDc1LCJpc3MiOiJ1ZGFwaS1nYXRld2F5LXNlcnZpY2UiLCJleHAiOjE3NDA0MzQ0MDB9.Y517rk0kQ7DftNp36n7SEBtVbgDKpjIMV32dPGDpUQs"; $wsUrl = "wss://api.upstox.com/live/marketdata?token=$accessToken"; try { echo "🔄 Connecting to: $wsUrl\n"; $client = new Client($wsUrl, ['timeout' => 10]); echo "✅ Connected to Upstox WebSocket\n"; while (true) { $response = $client->receive(); echo "📩 Server Response: $response\n"; } } catch (Exception $e) { echo "❌ WebSocket Error: " . $e->getMessage() . "\n"; } ?>

@shanmu @Pradeep_Jaiswar please give a solution as soon as possible @Upstox @Ketan

for me i could connect to websocket even fetched data but the ltp is delayed and i dont know how to make the websocket work without delays

Hello,

This happened with me also. Please check your internet connectivity. Your internet should be fast (at least 30 mb/s) and stable. I’ve created a virtual machine on cloud to use it. The data would not be delayed.

Thanks

1 Like

i have both

are you using v3 script and can you please share code like i am not able to fix my code to live stream data to excel sheet