# LongPort API Error Codes

## Authentication Errors
| Code | Meaning | Fix |
|------|---------|-----|
| 401004 | Token invalid | Token truncated/expired. Check bashrc has full token (1053 chars). Use Python to parse bashrc directly, don't rely on `source`. |
| 403201 | Auth failed | Similar to 401004 — token masking by terminal tool. Use `execute_code` + SDK instead of CLI. |

## Geo-Restriction Errors
| Code | Meaning | Fix |
|------|---------|-----|
| 602315 | Mainland China regulatory block | API detects mainland China IP. Must use VPN (HK/US/etc). Read-only may still work; trading is blocked. |

## Trading Errors
| Code | Meaning | Fix |
|------|---------|-----|
| 301607 | Too many k-lines requested | Max ~1000 per `candlesticks()` call. Use `history_candlesticks_by_offset()` for pagination. |

## Common Error Patterns
- **401004 + 602315**: Both appeared in same session. 401004 was from truncated token in .env, 602315 after token was fixed (real token loaded from bashrc).
- **Token "..." truncation**: bashrc shows `m_eyJh...jb-k` in grep output even when full 1053-char token exists. The `...` is just display truncation by the shell/terminal, not in the actual file. Use `python3 -c "import os; ..."` to verify real length.
