nautilus_tardis/
factories.rs1use std::{any::Any, cell::RefCell, rc::Rc};
19
20use nautilus_common::{cache::Cache, clients::DataClient, clock::Clock};
21use nautilus_model::identifiers::ClientId;
22use nautilus_system::factories::{ClientConfig, DataClientFactory};
23
24use crate::{common::consts::TARDIS, config::TardisDataClientConfig, data::TardisDataClient};
25
26impl ClientConfig for TardisDataClientConfig {
27 fn as_any(&self) -> &dyn Any {
28 self
29 }
30}
31
32#[derive(Debug)]
34pub struct TardisDataClientFactory;
35
36impl TardisDataClientFactory {
37 #[must_use]
39 pub const fn new() -> Self {
40 Self
41 }
42}
43
44impl Default for TardisDataClientFactory {
45 fn default() -> Self {
46 Self::new()
47 }
48}
49
50impl DataClientFactory for TardisDataClientFactory {
51 fn create(
52 &self,
53 name: &str,
54 config: &dyn ClientConfig,
55 _cache: Rc<RefCell<Cache>>,
56 _clock: Rc<RefCell<dyn Clock>>,
57 ) -> anyhow::Result<Box<dyn DataClient>> {
58 let tardis_config = config
59 .as_any()
60 .downcast_ref::<TardisDataClientConfig>()
61 .ok_or_else(|| {
62 anyhow::anyhow!(
63 "Invalid config type for TardisDataClientFactory. \
64 Expected TardisDataClientConfig, was {config:?}",
65 )
66 })?
67 .clone();
68
69 let client_id = ClientId::from(name);
70 let client = TardisDataClient::new(client_id, tardis_config)?;
71 Ok(Box::new(client))
72 }
73
74 fn name(&self) -> &'static str {
75 TARDIS
76 }
77
78 fn config_type(&self) -> &'static str {
79 "TardisDataClientConfig"
80 }
81}