Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
femtotrader opened this issue Nov 11, 2024 · 0 comments
Open

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

femtotrader opened this issue Nov 11, 2024 · 0 comments

Comments

@femtotrader
Copy link

femtotrader commented Nov 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant