#![warn(missing_docs)]
mod generated;
pub use generated::arvo::{
common::v1 as common, market::v1 as market, platform::v1 as platform,
portfolio::v1 as portfolio, research::v1 as research, session::v1 as session,
};
pub use generated::arvo::{
common::v1::*, market::v1::*, platform::v1::*, portfolio::v1::*, research::v1::*,
session::v1::*,
};
mod ergonomics {
use super::{
platform::{event_kind_view, plugin_status_view},
research::record_view,
EventKindView, EventView, FeedEvent, FindingsEvent, LibraryEvent, PluginEvent, SessionEvent,
SeverityView, StreamEvent,
BookView, ImportView, MetricsView, PanelView, PluginStatusView, PluginStatusViewReachable,
PluginStatusViewUnreachable, PluginView, PortfolioView, RecordView, ReportedView, StudyView,
TradesView, WalkForwardView,
};
#[must_use]
pub fn count(n: usize) -> u32 {
u32::try_from(n).unwrap_or(u32::MAX)
}
#[must_use]
pub fn size(n: u32) -> usize {
usize::try_from(n).unwrap_or(usize::MAX)
}
macro_rules! always {
($owner:ty, $field:ident, $ty:ty) => {
impl $owner {
#[must_use]
pub fn $field(&self) -> &$ty {
self.$field.as_ref().expect(concat!(stringify!($owner), " always carries ", stringify!($field)))
}
}
};
}
always!(StudyView, strategy, MetricsView);
always!(StudyView, benchmark, MetricsView);
always!(StudyView, trades_detail, TradesView);
always!(WalkForwardView, strategy, MetricsView);
always!(WalkForwardView, benchmark, MetricsView);
always!(WalkForwardView, trades_detail, TradesView);
always!(BookView, metrics, MetricsView);
always!(PortfolioView, import, ImportView);
impl PluginView {
#[must_use]
pub fn reachable(&self) -> bool {
matches!(self.status.as_ref().and_then(|s| s.of.as_ref()), Some(plugin_status_view::Of::Reachable(_)))
}
#[must_use]
pub fn reached(&self) -> Option<&PluginStatusViewReachable> {
match self.status.as_ref().and_then(|status| status.of.as_ref()) {
Some(plugin_status_view::Of::Reachable(status)) => Some(status),
_ => None,
}
}
#[must_use]
pub fn unreachable(&self) -> Option<&str> {
match self.status.as_ref().and_then(|status| status.of.as_ref()) {
Some(plugin_status_view::Of::Unreachable(status)) => Some(&status.reason),
Some(plugin_status_view::Of::Reachable(_)) => None,
None => Some("the engine sent no status"),
}
}
}
impl PluginStatusView {
#[must_use]
pub fn reachable(name: String, version: String, capabilities: Vec<String>) -> Self {
Self {
of: Some(plugin_status_view::Of::Reachable(PluginStatusViewReachable { name, version, capabilities })),
}
}
#[must_use]
pub fn unreachable(reason: String) -> Self {
Self { of: Some(plugin_status_view::Of::Unreachable(PluginStatusViewUnreachable { reason })) }
}
}
impl EventKindView {
#[must_use]
pub fn plugin(id: String, reachable: bool) -> Self {
Self { of: Some(event_kind_view::Of::Plugin(PluginEvent { id, reachable })) }
}
#[must_use]
pub fn feed(id: String, connected: bool) -> Self {
Self { of: Some(event_kind_view::Of::Feed(FeedEvent { id, connected })) }
}
#[must_use]
pub fn stream(live: bool) -> Self {
Self { of: Some(event_kind_view::Of::Stream(StreamEvent { live })) }
}
#[must_use]
pub fn findings(count: u32) -> Self {
Self { of: Some(event_kind_view::Of::Findings(FindingsEvent { count })) }
}
#[must_use]
pub fn session(id: String, state: String) -> Self {
Self { of: Some(event_kind_view::Of::Session(SessionEvent { id, state })) }
}
#[must_use]
pub fn library(instrument: String, fingerprint: String) -> Self {
Self { of: Some(event_kind_view::Of::Library(LibraryEvent { instrument, fingerprint })) }
}
}
impl EventView {
#[must_use]
pub fn new(kind: EventKindView, title: String, detail: String, severity: SeverityView) -> Self {
Self { kind: Some(kind), title, detail, severity: severity as i32 }
}
#[must_use]
pub fn of(&self) -> Option<&event_kind_view::Of> {
self.kind.as_ref()?.of.as_ref()
}
}
impl RecordView {
#[must_use]
pub fn study(view: StudyView) -> Self {
Self { of: Some(record_view::Of::Study(view)) }
}
#[must_use]
pub fn walk_forward(view: WalkForwardView) -> Self {
Self { of: Some(record_view::Of::Walkforward(view)) }
}
#[must_use]
pub fn panel(view: PanelView) -> Self {
Self { of: Some(record_view::Of::Panel(view)) }
}
#[must_use]
pub fn reported(view: ReportedView) -> Self {
Self { of: Some(record_view::Of::Reported(view)) }
}
}
}
pub use ergonomics::{count, size};