stock-analysis-plugin 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -642,13 +642,25 @@ def analyze_multi(symbol: str, period: str, count: int, periods: list) -> dict:
642
642
 
643
643
 
644
644
  def analyze(symbol: str, period: str = "daily", count: int = 120) -> dict:
645
- records = fetch_kline(symbol, period, count)
645
+ return analyze_records(symbol, fetch_kline(symbol, period, count), period)
646
+
647
+
648
+ def analyze_records(symbol: str, records: list, period: str = "daily") -> dict:
646
649
  if isinstance(records, dict) and "error" in records:
647
650
  return records
648
- if not records:
651
+ if not isinstance(records, list) or not records:
649
652
  return {"error": "No kline data returned"}
653
+ if any(not isinstance(row, dict) for row in records):
654
+ return {"error": "Invalid kline rows"}
650
655
 
651
656
  df = to_dataframe(records)
657
+ required = ["date", "close", "high", "low", "volume"]
658
+ if any(field not in df for field in required):
659
+ return {"error": "Missing kline fields"}
660
+ if df["date"].isna().any() or not np.isfinite(df[required[1:]]).all().all():
661
+ return {"error": "Invalid kline values"}
662
+ if (df[["close", "high", "low"]] <= 0).any().any() or (df["volume"] < 0).any():
663
+ return {"error": "Kline prices must be positive and volume nonnegative"}
652
664
  if len(df) < 30:
653
665
  return {"error": f"Insufficient data: {len(df)} rows (need at least 30)"}
654
666
 
@@ -731,6 +743,8 @@ def main():
731
743
  else:
732
744
  result = {"error": f"Unknown command: {args.command}"}
733
745
  print(json.dumps(result, ensure_ascii=False, default=str))
746
+ if "error" in result:
747
+ sys.exit(1)
734
748
 
735
749
 
736
750
  if __name__ == "__main__":