use crate::{
dex_request::DexError, BalanceResponse, CreateOrderResponse, FilledOrdersResponse, OrderSide,
TickerResponse,
};
use async_trait::async_trait;
pub struct TradeResult {
pub filled_size: f64,
pub filled_value: f64,
pub filled_fee: f64,
}
pub struct MarketInfo {
pub last_trade_price: Option<f64>,
pub min_order: Option<f64>,
pub min_tick: Option<f64>,
}
#[async_trait]
pub trait DexConnector: Send + Sync {
async fn start(&self) -> Result<(), DexError>;
async fn stop(&self) -> Result<(), DexError>;
async fn set_leverage(&self, symbol: &str, leverage: &str) -> Result<(), DexError>;
async fn get_ticker(&self, symbol: &str) -> Result<TickerResponse, DexError>;
async fn get_filled_orders(&self, symbol: &str) -> Result<FilledOrdersResponse, DexError>;
async fn get_balance(&self) -> Result<BalanceResponse, DexError>;
async fn clear_filled_order(&self, symbol: &str, order_id: &str) -> Result<(), DexError>;
async fn create_order(
&self,
symbol: &str,
size: &str,
side: OrderSide,
price: Option<String>,
) -> Result<CreateOrderResponse, DexError>;
async fn cancel_order(&self, symbol: &str, order_id: &str) -> Result<(), DexError>;
async fn cancel_all_orders(&self, symbol: Option<String>) -> Result<(), DexError>;
async fn close_all_positions(&self, symbol: Option<String>) -> Result<(), DexError>;
fn round_price(&self, price: f64, min_tick: f64) -> f64 {
(price / min_tick).round() * min_tick
}
fn round_size(&self, size: f64, min_order: f64) -> f64 {
(size / min_order).round() * min_order
}
}