# General Info

This module documents the HK Stocks Trading REST API. Base URL, HMAC / Ed25519 signing, timestamps,
`recvWindow`, and the sapi error envelope are identical to other SAPI endpoint families — see the
root [General Info](../common/sapi/general-info.md) for those.

This page lists only what is specific to the HK Stocks Trading module.

## Disclaimer Prerequisite

Before placing orders, the account must sign the Hong Kong disclaimer via
`POST /account/disclaimer`. Signing triggers opening of the Hong Kong stock account on the broker
side. Orders placed before signing are rejected with `670410`.

The Hong Kong and US disclaimers are **not interchangeable**: a user who has signed the US one must
still sign the Hong Kong one separately.

## Rate Limits

| Endpoint                                                                                                  | Limit (per user, per minute) |
| --------------------------------------------------------------------------------------------------------- | ---------------------------- |
| `POST /order/place`                                                                                       | 200                          |
| `POST /tokenized/mint`, `POST /tokenized/redeem`                                                          | 50                           |
| Others (market incl. depth, fx, queries, cancel, cancel-all, preview, max-quantity, listenKey, wss-token) | No separate limit            |

All endpoints share a global cap towards the upstream broker. When it is exceeded, SAPI returns the
standard rate-limit error `-1015` (`TOO_MANY_REQUESTS`); it is not an upstream pass-through error.

## URL Prefix

All endpoints in this module share the prefix:

```
/sapi/v1/equity-hk/
```

## Symbol Format

- `symbol` is the HKEX numeric ticker, **five digits, zero-padded**: `00700`, `03968`.
- Internal asset codes are not exposed. Tokenized assets use their own asset code (e.g. `03968B`).
- Unknown tickers return `-26004` / `SYMBOL_NOT_EXISTS`, depending on the endpoint.

## Quote Asset and Currency

- Orders, fills, and prices are denominated in **HKD**.
- Payment and freezing use **USDC** (`quoteAsset`, currently `USDC` only).
- The two are converted by `fxRate`. See the FX Rate endpoint and `/order/preview`.
- Amount fields are dual-denominated: no suffix = HKD, `*Quote` = USDC.

## Prices and Quantities

- Limit prices have at most 2 significant decimals and must match the HKEX tick table (a tiered
  table that varies with price — do not treat `tickSize` as a single value).
- `quantity` is always in shares and must be an integer. Buys must be an integer multiple of
  `lotSize`.
- There is no `notional` parameter.

## Settlement

Hong Kong stocks settle **T+2**, one day later than US stocks. After a sell fills, the proceeds are
recorded as unsettled and cannot be withdrawn until settlement completes.

## Unsettled Balance

There is **no Hong Kong-specific** unsettled-balance endpoint. Use:

```
GET /sapi/v1/equity/unsettled-balance
```

It returns the US + Hong Kong result merged by asset, because "how much money can I not withdraw
right now" is a wallet-level question, not a market-level one.

- Only non-equity assets (fiat / stablecoins) are returned; `EQ_*` (incl. `EQ_HK_*`) are filtered
  out.
- Returns an empty array `[]`, not `null`, when there is nothing unsettled.
- If the Hong Kong side fails to respond the whole call fails (fail closed) rather than silently
  returning a US-only result.
- The Hong Kong part of a USDC row is released later than the US part because of T+2.

Response example:

```javascript
[
  {
    asset: "USDC",
    unsettledAmount: "4104.83",
    btcValuation: "0.04104830",
  },
];
```

| Field             | Type    | Description                                                 |
| ----------------- | ------- | ----------------------------------------------------------- |
| `asset`           | STRING  | Asset code, e.g. `USDC`                                     |
| `unsettledAmount` | DECIMAL | Unsettled amount of the asset (US + Hong Kong combined)     |
| `btcValuation`    | DECIMAL | BTC valuation of the unsettled amount (8 decimals, HALF_UP) |

## Enum Contract

- All enum string values are **UPPERCASE** on both request and response.
- See [Common Definition](./common-definition.md) for the full enum sets.

## Fees

- Hong Kong statutory fees (stamp duty, trading levy, AFRC levy, trading fee, CCASS settlement fee,
  etc.) have steps — stamp duty is ceiled per order to whole HKD, CCASS has a minimum of 2 HKD per
  trade — and **cannot be derived by multiplying a ratio**.
- Call `/order/preview` before placing an order; `requiredPaymentQuote` is the amount actually
  frozen.

## Return Format

Business errors are returned with HTTP 400:

