I am trying to use the binance_async
library, tokio
, and futures
to make concurrent orders to Binance. (See notes at the end of this question.)
The binance_async
functions I'm using return a
binance_async::error::Result<impl futures::future::Future<_, _>>
type. I am facing the following issue, illustrated in these 2 examples:
- Say I'm trying to do this:
let bn = Binance::with_credential(&api_key, &secret_key);
let fut = bn.limit_sell(&symbol, qty, price);
tokio::spawn(fut.unwrap()); // ERROR
/* Error message:
error[E0277]: `impl futures::future::Future` is not a future
--> src/main.rs:23:5
|
23 | tokio::spawn(fut.unwrap());
| ^^^^^^^^^^^^ `impl futures::future::Future` is not a future
|
= help: the trait `futures::Future` is not implemented for `impl
futures::future::Future`
*/
This is super weird. First, I can't find futures::Future
anywhere -- only futures::future::Future
, which fut.unwrap()
implements. Any help?
- Okay, forget about Tokio, let's try this:
let mut orders : Vec<Result<_>> = Vec::new(); // not std::Result
let fut = bn.limit_sell(&symbol, qty, price);
orders.push(fut);
let mut futures = Vec::new(); // I want to unwrap them, to use join_all()
for f in orders.iter() {
match *f {
Ok(x) => {
futures.push(x);
},
Err(e) => {}
}
}
futures::future::join_all(futures).await; // <--- ERROR!
/* Error message (one of 3 similar ones):
error[E0277]: `impl futures::future::Future` is not a future
--> src/main.rs:37:5
|
37 | join_all(futures).await; // <--- ERROR!
| ^^^^^^^^^^^^^^^^^^^^^^^ `impl futures::future::Future` is not a future
|
= help: the trait `futures::Future` is not implemented for `impl
futures::future::Future`
= note: required because of the requirements on the impl of `futures::Future` for
`JoinAll<impl futures::future::Future>`
= note: required by `futures::Future::poll`
*/
Same error, same question.
Notes:
- I might be over-importing. If importing all these libraries looks like overkill or even the source of the problem, let me know!
- I am aware that
binance_async
is an under-maintained library. I am most likely going to ditch this approach altogether and go forbinance
crate instead. I am just really curious about this error. - My supervisor says it might have to do with attribute macros, but both of us only having a few months' experience in Rust and trying to get this work fast, we can't afford to dig deeper.
Thanks much :)