hyperliquid_capture_test_data/capture_test_data.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16// Simple script to capture real API responses for test fixtures
17
18use std::fs;
19
20use nautilus_hyperliquid::http::client::HyperliquidHttpClient;
21
22#[tokio::main]
23async fn main() -> Result<(), Box<dyn std::error::Error>> {
24 println!("Capturing Hyperliquid test data...");
25
26 let client = HyperliquidHttpClient::new(false, Some(60), None)?;
27
28 // Capture perpetuals metadata (first 3 markets to keep file small)
29 println!("Fetching perpetuals metadata...");
30 let meta = client.info_meta().await?;
31 let sample_meta = serde_json::json!({
32 "universe": meta.universe.iter().take(3).collect::<Vec<_>>()
33 });
34 fs::write(
35 "test_data/http_meta_perp_sample.json",
36 serde_json::to_string_pretty(&sample_meta)?,
37 )?;
38 println!("Saved http_meta_perp_sample.json (3 markets)");
39
40 // Note: Spot metadata endpoint not yet implemented in client
41
42 // Capture BTC order book
43 println!("Fetching BTC order book...");
44 let book = client.info_l2_book("BTC").await?;
45 // Keep only top 5 levels each side
46 let sample_book = serde_json::json!({
47 "coin": book.coin,
48 "levels": vec![
49 book.levels.first().unwrap().iter().take(5).collect::<Vec<_>>(),
50 book.levels[1].iter().take(5).collect::<Vec<_>>()
51 ],
52 "time": book.time
53 });
54 fs::write(
55 "test_data/http_l2_book_btc.json",
56 serde_json::to_string_pretty(&sample_book)?,
57 )?;
58 println!("Saved http_l2_book_btc.json (5 levels each side)");
59
60 println!("\nTest data capture complete!");
61 println!("Files saved in test_data/");
62
63 Ok(())
64}