barter_integration/
lib.rs

1#![forbid(unsafe_code)]
2#![warn(
3    unused,
4    clippy::cognitive_complexity,
5    unused_crate_dependencies,
6    unused_extern_crates,
7    clippy::unused_self,
8    clippy::useless_let_if_seq,
9    missing_debug_implementations,
10    rust_2018_idioms,
11    rust_2024_compatibility
12)]
13#![allow(clippy::type_complexity, clippy::too_many_arguments, type_alias_bounds)]
14
15//! # Barter-Integration
16//! High-performance, low-level framework for composing flexible web integrations.
17//!
18//! Utilised by other Barter trading ecosystem crates to build robust financial execution integrations,
19//! primarily for public data collection & trade execution. It is:
20//! * **Low-Level**: Translates raw data streams communicated over the web into any desired data model using arbitrary data transformations.
21//! * **Flexible**: Compatible with any protocol (WebSocket, FIX, Http, etc.), any input/output model, and any user defined transformations.
22//!
23//! ## Core abstractions:
24//! - **RestClient** providing configurable signed Http communication between client & server.
25//! - **ExchangeStream** providing configurable communication over any asynchronous stream protocols (WebSocket, FIX, etc.).
26//!
27//! Both core abstractions provide the robust glue you need to conveniently translate between server & client data models.
28
29use crate::error::SocketError;
30use serde::{Deserialize, Serialize};
31
32/// All [`Error`](std::error::Error)s generated in Barter-Integration.
33pub mod error;
34
35/// Contains `StreamParser` implementations for transforming communication protocol specific
36/// messages into a generic output data structure.
37pub mod protocol;
38
39/// Contains the flexible `Metric` type used for representing real-time metrics generically.
40pub mod metric;
41
42/// Utilities to assist deserialisation.
43pub mod de;
44
45/// Defines a [`SubscriptionId`](subscription::SubscriptionId) new type representing a unique
46/// `SmolStr` identifier for a data stream (market data, account data) that has been
47/// subscribed to.
48pub mod subscription;
49
50/// Defines a trait [`Tx`](channel::Tx) abstraction over different channel kinds, as well as
51/// other channel utilities.
52///
53/// eg/ `UnboundedTx`, `ChannelTxDroppable`, etc.
54pub mod channel;
55
56pub mod collection;
57
58/// Stream utilities.
59pub mod stream;
60
61pub mod snapshot;
62
63/// [`Validator`]s are capable of determining if their internal state is satisfactory to fulfill
64/// some use case defined by the implementor.
65pub trait Validator {
66    /// Check if `Self` is valid for some use case.
67    fn validate(self) -> Result<Self, SocketError>
68    where
69        Self: Sized;
70}
71
72/// [`Transformer`]s are capable of transforming any `Input` into an iterator of
73/// `Result<Self::Output, Self::Error>`s.
74pub trait Transformer {
75    type Error;
76    type Input: for<'de> Deserialize<'de>;
77    type Output;
78    type OutputIter: IntoIterator<Item = Result<Self::Output, Self::Error>>;
79    fn transform(&mut self, input: Self::Input) -> Self::OutputIter;
80}
81
82/// Determines if something is considered "unrecoverable", such as an unrecoverable error.
83///
84/// Note that the meaning of [`Unrecoverable`] may vary depending on the context.
85pub trait Unrecoverable {
86    fn is_unrecoverable(&self) -> bool;
87}
88
89/// Trait that communicates if something is terminal (eg/ requires shutdown or restart).
90pub trait Terminal {
91    fn is_terminal(&self) -> bool;
92}
93
94/// Indicates an `Iterator` or `Stream` has ended.
95#[derive(
96    Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Deserialize, Serialize,
97)]
98pub struct FeedEnded;