use std::any::Any;
use nautilus_infrastructure::sql::pg::PostgresConnectOptions;
use nautilus_model::{
defi::{Chain, DexType, SharedChain},
identifiers::{AccountId, TraderId},
};
use nautilus_system::ClientConfig;
#[derive(Debug, Clone, bon::Builder)]
#[cfg_attr(
feature = "python",
pyo3::pyclass(
module = "nautilus_trader.core.nautilus_pyo3.blockchain",
from_py_object
)
)]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.blockchain")
)]
pub struct DexPoolFilters {
#[builder(default = true)]
pub remove_pools_with_empty_erc20fields: bool,
}
impl DexPoolFilters {
#[must_use]
pub fn new(remove_pools_with_empty_erc20fields: Option<bool>) -> Self {
Self {
remove_pools_with_empty_erc20fields: remove_pools_with_empty_erc20fields
.unwrap_or(true),
}
}
}
impl Default for DexPoolFilters {
fn default() -> Self {
Self::builder().build()
}
}
#[derive(Debug, Clone, bon::Builder)]
#[cfg_attr(
feature = "python",
pyo3::pyclass(
module = "nautilus_trader.core.nautilus_pyo3.blockchain",
from_py_object
)
)]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.blockchain")
)]
pub struct BlockchainDataClientConfig {
pub chain: SharedChain,
#[builder(default)]
pub dex_ids: Vec<DexType>,
#[builder(default)]
pub use_hypersync_for_live_data: bool,
pub http_rpc_url: String,
pub rpc_requests_per_second: Option<u32>,
#[builder(default = 200)]
pub multicall_calls_per_rpc_request: u32,
pub wss_rpc_url: Option<String>,
pub http_proxy_url: Option<String>,
pub ws_proxy_url: Option<String>,
pub from_block: Option<u64>,
#[builder(default)]
pub pool_filters: DexPoolFilters,
pub postgres_cache_database_config: Option<PostgresConnectOptions>,
}
impl BlockchainDataClientConfig {
#[allow(clippy::too_many_arguments)]
#[must_use]
pub fn new(
chain: SharedChain,
dex_ids: Vec<DexType>,
http_rpc_url: String,
rpc_requests_per_second: Option<u32>,
multicall_calls_per_rpc_request: Option<u32>,
wss_rpc_url: Option<String>,
use_hypersync_for_live_data: bool,
from_block: Option<u64>,
pools_filters: Option<DexPoolFilters>,
postgres_cache_database_config: Option<PostgresConnectOptions>,
) -> Self {
Self {
chain,
dex_ids,
use_hypersync_for_live_data,
http_rpc_url,
rpc_requests_per_second,
multicall_calls_per_rpc_request: multicall_calls_per_rpc_request.unwrap_or(200),
wss_rpc_url,
http_proxy_url: None,
ws_proxy_url: None,
from_block,
pool_filters: pools_filters.unwrap_or_default(),
postgres_cache_database_config,
}
}
}
#[derive(Debug, Clone, bon::Builder)]
pub struct BlockchainExecutionClientConfig {
pub trader_id: TraderId,
pub client_id: AccountId,
pub chain: Chain,
pub wallet_address: String,
pub tokens: Option<Vec<String>>,
pub http_rpc_url: String,
pub rpc_requests_per_second: Option<u32>,
}
impl BlockchainExecutionClientConfig {
pub fn new(
trader_id: TraderId,
client_id: AccountId,
chain: Chain,
wallet_address: String,
tokens: Option<Vec<String>>,
http_rpc_url: String,
rpc_requests_per_second: Option<u32>,
) -> Self {
Self {
trader_id,
client_id,
chain,
wallet_address,
tokens,
http_rpc_url,
rpc_requests_per_second,
}
}
}
impl ClientConfig for BlockchainExecutionClientConfig {
fn as_any(&self) -> &dyn Any {
self
}
}