warnings cleanup and logging
This commit is contained in:
parent
2c151ae6c1
commit
b9564dc812
34
rustybot/Cargo.lock
generated
34
rustybot/Cargo.lock
generated
@ -35,6 +35,17 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@ -198,6 +209,17 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colored"
|
||||||
|
version = "1.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"lazy_static",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@ -269,6 +291,16 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fern"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065"
|
||||||
|
dependencies = [
|
||||||
|
"colored",
|
||||||
|
"log 0.4.11",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
@ -1097,7 +1129,9 @@ dependencies = [
|
|||||||
"async-trait",
|
"async-trait",
|
||||||
"bitfinex",
|
"bitfinex",
|
||||||
"dyn-clone",
|
"dyn-clone",
|
||||||
|
"fern",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"log 0.4.11",
|
||||||
"regex",
|
"regex",
|
||||||
"tokio 0.2.24",
|
"tokio 0.2.24",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite",
|
||||||
|
@ -13,4 +13,6 @@ tokio-tungstenite = "*"
|
|||||||
futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] }
|
futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] }
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
dyn-clone = "1"
|
dyn-clone = "1"
|
||||||
|
log = "0.4"
|
||||||
|
fern = {version = "0.6", features = ["colored"]}
|
@ -1,18 +1,12 @@
|
|||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use bitfinex::api::Bitfinex;
|
use log::{error, info};
|
||||||
use bitfinex::positions::Position;
|
|
||||||
use bitfinex::ticker::TradingPairTicker;
|
|
||||||
use futures_util::stream::FuturesUnordered;
|
|
||||||
use tokio::stream::StreamExt;
|
|
||||||
use tokio::time::delay_for;
|
use tokio::time::delay_for;
|
||||||
|
|
||||||
use crate::connectors::{Client, Connector, ExchangeKind};
|
use crate::connectors::{Client, ExchangeKind};
|
||||||
use crate::currency::{Symbol, SymbolPair};
|
use crate::currency::{Symbol, SymbolPair};
|
||||||
use crate::events::{Event, EventKind};
|
use crate::events::Event;
|
||||||
use crate::managers::{OrderManager, PositionManager, PriceManager};
|
use crate::managers::{OrderManager, PositionManager, PriceManager};
|
||||||
use crate::strategy::PositionStrategy;
|
|
||||||
use crate::ticker::Ticker;
|
use crate::ticker::Ticker;
|
||||||
use crate::BoxError;
|
use crate::BoxError;
|
||||||
|
|
||||||
@ -61,10 +55,16 @@ impl BfxBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_loop(&mut self) -> Result<(), BoxError> {
|
pub async fn start_loop(&mut self) -> Result<(), BoxError> {
|
||||||
self.update_managers().await?;
|
if let Err(e) = self.update_managers().await {
|
||||||
|
error!("Error while starting managers: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
self.update().await;
|
info!("Current tick: {}", self.ticker.current_tick());
|
||||||
|
|
||||||
|
if let Err(e) = self.update().await {
|
||||||
|
error!("Error in main bot loop: {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,9 @@ impl BfxBot {
|
|||||||
delay_for(self.ticker.duration()).await;
|
delay_for(self.ticker.duration()).await;
|
||||||
self.ticker.inc();
|
self.ticker.inc();
|
||||||
|
|
||||||
self.update_managers().await?;
|
if let Err(e) = self.update_managers().await {
|
||||||
|
error!("Error while updating managers: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -89,8 +91,6 @@ impl BfxBot {
|
|||||||
let tick = self.ticker.current_tick();
|
let tick = self.ticker.current_tick();
|
||||||
|
|
||||||
mgr.update(tick).await?;
|
mgr.update(tick).await?;
|
||||||
|
|
||||||
println!("{:?}", mgr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@ -117,7 +117,7 @@ impl BfxBot {
|
|||||||
price_entries.push(f.await??);
|
price_entries.push(f.await??);
|
||||||
}
|
}
|
||||||
|
|
||||||
for mut manager in &mut self.price_managers {
|
for manager in &mut self.price_managers {
|
||||||
let prices: Vec<_> = price_entries
|
let prices: Vec<_> = price_entries
|
||||||
.drain_filter(|x| x.pair() == manager.pair())
|
.drain_filter(|x| x.pair() == manager.pair())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::TryInto;
|
||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@ -6,10 +7,9 @@ use bitfinex::api::Bitfinex;
|
|||||||
use bitfinex::orders::{OrderForm, OrderMeta};
|
use bitfinex::orders::{OrderForm, OrderMeta};
|
||||||
use bitfinex::ticker::TradingPairTicker;
|
use bitfinex::ticker::TradingPairTicker;
|
||||||
|
|
||||||
use crate::currency::{Symbol, SymbolPair};
|
use crate::currency::SymbolPair;
|
||||||
use crate::models::{Order, OrderKind, Position, PositionState, PriceTicker};
|
use crate::models::{Order, OrderKind, Position, PositionState, PriceTicker};
|
||||||
use crate::BoxError;
|
use crate::BoxError;
|
||||||
use std::fmt::{Debug, Formatter};
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
|
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
|
||||||
pub enum ExchangeKind {
|
pub enum ExchangeKind {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt::{Display, Error, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashMap;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
use tokio::stream::StreamExt;
|
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
|
||||||
use crate::bot::BfxBot;
|
|
||||||
use crate::managers::PriceManager;
|
use crate::managers::PriceManager;
|
||||||
use crate::models::{Position, PositionProfitState};
|
use crate::models::{Position, PositionProfitState};
|
||||||
use crate::BoxError;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
pub enum SignalKind {
|
pub enum SignalKind {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#![feature(drain_filter)]
|
#![feature(drain_filter)]
|
||||||
|
|
||||||
use std::thread::JoinHandle;
|
use fern::colors::{Color, ColoredLevelConfig};
|
||||||
|
use log::LevelFilter::Info;
|
||||||
use tokio::time::{delay_for, Duration};
|
use tokio::time::Duration;
|
||||||
|
|
||||||
use crate::bot::BfxBot;
|
use crate::bot::BfxBot;
|
||||||
use crate::connectors::{BitfinexConnector, ExchangeKind};
|
use crate::connectors::ExchangeKind;
|
||||||
use crate::currency::{Symbol, SymbolPair};
|
use crate::currency::Symbol;
|
||||||
use crate::events::SignalKind;
|
|
||||||
|
|
||||||
mod bot;
|
mod bot;
|
||||||
mod connectors;
|
mod connectors;
|
||||||
@ -22,6 +21,8 @@ pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), BoxError> {
|
async fn main() -> Result<(), BoxError> {
|
||||||
|
setup_logger()?;
|
||||||
|
|
||||||
let test_api_key = "P1EVE68DJByDAkGQvpIkTwfrbYXd2Vo2ZaIhTYb9vx2";
|
let test_api_key = "P1EVE68DJByDAkGQvpIkTwfrbYXd2Vo2ZaIhTYb9vx2";
|
||||||
let test_api_secret = "1nicg8z0zKVEt5Rb7ZDpIYjVYVTgvCaCPMZqB0niFli";
|
let test_api_secret = "1nicg8z0zKVEt5Rb7ZDpIYjVYVTgvCaCPMZqB0niFli";
|
||||||
let affiliate_code = "XPebOgHxA";
|
let affiliate_code = "XPebOgHxA";
|
||||||
@ -41,3 +42,29 @@ async fn main() -> Result<(), BoxError> {
|
|||||||
|
|
||||||
Ok(bot.start_loop().await?)
|
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(Info)
|
||||||
|
.filter(|metadata| metadata.target().contains("rustybot"))
|
||||||
|
.chain(std::io::stdout())
|
||||||
|
.chain(fern::log_file("rustico.log")?)
|
||||||
|
.apply()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::connectors::{Client, Connector};
|
use crate::connectors::Client;
|
||||||
use crate::currency::SymbolPair;
|
use crate::currency::SymbolPair;
|
||||||
use crate::events::{Event, EventDispatcher, SignalKind};
|
use crate::events::{Event, SignalKind};
|
||||||
use crate::models::{Order, Position, PriceTicker};
|
use crate::models::{Order, Position, PriceTicker};
|
||||||
use crate::strategy::PositionStrategy;
|
use crate::strategy::PositionStrategy;
|
||||||
use crate::ticker::Ticker;
|
|
||||||
use crate::BoxError;
|
use crate::BoxError;
|
||||||
|
|
||||||
pub struct EventManager {
|
pub struct EventManager {
|
||||||
@ -173,7 +172,7 @@ impl PositionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(&mut self, tick: u64) -> Result<Option<Vec<Event>>, BoxError> {
|
pub async fn update(&mut self, tick: u64) -> Result<Option<Vec<Event>>, BoxError> {
|
||||||
let mut opt_active_positions = self.client.active_positions(&self.pair).await?;
|
let opt_active_positions = self.client.active_positions(&self.pair).await?;
|
||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
|
|
||||||
if opt_active_positions.is_none() {
|
if opt_active_positions.is_none() {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::events::{Event, EventKind, EventMetadata, SignalKind};
|
|
||||||
use crate::managers::{PositionManager, PriceManager};
|
|
||||||
use crate::models::{Position, PositionProfitState};
|
|
||||||
use dyn_clone::DynClone;
|
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
|
|
||||||
|
use dyn_clone::DynClone;
|
||||||
|
|
||||||
|
use crate::events::{Event, SignalKind};
|
||||||
|
use crate::managers::PositionManager;
|
||||||
|
use crate::models::Position;
|
||||||
|
|
||||||
pub trait PositionStrategy: DynClone {
|
pub trait PositionStrategy: DynClone {
|
||||||
fn on_new_tick(
|
fn on_new_tick(
|
||||||
&self,
|
&self,
|
||||||
|
Loading…
Reference in New Issue
Block a user