diff --git a/rustybot/src/bot.rs b/rustybot/src/bot.rs new file mode 100644 index 0000000..055cd9d --- /dev/null +++ b/rustybot/src/bot.rs @@ -0,0 +1,30 @@ +use std::collections::HashMap; + +use bitfinex::api::Bitfinex; + +use crate::pairs::PairStatus; +use crate::ticker::Ticker; +use core::time::Duration; + +struct BfxBot { + bfx: Bitfinex, + ticker: Ticker, + pair_status: HashMap, + quote: String, + account_info: String, + ledger: String, +} + +impl BfxBot { + pub fn new>(api_key: S, api_secret: S, pairs: Vec, quote: String, tick_duration: Duration) -> Self { + BfxBot { + bfx: Bitfinex::new(Some(api_key.into()), Some(api_secret.into())), + ticker: Ticker::new(tick_duration), + pair_status: HashMap::new(), + quote, + account_info: String::new(), + ledger: String::new(), + } + } +} + diff --git a/rustybot/src/currency.rs b/rustybot/src/currency.rs new file mode 100644 index 0000000..3d8e17e --- /dev/null +++ b/rustybot/src/currency.rs @@ -0,0 +1,111 @@ +#[derive(Clone)] +struct Symbol; + +impl Symbol { + const XMR: &'static str = "XMR"; + const BTC: &'static str = "BTC"; + const ETH: &'static str = "ETH"; + const USD: &'static str = "USD"; +} + +#[derive(Clone)] +struct TradingPair { + quote: Symbol +} + +impl TradingPair {} + +#[derive(Clone)] +struct Currency { + name: String, + amount: f64, + price: Option, +} + +impl Currency { + pub fn new, F: Into>(name: S, amount: F, price: Option) -> Self { + Currency { + name: name.into(), + amount: amount.into(), + price: price.map(|x| x.into()), + } + } + + pub fn name(&self) -> &str { + &self.name + } + pub fn amount(&self) -> f64 { + self.amount + } + pub fn price(&self) -> Option { + self.price + } +} + +#[derive(Clone)] +enum WalletKind { + Margin, + Exchange, + Funding, +} + +#[derive(Clone)] +struct Balance { + currency: Currency, + quote: Symbol, + quote_equivalent: f64, + wallet: WalletKind, +} + +impl Balance { + pub fn new(currency: Currency, quote: Symbol, quote_equivalent: f64, wallet: WalletKind) -> Self { + Balance { currency, quote, quote_equivalent, wallet } + } + + pub fn currency(&self) -> &Currency { + &self.currency + } + pub fn quote(&self) -> &Symbol { + &self.quote + } + pub fn quote_equivalent(&self) -> f64 { + self.quote_equivalent + } + pub fn wallet(&self) -> &WalletKind { + &self.wallet + } +} + +struct BalanceGroup { + quote: Symbol, + quote_equivalent: f64, + balances: Vec, +} + +impl BalanceGroup { + pub fn new(quote: Symbol) -> Self { + BalanceGroup { quote, balances: Vec::new(), quote_equivalent: 0f64 } + } + + pub fn add_balance(&mut self, balance: &Balance) { + self.balances.push(balance.clone()); + + self.quote_equivalent += balance.quote_equivalent() + } + + pub fn currency_names(&self) -> Vec { + self.balances.iter() + .map(|x| x.currency().name().into()) + .collect() + } + + pub fn quote(&self) -> &Symbol { + &self.quote + } + pub fn balances(&self) -> &Vec { + &self.balances + } +} + + + diff --git a/rustybot/src/main.rs b/rustybot/src/main.rs index 914da6e..d77b4e1 100644 --- a/rustybot/src/main.rs +++ b/rustybot/src/main.rs @@ -5,6 +5,8 @@ mod events; mod pairs; mod positions; mod strategy; +mod bot; +mod currency; pub type BoxError = Box; diff --git a/rustybot/src/ticker.rs b/rustybot/src/ticker.rs index 7bdf318..87226bb 100644 --- a/rustybot/src/ticker.rs +++ b/rustybot/src/ticker.rs @@ -7,7 +7,7 @@ pub struct Ticker { } impl Ticker { - fn new(duration: Duration) -> Self { + pub(crate) fn new(duration: Duration) -> Self { Ticker { duration, start_time: Instant::now(),