Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
soulmachine committed Jul 8, 2022
1 parent 6ff2df7 commit 8d3c3c0
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 67 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
Expand All @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
Expand All @@ -50,7 +50,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
Expand All @@ -63,7 +63,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
components: clippy
- uses: actions-rs/cargo@v1
Expand Down
6 changes: 3 additions & 3 deletions crypto-contract-value/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-contract-value"
version = "1.5.0"
version = "1.5.1"
authors = ["soulmachine <soulmachine@gmail.com>"]
edition = "2021"
description = "Get contract value."
Expand All @@ -12,8 +12,8 @@ keywords = ["cryptocurrency", "blockchain", "trading"]

[dependencies]
crypto-market-type = "1.1.1"
crypto-pair = "2.2.11"
once_cell = "1.12.0"
crypto-pair = "2.2.12"
once_cell = "1.13.0"
reqwest = { version = "0.11.11", features = ["blocking", "gzip"] }
serde = { version = "1.0.138", features = ["derive"] }
serde_json = "1.0.82"
2 changes: 1 addition & 1 deletion crypto-contract-value/src/exchanges/mexc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn fetch_linear_contract_sizes() -> BTreeMap<String, f64> {
pub(crate) fn get_contract_value(market_type: MarketType, pair: &str) -> Option<f64> {
match market_type {
MarketType::InverseSwap => Some(if pair.starts_with("BTC") { 100.0 } else { 10.0 }),
MarketType::LinearSwap => Some(LINEAR_CONTRACT_VALUES.get(pair).expect(pair).clone()),
MarketType::LinearSwap => Some(*LINEAR_CONTRACT_VALUES.get(pair).expect(pair)),
_ => None,
}
}
Expand Down
12 changes: 6 additions & 6 deletions crypto-crawler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-crawler"
version = "4.4.9"
version = "4.5.0"
authors = ["soulmachine <soulmachine@gmail.com>"]
edition = "2021"
description = "A rock-solid cryprocurrency crawler."
Expand All @@ -9,13 +9,13 @@ repository = "https://github.com/crypto-crawler/crypto-crawler-rs/tree/main/cryp
keywords = ["cryptocurrency", "blockchain", "trading"]

[dependencies]
crypto-markets = "1.3.1"
crypto-markets = "1.3.2"
crypto-market-type = "1.1.1"
crypto-msg-parser = "2.6.1"
crypto-msg-parser = "2.6.2"
crypto-msg-type = "1.0.8"
crypto-pair = "2.2.11"
crypto-rest-client = "0.9.3"
crypto-ws-client = "4.11.6"
crypto-pair = "2.2.12"
crypto-rest-client = "0.9.4"
crypto-ws-client = "4.11.7"
fslock = "0.2.1"
once_cell = "1.13.0"
log = "0.4.17"
Expand Down
10 changes: 4 additions & 6 deletions crypto-crawler/src/crawlers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ pub(crate) async fn crawl_event(
// split to chunks
let mut chunks: Vec<Vec<String>> = Vec::new();
for i in (0..real_symbols.len()).step_by(num_topics_per_connection) {
let chunk = (&real_symbols
[i..(std::cmp::min(i + num_topics_per_connection, real_symbols.len()))])
let chunk = real_symbols
[i..(std::cmp::min(i + num_topics_per_connection, real_symbols.len()))]
.to_vec();
chunks.push(chunk);
}
Expand Down Expand Up @@ -995,10 +995,8 @@ pub(crate) async fn crawl_candlestick_ext(
let mut chunks: Vec<Vec<(String, usize)>> = Vec::new();
{
for i in (0..symbol_interval_list.len()).step_by(num_topics_per_connection) {
let chunk: Vec<(String, usize)> = (&symbol_interval_list[i..(std::cmp::min(
i + num_topics_per_connection,
symbol_interval_list.len(),
))])
let chunk: Vec<(String, usize)> = symbol_interval_list
[i..(std::cmp::min(i + num_topics_per_connection, symbol_interval_list.len()))]
.to_vec();
chunks.push(chunk);
}
Expand Down
4 changes: 2 additions & 2 deletions crypto-markets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-markets"
version = "1.3.1"
version = "1.3.2"
authors = ["soulmachine <soulmachine@gmail.com>"]
edition = "2021"
description = "Fetch trading markets from a cryptocurrency exchange"
Expand All @@ -11,7 +11,7 @@ keywords = ["cryptocurrency", "blockchain", "trading"]
[dependencies]
chrono = "0.4.19"
crypto-market-type = "1.1.1"
crypto-pair = "2.2.11"
crypto-pair = "2.2.12"
reqwest = { version = "0.11.11", features = ["blocking", "gzip", "socks"] }
serde = { version = "1.0.138", features = ["derive"] }
serde_json = "1.0.82"
Expand Down
6 changes: 3 additions & 3 deletions crypto-markets/src/exchanges/bitmex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn fetch_instruments(market_type: MarketType) -> Result<Vec<Instrument>> {
for x in swap.iter() {
assert_eq!("FundingRate", x.fairMethod.as_str());
assert!(x.expiry.is_none()); // TODO: BitMEX data is not correct, comment it for now
assert!((&x.symbol[x.symbol.len() - 1..]).parse::<i32>().is_err());
assert!(x.symbol[x.symbol.len() - 1..].parse::<i32>().is_err());
if let Some(pos) = x.symbol.rfind('_') {
// e.g., ETHUSD_ETH
assert_eq!(
Expand All @@ -192,9 +192,9 @@ fn fetch_instruments(market_type: MarketType) -> Result<Vec<Instrument>> {
assert!(x.expiry.is_some());
if let Some(pos) = x.symbol.rfind('_') {
// e.g., ETHUSDM22_ETH
assert!((&x.symbol[pos - 2..pos]).parse::<i32>().is_ok());
assert!(x.symbol[pos - 2..pos].parse::<i32>().is_ok());
} else {
assert!((&x.symbol[x.symbol.len() - 2..]).parse::<i32>().is_ok());
assert!(x.symbol[x.symbol.len() - 2..].parse::<i32>().is_ok());
}
}
// Inverse
Expand Down
6 changes: 3 additions & 3 deletions crypto-markets/src/exchanges/bybit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn fetch_inverse_future_symbols() -> Result<Vec<String>> {
let symbols = fetch_markets_raw()?
.into_iter()
.filter(|m| {
m.quote_currency == "USD" && (&m.name[(m.name.len() - 2)..]).parse::<i64>().is_ok()
m.quote_currency == "USD" && m.name[(m.name.len() - 2)..].parse::<i64>().is_ok()
})
.map(|m| m.name)
.collect::<Vec<String>>();
Expand All @@ -119,7 +119,7 @@ fn to_market(raw_market: &BybitMarket) -> Market {
let v: Vec<&str> = pair.split('/').collect();
(v[0].to_string(), v[1].to_string())
};
let delivery_date: Option<u64> = if (&raw_market.name[(raw_market.name.len() - 2)..])
let delivery_date: Option<u64> = if raw_market.name[(raw_market.name.len() - 2)..]
.parse::<i64>()
.is_ok()
{
Expand Down Expand Up @@ -218,7 +218,7 @@ fn fetch_inverse_future_markets() -> Result<Vec<Market>> {
let markets = fetch_markets_raw()?
.into_iter()
.filter(|m| {
m.quote_currency == "USD" && (&m.name[(m.name.len() - 2)..]).parse::<i64>().is_ok()
m.quote_currency == "USD" && m.name[(m.name.len() - 2)..].parse::<i64>().is_ok()
})
.map(|m| to_market(&m))
.collect::<Vec<Market>>();
Expand Down
6 changes: 3 additions & 3 deletions crypto-markets/src/exchanges/ftx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn fetch_linear_future_symbols() -> Result<Vec<String>> {
x.type_ == "future"
&& !x.name.ends_with("-PERP")
&& !x.name.contains("-MOVE-")
&& (&x.name[(x.name.len() - 4)..]).parse::<u32>().is_ok()
&& x.name[(x.name.len() - 4)..].parse::<u32>().is_ok()
&& x.name.contains('-')
})
.map(|x| x.name)
Expand Down Expand Up @@ -140,7 +140,7 @@ fn to_market(raw_market: &FtxMarket) -> Market {
} else {
panic!("Unsupported type: {}", raw_market.type_);
};
let delivery_date: Option<u64> = if (&raw_market.name[(raw_market.name.len() - 4)..])
let delivery_date: Option<u64> = if raw_market.name[(raw_market.name.len() - 4)..]
.parse::<u32>()
.is_ok()
{
Expand Down Expand Up @@ -245,7 +245,7 @@ fn fetch_linear_future_markets() -> Result<Vec<Market>> {
x.type_ == "future"
&& !x.name.ends_with("-PERP")
&& !x.name.contains("-MOVE-")
&& (&x.name[(x.name.len() - 4)..]).parse::<u32>().is_ok()
&& x.name[(x.name.len() - 4)..].parse::<u32>().is_ok()
&& x.name.contains('-')
})
.map(|x| to_market(&x))
Expand Down
2 changes: 1 addition & 1 deletion crypto-markets/src/exchanges/kraken/kraken_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn fetch_futures_markets() -> Result<Vec<Market>> {
};
let (base_id, quote_id) = {
let pos = m.symbol.find("usd").unwrap();
((&m.symbol[3..pos]).to_string(), "usd".to_string())
(m.symbol[3..pos].to_string(), "usd".to_string())
};
Market {
exchange: "kraken".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crypto-markets/src/exchanges/zb/zb_spot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct SpotMarket {

// See https://zbgapi.github.io/docs/spot/v1/en/#public-get-all-supported-trading-symbols
fn fetch_spot_markets_raw() -> Result<Vec<SpotMarket>> {
let txt = http_get("https://api.zbex.site/data/v1/markets", None)?;
let txt = http_get("https://api.zb.com/data/v1/markets", None)?;
let m = serde_json::from_str::<HashMap<String, SpotMarket>>(&txt)?;
let mut markets = Vec::new();
for (symbol, mut market) in m {
Expand Down
8 changes: 4 additions & 4 deletions crypto-msg-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-msg-parser"
version = "2.6.1"
version = "2.6.2"
authors = ["soulmachine <soulmachine@gmail.com>"]
edition = "2021"
description = "Parse websocket messages from cryptocurreny exchanges"
Expand All @@ -10,11 +10,11 @@ keywords = ["cryptocurrency", "blockchain", "trading"]

[dependencies]
chrono = "0.4.19"
crypto-contract-value = "1.5.0"
crypto-contract-value = "1.5.1"
crypto-market-type = "1.1.1"
crypto-msg-type = "1.0.8"
crypto-message = "1.0.1"
crypto-pair = "2.2.11"
crypto-message = "1.0.2"
crypto-pair = "2.2.12"
if_chain = "1.0.2"
once_cell = "1.13.0"
reqwest = { version = "0.11.11", features = ["blocking", "gzip"] }
Expand Down
8 changes: 4 additions & 4 deletions crypto-msg-parser/tests/okx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ mod trade {
assert_eq!(trade.timestamp, 1646138219181);
assert_eq!(trade.price, 0.001);
assert_eq!(trade.quantity_contract, Some(85.0));
assert_eq!(trade.quantity_base, 85.0 * 0.1);
assert_eq!(trade.quantity_quote, 85.0 * 0.1 * 0.001);
assert_eq!(trade.quantity_base, 85.0);
assert_eq!(trade.quantity_quote, 85.0 * 0.001);
assert_eq!(trade.side, TradeSide::Buy);
}
}
Expand Down Expand Up @@ -475,8 +475,8 @@ mod l2_event {

assert_eq!(orderbook.asks[0].price, 0.0005);
assert_eq!(orderbook.asks[0].quantity_contract, Some(305.0));
assert_eq!(orderbook.asks[0].quantity_base, 305.0 * 0.1);
assert_eq!(orderbook.asks[0].quantity_quote, 305.0 * 0.1 * 0.0005);
assert_eq!(orderbook.asks[0].quantity_base, 305.0);
assert_eq!(orderbook.asks[0].quantity_quote, 305.0 * 0.0005);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crypto-pair/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-pair"
version = "2.2.11"
version = "2.2.12"
authors = ["soulmachine <soulmachine@gmail.com>"]
edition = "2021"
description = "Parse exchange-specific symbols to unified format"
Expand Down
4 changes: 2 additions & 2 deletions crypto-pair/src/exchanges/binance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn normalize_pair(symbol: &str) -> Option<String> {
let pos = symbol.find('-').unwrap();
let base = &symbol[..pos];
Some(format!("{}/USDT", base))
} else if symbol.len() > 7 && (&symbol[(symbol.len() - 6)..]).parse::<i64>().is_ok() {
} else if symbol.len() > 7 && (symbol[(symbol.len() - 6)..]).parse::<i64>().is_ok() {
// linear and inverse future
let remove_date = &symbol[..symbol.len() - 7];
if remove_date.ends_with("USDT") {
Expand All @@ -83,7 +83,7 @@ pub(crate) fn get_market_type(symbol: &str, is_spot: Option<bool>) -> MarketType
MarketType::InverseSwap
} else if symbol.ends_with("-P") || symbol.ends_with("-C") {
MarketType::EuropeanOption
} else if symbol.len() > 7 && (&symbol[(symbol.len() - 6)..]).parse::<i64>().is_ok() {
} else if symbol.len() > 7 && (symbol[(symbol.len() - 6)..]).parse::<i64>().is_ok() {
// linear and inverse future
let remove_date = &symbol[..symbol.len() - 7];
if remove_date.ends_with("USDT") {
Expand Down
8 changes: 4 additions & 4 deletions crypto-pair/src/exchanges/bitget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ pub(crate) fn normalize_pair(symbol: &str) -> Option<String> {
let pos = symbol.find('_').unwrap();
let pair = &symbol[..pos];
if pair.ends_with("USDT") {
return Some(format!("{}/USDT", pair.strip_suffix("USDT").unwrap()));
Some(format!("{}/USDT", pair.strip_suffix("USDT").unwrap()))
} else if pair.ends_with("USD") {
return Some(format!("{}/USD", pair.strip_suffix("USD").unwrap()));
Some(format!("{}/USD", pair.strip_suffix("USD").unwrap()))
} else if pair.ends_with("ETH") {
return Some(format!("{}/ETH", pair.strip_suffix("ETH").unwrap()));
Some(format!("{}/ETH", pair.strip_suffix("ETH").unwrap()))
} else if pair.ends_with("BTC") {
return Some(format!("{}/BTC", pair.strip_suffix("BTC").unwrap()));
Some(format!("{}/BTC", pair.strip_suffix("BTC").unwrap()))
} else {
panic!("Failed to parse {}", symbol);
}
Expand Down
4 changes: 2 additions & 2 deletions crypto-pair/src/exchanges/bybit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) fn normalize_pair(symbol: &str) -> Option<String> {
// inverse swap
let base = symbol.strip_suffix("USD").unwrap();
(base, "USD")
} else if (&symbol[symbol.len() - 2..]).parse::<i64>().is_ok() {
} else if symbol[symbol.len() - 2..].parse::<i64>().is_ok() {
// inverse future
let base = &symbol[..symbol.len() - 6];
(base, "USD")
Expand All @@ -24,7 +24,7 @@ pub(crate) fn get_market_type(symbol: &str) -> MarketType {
MarketType::LinearSwap
} else if symbol.ends_with("USD") {
MarketType::InverseSwap
} else if (&symbol[symbol.len() - 2..]).parse::<i64>().is_ok() {
} else if symbol[symbol.len() - 2..].parse::<i64>().is_ok() {
MarketType::InverseFuture
} else {
MarketType::Unknown
Expand Down
4 changes: 2 additions & 2 deletions crypto-pair/src/exchanges/deribit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) fn normalize_pair(symbol: &str) -> Option<String> {
// inverse_swap
let base = symbol.strip_suffix("-PERPETUAL").unwrap();
Some(format!("{}/USD", base))
} else if symbol.len() > 7 && (&symbol[(symbol.len() - 2)..]).parse::<i64>().is_ok() {
} else if symbol.len() > 7 && symbol[(symbol.len() - 2)..].parse::<i64>().is_ok() {
// inverse_future
let pos = symbol.find('-').unwrap();
let base = &symbol[..pos];
Expand All @@ -23,7 +23,7 @@ pub(crate) fn normalize_pair(symbol: &str) -> Option<String> {
pub(crate) fn get_market_type(symbol: &str) -> MarketType {
if symbol.ends_with("-PERPETUAL") {
MarketType::InverseSwap
} else if symbol.len() > 7 && (&symbol[(symbol.len() - 2)..]).parse::<i64>().is_ok() {
} else if symbol.len() > 7 && symbol[(symbol.len() - 2)..].parse::<i64>().is_ok() {
MarketType::InverseFuture
} else if symbol.ends_with("-P") || symbol.ends_with("-C") {
MarketType::EuropeanOption
Expand Down
2 changes: 1 addition & 1 deletion crypto-pair/src/exchanges/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn get_market_type(symbol: &str, is_spot: Option<bool>) -> MarketType
} else {
MarketType::LinearSwap
}
} else if symbol.len() > 8 && (&symbol[(symbol.len() - 8)..]).parse::<i64>().is_ok() {
} else if symbol.len() > 8 && symbol[(symbol.len() - 8)..].parse::<i64>().is_ok() {
if symbol.contains("_USD_") {
MarketType::InverseFuture
} else if symbol.contains("_USDT_") {
Expand Down
4 changes: 2 additions & 2 deletions crypto-pair/src/exchanges/kraken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn fetch_spot_quotes() -> BTreeSet<String> {
.map(|m| m.quote)
.map(|s| {
if s.len() > 3 && (s.starts_with('X') || s.starts_with('Z')) {
(&s[1..]).to_string()
s[1..].to_string()
} else {
s
}
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(crate) fn normalize_pair(symbol: &str) -> Option<String> {
} else {
panic!("Can not find usd or USD in symbol: {}", symbol);
};
let base = (&symbol[3..pos]).to_uppercase();
let base = symbol[3..pos].to_uppercase();
Some(format!("{}/USD", normalize_currency(&base),))
} else if SPOT_QUOTES.contains(&symbol[(symbol.len() - 4)..]) {
let base = &symbol[..(symbol.len() - 4)];
Expand Down
Loading

0 comments on commit 8d3c3c0

Please sign in to comment.