pub struct UdCore { /* private fields */ }Expand description
User data core: turns stream frames into order, execution and portfolio events.
It resolves the client order id of every order echo through the OrderIndex and advances the
local lifecycle of orders this process placed (so order_state and the stream agree).
Implements BrokerCore from brokapi-sansio.
§Examples
use std::sync::Arc;
use std::time::Instant;
use brokapi_core::{Event, SubscriptionId};
use brokapi_finam::core::ud::UdSubKind;
use brokapi_finam::core::{SubStatus, UdCore, UdEvent, UdFrame};
use brokapi_finam::index::OrderIndex;
use brokapi_sansio::{BrokerCore, EventSink};
use brokapi_finam_protocol::pb::grpc::tradeapi::v1::orders as po;
let sub = SubscriptionId::new(1000);
let mut core = UdCore::new(Arc::new(OrderIndex::new()));
core.register(sub, UdSubKind::Orders);
assert_eq!(core.status(sub), Some(SubStatus::Connecting));
// An order that this process did not place: it still reaches the consumer, under a made-up cid.
let echo = po::OrderState { order_id: "ORD-7".into(), ..Default::default() };
let mut out = EventSink::new();
core.on_frame(
UdFrame { sub, event: UdEvent::Orders(po::SubscribeOrdersResponse { orders: vec![echo] }) },
Instant::now(),
&mut out,
);
assert_eq!(core.status(sub), Some(SubStatus::Active));
assert!(matches!(out.drain()[0].payload, Event::Order(_)));Implementations§
Source§impl UdCore
impl UdCore
Sourcepub fn new(index: Arc<OrderIndex>) -> Self
pub fn new(index: Arc<OrderIndex>) -> Self
A core with no subscriptions. index is shared with the connector.
Sourcepub fn orders(&mut self) -> &mut OrderRuntime
pub fn orders(&mut self) -> &mut OrderRuntime
Local lifecycle of orders placed through this connector.
Sourcepub fn take_forgotten(&mut self) -> Vec<ClientOrderId> ⓘ
pub fn take_forgotten(&mut self) -> Vec<ClientOrderId> ⓘ
Takes the cids the core forgot since the last call: orders that finished long ago (see the memory
window of [OrderRuntime]). The connector drops what else it keeps for them.
Sourcepub fn index(&self) -> &Arc<OrderIndex> ⓘ
pub fn index(&self) -> &Arc<OrderIndex> ⓘ
The order index shared with the connector.
Sourcepub fn register(&mut self, sub: SubscriptionId, kind: UdSubKind)
pub fn register(&mut self, sub: SubscriptionId, kind: UdSubKind)
Adds a subscription of kind (status Connecting). Executions need this call because the
shared SubscriptionKind has no variant for them.
Sourcepub fn unregister(&mut self, sub: SubscriptionId)
pub fn unregister(&mut self, sub: SubscriptionId)
Forgets subscription sub and its status. Late frames for it are ignored.
Sourcepub fn status(&self, sub: SubscriptionId) -> Option<SubStatus>
pub fn status(&self, sub: SubscriptionId) -> Option<SubStatus>
Stream status of subscription sub. None for an id the core does not know.
Sourcepub fn ingest_order(&mut self, os: &OrderState, now: Instant) -> OrderSnapshot
pub fn ingest_order(&mut self, os: &OrderState, now: Instant) -> OrderSnapshot
Maps one order echo and advances the local lifecycle of orders we placed.
Trait Implementations§
Source§impl BrokerCore for UdCore
impl BrokerCore for UdCore
Source§fn apply(&mut self, desired: &SubscriptionSet)
fn apply(&mut self, desired: &SubscriptionSet)
Order-state and portfolio subscriptions. Executions are registered with register
because SubscriptionKind has no variant for them.
Source§type Frame = UdFrame
type Frame = UdFrame
String for WebSocket text, or a decoded message.Source§fn on_frame(&mut self, frame: UdFrame, now: Instant, out: &mut EventSink)
fn on_frame(&mut self, frame: UdFrame, now: Instant, out: &mut EventSink)
now. Read moreSource§fn poll_transmit(&mut self) -> Option<Outbound>
fn poll_transmit(&mut self) -> Option<Outbound>
None.Source§fn poll_timeout(&self) -> Option<Instant>
fn poll_timeout(&self) -> Option<Instant>
Source§fn on_timeout(&mut self, _now: Instant, _out: &mut EventSink)
fn on_timeout(&mut self, _now: Instant, _out: &mut EventSink)
now is the time the timer was due.Auto Trait Implementations§
impl Freeze for UdCore
impl RefUnwindSafe for UdCore
impl Send for UdCore
impl Sync for UdCore
impl Unpin for UdCore
impl UnsafeUnpin for UdCore
impl UnwindSafe for UdCore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].