barter/engine/action/
mod.rs1use crate::engine::{
2 action::{
3 generate_algo_orders::GenerateAlgoOrdersOutput,
4 send_requests::{SendCancelsAndOpensOutput, SendRequestsOutput},
5 },
6 error::UnrecoverableEngineError,
7};
8use barter_execution::order::request::{RequestCancel, RequestOpen};
9use barter_instrument::{exchange::ExchangeIndex, instrument::InstrumentIndex};
10use barter_integration::collection::one_or_many::OneOrMany;
11use derive_more::From;
12use serde::{Deserialize, Serialize};
13use std::fmt::Debug;
14
15pub mod cancel_orders;
17
18pub mod close_positions;
20
21pub mod generate_algo_orders;
23
24pub mod send_requests;
26
27#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, From)]
29#[allow(clippy::large_enum_variant)]
30pub enum ActionOutput<ExchangeKey = ExchangeIndex, InstrumentKey = InstrumentIndex> {
31 GenerateAlgoOrders(GenerateAlgoOrdersOutput<ExchangeKey, InstrumentKey>),
32 CancelOrders(SendRequestsOutput<RequestCancel, ExchangeKey, InstrumentKey>),
33 OpenOrders(SendRequestsOutput<RequestOpen, ExchangeKey, InstrumentKey>),
34 ClosePositions(SendCancelsAndOpensOutput<ExchangeKey, InstrumentKey>),
35}
36
37impl<ExchangeKey, InstrumentKey> ActionOutput<ExchangeKey, InstrumentKey> {
38 pub fn unrecoverable_errors(&self) -> Option<OneOrMany<UnrecoverableEngineError>> {
40 match self {
41 ActionOutput::GenerateAlgoOrders(algo) => algo.cancels_and_opens.unrecoverable_errors(),
42 ActionOutput::CancelOrders(cancels) => cancels.unrecoverable_errors(),
43 ActionOutput::OpenOrders(opens) => opens.unrecoverable_errors(),
44 ActionOutput::ClosePositions(requests) => requests.unrecoverable_errors(),
45 }
46 .into_option()
47 }
48}