Skip to main content
Glama
tw-stock-mcp

tw-stock-mcp

by jiawei-hong

Get margin trading and short selling (融資融券)

get_margin_trading
Read-onlyIdempotent

Query Taiwan stock margin trading and short selling data for TWSE and TPEx stocks and ETFs, including balances, limits, 券資比, utilisation, and ranked changes over one to 23 trading days.

Instructions

Margin trading (融資) and short selling (融券) for TWSE and TPEx stocks and ETFs: buys, sells, redemptions, balances and limits for each side, 資券互抵 (offset), 券資比 (short/margin ratio) and 融資使用率 (margin utilisation). Covers one trading day by default. For a period, set start (e.g. the 1st of the month for "this month") or days (number of trading days, e.g. 5 for "recently"), up to 23 trading days; buys, sells, redemptions and offsets become totals, previous_balance is from the first day, balance and limit from the last, and each stock gets a daily series. With symbols: per-stock figures. Without symbols: market-wide totals per exchange, including 融資金額 (margin loan amount, TWD), plus the stocks and ETFs with the largest balance increases and decreases ranked by rank_by. Share counts are in shares (the exchanges' lots x 1000) and amounts in TWD. The latest day's balance is provisional: the exchanges finalise it as the next day's previous_balance. Rankings are by shares, so low-priced stocks rank higher than their TWD value suggests. Optional include: ["sbl"] adds 借券賣出 (short sales of borrowed shares, SBL) next to 融券 for each stock and market: sold, returned, adjustment, balance and the next day's SBL sell limit, plus total_short_balance (融券 + 借券賣出) so short interest is complete. rank_by "sbl" ranks by the 借券賣出 balance change and implies the include. It costs one more request per exchange per day. Without date, the period ends on the most recent trading day with published data; the exchanges publish in the evening, around 21:00 Taipei, later than prices and institutional trading.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "get_margin_trading"
  }
}

Input Schema

NameRequiredDescriptionDefault
dateNoLast trading date of the period, YYYY-MM-DD. Default: latest available.
daysNoNumber of trading days ending at `date`, e.g. 5 for about a week. Default 1. Do not combine with start.
limitNoRows per ranking. Default 10.
startNoFirst date of the period, YYYY-MM-DD; every trading day from here to `date` is included (max 23). Do not combine with days.
marketNoRestrict totals, rankings or symbol lookup to one market.
includeNoExtra data to add: ["sbl"] for 借券賣出 (securities lending short sales) next to 融券. Omit for the default response.
rank_byNoBalance whose change ranks stocks when symbols are omitted: "margin" (融資餘額, default), "short" (融券餘額) or "sbl" (借券賣出餘額, implies include "sbl").
symbolsNoCodes or exact names, e.g. ["2330", "6488", "鴻海"]. Omit for the market totals and rankings.

Output Schema

