fix: add safe_float() to handle empty string conversions (issue #44) #48
Reference in New Issue
Block a user
Delete Branch "feature/issue-44-safe-float"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
safe_float()helper function for safe type conversionfloat()calls in trading_cycle withsafe_float()Problem
Docker logs showed float conversion errors (15% of failures):
KIS API returns empty strings when:
Solution
Applied to all float conversions:
stck_prpr,frgn_ntby_qty)tot_evlu_amt,dnca_tot_amt,pchs_amt_smtl_amt)Test Coverage
"123.45"→123.45""→0.0None→0.0"abc"→0.0123.45→123.45safe_float("", -1.0)→-1.0Benefits
Closes
Closes #44
🤖 Generated with Claude Code
Add safe_float() helper function to safely convert API response values to float, handling empty strings, None, and invalid values that cause ValueError: "could not convert string to float: ''". Changes: - Add safe_float() function in src/main.py with full docstring - Replace all float() calls with safe_float() in trading_cycle() - Domestic market: orderbook prices, balance amounts - Overseas market: price data, balance info - Add 6 comprehensive unit tests for safe_float() The function handles: - Empty strings ("") → default (0.0) - None values → default (0.0) - Invalid strings ("abc") → default (0.0) - Valid strings ("123.45") → parsed float - Float inputs (123.45) → pass through This prevents crashes when KIS API returns empty strings during market closed hours or data unavailability. Fixes: #44 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>