# Taiwan Securities Lending Balance & Borrow Fee API (TWSE+TPEx) (`chamarix/taiwan-securities-lending-balance`) Actor

Shares on loan for every Taiwan listed & OTC stock since 2004 — the exchange SLB system, broker OTC lending and lending-account borrowing — plus every SLB trade with its borrow fee rate and each securities firm's lending book. Official TWSE data, cross-checked report against report.

- **URL**: https://apify.com/chamarix/taiwan-securities-lending-balance.md
- **Developed by:** [chris](https://apify.com/chamarix) (community)
- **Categories:** AI, Developer tools, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Taiwan Securities Lending Balance & SLB Borrow Fee API (借券餘額・借券成交明細・借券費率)

**How many shares of every Taiwan stock are out on loan, through which channel, and at what borrow fee?** Daily securities lending balances for every TWSE-listed and TPEx OTC stock back to **2004-11-22**, split into the exchange's SLB system, broker OTC lending and lending-account borrowing — plus every trade struck on the SLB system with its fee rate and term, and each securities firm's lending book.

借券餘額 is the short-side number Taiwan's financial press quotes every day ("TSMC securities lending balance hits a new high"). It is not the same as the SBL short-sale balance: a lending balance counts every borrowed share not yet returned, whether it was sold short, used for hedging or held for settlement. This Actor publishes the exchange's own figures, splits them the way the exchange does, and checks them against a separate trade-by-trade report.

### Output

Four record types in one dataset, told apart by `record_type`. Real rows from 2026-10-08:

**`stock_balance`** — shares on loan per stock per day (TWT72U 借券餘額表, all four tables merged on one row)

```json
{
  "record_type": "stock_balance",
  "date": "2026-10-08",
  "market": "TWSE",
  "stock_code": "2330",
  "stock_name": "台積電",
  "close_price": 2550.0,
  "balance_prev_shares": 185732000,
  "borrowed_shares": 2592000,
  "returned_shares": 1010000,
  "balance_shares": 187314000,
  "balance_change_shares": 1582000,
  "balance_value_twd": 477650700000,
  "slb_balance_shares": 179834000,
  "slb_borrowed_shares": 2591000,
  "nlb_balance_shares": 7480000,
  "nlb_borrowed_shares": 1000,
  "lon_balance_shares": 11185000,
  "lon_borrowed_shares": 0,
  "balance_identity_ok": true,
  "value_matches_close": true,
  "trade_log_matches": true
}
```

(Each channel also carries `_balance_prev_shares`, `_returned_shares` and `_balance_value_twd`; trimmed here.)

**`market_total`** — the same columns for TWSE, TPEx and the whole market (`market: "ALL"`). On 2026-10-08 the whole market had 28,287,926,000 shares on loan worth NT$3.70 trillion.

**`slb_trade`** — every trade on the TWSE SLB system, with its borrow fee (t13sa710 歷史借券成交明細)

```json
{
  "record_type": "slb_trade",
  "date": "2026-10-08",
  "market": "TWSE",
  "stock_code": "2330",
  "stock_name": "台積電",
  "trade_method": "negotiated",
  "trade_method_zh": "議借",
  "lots": 591,
  "shares": 591000,
  "fee_rate_pct": 4.73,
  "close_price": 2550.0,
  "trade_value_twd": 1507050000.0,
  "agreed_return_date": "2027-04-08",
  "agreed_days": 182,
  "fee_rate_changed": false
}
```

**`broker_activity`** — each securities firm's and finance house's borrowed and lent balances (TWTBBU 證商/證金辦理有價證券借貸業務概況表)

```json
{
  "record_type": "broker_activity",
  "date": "2026-10-08",
  "broker_code": "9800",
  "broker_name": "元大",
  "borrowed_balance_shares": 4079772000,
  "borrowed_balance_value_twd": 248965569920,
  "lent_balance_shares": 4502903000,
  "lent_balance_value_twd": 305828407620
}
```

A default daily run returns about 2,070 rows (one per stock with a balance, plus three totals) in five requests.

### The three lending channels

The exchange publishes four balance tables. This Actor puts them side by side on one row:

| Prefix | Table | What it is | History |
|---|---|---|---|
| *(none)* | SLBNLB 合計表 | All lending: SLB system + OTC lending | 2004-11-22 → |
| `slb_` | 證交所借券系統 | Borrowed through the exchange's SLB system (excluding lending accounts) | 2004-11-22 → |
| `nlb_` | 證商/證金營業處所 | Borrowed from securities firms and finance houses over the counter | 2008-04-09 → |
| `lon_` | 借貸專戶自證交所借券系統借入 | Firms' lending accounts borrowing from the SLB system | 2008-09-09 → |

The total is exactly SLB + NLB, column by column, per the report's own footnote. LON is **not** part of SLB — the SLB table's footnote excludes lending-account borrowing — so it is a separate channel, not a subset. Channel columns are null before that channel's report begins, and null when `includeChannelBreakdown` is off.

### Verification

Every figure below was measured against the live reports before release.

- **The SLB trade log reconciles with the balance table, stock by stock.** SLB borrowing plus lending-account borrowing equals the lots traded on the SLB system that session × 1,000 — two separate reports — for every stock on six sessions sampled from 2010 to 2026 (393 of 393 stocks on 2026-10-07). Each row records the result in `trade_log_matches`.
- **Until 2007-06-29 the balance report booked an SLB trade one session late.** 1,200 lots of 2881 traded on 2004-11-22 appear as 2004-11-23's borrowing. Checked week by week through 2007: from 2007-07-02 trades are booked the same session. The cross-check follows the convention of each era, so it holds back to 2004 (41 of 41 stocks on 2004-11-23).
- **Totals add up.** Every column of each market's 合計 row equals the sum of its stocks, TWSE + TPEx equals 整體市場, and the total table equals SLB + NLB — exact on every session sampled from 2004 to 2026. A failure stops the run.
- **The trade log's own footnote** (trade count, lots, value at the close) is recomputed from the rows on every request.
- **Firm lending books add up** to the report's 合計 row in all four columns.
- **The balance identity** (4) = (1) + (2) − (3), printed in the column header, is checked on every row of every channel.

### Traps in the source that this Actor handles

- **The exchange's own slips are flagged, not hidden.** On 2011-01-03 the NLB row for 2377 微星 reads 1,079,000 − 1,187,000 = 108,000 — the sign is lost. The figure is published as printed with `balance_identity_ok: false`. A whole column read out of place would break nearly every row, so a session with more than a handful of breaks stops the run instead.
- **A trade is occasionally booked a session late even now.** In September 2026, 2409 友達 showed 12,109 lots more in the trade log than in the balance on 09-23 and the same 12,109 lots more in the balance on 09-24; every other stock matched on all 20 sessions. Such rows carry `trade_log_matches: false` and the run logs a warning; only a mismatch across many stocks stops it.
- **Value is not always balance × close.** On 2010-01-04 four OTC-lending rows (including 2014, 2344 and 5346) were valued at some other price. The published value is kept and `value_matches_close` is false.
- **The first session prints no prices.** 2004-11-22 shows 0.00 for every close; `close_price` is null that day, not zero.
- **The firm table changes meaning in 2016.** Before 2016-05-26 the same request answers a *monthly-average* table with different columns. Only the daily table is read; earlier dates return no `broker_activity` rows.
- **Firm names are padded inside the characters** (`合　　庫`, `宏    遠`); the padding is removed.
- **One report covers both markets.** TPEx publishes no lending balance of its own and links to this TWSE report; `market` comes from its 市場別 column.
- **Codes are not always four digits** (00400A, 00631L).

### Input

- `recordTypes` — `stock_balance` and `market_total` by default; add `slb_trade` and `broker_activity`.
- `startDate` / `endDate` — leave both empty for the latest session. Fill them in for history back to 2004-11-22.
- `market` — `both`, `twse` or `tpex`.
- `stockCodes` — keep only these.
- `includeChannelBreakdown` — the SLB / NLB / LON split (four requests a session). Off gives totals only, one request a session.
- `crossCheckTradeLog` — reconcile against the SLB trade log (one request a month).
- `maxRequests` — a cap for long backfills (default 400).
- `useApifyProxy` — for multi-year backfills; TWSE's firewall blocks an address that asks too often.

### Use cases

- **Short-side positioning**: rising lending balances ahead of earnings, and how much of a stock's float is on loan.
- **Borrow cost**: actual negotiated and auction fee rates per trade, by stock and term.
- **Squeeze screening**: combine `balance_shares` with the short-sale balance in [taiwan-sbl-short-sale-balance](https://apify.com/chamarix/taiwan-sbl-short-sale-balance) and shortable shares in [taiwan-short-sale-eligibility](https://apify.com/chamarix/taiwan-short-sale-eligibility).
- **Market structure**: which firms lend and borrow the most, and how the SLB system and OTC lending split the market.

### Limitations, stated plainly

- **The SBL short-sale balance is not always below the lending balance.** It usually is — on 2026-10-08, 2,051 of 2,055 stocks — but three ETFs (00711B, 00852L, 00875) and one stock (3694) showed a larger short-sale balance than lending balance. The two reports measure different things and neither is adjusted.
- **OTC lending (NLB) has no trade-by-trade report**, so only the SLB and LON channels can be reconciled against trades.
- `slb_trade.market` is looked up from the same session's balance table and is null when balances were not requested.

### Source

Taiwan Stock Exchange (臺灣證券交易所): `TWT72U` 借券餘額表 (selectType `SLBNLB`, `SLB`, `NLB`, `LON`, `TWTBBU`) and `t13sa710` 歷史借券成交明細. The TWT72U report covers both TWSE-listed and TPEx OTC stocks.

### Taiwan Market Data Suite

This Actor is part of a suite of 44 Taiwan market data APIs by [chamarix](https://apify.com/chamarix) — official sources only, cross-validated against independent official endpoints, clean JSON out. Code samples for the whole suite: [GitHub](https://github.com/cc77556/taiwan-market-data-actors).

**Market data:**

- [taiwan-corporate-bonds](https://apify.com/chamarix/taiwan-corporate-bonds) — Every corporate, bank & Formosa bond — terms, balance, ratings & ISINs, daily OTC trades since 2005 and USD bond fair values since 2017
- [taiwan-securities-lending-balance](https://apify.com/chamarix/taiwan-securities-lending-balance) — Shares on loan for every stock since 2004 by lending channel, every SLB trade with its borrow fee rate, and each firm's lending book
- [taiwan-ipo-listings](https://apify.com/chamarix/taiwan-ipo-listings) — Every TWSE & TPEx listing application since 2000 from filing to first trading day — review, approval, price, underwriter & withdrawals, plus delistings
- [taiwan-board-directors](https://apify.com/chamarix/taiwan-board-directors) — Every independent director's career and other board seats linked to stock codes, board rosters, chair/CEO duality & director elections
- [taiwan-broker-financials](https://apify.com/chamarix/taiwan-broker-financials) — Every securities firm's monthly balance sheet & P\&L since 2013, full trial balance, and the register of firms & branches
- [taiwan-short-sale-eligibility](https://apify.com/chamarix/taiwan-short-sale-eligibility) — Can it be shorted today? Below-close short list, shares available to borrow, borrow fees, margin haircuts & forced cover dates
- [taiwan-gold-spot](https://apify.com/chamarix/taiwan-gold-spot) — The Taipei Exchange physical gold board since 2015 — daily VWAP, traded high/low, market-maker spread and every print by firm and price
- [taiwan-convertible-bonds](https://apify.com/chamarix/taiwan-convertible-bonds) — Daily bars for every convertible bond on the Taipei Exchange, with conversion price, conversion window, put date & put price
- [taiwan-corporate-action-prices](https://apify.com/chamarix/taiwan-corporate-action-prices) — Capital reductions, par value changes & ETF splits — the official reopening price & adjustment factor for every price discontinuity since 2011
- [taiwan-ipo-subscription](https://apify.com/chamarix/taiwan-ipo-subscription) — Every IPO ballot since 2006 & every competitive auction since 2016 — odds, ticket cost, reserve & bid-to-cover
- [taiwan-intraday-5sec-stats](https://apify.com/chamarix/taiwan-intraday-5sec-stats) — Market-wide order book & all sector indices every 5 seconds since 2004, 3,241 rows a session
- [taiwan-stock-daily-quotes](https://apify.com/chamarix/taiwan-stock-daily-quotes) — Daily OHLCV, VWAP, P/E, price-to-book & dividend yield for every listed/OTC stock since 2004
- [taiwan-index-history](https://apify.com/chamarix/taiwan-index-history) — Daily TAIEX & TPEx index history since 1990 with market turnover, the total-return index & all 273 TWSE indices
- [twse-institutional-trades](https://apify.com/chamarix/twse-institutional-trades) — Daily institutional buy/sell (foreign, investment trust, dealer) per stock — TWSE listed
- [tpex-institutional-trades](https://apify.com/chamarix/tpex-institutional-trades) — Daily institutional buy/sell per stock — TPEx OTC market
- [taiwan-monthly-revenue](https://apify.com/chamarix/taiwan-monthly-revenue) — Monthly revenue of 1,900+ listed & OTC companies, MoM/YoY
- [taiwan-financial-statements](https://apify.com/chamarix/taiwan-financial-statements) — Quarterly income statement, balance sheet & cash flow back to 2013
- [taiwan-director-compensation](https://apify.com/chamarix/taiwan-director-compensation) — Board pay for 1,950+ companies, parent vs consolidated scope, with EPS, ROE & profit on the same row
- [taiwan-esg-disclosures](https://apify.com/chamarix/taiwan-esg-disclosures) — 21 ESG topics for 1,950+ companies — Scope 1/2/3 emissions, energy, water, waste, pay, board & climate risk
- [taiwan-dividend-calendar](https://apify.com/chamarix/taiwan-dividend-calendar) — Ex-dividend / ex-rights dates, reference prices & payouts back to 2003
- [taiwan-margin-trading](https://apify.com/chamarix/taiwan-margin-trading) — Daily margin trading & short sale balances per stock
- [taiwan-sbl-short-sale-balance](https://apify.com/chamarix/taiwan-sbl-short-sale-balance) — Securities-lending short sale balances per stock
- [taiwan-short-sale-volume](https://apify.com/chamarix/taiwan-short-sale-volume) — Daily short sale turnover per stock — margin & borrowed lots, value and implied price, since 2008
- [taiwan-day-trading-stats](https://apify.com/chamarix/taiwan-day-trading-stats) — Day-trading volume, value & ratio per stock since 2014
- [taiwan-odd-lot-trading](https://apify.com/chamarix/taiwan-odd-lot-trading) — Both odd-lot sessions per stock — intraday & after-hours, shares, turnover, OHLC & quotes since 2004
- [taiwan-broker-rankings](https://apify.com/chamarix/taiwan-broker-rankings) — Securities-firm turnover, market share & the top firms in each hot stock on the OTC board since 2007
- [tdcc-shareholding-dispersion](https://apify.com/chamarix/tdcc-shareholding-dispersion) — Weekly TDCC shareholding dispersion (retail vs whale structure)
- [taiwan-foreign-shareholding](https://apify.com/chamarix/taiwan-foreign-shareholding) — Foreign ownership percentage & remaining quota per stock
- [taiwan-futures-daily](https://apify.com/chamarix/taiwan-futures-daily) — Daily bars, settlement price & open interest for all 384 TAIFEX futures contracts since 1998, with the large-trader report
- [taifex-institutional-derivatives](https://apify.com/chamarix/taifex-institutional-derivatives) — Institutional futures & options positions (TAIFEX), incl. put/call ratio
- [taifex-options-chain](https://apify.com/chamarix/taifex-options-chain) — Full options chain by strike & expiry, both sessions, with the exchange's own Delta, since 2001
- [taiwan-warrants-daily](https://apify.com/chamarix/taiwan-warrants-daily) — Daily quotes, strike, expiry & moneyness for every listed/OTC warrant since 2004
- [taiwan-government-bonds](https://apify.com/chamarix/taiwan-government-bonds) — Central government bond benchmark yields, the full yield curve & issuance master, with staleness stated
- [taiwan-stock-alerts](https://apify.com/chamarix/taiwan-stock-alerts) — Watch-list, disposition & short-sale suspension alerts
- [taiwan-insider-share-transfers](https://apify.com/chamarix/taiwan-insider-share-transfers) — Insider share-transfer filings (directors, officers, 10% holders) since 2002
- [taiwan-director-shareholdings](https://apify.com/chamarix/taiwan-director-shareholdings) — Monthly director/officer shareholdings & share-pledge ratio since 1999
- [taiwan-block-trades](https://apify.com/chamarix/taiwan-block-trades) — Every block trade (鉅額交易) with price, size & basket constituents since 2005
- [taiwan-shareholder-meetings](https://apify.com/chamarix/taiwan-shareholder-meetings) — Shareholder meeting dates, book closure periods & e-voting since 2005
- [taiwan-emerging-stock-quotes](https://apify.com/chamarix/taiwan-emerging-stock-quotes) — Emerging (興櫃) board quotes, pre-IPO register & history since 2003
- [taiwan-etf-regular-investment](https://apify.com/chamarix/taiwan-etf-regular-investment) — Monthly regular savings plan (定期定額) rankings for stocks & ETFs since 2020
- [taiwan-treasury-stock-buybacks](https://apify.com/chamarix/taiwan-treasury-stock-buybacks) — Every treasury-stock buyback (庫藏股) filing, plan vs execution, since 2000

**Property market:**

- [taiwan-real-estate-transactions](https://apify.com/chamarix/taiwan-real-estate-transactions) — Actual registered sale, presale & lease prices (實價登錄) for all 22 cities since 2012

**Government & civic data:**

- [taiwan-legislator-monitor](https://apify.com/chamarix/taiwan-legislator-monitor) — Legislative Yuan bills, legislators & meetings
- [taiwan-tender-monitor](https://apify.com/chamarix/taiwan-tender-monitor) — Government e-procurement tenders (open calls, awards, failures)

# Actor input Schema

## `recordTypes` (type: `array`):

Four record types in one dataset, told apart by record_type.

## `market` (type: `string`):

TWSE listed, TPEx OTC, or both. The whole-market total is always included with market_total.

## `startDate` (type: `string`):

Leave both dates empty for the latest session, found by looking back over holidays. Fill them in for history back to 2004-11-22.

## `endDate` (type: `string`):

Last session to include, inclusive. Defaults to today in Taipei when a start date is given. Weekends are skipped; holidays answer empty and are not treated as errors.

## `stockCodes` (type: `array`):

Keep only these codes, e.g. 2330, 00400A. Leave empty for every stock. Applies to stock_balance and slb_trade.

## `includeChannelBreakdown` (type: `boolean`):

Add the three channels behind the total: the exchange's SLB system (slb\_*), broker and finance-house OTC lending (nlb\_*), and lending-account borrowing from the SLB system (lon\_\*). Four requests a session instead of one. Turn off for a long backfill of totals only.

## `crossCheckTradeLog` (type: `boolean`):

Check each stock's SLB + lending-account borrowing against the sum of that session's trades in the separate SLB trade report. One extra request a month. Needs the channel split.

## `maxRequests` (type: `integer`):

A safety cap for long backfills. When the plan exceeds it, the most recent sessions are kept. 0 lifts it.

## `useApifyProxy` (type: `boolean`):

Turn this on for a multi-year backfill. TWSE's firewall refuses an address that asks too often; the proxy gives the run another exit.

## Actor input object example

```json
{
  "recordTypes": [
    "stock_balance",
    "market_total"
  ],
  "market": "both",
  "startDate": "",
  "endDate": "",
  "stockCodes": [],
  "includeChannelBreakdown": true,
  "crossCheckTradeLog": true,
  "maxRequests": 400,
  "useApifyProxy": false
}
```

# Actor output Schema

## `datasetItems` (type: `string`):

Shares on loan per stock and per market by lending channel, every trade on the TWSE SLB system with its fee rate, and each securities firm's borrowing and lending, in one dataset told apart by record_type.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "recordTypes": [
        "stock_balance",
        "market_total"
    ],
    "market": "both",
    "startDate": "",
    "endDate": "",
    "stockCodes": [],
    "maxRequests": 400
};

// Run the Actor and wait for it to finish
const run = await client.actor("chamarix/taiwan-securities-lending-balance").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "recordTypes": [
        "stock_balance",
        "market_total",
    ],
    "market": "both",
    "startDate": "",
    "endDate": "",
    "stockCodes": [],
    "maxRequests": 400,
}

# Run the Actor and wait for it to finish
run = client.actor("chamarix/taiwan-securities-lending-balance").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "recordTypes": [
    "stock_balance",
    "market_total"
  ],
  "market": "both",
  "startDate": "",
  "endDate": "",
  "stockCodes": [],
  "maxRequests": 400
}' |
apify call chamarix/taiwan-securities-lending-balance --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,chamarix/taiwan-securities-lending-balance"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/GyVo9Yq8YNqGDuKR3/builds/cj2yHLoE8nhYVN6JH/openapi.json
