use std::{thread::sleep, time::Duration};
use alloy::signers::local::PrivateKeySigner;
use hyperliquid_rust_sdk_toaster::{
BaseUrl, ClientCancelRequestCloid, ClientLimit, ClientOrder, ClientOrderRequest, ExchangeClient,
};
use log::info;
use uuid::Uuid;
#[tokio::main]
async fn main() {
env_logger::init();
let wallet: PrivateKeySigner =
"e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
.parse()
.unwrap();
let exchange_client = ExchangeClient::new(None, wallet, Some(BaseUrl::Testnet), None, None, None)
.await
.unwrap();
let cloid = Uuid::new_v4();
let order = ClientOrderRequest {
asset: "ETH".to_string(),
is_buy: true,
reduce_only: false,
limit_px: 1800.0,
sz: 0.01,
cloid: Some(cloid),
order_type: ClientOrder::Limit(ClientLimit {
tif: "Gtc".to_string(),
}),
};
let response = exchange_client.order(order, None).await.unwrap();
info!("Order placed: {response:?}");
sleep(Duration::from_secs(10));
let cancel = ClientCancelRequestCloid {
asset: "ETH".to_string(),
cloid,
};
let response = exchange_client.cancel_by_cloid(cancel, None).await.unwrap();
info!("Order potentially cancelled: {response:?}");
}