NameRequiredDescriptionDefault
dateYesLast trading date of the data (same as end_date)
unitYesUnit of every share count; margin_amount is in TWD
notesYes
stocksNo
rank_byNo
end_dateYes
start_dateYes
unresolvedNo
trading_daysYesTrading days actually covered
top_decreasesNoLargest rank_by balance decreases over the period
top_increasesNoLargest rank_by balance increases over the period
market_summaryNoMarket-wide totals over the period per requested market; null for a market without totals for every day

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed17 schema fields changedv0.3.1
    • addedInput schema / properties / include
      Added value: +{
      +  "description": "Extra data to add: [\"sbl\"] for 借券賣出 (securities lending short sales) next to 融券. Omit for the default response.",
      +  "items": {
      +    "enum": [
      +      "sbl"
      +    ],
      +    "type": "string"
      +  },
      +  "maxItems": 1,
      +  "type": "array"
      +}
    • changedInput schema / properties / rank_by / description
      Previous value: -"Balance whose change ranks stocks when symbols are omitted: \"margin\" (融資餘額, default) or \"short\" (融券餘額)."New value: +"Balance whose change ranks stocks when symbols are omitted: \"margin\" (融資餘額, default), \"short\" (融券餘額) or \"sbl\" (借券賣出餘額, implies include \"sbl\")."
    • changedInput schema / properties / rank_by / enum
      Previous value: -[
      -  "margin",
      -  "short"
      -]New value: +[
      +  "margin",
      +  "short",
      +  "sbl"
      +]
    • addedOutput schema / properties / market_summary / properties / otc / properties / sbl
      Added value: +{
      +  "description": "Only with include \"sbl\": 借券賣出 market totals, shares; null when not available for every day",
      +  "properties": {
      +    "adjustment": {
      +      "description": "當日調整: transfers between normal, credit and SBL positions and error corrections; balance = previous_balance + sell - returned + adjustment",
      +      "type": "number"
      +    },
      +    "balance": {
      +      "description": "Balance at the end of the period, shares; provisional until the next day's report",
      +      "type": "number"
      +    },
      +    "change": {
      +      "description": "balance - previous_balance, shares",
      +      "type": "number"
      +    },
      +    "previous_balance": {
      +      "description": "Balance before the period, shares; the exchange's final figure",
      +      "type": "number"
      +    },
      +    "returned": {
      +      "description": "當日還券: borrowed shares returned",
      +      "type": "number"
      +    },
      +    "sell": {
      +      "description": "當日賣出: new short sales of borrowed shares",
      +      "type": "number"
      +    }
      +  },
      +  "type": [
      +    "object",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / market_summary / properties / otc / properties / total_short_balance
      Added value: +{
      +  "description": "Only with include \"sbl\": short.balance + sbl.balance, shares",
      +  "type": [
      +    "number",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / market_summary / properties / tse / properties / sbl
      Added value: +{
      +  "description": "Only with include \"sbl\": 借券賣出 market totals, shares; null when not available for every day",
      +  "properties": {
      +    "adjustment": {
      +      "description": "當日調整: transfers between normal, credit and SBL positions and error corrections; balance = previous_balance + sell - returned + adjustment",
      +      "type": "number"
      +    },
      +    "balance": {
      +      "description": "Balance at the end of the period, shares; provisional until the next day's report",
      +      "type": "number"
      +    },
      +    "change": {
      +      "description": "balance - previous_balance, shares",
      +      "type": "number"
      +    },
      +    "previous_balance": {
      +      "description": "Balance before the period, shares; the exchange's final figure",
      +      "type": "number"
      +    },
      +    "returned": {
      +      "description": "當日還券: borrowed shares returned",
      +      "type": "number"
      +    },
      +    "sell": {
      +      "description": "當日賣出: new short sales of borrowed shares",
      +      "type": "number"
      +    }
      +  },
      +  "type": [
      +    "object",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / market_summary / properties / tse / properties / total_short_balance
      Added value: +{
      +  "description": "Only with include \"sbl\": short.balance + sbl.balance, shares",
      +  "type": [
      +    "number",
      +    "null"
      +  ]
      +}
    • changedOutput schema / properties / rank_by / enum
      Previous value: -[
      -  "margin",
      -  "short"
      -]New value: +[
      +  "margin",
      +  "short",
      +  "sbl"
      +]
    • changedOutput schema / properties / stocks / items / properties / daily / description
      Previous value: -"Only when the period has more than one trading day: per-day buys, sells, balances and changes in shares, oldest first. Balances are the restated figures from the next day's report, except on the last day."New value: +"Only when the period has more than one trading day: per-day buys, sells, balances and changes in shares, oldest first, plus sbl_sell, sbl_returned, sbl_balance and sbl_change with include \"sbl\". Balances are the restated figures from the next day's report, except on the last day."
    • addedOutput schema / properties / stocks / items / properties / sbl
      Added value: +{
      +  "description": "Only with include \"sbl\": 借券賣出 (short sales of borrowed shares, SBL), in shares. Null when the exchange has no 借券賣出 data for this stock on every day of the period.",
      +  "properties": {
      +    "adjustment": {
      +      "description": "當日調整: transfers between normal, credit and SBL positions and error corrections; balance = previous_balance + sell - returned + adjustment",
      +      "type": "number"
      +    },
      +    "balance": {
      +      "description": "Balance at the end of the period, shares; provisional until the next day's report",
      +      "type": "number"
      +    },
      +    "change": {
      +      "description": "balance - previous_balance, shares",
      +      "type": "number"
      +    },
      +    "limit": {
      +      "description": "次一營業日可借券賣出限額: next trading day's cap on intraday SBL sell orders, shares. Hedging sales by brokers are exempt, so sell can exceed it.",
      +      "type": "number"
      +    },
      +    "previous_balance": {
      +      "description": "Balance before the period, shares; the exchange's final figure",
      +      "type": "number"
      +    },
      +    "restrictions": {
      +      "description": "From the exchange remark for the next trading day: V 不得借券交易且無借券餘額停止借券賣出 (sbl_unavailable), Z 借券賣出餘額已達總量控管標準 or no quota yet (sbl_quota_reached)",
      +      "items": {
      +        "enum": [
      +          "sbl_unavailable",
      +          "sbl_quota_reached"
      +        ],
      +        "type": "string"
      +      },
      +      "type": "array"
      +    },
      +    "returned": {
      +      "description": "當日還券: borrowed shares returned",
      +      "type": "number"
      +    },
      +    "sell": {
      +      "description": "當日賣出: new short sales of borrowed shares",
      +      "type": "number"
      +    }
      +  },
      +  "type": [
      +    "object",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / stocks / items / properties / total_short_balance
      Added value: +{
      +  "description": "Only with include \"sbl\": short.balance + sbl.balance (融券 + 借券賣出), the complete short interest in shares; null when sbl is null",
      +  "type": [
      +    "number",
      +    "null"
      +  ]
      +}
    • changedOutput schema / properties / top_decreases / items / properties / daily / description
      Previous value: -"Only when the period has more than one trading day: per-day buys, sells, balances and changes in shares, oldest first. Balances are the restated figures from the next day's report, except on the last day."New value: +"Only when the period has more than one trading day: per-day buys, sells, balances and changes in shares, oldest first, plus sbl_sell, sbl_returned, sbl_balance and sbl_change with include \"sbl\". Balances are the restated figures from the next day's report, except on the last day."
    • addedOutput schema / properties / top_decreases / items / properties / sbl
      Added value: +{
      +  "description": "Only with include \"sbl\": 借券賣出 (short sales of borrowed shares, SBL), in shares. Null when the exchange has no 借券賣出 data for this stock on every day of the period.",
      +  "properties": {
      +    "adjustment": {
      +      "description": "當日調整: transfers between normal, credit and SBL positions and error corrections; balance = previous_balance + sell - returned + adjustment",
      +      "type": "number"
      +    },
      +    "balance": {
      +      "description": "Balance at the end of the period, shares; provisional until the next day's report",
      +      "type": "number"
      +    },
      +    "change": {
      +      "description": "balance - previous_balance, shares",
      +      "type": "number"
      +    },
      +    "limit": {
      +      "description": "次一營業日可借券賣出限額: next trading day's cap on intraday SBL sell orders, shares. Hedging sales by brokers are exempt, so sell can exceed it.",
      +      "type": "number"
      +    },
      +    "previous_balance": {
      +      "description": "Balance before the period, shares; the exchange's final figure",
      +      "type": "number"
      +    },
      +    "restrictions": {
      +      "description": "From the exchange remark for the next trading day: V 不得借券交易且無借券餘額停止借券賣出 (sbl_unavailable), Z 借券賣出餘額已達總量控管標準 or no quota yet (sbl_quota_reached)",
      +      "items": {
      +        "enum": [
      +          "sbl_unavailable",
      +          "sbl_quota_reached"
      +        ],
      +        "type": "string"
      +      },
      +      "type": "array"
      +    },
      +    "returned": {
      +      "description": "當日還券: borrowed shares returned",
      +      "type": "number"
      +    },
      +    "sell": {
      +      "description": "當日賣出: new short sales of borrowed shares",
      +      "type": "number"
      +    }
      +  },
      +  "type": [
      +    "object",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / top_decreases / items / properties / total_short_balance
      Added value: +{
      +  "description": "Only with include \"sbl\": short.balance + sbl.balance (融券 + 借券賣出), the complete short interest in shares; null when sbl is null",
      +  "type": [
      +    "number",
      +    "null"
      +  ]
      +}
    • changedOutput schema / properties / top_increases / items / properties / daily / description
      Previous value: -"Only when the period has more than one trading day: per-day buys, sells, balances and changes in shares, oldest first. Balances are the restated figures from the next day's report, except on the last day."New value: +"Only when the period has more than one trading day: per-day buys, sells, balances and changes in shares, oldest first, plus sbl_sell, sbl_returned, sbl_balance and sbl_change with include \"sbl\". Balances are the restated figures from the next day's report, except on the last day."
    • addedOutput schema / properties / top_increases / items / properties / sbl
      Added value: +{
      +  "description": "Only with include \"sbl\": 借券賣出 (short sales of borrowed shares, SBL), in shares. Null when the exchange has no 借券賣出 data for this stock on every day of the period.",
      +  "properties": {
      +    "adjustment": {
      +      "description": "當日調整: transfers between normal, credit and SBL positions and error corrections; balance = previous_balance + sell - returned + adjustment",
      +      "type": "number"
      +    },
      +    "balance": {
      +      "description": "Balance at the end of the period, shares; provisional until the next day's report",
      +      "type": "number"
      +    },
      +    "change": {
      +      "description": "balance - previous_balance, shares",
      +      "type": "number"
      +    },
      +    "limit": {
      +      "description": "次一營業日可借券賣出限額: next trading day's cap on intraday SBL sell orders, shares. Hedging sales by brokers are exempt, so sell can exceed it.",
      +      "type": "number"
      +    },
      +    "previous_balance": {
      +      "description": "Balance before the period, shares; the exchange's final figure",
      +      "type": "number"
      +    },
      +    "restrictions": {
      +      "description": "From the exchange remark for the next trading day: V 不得借券交易且無借券餘額停止借券賣出 (sbl_unavailable), Z 借券賣出餘額已達總量控管標準 or no quota yet (sbl_quota_reached)",
      +      "items": {
      +        "enum": [
      +          "sbl_unavailable",
      +          "sbl_quota_reached"
      +        ],
      +        "type": "string"
      +      },
      +      "type": "array"
      +    },
      +    "returned": {
      +      "description": "當日還券: borrowed shares returned",
      +      "type": "number"
      +    },
      +    "sell": {
      +      "description": "當日賣出: new short sales of borrowed shares",
      +      "type": "number"
      +    }
      +  },
      +  "type": [
      +    "object",
      +    "null"
      +  ]
      +}
    • addedOutput schema / properties / top_increases / items / properties / total_short_balance
      Added value: +{
      +  "description": "Only with include \"sbl\": short.balance + sbl.balance (融券 + 借券賣出), the complete short interest in shares; null when sbl is null",
      +  "type": [
      +    "number",
      +    "null"
      +  ]
      +}
  2. Addedv0.2.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only declare readOnly/idempotent/openWorld, so the description carries the real burden and does so richly: the latest day's balance is provisional and is finalised as the next day's previous_balance, exchanges publish around 21:00 Taipei later than prices, `rank_by: "sbl"` implies the include and costs one extra request per exchange per day, and rankings are by shares so low-priced stocks over-rank relative to TWD value. These are non-obvious behaviors an agent could not infer from annotations or schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Content is front-loaded with purpose and scope, and nearly every clause carries information (units in shares vs TWD, aggregation semantics, SBL cost). The main weakness is that it is one dense, unsegmented paragraph, which makes scanning for a specific parameter behavior harder than a structured layout would.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an 8-parameter, 0-required tool with an output schema, the description covers everything an agent needs to call it correctly: period construction, aggregation effects, provisional-data caveats, ranking caveats, unit conventions, and the SBL extension. Return values are additionally sketched even though the output schema would have covered them.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description still adds meaning beyond it by explaining what each mode does to the output — buys/sells/redemptions/offsets become totals, previous_balance comes from the first day, balance and limit from the last, and each stock gains a `daily` series. It also gives concrete examples for `start` (1st of the month) and `days` (5 for "recently").

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a precise verb-resource pair up front: margin trading (融資) and short selling (融券) data for TWSE/TPEx stocks and ETFs, enumerated as buys, sells, redemptions, balances and limits. The domain (margin/short balances) is distinct from siblings like get_institutional_trading or get_day_trading without needing to name them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear operational guidance: single day by default, use `start` or `days` (not both) for a period up to 23 trading days, use `symbols` for per-stock figures vs omitting it for market-wide totals and rankings, and add `include: ["sbl"]` when short interest must be complete. It does not explicitly say when to prefer a sibling tool, but within its own parameter space the when-to-use conditions are well spelled out.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.