/main.rs Secret
Created
June 21, 2021 20:25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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