core/rustybot/src/main.rs

71 lines
1.7 KiB
Rust
Raw Normal View History

2021-01-14 12:42:23 +00:00
#![feature(drain_filter)]
2021-01-14 18:56:31 +00:00
use fern::colors::{Color, ColoredLevelConfig};
use log::LevelFilter::Debug;
2021-01-14 18:56:31 +00:00
use tokio::time::Duration;
2021-01-04 10:45:54 +00:00
use crate::bot::BfxBot;
2021-01-14 18:56:31 +00:00
use crate::connectors::ExchangeKind;
use crate::currency::Symbol;
2021-01-14 19:20:58 +00:00
use crate::strategy::TrailingStop;
2021-01-02 14:10:16 +00:00
2021-01-05 12:58:47 +00:00
mod bot;
mod connectors;
mod currency;
2021-01-02 12:15:19 +00:00
mod events;
2021-01-13 09:03:24 +00:00
mod managers;
mod models;
2021-01-02 14:10:16 +00:00
mod strategy;
2021-01-05 12:58:47 +00:00
mod ticker;
2021-01-01 14:07:16 +00:00
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
#[tokio::main]
async fn main() -> Result<(), BoxError> {
2021-01-14 18:56:31 +00:00
setup_logger()?;
2021-01-05 19:50:14 +00:00
let test_api_key = "P1EVE68DJByDAkGQvpIkTwfrbYXd2Vo2ZaIhTYb9vx2";
let test_api_secret = "1nicg8z0zKVEt5Rb7ZDpIYjVYVTgvCaCPMZqB0niFli";
2021-01-14 12:42:23 +00:00
let bitfinex = ExchangeKind::Bitfinex {
api_key: test_api_key.into(),
api_secret: test_api_secret.into(),
};
2021-01-05 19:50:14 +00:00
let mut bot = BfxBot::new(
2021-01-14 12:42:23 +00:00
vec![bitfinex],
2021-01-05 19:50:14 +00:00
vec![Symbol::TESTBTC],
Symbol::TESTUSD,
2021-01-14 12:42:23 +00:00
Duration::new(1, 0),
2021-01-14 19:20:58 +00:00
)
.with_position_strategy(Box::new(TrailingStop::new()));
2021-01-02 14:10:16 +00:00
2021-01-05 19:50:14 +00:00
Ok(bot.start_loop().await?)
2021-01-01 14:07:16 +00:00
}
2021-01-14 18:56:31 +00:00
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)
2021-01-14 18:56:31 +00:00
.filter(|metadata| metadata.target().contains("rustybot"))
.chain(std::io::stdout())
2021-01-15 10:40:48 +00:00
// .chain(fern::log_file("rustico.log")?)
2021-01-14 18:56:31 +00:00
.apply()?;
Ok(())
}