use nautilus_coinbase::{
common::{consts::COINBASE_CLIENT_ID, enums::CoinbaseEnvironment},
config::CoinbaseDataClientConfig,
factories::CoinbaseDataClientFactory,
};
use nautilus_common::enums::Environment;
use nautilus_live::node::LiveNode;
use nautilus_model::{
data::bar::BarType,
identifiers::{InstrumentId, TraderId},
};
use nautilus_testkit::testers::{DataTester, DataTesterConfig};
const COINBASE_ENVIRONMENT: CoinbaseEnvironment = CoinbaseEnvironment::Live;
const TRADER_ID: &str = "TESTER-001";
const NODE_NAME: &str = "COINBASE-TESTER-001";
const INSTRUMENT_ID: &str = "BTC-USD.COINBASE";
const BAR_SPEC: &str = "1-MINUTE-LAST-EXTERNAL";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let environment = Environment::Live;
let coinbase_environment = COINBASE_ENVIRONMENT;
let trader_id = TraderId::from(TRADER_ID);
let node_name = NODE_NAME.to_string();
let client_id = *COINBASE_CLIENT_ID;
let instrument_ids = vec![InstrumentId::from(INSTRUMENT_ID)];
let bar_types: Vec<BarType> = instrument_ids
.iter()
.map(|id| BarType::from(format!("{id}-{BAR_SPEC}").as_str()))
.collect();
let coinbase_config = CoinbaseDataClientConfig {
environment: coinbase_environment,
api_key: None, api_secret: None, ..Default::default()
};
let client_factory = CoinbaseDataClientFactory::new();
let mut node = LiveNode::builder(trader_id, environment)?
.with_name(node_name)
.with_load_state(false)
.with_save_state(false)
.with_delay_post_stop_secs(2)
.add_data_client(None, Box::new(client_factory), Box::new(coinbase_config))?
.build()?;
let tester_config = DataTesterConfig::builder()
.client_id(client_id)
.instrument_ids(instrument_ids)
.subscribe_quotes(true)
.subscribe_trades(true)
.subscribe_book_deltas(true)
.bar_types(bar_types)
.subscribe_bars(true)
.request_bars(true)
.request_book_snapshot(true)
.manage_book(true)
.build()?;
let tester = DataTester::new(tester_config);
node.add_actor(tester)?;
node.run().await?;
Ok(())
}