@@ -29,9 +29,10 @@ use std::{
29
29
use chrono:: TimeDelta ;
30
30
use nautilus_common:: {
31
31
cache:: Cache ,
32
+ clock:: Clock ,
32
33
msgbus:: { self } ,
33
34
} ;
34
- use nautilus_core:: { AtomicTime , UUID4 , UnixNanos } ;
35
+ use nautilus_core:: { UUID4 , UnixNanos } ;
35
36
use nautilus_model:: {
36
37
data:: { Bar , BarType , OrderBookDelta , OrderBookDeltas , QuoteTick , TradeTick , order:: BookOrder } ,
37
38
enums:: {
@@ -84,7 +85,7 @@ pub struct OrderMatchingEngine {
84
85
pub market_status : MarketStatus ,
85
86
/// The config for the matching engine.
86
87
pub config : OrderMatchingEngineConfig ,
87
- clock : & ' static AtomicTime ,
88
+ clock : Rc < RefCell < dyn Clock > > ,
88
89
cache : Rc < RefCell < Cache > > ,
89
90
book : OrderBook ,
90
91
pub core : OrderMatchingCore ,
@@ -112,7 +113,7 @@ impl OrderMatchingEngine {
112
113
book_type : BookType ,
113
114
oms_type : OmsType ,
114
115
account_type : AccountType ,
115
- clock : & ' static AtomicTime ,
116
+ clock : Rc < RefCell < dyn Clock > > ,
116
117
cache : Rc < RefCell < Cache > > ,
117
118
config : OrderMatchingEngineConfig ,
118
119
) -> Self {
@@ -495,7 +496,7 @@ impl OrderMatchingEngine {
495
496
// Check for instrument expiration or activation
496
497
if EXPIRING_INSTRUMENT_TYPES . contains ( & self . instrument . instrument_class ( ) ) {
497
498
if let Some ( activation_ns) = self . instrument . activation_ns ( ) {
498
- if self . clock . get_time_ns ( ) < activation_ns {
499
+ if self . clock . borrow ( ) . timestamp_ns ( ) < activation_ns {
499
500
self . generate_order_rejected (
500
501
order,
501
502
format ! (
@@ -509,7 +510,7 @@ impl OrderMatchingEngine {
509
510
}
510
511
}
511
512
if let Some ( expiration_ns) = self . instrument . expiration_ns ( ) {
512
- if self . clock . get_time_ns ( ) >= expiration_ns {
513
+ if self . clock . borrow ( ) . timestamp_ns ( ) >= expiration_ns {
513
514
self . generate_order_rejected (
514
515
order,
515
516
format ! (
@@ -1045,7 +1046,7 @@ impl OrderMatchingEngine {
1045
1046
/// Iterate the matching engine by processing the bid and ask order sides
1046
1047
/// and advancing time up to the given UNIX `timestamp_ns`.
1047
1048
pub fn iterate ( & mut self , timestamp_ns : UnixNanos ) {
1048
- self . clock . set_time ( timestamp_ns ) ;
1049
+ // TODO implement correct clock fixed time setting self.clock.set_time(ts_now );
1049
1050
1050
1051
// Check for updates in orderbook and set bid and ask in order matching core and iterate
1051
1052
if self . book . has_bid ( ) {
@@ -2104,7 +2105,7 @@ impl OrderMatchingEngine {
2104
2105
// -- EVENT GENERATORS -----------------------------------------------------
2105
2106
2106
2107
fn generate_order_rejected ( & self , order : & OrderAny , reason : Ustr ) {
2107
- let ts_now = self . clock . get_time_ns ( ) ;
2108
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2108
2109
let account_id = order
2109
2110
. account_id ( )
2110
2111
. unwrap_or ( self . account_ids . get ( & order. trader_id ( ) ) . unwrap ( ) . to_owned ( ) ) ;
@@ -2125,7 +2126,7 @@ impl OrderMatchingEngine {
2125
2126
}
2126
2127
2127
2128
fn generate_order_accepted ( & self , order : & mut OrderAny , venue_order_id : VenueOrderId ) {
2128
- let ts_now = self . clock . get_time_ns ( ) ;
2129
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2129
2130
let account_id = order
2130
2131
. account_id ( )
2131
2132
. unwrap_or ( self . account_ids . get ( & order. trader_id ( ) ) . unwrap ( ) . to_owned ( ) ) ;
@@ -2158,7 +2159,7 @@ impl OrderMatchingEngine {
2158
2159
venue_order_id : Option < VenueOrderId > ,
2159
2160
account_id : Option < AccountId > ,
2160
2161
) {
2161
- let ts_now = self . clock . get_time_ns ( ) ;
2162
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2162
2163
let event = OrderEventAny :: ModifyRejected ( OrderModifyRejected :: new (
2163
2164
trader_id,
2164
2165
strategy_id,
@@ -2186,7 +2187,7 @@ impl OrderMatchingEngine {
2186
2187
venue_order_id : VenueOrderId ,
2187
2188
reason : Ustr ,
2188
2189
) {
2189
- let ts_now = self . clock . get_time_ns ( ) ;
2190
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2190
2191
let event = OrderEventAny :: CancelRejected ( OrderCancelRejected :: new (
2191
2192
trader_id,
2192
2193
strategy_id,
@@ -2210,7 +2211,7 @@ impl OrderMatchingEngine {
2210
2211
price : Option < Price > ,
2211
2212
trigger_price : Option < Price > ,
2212
2213
) {
2213
- let ts_now = self . clock . get_time_ns ( ) ;
2214
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2214
2215
let event = OrderEventAny :: Updated ( OrderUpdated :: new (
2215
2216
order. trader_id ( ) ,
2216
2217
order. strategy_id ( ) ,
@@ -2233,7 +2234,7 @@ impl OrderMatchingEngine {
2233
2234
}
2234
2235
2235
2236
fn generate_order_canceled ( & self , order : & OrderAny , venue_order_id : VenueOrderId ) {
2236
- let ts_now = self . clock . get_time_ns ( ) ;
2237
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2237
2238
let event = OrderEventAny :: Canceled ( OrderCanceled :: new (
2238
2239
order. trader_id ( ) ,
2239
2240
order. strategy_id ( ) ,
@@ -2250,7 +2251,7 @@ impl OrderMatchingEngine {
2250
2251
}
2251
2252
2252
2253
fn generate_order_triggered ( & self , order : & OrderAny ) {
2253
- let ts_now = self . clock . get_time_ns ( ) ;
2254
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2254
2255
let event = OrderEventAny :: Triggered ( OrderTriggered :: new (
2255
2256
order. trader_id ( ) ,
2256
2257
order. strategy_id ( ) ,
@@ -2267,7 +2268,7 @@ impl OrderMatchingEngine {
2267
2268
}
2268
2269
2269
2270
fn generate_order_expired ( & self , order : & OrderAny ) {
2270
- let ts_now = self . clock . get_time_ns ( ) ;
2271
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2271
2272
let event = OrderEventAny :: Expired ( OrderExpired :: new (
2272
2273
order. trader_id ( ) ,
2273
2274
order. strategy_id ( ) ,
@@ -2295,7 +2296,7 @@ impl OrderMatchingEngine {
2295
2296
commission : Money ,
2296
2297
liquidity_side : LiquiditySide ,
2297
2298
) {
2298
- let ts_now = self . clock . get_time_ns ( ) ;
2299
+ let ts_now = self . clock . borrow ( ) . timestamp_ns ( ) ;
2299
2300
let account_id = order
2300
2301
. account_id ( )
2301
2302
. unwrap_or ( self . account_ids . get ( & order. trader_id ( ) ) . unwrap ( ) . to_owned ( ) ) ;
0 commit comments