Crates.io | ftx_async |
lib.rs | ftx_async |
version | 0.0.4 |
source | src |
created_at | 2022-11-06 13:26:35.392071 |
updated_at | 2022-11-08 13:17:48.650886 |
description | Unofficial asynchronous Rust library for the FTX crypto exchange Websocket and REST API. The websocket interface fully abstracts the connection to FTX by publishing messages onto a MPSC channel and managing authentication, reconnections and keep-alives in the background. |
homepage | |
repository | https://github.com/IanMichaelAsh/ftx-async |
max_upload_size | |
id | 706531 |
size | 65,536 |
Unofficial Rust implementation of an asynchronous Websocket and REST client for the FTX crypto exchange
06/11/2022 - *** WARNING *** This code base is alpha, though it is now available as a crate.
[dependencies]
tokio = {version = "*"}
ftx_async = {version = "*"}
Then, on your main.rs:
use ftx_async::ws::{UpdateMessage, WebsocketManager};
use tokio::signal;
#[tokio::main]
async fn main() {
let api_key = ""; // Set a valid FTX API key!
let api_secret = ""; // Set a valid FTX secret key!
let ftx = WebsocketManager::new(api_key, api_secret, "BTC-PERP").await;
let mut listener = ftx.get_order_channel();
ftx.subscribe_channel_ticker(true).await;
let mut terminated = false;
while !terminated {
tokio::select! {
Ok(msg) = listener.recv() => {
if let UpdateMessage::Ticker {market, bid, ask, bid_size : _, ask_size : _, last_trade : _}= msg {
print!("\r{market}: Bid: {:.0} - Ask: {:.0}", bid.unwrap(), ask.unwrap());
}
}
_ = signal::ctrl_c() => {
terminated = true;
}
}
}
}