#[cfg(feature = "mexc")]
pub mod mexc_market;
pub mod simulated;
#[cfg(test)]
use mockall::automock;
use rust_decimal::Decimal;
use std::fmt;
use std::future::Future;
use crate::clock::ClockBase;
#[cfg(test)]
use crate::clock::RunningCheatClock;
use crate::core::CoreResult;
#[cfg(test)]
use crate::generics::order::EmptySpecificOrderDetails;
use crate::generics::order::{Crypto, Order, SpecificOrderDetails, UpdateOrderOutput};
#[derive(Debug, Clone, Copy)]
pub struct Balance {
pub free: Decimal,
pub locked: Decimal,
}
pub trait MarketFactory: Send + Sync + 'static {
type _Market: Market;
fn with_clock(self, clock: <Self::_Market as Market>::_Clock) -> Self;
fn build(self) -> impl Future<Output = CoreResult<Self::_Market>> + Send;
}
#[cfg_attr(test, automock(type _Clock = RunningCheatClock; type _OrderDetails = EmptySpecificOrderDetails;))]
pub trait Market: Send + Sync + fmt::Debug + 'static {
type _Clock: ClockBase;
type _OrderDetails: SpecificOrderDetails;
fn name(&self) -> String;
fn get_balance(&self, crypto: Crypto) -> impl Future<Output = CoreResult<Balance>> + Send;
fn send_order(
&self,
order: &Order<Self::_OrderDetails>,
) -> impl Future<Output = CoreResult<UpdateOrderOutput<Self::_OrderDetails>>> + Send;
fn cancel_order(
&self,
order: &Order<Self::_OrderDetails>,
) -> impl Future<Output = CoreResult<UpdateOrderOutput<Self::_OrderDetails>>> + Send;
fn update_order(
&self,
order: &Order<Self::_OrderDetails>,
) -> impl Future<Output = CoreResult<UpdateOrderOutput<Self::_OrderDetails>>> + Send;
}
#[cfg(test)]
pub struct MockMarketFactory {
pub mock_market: MockMarket,
}
#[cfg(test)]
impl MarketFactory for MockMarketFactory {
type _Market = MockMarket;
fn with_clock(self, _: <Self::_Market as Market>::_Clock) -> Self {
self
}
async fn build(self) -> CoreResult<MockMarket> {
Ok(self.mock_market)
}
}