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

Futures API support? #3

Closed
0ihsan opened this issue Jun 21, 2021 · 5 comments
Closed

Futures API support? #3

0ihsan opened this issue Jun 21, 2021 · 5 comments

Comments

@0ihsan
Copy link

0ihsan commented Jun 21, 2021

See implementation in https://github.com/wisespace-io/binance-rs/tree/master/src/futures

@Igosuki
Copy link
Owner

Igosuki commented Jun 22, 2021

Sure, I'm not currently using futures but it shouldn't be hard to add.

@Igosuki
Copy link
Owner

Igosuki commented Jun 24, 2021

Here : #4
You can use it but I haven't tested every endpoint for now.

@0ihsan
Copy link
Author

0ihsan commented Jun 25, 2021

Thank you. But, I am getting runtime panic for this code

use binance::api::*;
use binance::futures::general::*;
use futures::executor::block_on;

async fn get_all_symbols() {

    let general: FuturesGeneral = Binance::new(None, None);

    match general.exchange_info().await {
        Ok(answer) => println!("Exchange information: {:?}", answer),
        Err(e) => println!("Error: {:?}", e),
    }

}

fn main() {

    block_on(get_all_symbols());

}
thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x
runtime', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.7.0/src/runtime/blocking/pool.rs:84:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@0ihsan
Copy link
Author

0ihsan commented Jun 25, 2021

I solved that by adding tokio = { version = "1", features = ["full"] } to dependencies and making these changes

use binance::api::*;
use binance::futures::general::*;
use futures::executor::block_on;
+use tokio;

async fn get_all_symbols() {

    let general: FuturesGeneral = Binance::new(None, None);

    match general.exchange_info().await {
        Ok(answer) => println!("Exchange information: {:?}", answer),
        Err(e) => println!("Error: {:?}", e),
    }

}

+#[tokio::main]
+async fn async_main() {
+
+    block_on(get_all_symbols());
+
+}

fn main() {

-    block_on(get_all_symbols());
+    async_main();

}

@Igosuki
Copy link
Owner

Igosuki commented Jun 25, 2021

Didn't see that everything started requiring tokio, I updated the examples accordingly.
The examples are passing so I see no reason to not merge into master. Let me know if you need anymore patches.

@Igosuki Igosuki closed this as completed Jun 25, 2021
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

2 participants