network_stream/
network_stream.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::{cell::UnsafeCell, rc::Rc};
17
18use nautilus_common::{actor::registry::register_actor, testing::init_logger_for_testing};
19use nautilus_demo::{
20    LiveRunner, big_brain_actor::BigBrainActor, http_server::start_positive_stream_http_server,
21    init_data_engine, websocket_server::NegativeStreamServer,
22};
23
24async fn main_logic() {
25    let http_address = start_positive_stream_http_server().await.unwrap();
26    let websocket_server = NegativeStreamServer::setup().await;
27
28    // Initialize data client with http and websocket streams
29    let (http_stream, websocket_stream) =
30        init_data_engine(http_address, websocket_server.address).await;
31
32    // Initialize big brain actor
33    let big_brain_actor = BigBrainActor::new();
34    let big_brain_actor = Rc::new(UnsafeCell::new(big_brain_actor));
35    register_actor(big_brain_actor);
36    BigBrainActor::register_message_handlers();
37
38    let mut runner = LiveRunner::default();
39    runner.new_add_data_response_stream(http_stream);
40    runner.new_message_stream(websocket_stream);
41    runner.run().await;
42}
43
44pub fn main() {
45    init_logger_for_testing(None).unwrap();
46    let runtime = tokio::runtime::Runtime::new().unwrap();
47    runtime.block_on(main_logic());
48}