Skip to content

margin · Margin Trading

sdk.margin exposes A-share margin trading (融资融券) data: market-level account stats and stock-level margin target details.

ts
import { StockSDK } from 'stock-sdk'

const sdk = new StockSDK()
const account = await sdk.margin.accountInfo()

Methods

MethodDescription
margin.accountInfo()Margin account stats (daily, market-wide macro data)
margin.targetList(date?)Margin target details, filterable by trading day

Amount fields are in CNY; quantity fields such as loanBalance (short-sell balance, in shares) are in shares. Items with a date follow the unified data contract and carry date / timestamp (number | null) / tz. Exact fields follow the implementation.

margin.accountInfo

Market-wide margin account stats, returned by day, reflecting overall leverage and guarantee ratios.

Example

ts
const account = await sdk.margin.accountInfo()
const latest = account[0]

console.log(`Latest financing balance ${latest?.finBalance}`)
console.log(`Average guarantee ratio ${latest?.avgGuaranteeRatio}%`)

// Financing-balance change over the last 30 days
const last30 = account.slice(0, 30)
const delta = (last30[0]?.finBalance ?? 0) - (last30.at(-1)?.finBalance ?? 0)
console.log(`30-day financing-balance change ${delta}`)

Returns

MarginAccountItem[]. Representative fields:

FieldDescription
dateStat date
finBalanceFinancing (margin buy) balance (CNY)
loanBalanceShort-sell balance (CNY)
finBuyAmountFinancing buy amount (CNY)
loanSellAmountShort-sell amount (CNY)
investorCountNumber of participating investors
liabilityInvestorCountNumber of investors with margin liabilities
totalGuaranteeTotal collateral value (CNY)
avgGuaranteeRatioAverage maintenance guarantee ratio (percentage)

Exact fields follow the implementation.

margin.targetList

Margin target details. Each record represents one stock eligible for margin trading. When no date is given, the server's latest trading day is used.

Example

ts
// Server's latest trading day by default
const targets = await sdk.margin.targetList()
console.log(`${targets.length} margin targets`)

// Sort by financing balance, find the 10 most leveraged
const top10 = [...targets]
  .sort((a, b) => (b.finBalance ?? 0) - (a.finBalance ?? 0))
  .slice(0, 10)

top10.forEach((t, i) => {
  console.log(`#${i + 1} ${t.name}(${t.code}) financing balance ${t.finBalance}`)
})

// Query a specific date
const jan15 = await sdk.margin.targetList('2024-01-15')

Parameters

ParameterTypeDescription
datestring?Trading day, e.g. '2024-01-15'; defaults to the latest trading day

Returns

MarginTargetItem[]. Representative fields:

FieldDescription
code / nameStock code / name
dateData date
finBalanceFinancing balance (CNY)
finBuyAmountFinancing buy amount (CNY)
finRepayAmountFinancing repayment amount (CNY)
loanBalanceShort-sell balance (shares)
loanSellVolumeShort-sell volume (shares)
loanRepayVolumeShort-sell repayment volume (shares)

Exact fields follow the implementation.