fix: ValueError when price data returns empty string #49

Closed
opened 2026-02-05 00:27:06 +09:00 by agentson · 0 comments
Collaborator

Problem

trading_cycle crashes with ValueError: could not convert string to float: '' at src/main.py:110 when KIS API returns empty string for price data.

Error Log

ValueError: could not convert string to float: ''
  File "/home/agentson/repos/The-Ouroboros/src/main.py", line 110, in trading_cycle
    current_price = float(price_data.get("output", {}).get("last", "0"))

Occurs repeatedly for multiple stocks (AAPL, MSFT, GOOGL) when API returns empty string in price_data["output"]["last"].

Root Cause

Line 110 uses .get("last", "0") but doesn't handle empty strings. Lines 106-108 use the or "0" pattern correctly:

total_eval = float(balance_info.get("frcr_evlu_tota", "0") or "0")  # ✓ correct
current_price = float(price_data.get("output", {}).get("last", "0"))  # ✗ missing

Solution

Apply consistent empty-string handling:

current_price = float(price_data.get("output", {}).get("last", "0") or "0")

Impact

  • Severity: HIGH - causes trading cycle crash
  • Frequency: Common during market hours when API is busy
  • Markets affected: Overseas markets (US_NASDAQ, US_NYSE)
## Problem `trading_cycle` crashes with `ValueError: could not convert string to float: ''` at src/main.py:110 when KIS API returns empty string for price data. ## Error Log ``` ValueError: could not convert string to float: '' File "/home/agentson/repos/The-Ouroboros/src/main.py", line 110, in trading_cycle current_price = float(price_data.get("output", {}).get("last", "0")) ``` Occurs repeatedly for multiple stocks (AAPL, MSFT, GOOGL) when API returns empty string in `price_data["output"]["last"]`. ## Root Cause Line 110 uses `.get("last", "0")` but doesn't handle empty strings. Lines 106-108 use the `or "0"` pattern correctly: ```python total_eval = float(balance_info.get("frcr_evlu_tota", "0") or "0") # ✓ correct current_price = float(price_data.get("output", {}).get("last", "0")) # ✗ missing ``` ## Solution Apply consistent empty-string handling: ```python current_price = float(price_data.get("output", {}).get("last", "0") or "0") ``` ## Impact - **Severity**: HIGH - causes trading cycle crash - **Frequency**: Common during market hours when API is busy - **Markets affected**: Overseas markets (US_NASDAQ, US_NYSE)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#49