wisespace-io / binance-rs

Rust Library for the Binance API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

websocket receive MarketData error

Ultraman95 opened this issue · comments

thread 'main' panicked at 'called Result::unwrap() on an Err value: Error(Msg("Error during handshake URL error: Unable to connect to wss://stream.binance.com:9443/stream?streams=ethbtc@depth@100ms/bnbeth@depth@100ms"), State { next_error: None, backtrace: InternalBacktrace })'

Rust Version 1.53

I used vpn

@Ultraman95 It sounds like it could be solved by adding Proxy support to this crate.

@wisespace-io I had this issue too, until I got rid of the port number from the URL in my script. Need a quick fix?

@siegfried It is weird. The port is part of the url as stated in the Binance docs.

Have you tried to overwrite it? See https://github.com/wisespace-io/binance-rs#testnet-and-api-clusters. All URLs can be overwritten with a custom config.

let config = Config::default().set_ws_endpoint("wss://stream.binance.com/ws");
let user_stream: UserStream = Binance::new_with_config(api_key_user, None, &config);

See where it happens, https://github.com/wisespace-io/binance-rs/blob/master/src/websockets.rs#L23

Thanks. I haven't tried this crate. Great work. Will do soon. This just reminded me the issue I had in my script a few weeks ago. I just checked the document, it seems they added the port number back.

@wisespace-io The issue still exists. I got this error by running the example.

use binance::websockets::*;
use std::sync::atomic::{AtomicBool};

fn main() {
    let keep_running = AtomicBool::new(true); // Used to control the event loop
    let kline: String = format!("{}", "ethbtc@kline_1m");
    let mut web_socket: WebSockets = WebSockets::new(|event: WebsocketEvent| {
        match event {
            WebsocketEvent::Kline(kline_event) => {
                println!("Symbol: {}, high: {}, low: {}", kline_event.kline.symbol, kline_event.kline.low, kline_event.kline.high);
            },
            _ => (),
        };
        Ok(())
    });
 
    web_socket.connect(&kline).unwrap(); // check error
    if let Err(e) = web_socket.event_loop(&keep_running) {
        match e {
          err => {
             println!("Error: {:?}", err);
          }
        }
     }
     web_socket.disconnect().unwrap();
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error(Msg("Error during handshake TLS error: native-tls error: connection closed via error"), State { next_error: None, backtrace: InternalBacktrace })', src/main.rs:17:32

After remove the port number, it works.

use binance::websockets::{
    WebSockets,
    WebsocketEvent
};
use binance::config::Config;
use std::sync::atomic::{AtomicBool};

fn main() {
    let config = Config::default().set_ws_endpoint("wss://stream.binance.com/ws");
    let keep_running = AtomicBool::new(true); // Used to control the event loop
    let kline: String = format!("{}", "ethbtc@kline_1m");
    let mut web_socket: WebSockets = WebSockets::new(|event: WebsocketEvent| {
        match event {
            WebsocketEvent::Kline(kline_event) => {
                println!("Symbol: {}, high: {}, low: {}", kline_event.kline.symbol, kline_event.kline.low, kline_event.kline.high);
            },
            _ => (),
        };
        Ok(())
    });

    web_socket.connect_with_config(&kline, &config).unwrap(); // check error
    if let Err(e) = web_socket.event_loop(&keep_running) {
        match e {
            err => {
                println!("Error: {:?}", err);
            }
        }
    }
    web_socket.disconnect().unwrap();
}

I can help on changing the default and do some refactor if you need.

@siegfried All binance libraries use the default port. As this crate gives the possibility of overwrite the url, wouldn't be enough?

 let config = Config::default().set_ws_endpoint("wss://stream.binance.com/ws");

Maybe we just need to add the example to the README in case someone else has problems with the default port. It seems more an issue with your connection. Check similar issue in ratchetphp/Pawl#100

I will add support to Proxy, it may also help.

Add the example to the README is fine, I think. Thanks.

@wisespace-io There is no config option for connect_multiple_streams. Maybe we should make the endpoint setting global?