| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- use rust_decimal::Decimal;
- use tracing::trace;
- use exchanges::proxy;
- use crate::exchange::ExchangeEnum;
- /// 修改交易对连接符号
- /// - `symbol(str)`: 交易对, "BTC_USDT", 默认以下划线传递
- /// - `pat(str)`: 替换字符, "-", 把 “_” 替换为 "-"
- pub fn format_symbol(symbol: String, pat: &str) -> String {
- return symbol.to_uppercase().replace("_", pat);
- }
- // 检测是否走代理
- pub fn proxy_handle(is_unusual: Option<&str>) {
- if proxy::ParsingDetail::http_enable_proxy(is_unusual) {
- trace!("检测有代理配置,配置走代理");
- }
- }
- /// 币种映射器
- #[allow(dead_code)]
- pub fn symbol_enter_mapper(exchange_enum: ExchangeEnum, symbol: &str) -> String {
- let symbol_upper = symbol.to_uppercase();
- match exchange_enum {
- // ExchangeEnum::KucoinSwap => {
- // if symbol_upper.contains("BTC") {
- // symbol_upper.replace("BTC", "XBT")
- // } else { symbol_upper.to_string() }
- // }
- _ => {
- symbol_upper.to_string()
- }
- }
- }
- // 截取指定精度的decimal(不会四舍五入)
- pub fn truncate_decimal(amount: Decimal, precision: u32) -> Decimal {
- let scale = Decimal::new(10i64.pow(precision), 0);
- (amount * scale).trunc() / scale
- }
- // 获取指定精度下的tick_size
- pub fn get_tick_size(precision: u32) -> Decimal {
- return Decimal::new(1, 0) / Decimal::new(10i64.pow(precision), 0);
- }
- /// 币种映射器
- #[allow(dead_code)]
- pub fn symbol_out_mapper(exchange_enum: ExchangeEnum, symbol: &str) -> String {
- let symbol_upper = symbol.to_uppercase();
- match exchange_enum {
- // ExchangeEnum::KucoinSwap => {
- // if symbol_upper.contains("XBT") {
- // symbol_upper.replace("XBT", "BTC")
- // } else { symbol_upper.to_string() }
- // }
- _ => {
- symbol_upper.to_string()
- }
- }
- }
|