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:
@@ -338,6 +338,28 @@ class TestMarketScanner:
|
||||
assert metrics.stock_code == "AAPL"
|
||||
assert metrics.current_price == 150.50
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_stock_overseas_empty_price(
|
||||
self,
|
||||
scanner: MarketScanner,
|
||||
mock_overseas_broker: OverseasBroker,
|
||||
context_store: ContextStore,
|
||||
) -> None:
|
||||
"""Test scanning overseas stock with empty price string (issue #49)."""
|
||||
mock_overseas_broker.get_overseas_price.return_value = {
|
||||
"output": {
|
||||
"last": "", # Empty string
|
||||
"tvol": "", # Empty string
|
||||
}
|
||||
}
|
||||
|
||||
market = MARKETS["US_NASDAQ"]
|
||||
metrics = await scanner.scan_stock("AAPL", market)
|
||||
|
||||
assert metrics is not None
|
||||
assert metrics.stock_code == "AAPL"
|
||||
assert metrics.current_price == 0.0 # Should default to 0.0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_stock_error_handling(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user