```javascript
{
  "code": 670418,
  "msg": "Order quantity must be a multiple of the minimum lot size."
}
```

- `code` is an integer. Hong Kong endpoints return two kinds: negative numbers are common SAPI
  codes; `670xxx` are Hong Kong business codes.
- `msg` is English text intended for end users.
- Several codes may share one `msg` (e.g. _The system is temporarily unavailable. Please try again
  later._ for `670003` / `670301` / `670404` / `670406` / `670430`). Programs must branch on `code`,
  not match `msg`.

## Integration Checklist

When migrating from the US stocks SAPI, check these items one by one to avoid most pitfalls:

1. **Sign the disclaimer first** — `/account/disclaimer` is a prerequisite and triggers broker-side
   account opening; unsigned returns `670410`.
2. **`clientOrderId` is at most 20 characters** — not 36 as for US stocks; too long returns
   `670453`.
3. **Market orders are not open yet** — `MARKET` returns `670472`; use limit orders.
4. **Do not send `notional`** — all Hong Kong orders are placed by `quantity`.
5. **Buy quantity must be a multiple of `lotSize`** — check `/market/exchangeInfo`, or use the value
   returned by `/order/max-quantity` (already rounded).
6. **Do not send `price` on `MARKET`, `tradingSession` on non-`LIMIT`, or `stopPrice` on non-stop
   types** — they error rather than being ignored.
7. **`tradingSession` chooses whether to take part in the pre-opening auction** — `HK_AUC_CTS` is
   the opening auction (09:00–09:30), not the closing one; the closing auction (CAS) is entered
   automatically by both values and is not an option. Only `LIMIT` may send it.
8. **`GTC` is for whole-lot limit orders only** — an odd-lot order with `GTC` is rejected after the
   freeze (`670463`) and funds get stuck; use `DAY` explicitly for odd lots.
9. **Do not swap the two stop-order prices** — `stopPrice` decides when it enters, `price` is the
   limit after entering; violations are `670474`–`670477`.
10. **Call `/order/preview` before placing** — fees have steps and cannot be derived by a ratio.
11. **Amounts are dual-denominated** — no suffix is HKD, `*Quote` is USDC, converted by `fxRate`;
    use `/fx/rate` for a pure rate lookup.
12. **`fxRate` is not a locked rate** — the rate table has one row per day and cross-day settlement
    uses the settlement-day row, with the difference refunded / charged. T+2 makes cross-day the
    norm; do not reconcile the final debit against the placement-time rate.
13. **`tokenize` defaults to `false`** — US stocks default to `true`; mind this when reusing code.
14. **Odd lots have their own rules** — whole lots and odd lots must be separate orders, limit only,
    `DAY` only.
15. **Tokenization supports whole shares only, and the redeem fee is charged on top** — use
    `totalAmount` to confirm the actual debit.
16. **Settlement is T+2** — `settlementDate` is one day later than US, and unsettled funds take
    longer to release.
17. **There is no Hong Kong unsettled-balance endpoint** — use `/sapi/v1/equity/unsettled-balance`,
    which already merges US and Hong Kong; do not look for `/equity-hk/unsettled-balance` (it does
    not exist).
18. **Exchange a `wss-token` before subscribing to market data** — US market data is anonymous, Hong
    Kong is not (HKEX requires login); subscribing directly gets `-1124`.
19. **`wss-token` and `listenKey` are not interchangeable** — the former subscribes to market data
    and is verified via `AUTHENTICATE`; the latter subscribes to orders and is part of the stream
    name, with no verification.
20. **Connect to the base endpoint, then `SUBSCRIBE`** — putting the stream name in the URL path
    (`/equity/ws/{stream}`) is rejected with a 400 at handshake, with a misleading message.
21. **`expiresIn` is remaining seconds, not a timestamp** — treating it as absolute pushes renewal
    decades away and the market stream silently drops.
22. **L2 depth is open to CN entities only** — non-CN subscribing to `@depth_10@hk` gets `-1125`,
    while L1 (quote / price / kline) works as usual; do not read it as an invalid credential.
23. **Filter pushes by `assetClass`** — Hong Kong is `hk_equity`; without filtering, US events mix
    in.
24. **`670301` does not mean the order failed** — retry with the same `clientOrderId`; do not
    replace it with a new ID.
25. **The L2 depth snapshot needs whitelisting first** — `/market/depth` is closed by default; the
    caller UID (the sub-account UID for a sub-account key) must be configured by Binance, otherwise
    `-99020`.
