fix: handle empty strings in price data parsing (issue #49)
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
Apply consistent empty-string handling across main.py and scanner.py to prevent ValueError when KIS API returns empty strings. Changes: - src/main.py:110 - Add 'or "0"' for current_price parsing - src/analysis/scanner.py:86-87 - Add 'or "0"' for price/volume parsing - tests/test_main.py - Add test_overseas_price_empty_string - tests/test_volatility.py - Add test_scan_stock_overseas_empty_price Before: ValueError crashes trading cycle After: Empty strings default to 0.0, trading continues Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -83,8 +83,8 @@ class MarketScanner:
|
||||
# Convert to orderbook-like structure
|
||||
orderbook = {
|
||||
"output1": {
|
||||
"stck_prpr": price_data.get("output", {}).get("last", "0"),
|
||||
"acml_vol": price_data.get("output", {}).get("tvol", "0"),
|
||||
"stck_prpr": price_data.get("output", {}).get("last", "0") or "0",
|
||||
"acml_vol": price_data.get("output", {}).get("tvol", "0") or "0",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ async def trading_cycle(
|
||||
total_cash = float(balance_info.get("frcr_dncl_amt_2", "0") or "0")
|
||||
purchase_total = float(balance_info.get("frcr_buy_amt_smtl", "0") or "0")
|
||||
|
||||
current_price = float(price_data.get("output", {}).get("last", "0"))
|
||||
current_price = float(price_data.get("output", {}).get("last", "0") or "0")
|
||||
foreigner_net = 0.0 # Not available for overseas
|
||||
|
||||
# Calculate daily P&L %
|
||||
|
||||
Reference in New Issue
Block a user