浏览代码

整理添加bybit导出

gepangpang 1 年之前
父节点
当前提交
5110de3732
共有 4 个文件被更改,包括 19 次插入49 次删除
  1. 1 1
      config_balance.toml.sample
  2. 14 41
      src/export_balance.rs
  3. 3 7
      src/swap_bybit/bybit_swap_rest_utils.rs
  4. 1 0
      src/swap_bybit/bybit_swap_standard.rs

+ 1 - 1
config_balance.toml.sample

@@ -4,7 +4,7 @@ is_export = true
 proxy_address = "127.0.0.1:7890"
 # 账号列表(account_name: 导出展示名字)
 account_list = [["account_name", "access_key", "secret_key", "pass_key"]]
-# 配置交易所 目前支持["gate"]
+# 配置交易所 目前支持["gate","bybit"]
 exchanges = ["gate"]
 # 配置查询时间(格式:2023-12-6 15:00:00)
 range_time = ["2023-12-20 18:00:00", "2023-12-26 10:00:00"]

+ 14 - 41
src/export_balance.rs

@@ -25,7 +25,7 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
     }
     for exchange in config_info.exchanges.clone() {
         let exchange_up = exchange.to_uppercase();
-        let exchange_result = match exchange_up.as_str() {
+        match exchange_up.as_str() {
             "GATE" => {
                 for account in config_info_clone.account_list.clone() {
                     let mut account_info: BTreeMap<String, String> = BTreeMap::new();
@@ -111,7 +111,7 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
                         }
                     }
                     // break;
-                }
+                };
             }
             "BYBIT" => {
                 for account in config_info_clone.account_list.clone() {
@@ -119,12 +119,9 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
                     account_info.insert("account_name".to_string(), account[0].clone());
                     account_info.insert("access_key".to_string(), account[1].clone());
                     account_info.insert("secret_key".to_string(), account[2].clone());
-                    info!("账号:{:?}",account_info);
 
-                    let mut gate_exc = BybitSwapRest::new(false, account_info.clone());
-                    let data = gate_exc.get_account_transaction_log().await;
-                    // let data = gate_exc.get_position_closed_pnl("BSVUSDT".to_string()).await;
-                    // let data = gate_exc.get_account_wallet_fund_records(0, 0).await;
+                    let mut bybit_exc = BybitSwapRest::new(false, account_info.clone());
+                    let data = bybit_exc.get_account_transaction_log().await;
 
                     // info!("请求完成{:?}",data.clone());
                     if data.code.as_str() == "200" {
@@ -142,20 +139,11 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
                                 let mut name_data_all: Vec<Vec<String>> = vec![];
 
                                 for item in array {
-                                    // info!("数据{:?}",item.clone().to_string());
-
                                     let id = item.get("id").unwrap().as_str().unwrap();
                                     let type_str = item.get("type").unwrap().as_str().unwrap();
-                                    let b_symbol = item.get("symbol").unwrap().as_str().unwrap();
-                                    let side = item.get("side").unwrap().as_str().unwrap();
-                                    let currency = item.get("currency").unwrap().as_str().unwrap();
-                                    let tradePrice = item.get("tradePrice").unwrap().as_str().unwrap();
-                                    let funding = item.get("funding").unwrap().as_str().unwrap();
-                                    let fee = item.get("fee").unwrap().as_str().unwrap();
-                                    let cashFlow = item.get("cashFlow").unwrap().as_str().unwrap();
                                     let change = item.get("change").unwrap().as_str().unwrap();
-                                    let cashBalance = item.get("cashBalance").unwrap().as_str().unwrap();
-                                    let transactionTime = item.get("transactionTime").unwrap().as_str().unwrap();
+                                    let cash_balance = item.get("cashBalance").unwrap().as_str().unwrap();
+                                    let transaction_time = item.get("transactionTime").unwrap().as_str().unwrap();
 
                                     let type_str = match type_str {
                                         "TRADE" => { "交易" }
@@ -165,24 +153,13 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
                                         }
                                     };
 
-                                    // info!("result 数据\
-                                    //  transactionTime:{:?} id:{:?},symbol:{:?},side:{:?},currency:{:?},tradePrice:{:?},funding:{:?},fee:{:?},cashFlow:{:?},cashBalance:{:?},change:{:?}"
-                                    //     ,transactionTime, id,b_symbol,side,currency,tradePrice,funding,fee,cashFlow,cashBalance,change);//change 變更 = cashFlow + funding - fee
-
-//                                     "{\"bonusChange\":\"0\",\"cashBalance\":\"97.95598152\",\"cashFlow\":\"0\",\"category\":\"linear\",\"change\":\"-0.01119174\",\"currency\":\"USDT\",\"fee\":\"0.01119174
-// \",\"feeRate\":\"0.00014\",\"funding\":\"0\",\"id\":\"123105018_INJUSDT_618678386870\",\"orderId\":\"3d3da36b-c803-441a-bb0b-24fdef56d6f3\",\"orderLinkId\":\"t-459097906\",\"qty\":\"2\",\"side\":\"Buy\",\"size\":\"2\",\"symbol\"
-// :\"INJUSDT\",\"tradeId\":\"ed458708-3de4-5bc8-bc27-f6b4ba7a8921\",\"tradePrice\":\"39.9705\",\"transactionTime\":\"1703224750479\",\"type\":\"TRADE\"}"
-
-//              "{\"balance\":\"49.051791949878\",\"change\":\"-0.0576\",\"contract\":\"OP_USDT\",\"text\":\"OP_USDT:376554197685\",\"time\":1702110912,\"trade_id\":\"16306596\",\"type
-// \":\"pnl\"}"
-
-                                    let time = transactionTime.parse::<i64>().unwrap() / 1000;
+                                    let time = transaction_time.parse::<i64>().unwrap() / 1000;
 
                                     let mut name_data_array: Vec<String> = vec![];
                                     name_data_array.push(time.to_string());
                                     name_data_array.push(id.to_string());
                                     name_data_array.push(change.to_string());
-                                    name_data_array.push(cashBalance.to_string());
+                                    name_data_array.push(cash_balance.to_string());
                                     name_data_array.push(type_str.to_string());
                                     name_data_array.push("".to_string());
                                     name_data_array.push("".to_string());
@@ -198,7 +175,7 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
                         }
                     }
                     // break;
-                }
+                };
             }
             _ => {
                 error!("交易所输入错误!");
@@ -206,8 +183,6 @@ pub async fn export_balance(config_info: BalanceConfigInfo) {
             }
         };
     }
