-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
52 lines (44 loc) · 1.2 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pub mod datasource;
pub mod graph;
pub mod strategy;
pub mod types;
use std::error::Error;
use clap::Parser;
use strategy::ArbitrageStrategy;
use crate::datasource::Datasource;
#[derive(Parser)]
pub struct ArbitrConfig {}
impl Default for ArbitrConfig {
fn default() -> Self {
ArbitrConfig {}
}
}
pub struct Arbitr<'a> {
pub config: ArbitrConfig,
pub datasource: &'a mut dyn Datasource<'a>,
pub strategy: &'a mut dyn ArbitrageStrategy<'a>,
}
impl<'a> Arbitr<'a> {
pub fn new(
config: ArbitrConfig,
datasource: &'a mut dyn Datasource<'a>,
strategy: &'a mut dyn ArbitrageStrategy<'a>,
) -> Arbitr<'a> {
Arbitr {
config,
datasource,
strategy,
}
}
pub fn execute(&'a mut self) -> Result<(), Box<dyn Error>> {
self.datasource.init()?;
loop {
let pairs = self.datasource.pairs()?;
self.strategy.refresh(pairs)?;
self.strategy.compute()?;
// TODO: have self.strategy.compute() return some sort of intermediate
// trade instruction that will then be executed via self.datasource at
// the end of this loop
}
}
}