Skip to content

Commit 9c04443

Browse files
committed
change clock type in simulated exchange
1 parent 5f7eca7 commit 9c04443

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

crates/backtest/src/exchange.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use std::{
2525
rc::Rc,
2626
};
2727

28-
use nautilus_common::cache::Cache;
28+
use nautilus_common::{cache::Cache, clock::Clock};
2929
use nautilus_core::{
30-
AtomicTime, UnixNanos,
30+
UnixNanos,
3131
correctness::{FAILED, check_equal},
3232
};
3333
use nautilus_execution::{
@@ -105,7 +105,7 @@ pub struct SimulatedExchange {
105105
matching_engines: HashMap<InstrumentId, OrderMatchingEngine>,
106106
leverages: HashMap<InstrumentId, Decimal>,
107107
modules: Vec<Box<dyn SimulationModule>>,
108-
clock: &'static AtomicTime,
108+
clock: Rc<RefCell<dyn Clock>>,
109109
cache: Rc<RefCell<Cache>>,
110110
message_queue: VecDeque<TradingCommand>,
111111
inflight_queue: BinaryHeap<InflightCommand>,
@@ -134,7 +134,7 @@ impl SimulatedExchange {
134134
leverages: HashMap<InstrumentId, Decimal>,
135135
modules: Vec<Box<dyn SimulationModule>>,
136136
cache: Rc<RefCell<Cache>>,
137-
clock: &'static AtomicTime,
137+
clock: Rc<RefCell<dyn Clock>>,
138138
fill_model: FillModel,
139139
fee_model: FeeModelAny,
140140
book_type: BookType,
@@ -249,7 +249,7 @@ impl SimulatedExchange {
249249
self.book_type,
250250
self.oms_type,
251251
self.account_type,
252-
self.clock,
252+
self.clock.clone(),
253253
Rc::clone(&self.cache),
254254
matching_engine_config,
255255
);
@@ -380,7 +380,7 @@ impl SimulatedExchange {
380380
vec![current_balance],
381381
margins.values().copied().collect(),
382382
true,
383-
self.clock.get_time_ns(),
383+
self.clock.borrow().timestamp_ns(),
384384
)
385385
.unwrap();
386386
}
@@ -606,7 +606,7 @@ impl SimulatedExchange {
606606
}
607607

608608
pub fn process(&mut self, ts_now: UnixNanos) {
609-
self.clock.set_time(ts_now);
609+
// TODO implement correct clock fixed time setting self.clock.set_time(ts_now);
610610

611611
// Process inflight commands
612612
while let Some(inflight) = self.inflight_queue.peek() {
@@ -684,7 +684,7 @@ impl SimulatedExchange {
684684

685685
if let Some(exec_client) = &self.exec_client {
686686
exec_client
687-
.generate_account_state(balances, vec![], true, self.clock.get_time_ns())
687+
.generate_account_state(balances, vec![], true, self.clock.borrow().timestamp_ns())
688688
.unwrap();
689689
}
690690

@@ -766,7 +766,7 @@ mod tests {
766766
cache: Option<Rc<RefCell<Cache>>>,
767767
) -> Rc<RefCell<SimulatedExchange>> {
768768
let cache = cache.unwrap_or(Rc::new(RefCell::new(Cache::default())));
769-
769+
let clock = Rc::new(RefCell::new(TestClock::new()));
770770
let exchange = Rc::new(RefCell::new(
771771
SimulatedExchange::new(
772772
venue,
@@ -778,7 +778,7 @@ mod tests {
778778
HashMap::new(),
779779
vec![],
780780
cache.clone(),
781-
&ATOMIC_TIME,
781+
clock,
782782
FillModel::default(),
783783
FeeModelAny::MakerTaker(MakerTakerFeeModel),
784784
book_type,

0 commit comments

Comments
 (0)