Skip to content

Commit e738a57

Browse files
committed
Add errors and panics docs
1 parent cf354f6 commit e738a57

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

crates/analysis/src/analyzer.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ impl PortfolioAnalyzer {
194194
}
195195

196196
/// Calculates total `PnL` including unrealized `PnL` if provided.
197+
///
198+
/// # Errors
199+
///
200+
/// Returns an error if:
201+
///
202+
/// - No currency is specified in a multi-currency portfolio.
203+
/// - The specified currency is not found in account balances.
204+
/// - The unrealized PnL currency does not match the specified currency.
197205
pub fn total_pnl(
198206
&self,
199207
currency: Option<&Currency>,
@@ -229,6 +237,14 @@ impl PortfolioAnalyzer {
229237
}
230238

231239
/// Calculates total `PnL` as a percentage of starting balance.
240+
///
241+
/// # Errors
242+
///
243+
/// Returns an error if:
244+
///
245+
/// - No currency is specified in a multi-currency portfolio.
246+
/// - The specified currency is not found in account balances.
247+
/// - The unrealized PnL currency does not match the specified currency.
232248
pub fn total_pnl_percentage(
233249
&self,
234250
currency: Option<&Currency>,
@@ -272,6 +288,14 @@ impl PortfolioAnalyzer {
272288
}
273289

274290
/// Gets all PnL-related performance statistics.
291+
///
292+
/// # Errors
293+
///
294+
/// Returns an error if PnL calculations fail, for example due to:
295+
///
296+
/// - No currency specified for a multi-currency portfolio.
297+
/// - Unrealized PnL currency not matching the specified currency.
298+
/// - Specified currency not found in account balances.
275299
pub fn get_performance_stats_pnls(
276300
&self,
277301
currency: Option<&Currency>,
@@ -338,6 +362,10 @@ impl PortfolioAnalyzer {
338362
}
339363

340364
/// Gets formatted `PnL` statistics as strings.
365+
///
366+
/// # Errors
367+
///
368+
/// Returns an error if PnL statistics calculation fails.
341369
pub fn get_stats_pnls_formatted(
342370
&self,
343371
currency: Option<&Currency>,

crates/analysis/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
#![deny(unsafe_code)]
3737
#![deny(nonstandard_style)]
3838
#![deny(missing_debug_implementations)]
39-
// #![deny(clippy::missing_errors_doc)]
39+
#![deny(clippy::missing_errors_doc)]
40+
#![deny(clippy::missing_panics_doc)]
4041
#![deny(rustdoc::broken_intra_doc_links)]
4142

4243
pub mod analyzer;

crates/backtest/src/engine.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ impl BacktestEngine {
178178
todo!("implement change_fill_model")
179179
}
180180

181+
/// Adds an instrument to the backtest engine for the specified venue.
182+
///
183+
/// # Errors
184+
///
185+
/// Returns an error if:
186+
///
187+
/// - The instrument's associated venue has not been added via `add_venue`.
188+
/// - Attempting to add a `CurrencyPair` instrument for a single-currency CASH account.
181189
pub fn add_instrument(&mut self, instrument: InstrumentAny) -> anyhow::Result<()> {
182190
let instrument_id = instrument.id();
183191
if let Some(exchange) = self.venues.get_mut(&instrument.id().venue) {

crates/backtest/src/exchange.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ pub struct SimulatedExchange {
123123

124124
impl SimulatedExchange {
125125
/// Creates a new [`SimulatedExchange`] instance.
126+
///
127+
/// # Errors
128+
///
129+
/// Returns an error if:
130+
///
131+
/// - `starting_balances` is empty.
132+
/// - `base_currency` is `Some` but `starting_balances` contains multiple currencies.
126133
#[allow(clippy::too_many_arguments)]
127134
pub fn new(
128135
venue: Venue,
@@ -213,6 +220,13 @@ impl SimulatedExchange {
213220
self.generate_fresh_account_state();
214221
}
215222

223+
/// Adds an instrument to the simulated exchange and initializes its matching engine.
224+
///
225+
/// # Errors
226+
///
227+
/// Returns an error if:
228+
///
229+
/// - The exchange account type is `Cash` and the instrument is a `CryptoPerpetual` or `CryptoFuture`.
216230
pub fn add_instrument(&mut self, instrument: InstrumentAny) -> anyhow::Result<()> {
217231
check_equal(
218232
&instrument.id().venue,

crates/backtest/src/ffi/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515

1616
//! C foreign function interface (FFI) from [cbindgen](https://github.com/mozilla/cbindgen).
1717
18+
#![allow(unsafe_code)]
19+
1820
pub mod engine;

crates/backtest/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
3030
3131
#![warn(rustc::all)]
32+
#![deny(unsafe_code)]
3233
#![deny(nonstandard_style)]
33-
// #![deny(clippy::missing_errors_doc)]
34+
// #![deny(missing_debug_implementations)]
35+
#![deny(clippy::missing_errors_doc)]
36+
// #![deny(clippy::missing_panics_doc)]
3437
#![deny(rustdoc::broken_intra_doc_links)]
3538

36-
// Uncomment once we've added trivial `Debug` impls everywhere
37-
// #![warn(missing_debug_implementations)]
38-
3939
pub mod accumulator;
4040
pub mod config;
4141
pub mod data_client;

0 commit comments

Comments
 (0)