Skip to content

Instantly share code, notes, and snippets.

@cy3r0

cy3r0/main.rs Secret

Created June 21, 2021 20:25
Show Gist options
  • Save cy3r0/f94fa4f0bc3da5f0a06acc67900ab5b4 to your computer and use it in GitHub Desktop.
Save cy3r0/f94fa4f0bc3da5f0a06acc67900ab5b4 to your computer and use it in GitHub Desktop.
/* Cargo.toml
[dependencies]
teloxide = { version = "0.4", features = ["auto-send", "macros"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3", features = ["rt-multi-thread", "macros"] }
binance = { git = "https://github.com/wisespace-io/binance-rs.git" }
*/
use binance::{api::*, market::*};
use std::error::Error;
use teloxide::{prelude::*, utils::command::BotCommand};
#[derive(BotCommand)]
#[command(rename = "lowercase", description = "These commands are supported:")]
enum Command {
#[command(description = "Show ETH Price")]
ETH,
}
async fn answer(
cx: UpdateWithCx<AutoSend<Bot>, Message>,
command: Command,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let market: Market = Binance::new(None, None);
match command {
Command::ETH => {
let pair: String = "ETHUSDT".to_string();
match market.get_average_price(pair) {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {:?}", e),
};
cx.answer("Test").await?
}
};
Ok(())
}
#[tokio::main]
async fn main() {
run().await;
}
async fn run() {
teloxide::enable_logging!();
log::info!("Starting...");
let bot = Bot::new("160175....").auto_send();
let bot_name: String = "binance_bot".into();
teloxide::commands_repl(bot, bot_name, answer).await;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment