Browse Source

尝试处理len为0的问题。

skyffire 1 year ago
parent
commit
35ac0f397f
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/symbol_filter.rs

+ 4 - 0
src/symbol_filter.rs

@@ -44,6 +44,10 @@ fn calc_total_volume(records: Value) -> Decimal {
 fn calc_rise_percentage(records: Value) -> Decimal {
 fn calc_rise_percentage(records: Value) -> Decimal {
     let records_array = records.as_array().unwrap();
     let records_array = records.as_array().unwrap();
 
 
+    if records_array.len() == 0 {
+        return Decimal::ZERO
+    }
+
     let first_record = records_array[records_array.len() - 1].clone();
     let first_record = records_array[records_array.len() - 1].clone();
     let last_record = records_array[0].clone();
     let last_record = records_array[0].clone();
     let open = Decimal::from_str(first_record["open"].as_str().unwrap().to_string().as_str()).unwrap();
     let open = Decimal::from_str(first_record["open"].as_str().unwrap().to_string().as_str()).unwrap();