Skip to content

Commit

Permalink
Adds rustfmt.toml. include README in generated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisWellmann committed Mar 19, 2023
1 parent d33b684 commit 7997155
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trade_aggregation"
version = "7.2.0"
version = "7.2.1"
authors = ["MathisWellmann <wellmannmathis@gmail.com>"]
edition = "2021"
license-file = "LICENSE"
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ These are getters automatically generated by the [Candle](trade_aggregation_deri
that have the same name as the field.
In this case the 'Candle' derive macro for 'MyCandle' expands into this:
```rust
use trade_aggregation::{
candle_components::{Close, High, Low, Open},
*,
};

#[derive(Debug, Default, Clone)]
struct MyCandle {
open: Open,
high: High,
low: Low,
close: Close,
}

impl MyCandle {
fn open(&self) -> f64 {
self.open.value()
Expand All @@ -120,6 +133,7 @@ impl MyCandle {
self.close.value()
}
}

impl ModularCandle<Trade> for MyCandle {
fn update(&mut self, trade: &Trade) {
self.open.update(trade);
Expand All @@ -138,15 +152,15 @@ impl ModularCandle<Trade> for MyCandle {

See examples folder for more.
Run examples using
```
```ignore
cargo run --release --example aggregate_all_ohlc
cargo run --release --example streaming_aggregate_ohlc
```

## Performance:
To run the benchmarks, written using criterion, run:

```shell
```ignore
cargo bench
```

Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
9 changes: 4 additions & 5 deletions src/aggregation_rules/aligned_time_rule.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::aggregation_rules::TimestampResolution;
use crate::{AggregationRule, ModularCandle, TakerTrade};
use crate::{aggregation_rules::TimestampResolution, AggregationRule, ModularCandle, TakerTrade};

/// The classic time based aggregation rule,
/// creating a new candle every n seconds. The time trigger is aligned such that
Expand Down Expand Up @@ -72,14 +71,14 @@ where

#[cfg(test)]
mod tests {
use trade_aggregation_derive::Candle;

use super::*;
use crate::{
aggregate_all_trades,
candle_components::{CandleComponent, CandleComponentUpdate, Close, High, Low, Open},
load_trades_from_csv, GenericAggregator, ModularCandle, Trade, M15,
};
use trade_aggregation_derive::Candle;

use super::*;

#[test]
fn aligned_time_rule() {
Expand Down
3 changes: 1 addition & 2 deletions src/aggregation_rules/relative_price_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ where

#[cfg(test)]
mod tests {
use crate::{plot::OhlcCandle, Trade};

use super::*;
use crate::{plot::OhlcCandle, Trade};

#[test]
fn relative_price_rule() {
Expand Down
3 changes: 1 addition & 2 deletions src/aggregation_rules/tick_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ where

#[cfg(test)]
mod tests {
use super::*;
use crate::{
aggregate_all_trades, load_trades_from_csv, plot::OhlcCandle, GenericAggregator, Trade,
};

use super::*;

#[test]
fn tick_rule() {
let trades = load_trades_from_csv("data/Bitmex_XBTUSD_1M.csv").unwrap();
Expand Down
3 changes: 1 addition & 2 deletions src/aggregation_rules/time_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ where

#[cfg(test)]
mod tests {
use super::*;
use crate::{
aggregate_all_trades, load_trades_from_csv,
plot::{plot_ohlc_candles, OhlcCandle},
GenericAggregator, Trade, H1, M15, M5,
};

use super::*;

#[test]
fn time_candles_plot() {
let trades = load_trades_from_csv("data/Bitmex_XBTUSD_1M.csv").unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ where

#[cfg(test)]
mod tests {
use trade_aggregation_derive::Candle;

use super::*;
use crate::{
candle_components::{CandleComponent, CandleComponentUpdate, Close, Open},
load_trades_from_csv, ModularCandle, TimeRule, TimestampResolution, Trade, M1,
};
use trade_aggregation_derive::Candle;

use super::*;

#[derive(Default, Debug, Clone, Candle)]
struct MyCandle {
Expand Down
3 changes: 2 additions & 1 deletion src/candle_components/directional_volume_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ impl<T: TakerTrade> CandleComponentUpdate<T> for DirectionalVolumeRatio {

#[cfg(test)]
mod tests {
use super::*;
use round::round;

use super::*;

#[test]
fn volume_direction_ratio() {
let mut m = DirectionalVolumeRatio::default();
Expand Down
3 changes: 1 addition & 2 deletions src/candle_components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ mod volume;
mod weighted_price;

pub use average_price::AveragePrice;
pub use candle_component_trait::CandleComponent;
pub use candle_component_trait::CandleComponentUpdate;
pub use candle_component_trait::{CandleComponent, CandleComponentUpdate};
pub use close::Close;
pub use directional_trade_ratio::DirectionalTradeRatio;
pub use directional_volume_ratio::DirectionalVolumeRatio;
Expand Down
3 changes: 1 addition & 2 deletions src/candle_components/std_dev_prices.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::welford_online::WelfordOnline;
use crate::{CandleComponent, CandleComponentUpdate, TakerTrade};
use crate::{welford_online::WelfordOnline, CandleComponent, CandleComponentUpdate, TakerTrade};

/// This 'CandleComponent' keeps track of the standard deviation in trade prices
#[derive(Debug, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions src/candle_components/std_dev_sizes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::welford_online::WelfordOnline;
use crate::{CandleComponent, CandleComponentUpdate, TakerTrade};
use crate::{welford_online::WelfordOnline, CandleComponent, CandleComponentUpdate, TakerTrade};

/// This 'CandleComponent' keeps track of the standard deviation in the trade sizes
#[derive(Debug, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(missing_docs, rustdoc::missing_crate_level_docs)]
#![warn(clippy::all)]
#![doc = include_str!("../README.md")]

//! This crate is used for aggregating raw trade data into candles using various methods
Expand Down
5 changes: 3 additions & 2 deletions src/plot.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use plotters::prelude::*;
use trade_aggregation_derive::Candle;

use crate::{
candle_components::{CandleComponent, CandleComponentUpdate, Close, High, Low, Open},
ModularCandle, Trade,
};
use plotters::prelude::*;
use trade_aggregation_derive::Candle;

#[derive(Debug, Default, Clone, Candle)]
pub(crate) struct OhlcCandle {
Expand Down
3 changes: 2 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ pub fn load_trades_from_csv(filename: &str) -> Result<Vec<Trade>> {

#[cfg(test)]
mod tests {
use super::*;
use round::round;

use super::*;

// TODO: re-enable this test
/*
#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/welford_online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ impl WelfordOnline {

#[cfg(test)]
mod tests {
use super::*;
use round::round;

use super::*;

const VALS: [f64; 4] = [1.0, 2.0, 1.0, 2.0];

#[test]
Expand Down

0 comments on commit 7997155

Please sign in to comment.