Skip to content

OpenSSL.SSLStream does not support byte I/O #187

@femtotrader

Description

@femtotrader

Hello,

The following code

# Import the WebSockets library for WebSocket communication and JSON for data handling
using WebSockets
using JSON

# Function to fetch data from Binance WebSocket API
function fetch_binance_data(url::String)
    # Open a WebSocket connection to the provided URL
    WebSockets.open(url) do ws
        # Loop to continuously read incoming messages from WebSocket
        while true
            try
                # Read a single message from the WebSocket connection
                msg = read(ws, String)
                
                # Parse the JSON message into a Julia dictionary
                data = JSON.parse(msg)
                
                # Print the received data (you may replace this with other processing code)
                println(data)
            catch e
                # Print any errors encountered while reading/parsing data
                println("Error encountered: $e")
                
                # Break out of the loop on error to avoid infinite error printing
                break
            end
        end
    end
end

# Binance WebSocket URL to fetch depth data for ADA/USDT and BTC/USDT pairs
url = "wss://stream.binance.com:9443/stream?streams=adausdt@depth20@100ms/btcusdt@depth20@100ms"

# Call the function to initiate WebSocket data fetching
fetch_binance_data(url)

raises

Error encountered: ErrorException("OpenSSL.SSLStream does not support byte I/O")

I have no idea why?

Best regards

PS :

# Import the HTTP library for WebSocket communication and JSON for data handling
using HTTP
using JSON

# Function to fetch data from Binance WebSocket API
function fetch_binance_data(url::String)
    # Open a WebSocket connection to the provided URL
    HTTP.WebSockets.open(url) do ws
        # Loop to continuously read incoming messages from WebSocket
        for msg in ws
            # Parse the JSON message into a Julia dictionary
            data = JSON.parse(msg)
            
            # Print the received data (you may replace this with other processing code)
            println(data)
        end
    end
end

# Binance WebSocket URL to fetch depth data for ADA/USDT and BTC/USDT pairs
url = "wss://stream.binance.com:9443/stream?streams=adausdt@depth20@100ms/btcusdt@depth20@100ms"

# Call the function to initiate WebSocket data fetching
fetch_binance_data(url)

is a workaround

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