Skip to content

Commit

Permalink
Merge pull request #38 from Overmuse/SR/more_metrics
Browse files Browse the repository at this point in the history
some more metrics
  • Loading branch information
SebRollen authored Jul 8, 2021
2 parents 59aee1a + 7cb065f commit 011eaba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "order-manager"
version = "6.1.3"
version = "6.1.4"
authors = ["Sebastian Rollen <seb@overmu.se>"]
edition = "2018"

Expand Down
7 changes: 5 additions & 2 deletions src/manager/order_updates.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::OrderManager;
use crate::db;
use crate::metrics::NUM_TRADES;
use crate::metrics::{GROSS_TRADE_AMOUNT, NUM_TRADES};
use crate::types::{split_lot, Allocation, Lot};
use alpaca::{Event, OrderEvent, Side};
use anyhow::{anyhow, Context, Result};
Expand Down Expand Up @@ -33,7 +33,10 @@ impl OrderManager {
price, timestamp, ..
} => {
debug!("Order filled");
NUM_TRADES.inc();
NUM_TRADES.with_label_values(&[&ticker]).inc();
GROSS_TRADE_AMOUNT
.with_label_values(&[&ticker])
.inc_by((qty * price).abs().to_f64().unwrap());
let new_lot = self
.make_lot(&id, ticker, timestamp, price, qty)
.await
Expand Down
15 changes: 12 additions & 3 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
use lazy_static::lazy_static;
use prometheus::{IntCounter, Registry};
use prometheus::{CounterVec, IntCounterVec, Opts, Registry};

lazy_static! {
pub static ref REGISTRY: Registry = Registry::new();
pub static ref NUM_TRADES: IntCounter =
IntCounter::new("num_trades", "Number of trades").expect("Metric can be created");
pub static ref NUM_TRADES: IntCounterVec =
IntCounterVec::new(Opts::new("num_trades", "Number of trades"), &["ticker"])
.expect("Metric can be created");
pub static ref GROSS_TRADE_AMOUNT: CounterVec = CounterVec::new(
Opts::new("gross_trade_amount", "Gross dollar amount traded"),
&["ticker"]
)
.expect("Metric can be created");
}

pub fn register_custom_metrics() {
REGISTRY
.register(Box::new(NUM_TRADES.clone()))
.expect("collector can be registered");
REGISTRY
.register(Box::new(GROSS_TRADE_AMOUNT.clone()))
.expect("collector can be registered");
}

0 comments on commit 011eaba

Please sign in to comment.