Skip to content

Commit 468f3b1

Browse files
Michael YuanMichael Yuan
authored andcommitted
Fix all clippy warnings and rustfmt issues
- Remove unused imports, dead code (base_url, cryptopanic_token, newsapi_key) - Inline emoji literals instead of passing as format args - Fix wildcard pattern covers other pattern in predict.rs - Use map.values() instead of iterating key-value pairs in report.rs - All clippy warnings resolved, rustfmt clean
1 parent a224507 commit 468f3b1

16 files changed

Lines changed: 592 additions & 286 deletions

src/cli.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use clap::{Parser, Subcommand};
22

33
#[derive(Parser)]
4-
#[command(name = "fintool", about = "Financial trading CLI for crypto and stocks")]
4+
#[command(
5+
name = "fintool",
6+
about = "Financial trading CLI for crypto and stocks"
7+
)]
58
pub struct Cli {
69
#[command(subcommand)]
710
pub command: Commands,
@@ -17,9 +20,7 @@ pub enum Commands {
1720
Init,
1821

1922
/// Get spot price quote (Hyperliquid spot → Yahoo Finance fallback)
20-
Quote {
21-
symbol: String,
22-
},
23+
Quote { symbol: String },
2324

2425
/// Get latest news for a symbol
2526
News { symbol: String },

src/commands/balance.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use colored::Colorize;
33
use serde_json::{json, Value};
4-
use tabled::{Table, settings::Style, Tabled};
4+
use tabled::{settings::Style, Table, Tabled};
55

66
use crate::config;
77

@@ -41,7 +41,7 @@ pub async fn run(json_output: bool) -> Result<()> {
4141
let available = margin["totalNtlPos"].as_str().unwrap_or("0");
4242

4343
println!();
44-
println!(" {} Account Balance", "💰");
44+
println!(" 💰 Account Balance");
4545
println!();
4646

4747
let rows = vec![BalanceRow {
@@ -59,9 +59,18 @@ pub async fn run(json_output: bool) -> Result<()> {
5959
// Cross margin details
6060
if let Some(cross) = resp.get("crossMarginSummary") {
6161
println!();
62-
println!(" Account Value: ${}", cross["accountValue"].as_str().unwrap_or("-").green());
63-
println!(" Total Margin: ${}", cross["totalMarginUsed"].as_str().unwrap_or("-"));
64-
println!(" Notional: ${}", cross["totalNtlPos"].as_str().unwrap_or("-"));
62+
println!(
63+
" Account Value: ${}",
64+
cross["accountValue"].as_str().unwrap_or("-").green()
65+
);
66+
println!(
67+
" Total Margin: ${}",
68+
cross["totalMarginUsed"].as_str().unwrap_or("-")
69+
);
70+
println!(
71+
" Notional: ${}",
72+
cross["totalNtlPos"].as_str().unwrap_or("-")
73+
);
6574
}
6675
println!();
6776

src/commands/cancel.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{Result, Context};
1+
use anyhow::{Context, Result};
22
use colored::Colorize;
33
use serde_json::json;
44

@@ -21,10 +21,13 @@ pub async fn run(order_id: &str, json_output: bool) -> Result<()> {
2121

2222
if !json_output {
2323
println!();
24-
println!(" {} Cancelling order", "🗑️");
24+
println!(" 🗑️ Cancelling order");
2525
println!(" Symbol: {}", asset.cyan());
2626
println!(" Order ID: {}", oid);
27-
println!(" Network: {}", if cfg.testnet { "Testnet" } else { "Mainnet" });
27+
println!(
28+
" Network: {}",
29+
if cfg.testnet { "Testnet" } else { "Mainnet" }
30+
);
2831
println!();
2932
}
3033

@@ -43,11 +46,11 @@ pub async fn run(order_id: &str, json_output: bool) -> Result<()> {
4346
} else {
4447
match result {
4548
hyperliquid_rust_sdk::ExchangeResponseStatus::Ok(data) => {
46-
println!(" {} Order cancelled!", "✅".green());
49+
println!(" Order cancelled!");
4750
println!(" Response: {:?}", data);
4851
}
4952
hyperliquid_rust_sdk::ExchangeResponseStatus::Err(e) => {
50-
println!(" {} Cancel failed: {}", "❌".red(), e);
53+
println!(" Cancel failed: {}", e);
5154
}
5255
}
5356
println!();

src/commands/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
pub mod quote;
1+
pub mod balance;
2+
pub mod cancel;
23
pub mod news;
4+
pub mod options;
35
pub mod order;
46
pub mod orders;
5-
pub mod cancel;
6-
pub mod balance;
7-
pub mod positions;
87
pub mod perp;
9-
pub mod options;
8+
pub mod positions;
109
pub mod predict;
10+
pub mod quote;
1111
pub mod report;

src/commands/news.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{Result, Context};
1+
use anyhow::{Context, Result};
22
use colored::Colorize;
33
use serde_json::{json, Value};
44

@@ -17,10 +17,7 @@ pub async fn run(symbol: &str, json_output: bool) -> Result<()> {
1717
}
1818

1919
async fn fetch_google_news(client: &reqwest::Client, symbol: &str) -> Result<Vec<Value>> {
20-
let url = format!(
21-
"https://news.google.com/rss/search?q={}+stock",
22-
symbol
23-
);
20+
let url = format!("https://news.google.com/rss/search?q={}+stock", symbol);
2421
let text = client
2522
.get(&url)
2623
.header("User-Agent", "Mozilla/5.0")
@@ -69,7 +66,7 @@ fn extract_xml_tag(text: &str, tag: &str) -> Option<String> {
6966

7067
fn print_news(symbol: &str, articles: &[Value]) {
7168
println!();
72-
println!(" {} News for {}", "📰", symbol.bold().cyan());
69+
println!(" 📰 News for {}", symbol.bold().cyan());
7370
println!();
7471

7572
if articles.is_empty() {

src/commands/options.rs

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,72 @@
11
use anyhow::Result;
22
use colored::Colorize;
33

4-
pub async fn buy(symbol: &str, option_type: &str, strike: &str, expiry: &str, size: &str, json_output: bool) -> Result<()> {
4+
pub async fn buy(
5+
symbol: &str,
6+
option_type: &str,
7+
strike: &str,
8+
expiry: &str,
9+
size: &str,
10+
json_output: bool,
11+
) -> Result<()> {
512
if json_output {
6-
println!("{}", serde_json::json!({
7-
"status": "not_implemented",
8-
"note": "Native options support coming with Hyperliquid HIP-4",
9-
"params": { "symbol": symbol, "type": option_type, "strike": strike, "expiry": expiry, "size": size }
10-
}));
13+
println!(
14+
"{}",
15+
serde_json::json!({
16+
"status": "not_implemented",
17+
"note": "Native options support coming with Hyperliquid HIP-4",
18+
"params": { "symbol": symbol, "type": option_type, "strike": strike, "expiry": expiry, "size": size }
19+
})
20+
);
1121
} else {
1222
println!();
13-
println!(" {} Options Buy (Stub)", "📋");
23+
println!(" 📋 Options Buy (Stub)");
1424
println!(" Symbol: {}", symbol.cyan());
1525
println!(" Type: {}", option_type);
1626
println!(" Strike: ${}", strike);
1727
println!(" Expiry: {}", expiry);
1828
println!(" Size: {}", size);
1929
println!();
20-
println!(" {} Native options support coming with Hyperliquid HIP-4.", "ℹ️".blue());
30+
println!(
31+
" {} Native options support coming with Hyperliquid HIP-4.",
32+
"ℹ️".blue()
33+
);
2134
println!(" Currently, options-like exposure can be achieved via perps with stop-losses.");
2235
println!();
2336
}
2437
Ok(())
2538
}
2639

27-
pub async fn sell(symbol: &str, option_type: &str, strike: &str, expiry: &str, size: &str, json_output: bool) -> Result<()> {
40+
pub async fn sell(
41+
symbol: &str,
42+
option_type: &str,
43+
strike: &str,
44+
expiry: &str,
45+
size: &str,
46+
json_output: bool,
47+
) -> Result<()> {
2848
if json_output {
29-
println!("{}", serde_json::json!({
30-
"status": "not_implemented",
31-
"note": "Native options support coming with Hyperliquid HIP-4",
32-
"params": { "symbol": symbol, "type": option_type, "strike": strike, "expiry": expiry, "size": size }
33-
}));
49+
println!(
50+
"{}",
51+
serde_json::json!({
52+
"status": "not_implemented",
53+
"note": "Native options support coming with Hyperliquid HIP-4",
54+
"params": { "symbol": symbol, "type": option_type, "strike": strike, "expiry": expiry, "size": size }
55+
})
56+
);
3457
} else {
3558
println!();
36-
println!(" {} Options Sell (Stub)", "📋");
59+
println!(" 📋 Options Sell (Stub)");
3760
println!(" Symbol: {}", symbol.cyan());
3861
println!(" Type: {}", option_type);
3962
println!(" Strike: ${}", strike);
4063
println!(" Expiry: {}", expiry);
4164
println!(" Size: {}", size);
4265
println!();
43-
println!(" {} Native options support coming with Hyperliquid HIP-4.", "ℹ️".blue());
66+
println!(
67+
" {} Native options support coming with Hyperliquid HIP-4.",
68+
"ℹ️".blue()
69+
);
4470
println!();
4571
}
4672
Ok(())

src/commands/order.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
use anyhow::{Result, Context};
1+
use anyhow::{Context, Result};
22
use colored::Colorize;
33
use serde_json::json;
44

55
use crate::config;
66
use crate::signing;
77

88
/// Spot limit buy — price is the maximum price you'll pay per unit
9-
pub async fn buy(symbol: &str, amount_usdc: &str, max_price: &str, json_output: bool) -> Result<()> {
9+
pub async fn buy(
10+
symbol: &str,
11+
amount_usdc: &str,
12+
max_price: &str,
13+
json_output: bool,
14+
) -> Result<()> {
1015
let cfg = config::load_hl_config()?;
1116
let symbol = symbol.to_uppercase();
1217
let price_f: f64 = max_price.parse().context("Invalid max price")?;
@@ -15,12 +20,15 @@ pub async fn buy(symbol: &str, amount_usdc: &str, max_price: &str, json_output:
1520

1621
if !json_output {
1722
println!();
18-
println!(" {} Placing spot limit BUY", "📝");
23+
println!(" 📝 Placing spot limit BUY");
1924
println!(" Symbol: {}", symbol.cyan());
2025
println!(" Size: {:.6}", size);
2126
println!(" Max Price: ${}", max_price);
2227
println!(" Total: ${}", amount_usdc);
23-
println!(" Network: {}", if cfg.testnet { "Testnet" } else { "Mainnet" });
28+
println!(
29+
" Network: {}",
30+
if cfg.testnet { "Testnet" } else { "Mainnet" }
31+
);
2432
println!();
2533
}
2634

@@ -41,11 +49,11 @@ pub async fn buy(symbol: &str, amount_usdc: &str, max_price: &str, json_output:
4149
} else {
4250
match result {
4351
hyperliquid_rust_sdk::ExchangeResponseStatus::Ok(data) => {
44-
println!(" {} Spot buy order placed!", "✅".green());
52+
println!(" Spot buy order placed!");
4553
println!(" Response: {:?}", data);
4654
}
4755
hyperliquid_rust_sdk::ExchangeResponseStatus::Err(e) => {
48-
println!(" {} Order failed: {}", "❌".red(), e);
56+
println!(" Order failed: {}", e);
4957
}
5058
}
5159
println!();
@@ -63,11 +71,14 @@ pub async fn sell(symbol: &str, amount: &str, min_price: &str, json_output: bool
6371

6472
if !json_output {
6573
println!();
66-
println!(" {} Placing spot limit SELL", "📝");
74+
println!(" 📝 Placing spot limit SELL");
6775
println!(" Symbol: {}", symbol.cyan());
6876
println!(" Size: {}", amount);
6977
println!(" Min Price: ${}", min_price);
70-
println!(" Network: {}", if cfg.testnet { "Testnet" } else { "Mainnet" });
78+
println!(
79+
" Network: {}",
80+
if cfg.testnet { "Testnet" } else { "Mainnet" }
81+
);
7182
println!();
7283
}
7384

@@ -87,11 +98,11 @@ pub async fn sell(symbol: &str, amount: &str, min_price: &str, json_output: bool
8798
} else {
8899
match result {
89100
hyperliquid_rust_sdk::ExchangeResponseStatus::Ok(data) => {
90-
println!(" {} Spot sell order placed!", "✅".green());
101+
println!(" Spot sell order placed!");
91102
println!(" Response: {:?}", data);
92103
}
93104
hyperliquid_rust_sdk::ExchangeResponseStatus::Err(e) => {
94-
println!(" {} Order failed: {}", "❌".red(), e);
105+
println!(" Order failed: {}", e);
95106
}
96107
}
97108
println!();

src/commands/orders.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use colored::Colorize;
33
use serde_json::{json, Value};
4-
use tabled::{Table, settings::Style, Tabled};
4+
use tabled::{settings::Style, Table, Tabled};
55

66
use crate::config;
77

@@ -39,9 +39,10 @@ pub async fn run(symbol: Option<&str>, json_output: bool) -> Result<()> {
3939
// Filter by symbol if provided
4040
let orders: Vec<&Value> = if let Some(sym) = symbol {
4141
let sym = sym.to_uppercase();
42-
orders.iter().filter(|o| {
43-
o.get("coin").and_then(|c| c.as_str()) == Some(sym.as_str())
44-
}).collect()
42+
orders
43+
.iter()
44+
.filter(|o| o.get("coin").and_then(|c| c.as_str()) == Some(sym.as_str()))
45+
.collect()
4546
} else {
4647
orders.iter().collect()
4748
};
@@ -56,18 +57,23 @@ pub async fn run(symbol: Option<&str>, json_output: bool) -> Result<()> {
5657
return Ok(());
5758
}
5859

59-
let rows: Vec<OrderRow> = orders.iter().map(|o| {
60-
OrderRow {
60+
let rows: Vec<OrderRow> = orders
61+
.iter()
62+
.map(|o| OrderRow {
6163
oid: o["oid"].as_str().unwrap_or("").chars().take(8).collect(),
6264
symbol: o["coin"].as_str().unwrap_or("").to_string(),
63-
side: if o["side"].as_str() == Some("B") { "BUY".green().to_string() } else { "SELL".red().to_string() },
65+
side: if o["side"].as_str() == Some("B") {
66+
"BUY".green().to_string()
67+
} else {
68+
"SELL".red().to_string()
69+
},
6470
size: o["sz"].as_str().unwrap_or("0").to_string(),
6571
price: format!("${}", o["limitPx"].as_str().unwrap_or("0")),
6672
order_type: o["orderType"].as_str().unwrap_or("Limit").to_string(),
67-
}
68-
}).collect();
73+
})
74+
.collect();
6975

70-
println!("\n {} Open Orders\n", "📋");
76+
println!("\n 📋 Open Orders\n");
7177
let table = Table::new(rows).with(Style::rounded()).to_string();
7278
for line in table.lines() {
7379
println!(" {}", line);

0 commit comments

Comments
 (0)