core/rustybot/src/main.rs
2021-01-15 10:40:48 +00:00

71 lines
1.7 KiB
Rust

#![feature(drain_filter)]
use fern::colors::{Color, ColoredLevelConfig};
use log::LevelFilter::Debug;
use tokio::time::Duration;
use crate::bot::BfxBot;
use crate::connectors::ExchangeKind;
use crate::currency::Symbol;
use crate::strategy::TrailingStop;
mod bot;
mod connectors;
mod currency;
mod events;
mod managers;
mod models;
mod strategy;
mod ticker;
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
#[tokio::main]
async fn main() -> Result<(), BoxError> {
setup_logger()?;
let test_api_key = "P1EVE68DJByDAkGQvpIkTwfrbYXd2Vo2ZaIhTYb9vx2";
let test_api_secret = "1nicg8z0zKVEt5Rb7ZDpIYjVYVTgvCaCPMZqB0niFli";
let bitfinex = ExchangeKind::Bitfinex {
api_key: test_api_key.into(),
api_secret: test_api_secret.into(),
};
let mut bot = BfxBot::new(
vec![bitfinex],
vec![Symbol::TESTBTC],
Symbol::TESTUSD,
Duration::new(1, 0),
)
.with_position_strategy(Box::new(TrailingStop::new()));
Ok(bot.start_loop().await?)
}
fn setup_logger() -> Result<(), fern::InitError> {
let colors = ColoredLevelConfig::new()
.info(Color::Green)
.error(Color::Red)
.trace(Color::Blue)
.debug(Color::Cyan)
.warn(Color::Yellow);
fern::Dispatch::new()
.format(move |out, message, record| {
out.finish(format_args!(
"[{}][{}] {}",
record.target(),
colors.color(record.level()),
message
))
})
.level(Debug)
.filter(|metadata| metadata.target().contains("rustybot"))
.chain(std::io::stdout())
// .chain(fern::log_file("rustico.log")?)
.apply()?;
Ok(())
}