Reference

String numbers

On the quote, indicator and financial endpoints the numbers arrive as strings ("1723.50") rather than numbers. Doing arithmetic, comparisons or sorting on them directly goes wrong — check the type before converting.

In one line

Most endpoints return numbers as strings ("1723.50"); only orderbook and snapshot return native numbers.

Which endpoints return strings

Measured on 2026-10-07 by printing the type of every field, endpoint by endpoint:

Endpoint Type of numeric fields
quote · kline · minute · hot · technical · chip · profile · search · ipo · dividend · block-trade · margin-trade strings
fund strings (main_net, main_rank, close, …)
orderbook · snapshot native numbers (price, high, low, … are float/int)
Text endpoints (sector, lhb, screen, …) values live in markdown, and after parsing structured / tables they are still strings

⚠️ Do not guess from the endpoint name — the same field name can have a different type on different endpoints. orderbook’s price is a number, while quote’s last is a string.

Why they are strings

The upstream data arrives in text form (and some fields can be an empty string, or carry padding). Keeping everything as a string avoids the messier alternative of mixed types — some rows numeric, some None or "".

How to convert safely

def num(v, default=None):
    """Convert a possibly-string / empty / None value to float safely."""
    if v is None:
        return default
    s = str(v).strip().replace(",", "")
    if not s:
        return default
    try:
        return float(s)
    except ValueError:
        return default

rows = resp["data"]
rows.sort(key=lambda r: num(r["amount"]) or 0, reverse=True)

Three things matter: strip() first (there may be padding), remove thousands separators, and handle the empty string (otherwise float("") raises).

Common misuses

  • Adding them directly — "10" + "20" gives "1020" (string concatenation), not 30.
  • Comparing them directly — strings compare lexicographically, so "9" > "10" is true while numerically 9 < 10. Sorting comes out scrambled.
  • Calling float() without a fallback — an empty or non-numeric field raises ValueError and breaks the flow.
  • sort without converting — sorting strings gives lexicographic order, not order by price or amount.
  • Guessing the type from the endpoint name — snapshot is numeric while quote is a string, so a guess is always wrong somewhere.

Last updated: 2026-10-07

Measured endpoint by endpoint on 2026-10-07 (calling the data layer and printing the Python type of every field) — the numeric fields of quote / technical / chip / ipo / dividend / profile / fund are all strings, while orderbook / snapshot return native numbers.