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

websocket receive MarketData error #123

Open
Ultraman95 opened this issue Jul 14, 2021 · 10 comments
Open

websocket receive MarketData error #123

Ultraman95 opened this issue Jul 14, 2021 · 10 comments

Comments

@Ultraman95
Copy link

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

@Ultraman95
Copy link
Author

I used vpn

@wisespace-io
Copy link
Owner

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

@siegfried
Copy link
Contributor

siegfried commented Nov 12, 2021

@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?

@wisespace-io
Copy link
Owner

wisespace-io commented Nov 12, 2021

@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

@siegfried
Copy link
Contributor

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.

@siegfried
Copy link
Contributor

@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.

@wisespace-io
Copy link
Owner

@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

@wisespace-io
Copy link
Owner

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

@siegfried
Copy link
Contributor

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

@siegfried
Copy link
Contributor

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

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

3 participants