-    info!("all_account_balance_info:{:?}",all_account_balance_info);
-
 
     // 根据账户变动填充
     let mut count_time_list = vec![];
@@ -315,13 +290,11 @@ pub fn supply_balance(source_balance_info: BTreeMap<String, Vec<Vec<String>>>, t
                     let balance_info_filter: Vec<Vec<String>> = balance_info.iter().filter(|item| {
                         item[0].parse::<i64>().unwrap() < time
                     }).cloned().collect();
-                    info!("balance_info_filter:{:?}",balance_info_filter.clone());
-                    let mut last_balance_info = vec![];
-                    if balance_info_filter.len() == 0{
-                        last_balance_info = balance_info[0].clone();
-                    }else{
-                        last_balance_info = balance_info_filter[balance_info_filter.len() - 1].clone();
-                    }
+                    let mut last_balance_info = if balance_info_filter.len() == 0 {
+                        balance_info[0].clone()
+                    } else {
+                        balance_info_filter[balance_info_filter.len() - 1].clone()
+                    };
                     last_balance_info.insert(0, key.clone());
                     total_price += Decimal::from_str(&last_balance_info[4]).unwrap();
                     balance_info_list.push(last_balance_info);

+ 3 - 7
src/swap_bybit/bybit_swap_rest_utils.rs

@@ -129,12 +129,8 @@ impl BybitSwapRest {
             "walletFundType":"RealisedPNL",
             "limit":"50",
          });
-        // if start_time > 0 {
-        params["startTime"] = serde_json::json!(1703124000000 as i64);
-        // }
-        // if end_time > 0 {
-        params["endTime"] = serde_json::json!(1703664000000  as i64);
-        // }
+        params["startTime"] = serde_json::json!(start_time);
+        params["endTime"] = serde_json::json!(end_time);
 
         let data = self.request("GET".to_string(),
                                 "/contract/v3".to_string(),
@@ -350,7 +346,7 @@ impl BybitSwapRest {
         let res = Response::new();
         trace!("原始数据:{:?}",result);
         match result {
-            Ok(mut res_data) => {
+            Ok(res_data) => {
                 if res_data.code != "200" {
                     // res_data
                     trace!("不等于200");

+ 1 - 0
src/swap_bybit/bybit_swap_standard.rs

@@ -22,6 +22,7 @@ pub struct SwapTrades {
     ts: String,//成交时间,Unix时间戳的毫秒数格式, 如1597026383085
 }
 
+#[allow(dead_code)]
 pub(crate) async fn standard_history_candles(symbol: &str, start_at: &str, end_at: &str, ct_val: Decimal) -> Result<Vec<Trades>, Error> {
     let mut symbol_fmt = format!("{}-SWAP", symbol.replace("_", "-").clone());
     symbol_fmt = symbol_fmt.to_uppercase();