nautilus_common/cache/
database.rs1#![allow(dead_code)]
20#![allow(unused_variables)]
21
22use std::collections::HashMap;
23
24use bytes::Bytes;
25use nautilus_core::UnixNanos;
26use nautilus_model::{
27 accounts::AccountAny,
28 data::{Bar, DataType, QuoteTick, TradeTick},
29 events::{position::snapshot::PositionSnapshot, OrderEventAny, OrderSnapshot},
30 identifiers::{
31 AccountId, ClientId, ClientOrderId, ComponentId, InstrumentId, PositionId, StrategyId,
32 VenueOrderId,
33 },
34 instruments::{InstrumentAny, SyntheticInstrument},
35 orderbook::OrderBook,
36 orders::OrderAny,
37 position::Position,
38 types::Currency,
39};
40use ustr::Ustr;
41
42use crate::{custom::CustomData, signal::Signal};
43
44pub trait CacheDatabaseAdapter {
45 fn close(&mut self) -> anyhow::Result<()>;
46
47 fn flush(&mut self) -> anyhow::Result<()>;
48
49 fn load(&self) -> anyhow::Result<HashMap<String, Bytes>>;
50
51 fn load_currencies(&mut self) -> anyhow::Result<HashMap<Ustr, Currency>>;
52
53 fn load_instruments(&mut self) -> anyhow::Result<HashMap<InstrumentId, InstrumentAny>>;
54
55 fn load_synthetics(&mut self) -> anyhow::Result<HashMap<InstrumentId, SyntheticInstrument>>;
56
57 fn load_accounts(&mut self) -> anyhow::Result<HashMap<AccountId, AccountAny>>;
58
59 fn load_orders(&mut self) -> anyhow::Result<HashMap<ClientOrderId, OrderAny>>;
60
61 fn load_positions(&mut self) -> anyhow::Result<HashMap<PositionId, Position>>;
62
63 fn load_index_order_position(&self) -> anyhow::Result<HashMap<ClientOrderId, Position>>;
64
65 fn load_index_order_client(&self) -> anyhow::Result<HashMap<ClientOrderId, ClientId>>;
66
67 fn load_currency(&self, code: &Ustr) -> anyhow::Result<Option<Currency>>;
68
69 fn load_instrument(
70 &self,
71 instrument_id: &InstrumentId,
72 ) -> anyhow::Result<Option<InstrumentAny>>;
73
74 fn load_synthetic(&self, instrument_id: &InstrumentId) -> anyhow::Result<SyntheticInstrument>;
75
76 fn load_account(&self, account_id: &AccountId) -> anyhow::Result<Option<AccountAny>>;
77
78 fn load_order(&self, client_order_id: &ClientOrderId) -> anyhow::Result<Option<OrderAny>>;
79
80 fn load_position(&self, position_id: &PositionId) -> anyhow::Result<Position>;
81
82 fn load_actor(&self, component_id: &ComponentId) -> anyhow::Result<HashMap<String, Bytes>>;
83
84 fn load_strategy(&self, strategy_id: &StrategyId) -> anyhow::Result<HashMap<String, Bytes>>;
85
86 fn load_signals(&self, name: &str) -> anyhow::Result<Vec<Signal>>;
87
88 fn load_custom_data(&self, data_type: &DataType) -> anyhow::Result<Vec<CustomData>>;
89
90 fn load_order_snapshot(
91 &self,
92 client_order_id: &ClientOrderId,
93 ) -> anyhow::Result<Option<OrderSnapshot>>;
94
95 fn load_position_snapshot(
96 &self,
97 position_id: &PositionId,
98 ) -> anyhow::Result<Option<PositionSnapshot>>;
99
100 fn load_quotes(&self, instrument_id: &InstrumentId) -> anyhow::Result<Vec<QuoteTick>>;
101
102 fn load_trades(&self, instrument_id: &InstrumentId) -> anyhow::Result<Vec<TradeTick>>;
103
104 fn load_bars(&self, instrument_id: &InstrumentId) -> anyhow::Result<Vec<Bar>>;
105
106 fn add(&self, key: String, value: Bytes) -> anyhow::Result<()>;
107
108 fn add_currency(&self, currency: &Currency) -> anyhow::Result<()>;
109
110 fn add_instrument(&self, instrument: &InstrumentAny) -> anyhow::Result<()>;
111
112 fn add_synthetic(&self, synthetic: &SyntheticInstrument) -> anyhow::Result<()>;
113
114 fn add_account(&self, account: &AccountAny) -> anyhow::Result<()>;
115
116 fn add_order(&self, order: &OrderAny, client_id: Option<ClientId>) -> anyhow::Result<()>;
117
118 fn add_order_snapshot(&self, snapshot: &OrderSnapshot) -> anyhow::Result<()>;
119
120 fn add_position(&self, position: &Position) -> anyhow::Result<()>;
121
122 fn add_position_snapshot(&self, snapshot: &PositionSnapshot) -> anyhow::Result<()>;
123
124 fn add_order_book(&self, order_book: &OrderBook) -> anyhow::Result<()>;
125
126 fn add_signal(&self, signal: &Signal) -> anyhow::Result<()>;
127
128 fn add_custom_data(&self, data: &CustomData) -> anyhow::Result<()>;
129
130 fn add_quote(&self, quote: &QuoteTick) -> anyhow::Result<()>;
131
132 fn add_trade(&self, trade: &TradeTick) -> anyhow::Result<()>;
133
134 fn add_bar(&self, bar: &Bar) -> anyhow::Result<()>;
135
136 fn delete_actor(&self, component_id: &ComponentId) -> anyhow::Result<()>;
137
138 fn delete_strategy(&self, component_id: &StrategyId) -> anyhow::Result<()>;
139
140 fn index_venue_order_id(
141 &self,
142 client_order_id: ClientOrderId,
143 venue_order_id: VenueOrderId,
144 ) -> anyhow::Result<()>;
145
146 fn index_order_position(
147 &self,
148 client_order_id: ClientOrderId,
149 position_id: PositionId,
150 ) -> anyhow::Result<()>;
151
152 fn update_actor(&self) -> anyhow::Result<()>;
153
154 fn update_strategy(&self) -> anyhow::Result<()>;
155
156 fn update_account(&self, account: &AccountAny) -> anyhow::Result<()>;
157
158 fn update_order(&self, order_event: &OrderEventAny) -> anyhow::Result<()>;
159
160 fn update_position(&self, position: &Position) -> anyhow::Result<()>;
161
162 fn snapshot_order_state(&self, order: &OrderAny) -> anyhow::Result<()>;
163
164 fn snapshot_position_state(&self, position: &Position) -> anyhow::Result<()>;
165
166 fn heartbeat(&self, timestamp: UnixNanos) -> anyhow::Result<()>;
167}