DEV Community

Cover image for How to make a cryptocurrency Telegram bot with Rust and Teloxide

How to make a cryptocurrency Telegram bot with Rust and Teloxide

Steadylearner on May 19, 2021

In this post, you will learn how to make a simple cryptocurrency Telegram bot. You can contact me with Telegram if you need to hire a full stack b...
Collapse
 
scyart profile image
Scy

Hi, I got this error, is there any solution? Thank you so much.

thread 'tokio-runtime-worker' panicked at 'Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.

Collapse
 
steadylearner profile image
Steadylearner

Did you use the exact same version of tokio crate used for this post?

tokio = { version = "1.3", features = ["rt-multi-thread", "macros"]

I asked the author of Teloxide and he told me no recent change currently. So, it could be relevant to the tokio crate.

Collapse
 
scyart profile image
Scy • Edited

Yes, I used your code completely, without any changes.
I have just confirmed that it is not a Tokio version issue, I used "=1.3.0", and I tried Ubuntu(x86), Windows, MacOS (M1), all with the same error :(

Thread Thread
 
steadylearner profile image
Steadylearner • Edited

What rust version you used? (I used rustup 1.24.1) I think it can be better to get help from the teloxide Telegram group.

Did you make the dice example work first?

If you can, please join the group t.me/teloxide and ask questions there. I think it can save your time much better. There are more experienced one and authors that can help you to solve that issue all long.

Thread Thread
 
scyart profile image
Scy

Ok, I'm using version 1.24.3, and I can use dice example as well as binance's example

Thread Thread
 
steadylearner profile image
Steadylearner • Edited

Ok, so is everything ok now?

Thread Thread
 
scyart profile image
Scy • Edited

No, I said the example of teloxide and the example of binance-rs. But if I copy your code directly, I get the same error xD
Really weird, I've tried all kinds of operating systems, I've tried to copy all the same conditions as yours and it still shows this error.
But thank you very much for your quick reply! I will try to test other possible causes :)

Thread Thread
 
steadylearner profile image
Steadylearner

Ok, there maybe something different between your machine and my laptop.

Maybe you can test without cargo.lock

Anyway, hope you can find the solution for that.

If there are something I can help more, please let me know.

Thread Thread
 
scyart profile image
Scy

I'm trying to figure out what the problem is, I've tried different computers and they have the same error.
Here is my code (with my Cargo.toml dependencies above),
I hope you can help me test it when you are free. I don't know if you can run it or if the same error message appears with me.
Thank you very much! I'm not in a hurry. You can take a look at it when you are free.
gist.github.com/cy3r0/f94fa4f0bc3d...

Thread Thread
 
steadylearner profile image
Steadylearner • Edited

I tested it at github.com/steadylearner/blockchai...

I think it is ok here. I included the result image there.

dev-to-uploads.s3.amazonaws.com/up...

dev-to-uploads.s3.amazonaws.com/up...

Thread Thread
 
scyart profile image
Scy

Thank you very much. That will be very helpful.
It's pretty clear now that the problem is the Rust version, since I'm also using the M1 MacBook Air.
I would like to ask what is your rustc version? I am 1.53

Thread Thread
 
steadylearner profile image
Steadylearner • Edited

It is 1.52.1 and cargo 1.54.0-nightly here.

github.com/rust-lang/rust/blob/mas...

You can read more here.

github.com/rust-lang/cargo

Thread Thread
 
scyart profile image
Scy

Hello there,
I found that it may be my own problem.
Because I have been using cargo run, I have succeeded after trying cargo run --release.
Actually I don't know the difference between the two, but I have succeeded. Thank you very much for your help.

Thread Thread
 
steadylearner profile image
Steadylearner

--release is for without debug relevant information.

Happy to hear that you could make that.

Collapse
 
shahram_ava profile image
shahram cohen

You are absolutely right, and it has nothing with version , the code above would not work at all, the error message is very clear.

stackoverflow.com/questions/654266...

stackoverflow.com/questions/625365...

stackoverflow.com/questions/617528....

I found a solution, I can help you on that.

Collapse
 
scyart profile image
Scy

wow, thank you!

Collapse
 
shahram_ava profile image
shahram cohen

@steadylearner It is impossible that the code above works. For the simple reason that @Scy has mentioned.

We need a async version of binance-re, thee are two repo, that they have done it, I made my own solution.

Collapse
 
steadylearner profile image
Steadylearner

Ok, can you share the code or repository that works?

Collapse
 
shahram_ava profile image
shahram cohen

I invited you to the github repo, I got the initial code from openlimits. Their code was not working and even if we could there were lot of mismatching in versions of libraries so I copied it and remove some unnecessary part of their code and fixed the versions. In long run I like to improve it as I really need it for my trading algos. My algos are not fully automatic so I need a telgram bot that generates some alerts for me.

Thank you for your initial code.

Thread Thread
 
steadylearner profile image
Steadylearner • Edited

Ok, I accepted, can you contact me with t.me/steadylearner and explain what can be done by me to help you?