extern crate kucoin_api;
use kucoin_api::failure;
use kucoin_api::futures::TryStreamExt;
use kucoin_api::{
client::{Kucoin, KucoinEnv},
model::websocket::{KucoinWebsocketMsg, WSTopic, WSType},
websocket::KucoinWebsocket,
};
#[tokio::main]
async fn main() -> Result<(), failure::Error> {
kucoin_arbitrage::logger::log_init();
log::info!("Testing Kucoin WS Message Rate");
let credentials = kucoin_arbitrage::global::config::credentials();
log::info!("{credentials:#?}");
let api = Kucoin::new(KucoinEnv::Live, Some(credentials))?;
let url = api.get_socket_endpoint(WSType::Public).await?;
let mut ws = api.websocket();
let symbols = [
"ETH-BTC".to_string(),
"BTC-USDT".to_string(),
"ETH-USDT".to_string(),
];
let subs = vec![WSTopic::OrderBook(symbols.to_vec())];
ws.subscribe(url, subs).await?;
log::info!("Async polling");
tokio::spawn(async move { sync_tickers(ws).await });
kucoin_arbitrage::global::task::background_routine().await
}
async fn sync_tickers(mut ws: KucoinWebsocket) -> Result<(), failure::Error> {
while let Some(msg) = ws.try_next().await? {
match msg {
KucoinWebsocketMsg::OrderBookMsg(_msg) => {
kucoin_arbitrage::global::performance::increment().await;
}
KucoinWebsocketMsg::PongMsg(_) => continue,
KucoinWebsocketMsg::WelcomeMsg(_) => continue,
_ => {
panic!("unexpected msgs received: {msg:?}")
}
}
}
Ok(())
}