use std::num::NonZeroU64;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use uuid::Uuid;
use crate::shared::{
models::{
leverage::Leverage,
price::Price,
quantity::Quantity,
trade::{TradeExecution, TradeSide, TradeSize},
},
rest::error::Result,
};
use super::models::{
account::Account,
client_id::ClientId,
cross_leverage::CrossLeverage,
funding::{CrossFunding, FundingSettlement, IsolatedFunding},
ohlc_candle::{OhlcCandle, OhlcRange},
oracle::{Index, LastPrice},
page::Page,
ticker::Ticker,
trade::{CrossOrder, CrossPosition, Trade},
transfer::CrossTransfer,
};
#[async_trait]
pub trait UtilitiesRepository: crate::sealed::Sealed + Send + Sync {
async fn ping(&self) -> Result<()>;
async fn time(&self) -> Result<DateTime<Utc>>;
}
#[async_trait]
pub trait FuturesIsolatedRepository: crate::sealed::Sealed + Send + Sync {
async fn add_margin_to_trade(&self, id: Uuid, amount: NonZeroU64) -> Result<Trade>;
async fn cancel_all_trades(&self) -> Result<Vec<Trade>>;
async fn cancel_trade(&self, id: Uuid) -> Result<Trade>;
async fn cash_in_trade(&self, id: Uuid, amount: NonZeroU64) -> Result<Trade>;
async fn close_trade(&self, id: Uuid) -> Result<Trade>;
async fn get_open_trades(&self) -> Result<Vec<Trade>>;
async fn get_running_trades(&self) -> Result<Vec<Trade>>;
async fn get_closed_trades(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<Trade>>;
async fn get_canceled_trades(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<Trade>>;
async fn update_takeprofit(&self, id: Uuid, value: Option<Price>) -> Result<Trade>;
async fn update_stoploss(&self, id: Uuid, value: Option<Price>) -> Result<Trade>;
#[allow(clippy::too_many_arguments)]
async fn new_trade(
&self,
side: TradeSide,
size: TradeSize,
leverage: Leverage,
execution: TradeExecution,
stoploss: Option<Price>,
takeprofit: Option<Price>,
client_id: Option<ClientId>,
) -> Result<Trade>;
async fn get_funding_fees(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<IsolatedFunding>>;
}
#[async_trait]
pub trait FuturesCrossRepository: crate::sealed::Sealed + Send + Sync {
async fn cancel_all_orders(&self) -> Result<Vec<CrossOrder>>;
async fn cancel_order(&self, id: Uuid) -> Result<CrossOrder>;
async fn place_order(
&self,
side: TradeSide,
quantity: Quantity,
execution: TradeExecution,
client_id: Option<ClientId>,
) -> Result<CrossOrder>;
async fn get_open_orders(&self) -> Result<Vec<CrossOrder>>;
async fn get_position(&self) -> Result<CrossPosition>;
async fn get_filled_orders(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<CrossOrder>>;
async fn close_position(&self) -> Result<CrossOrder>;
async fn get_funding_fees(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<CrossFunding>>;
async fn get_transfers(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<CrossTransfer>>;
async fn deposit(&self, amount: NonZeroU64) -> Result<CrossPosition>;
async fn set_leverage(&self, leverage: CrossLeverage) -> Result<CrossPosition>;
async fn withdraw(&self, amount: NonZeroU64) -> Result<CrossPosition>;
}
#[async_trait]
pub trait FuturesDataRepository: crate::sealed::Sealed + Send + Sync {
async fn get_funding_settlements(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<FundingSettlement>>;
async fn get_ticker(&self) -> Result<Ticker>;
async fn get_candles(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
range: Option<OhlcRange>,
cursor: Option<DateTime<Utc>>,
) -> Result<Page<OhlcCandle>>;
}
#[allow(dead_code)] #[async_trait]
pub trait SyntheticUsdRepository: crate::sealed::Sealed + Send + Sync {
async fn get_swaps(&self) -> Result<()> {
todo!()
}
async fn create_new_swap(&self) -> Result<()> {
todo!()
}
async fn get_best_price(&self) -> Result<()> {
todo!()
}
}
#[async_trait]
pub trait AccountRepository: crate::sealed::Sealed + Send + Sync {
async fn get_account(&self) -> Result<Account>;
}
#[allow(dead_code)] #[async_trait]
pub trait DepositsRepository: crate::sealed::Sealed + Send + Sync {
async fn get_internal_deposits(&self) -> Result<()> {
todo!()
}
async fn get_onchain_deposits(&self) -> Result<()> {
todo!()
}
async fn get_lightning_deposits(&self) -> Result<()> {
todo!()
}
async fn deposit(&self) -> Result<()> {
todo!()
}
}
#[allow(dead_code)] #[async_trait]
pub trait WithdrawalsRepository: crate::sealed::Sealed + Send + Sync {
async fn get_internal_withdrawals(&self) -> Result<()> {
todo!()
}
async fn get_onchain_withdrawals(&self) -> Result<()> {
todo!()
}
async fn get_lightning_withdrawals(&self) -> Result<()> {
todo!()
}
async fn withdrawal_internal(&self) -> Result<()> {
todo!()
}
async fn withdrawal_onchain(&self) -> Result<()> {
todo!()
}
async fn withdrawal_lightning(&self) -> Result<()> {
todo!()
}
}
#[async_trait]
pub trait OracleRepository: crate::sealed::Sealed + Send + Sync {
async fn get_index(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Vec<Index>>;
async fn get_last_price(
&self,
from: Option<DateTime<Utc>>,
to: Option<DateTime<Utc>>,
limit: Option<NonZeroU64>,
cursor: Option<DateTime<Utc>>,
) -> Result<Vec<LastPrice>>;
}