Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ByBit socket: party closed the WebSocket connection without completing the close handshake. #27450

@OdCheban

Description

@OdCheban

Operating System

Windows

Programming Language

C#

CCXT Version

4.5.22

Description

ByBit after 2 min send "party closed the WebSocket connection without completing the close handshake."

Verbose Log:

[15:16] WebSocket connected to wss://stream.bybit.com/v5/public/spot
[15:16] Sending message: {"op":"subscribe","req_id":2,"args":["orderbook.50.PIEVERSEUSDT"]}
...
[15:16] Sending message: {"req_id":50869,"op":"ping"}
[15:17] On message: {"success":true,"ret_msg":"pong","conn_id":"d49d7dtpfljs93ea6ppg-3esan","req_id":"50869","op":"ping"}
[15:18] The remote party closed the WebSocket connection without completing the close handshake.

Code:

using ccxt.pro;
using Newtonsoft.Json.Linq;

class Program
{
    static async Task Main()
    {
        var exchange = new Bybit();
        var markets = await exchange.LoadMarkets();

        JObject marketsObject = JObject.FromObject(exchange.markets);
        var spotSymbols = marketsObject
            .Properties()
            .Where(p => (string)p.Value["type"] == "spot")
            .Select(p => p.Name)
            .ToList();
        Console.WriteLine($"[{DateTime.Now:HH:mm}] Found {spotSymbols.Count} spot symbols.");

        var tasks = spotSymbols.Select(symbol => WatchOrderBookLoop(exchange, symbol)).ToArray();
        await Task.WhenAll(tasks);
    }

    private static async Task WatchOrderBookLoop(Bybit exchange, string symbol)
    {
        while (true)
        {
            try
            {
                var ob = await exchange.WatchOrderBook(symbol);
            }
            catch (Exception ex)
            {
                //after 2 min: (The remote party closed the WebSocket connection without completing the close handshake.)
                Console.WriteLine($"[{DateTime.Now:HH:mm}] Error on {symbol}: {ex}");
                await Task.Delay(1000);
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions