Skip to content

Commit 7ff7b17

Browse files
committed
add hip3 missing
1 parent b2da8b6 commit 7ff7b17

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

rust/examples/hip3_order.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use hyperliquid_api_examples::Client;
2+
use serde_json::json;
3+
4+
const COIN: &str = "xyz:SILVER";
5+
6+
#[tokio::main]
7+
async fn main() {
8+
let client = Client::from_env();
9+
10+
let mut mid = client.get_hip3_mid(COIN).await;
11+
if mid == 0.0 {
12+
println!("Could not fetch {COIN} mid price, using fallback");
13+
mid = 78.0;
14+
}
15+
16+
let sz = format!("{:.2}", 10.0 / mid);
17+
let buy_px = format!("{:.2}", mid * 1.03);
18+
19+
println!("{COIN} mid: ${mid:.2}");
20+
println!("BUY {sz} @ {buy_px} (IOC, ~${:.2} notional)\n", sz.parse::<f64>().unwrap() * mid);
21+
22+
let res = client
23+
.exchange(&json!({
24+
"action": {
25+
"type": "order",
26+
"orders": [{"asset": COIN, "side": "buy", "price": buy_px, "size": sz, "tif": "ioc"}],
27+
},
28+
}))
29+
.await;
30+
31+
let hash = res["hash"].as_str().unwrap();
32+
let sig = client.sign_hash(hash).await;
33+
34+
let result = client
35+
.exchange(&json!({
36+
"action": res["action"],
37+
"nonce": res["nonce"],
38+
"signature": sig,
39+
}))
40+
.await;
41+
42+
println!(
43+
"{}",
44+
serde_json::to_string_pretty(&result["exchangeResponse"]).unwrap()
45+
);
46+
}

0 commit comments

Comments
 (0)