Files
qrust/src/threads/trading/mod.rs
Nikolaos Karaolidis 4b194e168f Add paper URL support
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
2024-02-14 21:15:27 +00:00

22 lines
672 B
Rust

mod websocket;
use crate::{
config::{Config, ALPACA_WEBSOCKET_URL},
types::alpaca,
};
use futures_util::StreamExt;
use std::sync::Arc;
use tokio::spawn;
use tokio_tungstenite::connect_async;
pub async fn run(config: Arc<Config>) {
let (websocket, _) = connect_async(&*ALPACA_WEBSOCKET_URL).await.unwrap();
let (mut websocket_sink, mut websocket_stream) = websocket.split();
alpaca::websocket::trading::authenticate(&config, &mut websocket_sink, &mut websocket_stream)
.await;
alpaca::websocket::trading::subscribe(&mut websocket_sink, &mut websocket_stream).await;
spawn(websocket::run(config, websocket_stream, websocket_sink));
}