Skip to main content

wickra_terminal_core/
lib.rs

1//! # wickra-terminal-core
2//!
3//! The data-driven core of the Wickra trading terminal. It folds market events
4//! into an O(1) [`AppState`] and turns [`panels`] into [`view`]-models — plain
5//! data (values, series, sides), never renderer commands. Two reference
6//! renderers consume those view-models (a native TUI and a Web app), and the
7//! same core is exposed as a JSON data API in ten languages.
8//!
9//! ## Shape
10//!
11//! - [`DataSource`] unifies the feed modules ([`Live`](source::LiveSource),
12//!   [`Replay`](source::ReplaySource), [`Synth`](source::SynthSource)) behind one
13//!   symbol-tagged `poll()`.
14//! - [`AppState::fold`] applies one event incrementally; nothing is recomputed
15//!   over history.
16//! - [`Panel`] maps state to a [`PanelView`]; a [`Frame`] is the set of them.
17//! - [`Terminal`] ties it together, with [`Terminal::command_json`] as the
18//!   data-driven FFI boundary the bindings drive.
19//!
20//! ```
21//! use wickra_terminal_core::{Config, SourceSpec, Terminal, Symbol};
22//!
23//! let mut cfg = Config::default_layout();
24//! cfg.sources = vec![SourceSpec::Synth { seed: 1 }];
25//! let mut term = Terminal::new(&cfg).unwrap();
26//! term.subscribe(0, &Symbol::new("BTC", "USDT")).unwrap();
27//! let frame = term.tick();
28//! assert_eq!(frame.panels.len(), 5);
29//! ```
30
31// docs.rs builds with nightly and passes --cfg docsrs, so this turns on the
32// feature-gate annotations there and nowhere else. `source::live` and
33// `LiveSource` are behind the `live` feature; without this they render on
34// docs.rs as though they were unconditional, because the manifest asks for
35// all-features and nothing then says which items needed one.
36#![cfg_attr(docsrs, feature(doc_cfg))]
37
38pub mod candle;
39pub mod config;
40pub mod error;
41pub mod panels;
42pub mod registry;
43pub mod source;
44pub mod state;
45pub mod terminal;
46pub mod view;
47
48pub use candle::{CandleBuilder, Timeframe};
49pub use config::{
50    default_indicators, Config, IndicatorSpec, Keybinds, Layout, Market, PanelSpec, RectSpec,
51    SourceSpec,
52};
53pub use error::{Error, Result};
54pub use panels::{build_panel, Panel, PanelKind};
55pub use registry::{build as build_indicator, TickIndicator, TickInput, KINDS};
56pub use source::{build_source, DataSource, Event, SourceId, SourceKind, Symbol};
57pub use state::{AppState, IndicatorReading, IndicatorSet};
58pub use terminal::Terminal;
59pub use view::{Frame, IndicatorField, IndicatorValue, PanelView};
60
61/// The crate version (the same string [`Terminal::version`] returns).
62#[must_use]
63pub fn version() -> &'static str {
64    env!("CARGO_PKG_VERSION")
65}