diff --git a/rustybot/Cargo.toml b/rustybot/Cargo.toml index 511dbcf..c4e7e80 100644 --- a/rustybot/Cargo.toml +++ b/rustybot/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bitfinex = { path= "/home/giulio/gitstuff/bitfinex-rs" } +bitfinex = { path= "/home/giulio/dev/bitfinex-rs" } tokio = { version = "0.3", features=["full"]} tokio-tungstenite = "*" futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] } \ No newline at end of file diff --git a/rustybot/src/main.rs b/rustybot/src/main.rs index 857b298..bfc351e 100644 --- a/rustybot/src/main.rs +++ b/rustybot/src/main.rs @@ -1,35 +1,12 @@ -use std::env; -use std::net::SocketAddr; +mod ticker; +mod positions; +mod events; +mod pairs; -use futures_util::StreamExt; -use tokio::net::{TcpListener, TcpStream}; pub type BoxError = Box; -async fn accept_connection(stream: TcpStream, addr: SocketAddr) -> Result<(), BoxError> { - println!("Peer address: {}", addr); - - - let ws_stream = tokio_tungstenite::accept_async(stream) - .await - .err(format!("Error during WS handshake.").into()); - - println!("New WebSocket connection: {}", addr); - - let (write, read) = ws_stream.split(); - read.forward(write).await.expect("Failed to forward message") -} - #[tokio::main] async fn main() -> Result<(), BoxError> { - // Create the event loop and TCP listener we'll accept connections on. - let addr = env::args().nth(1).unwrap_or_else(|| "127.0.0.1:8080".to_string()); - let try_socket = TcpListener::bind(&addr).await; - let mut listener = try_socket.expect("Failed to bind"); - - while let Ok((stream, addr)) = listener.accept().await { - tokio::spawn(accept_connection(stream, addr)); - } - Ok(()) }