use crate::engine::{
action::{
generate_algo_orders::GenerateAlgoOrdersOutput,
send_requests::{SendCancelsAndOpensOutput, SendRequestsOutput},
},
error::UnrecoverableEngineError,
};
use barter_execution::order::request::{RequestCancel, RequestOpen};
use barter_instrument::{exchange::ExchangeIndex, instrument::InstrumentIndex};
use barter_integration::collection::one_or_many::OneOrMany;
use derive_more::From;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
pub mod cancel_orders;
pub mod close_positions;
pub mod generate_algo_orders;
pub mod send_requests;
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, From)]
#[allow(clippy::large_enum_variant)]
pub enum ActionOutput<ExchangeKey = ExchangeIndex, InstrumentKey = InstrumentIndex> {
GenerateAlgoOrders(GenerateAlgoOrdersOutput<ExchangeKey, InstrumentKey>),
CancelOrders(SendRequestsOutput<RequestCancel, ExchangeKey, InstrumentKey>),
OpenOrders(SendRequestsOutput<RequestOpen, ExchangeKey, InstrumentKey>),
ClosePositions(SendCancelsAndOpensOutput<ExchangeKey, InstrumentKey>),
}
impl<ExchangeKey, InstrumentKey> ActionOutput<ExchangeKey, InstrumentKey> {
pub fn unrecoverable_errors(&self) -> Option<OneOrMany<UnrecoverableEngineError>> {
match self {
ActionOutput::GenerateAlgoOrders(algo) => algo.cancels_and_opens.unrecoverable_errors(),
ActionOutput::CancelOrders(cancels) => cancels.unrecoverable_errors(),
ActionOutput::OpenOrders(opens) => opens.unrecoverable_errors(),
ActionOutput::ClosePositions(requests) => requests.unrecoverable_errors(),
}
.into_option()
}
}