Skip to content

Technical Indicators

Get K-line data with built-in technical indicator calculations.

getKlineWithIndicators

One-stop API to get K-line with multiple indicators.

typescript
const data = await sdk.getKlineWithIndicators('sz000858', {
  period: 'daily',
  startDate: '20240101',
  endDate: '20241231',
  indicators: {
    ma: { periods: [5, 10, 20, 60] },
    macd: true,
    boll: true,
    kdj: true,
    rsi: { periods: [6, 12, 24] },
    wr: true,
    bias: { periods: [6, 12, 24] },
    cci: true,
    atr: true,
  }
});

Parameters

ParameterTypeRequiredDescription
codestringYesStock code
options.period'daily' | 'weekly' | 'monthly'NoK-line period
options.startDatestringNoStart date
options.endDatestringNoEnd date
options.adjust'' | 'qfq' | 'hfq'NoPrice adjustment
options.indicatorsIndicatorConfigNoIndicators to calculate

Indicator Configuration

typescript
interface IndicatorConfig {
  ma?: { periods: number[] };      // Moving Average
  macd?: boolean;                   // MACD
  boll?: boolean;                   // Bollinger Bands
  kdj?: boolean;                    // KDJ
  rsi?: { periods: number[] };     // RSI
  wr?: boolean;                     // Williams %R
  bias?: { periods: number[] };    // BIAS
  cci?: boolean;                    // CCI
  atr?: boolean;                    // ATR
}

Return Type

Each K-line record includes indicator values:

typescript
interface KlineWithIndicators extends KlineData {
  ma?: {
    ma5?: number;
    ma10?: number;
    ma20?: number;
    ma60?: number;
    // ... dynamic based on periods
  };
  macd?: {
    dif: number;
    dea: number;
    macd: number;
  };
  boll?: {
    upper: number;
    mid: number;
    lower: number;
  };
  kdj?: {
    k: number;
    d: number;
    j: number;
  };
  rsi?: {
    rsi6?: number;
    rsi12?: number;
    rsi24?: number;
  };
  wr?: {
    wr6: number;
    wr10: number;
  };
  bias?: {
    bias6?: number;
    bias12?: number;
    bias24?: number;
  };
  cci?: {
    cci: number;
  };
  atr?: {
    atr: number;
  };
}

Example

typescript
import { StockSDK } from 'stock-sdk';

const sdk = new StockSDK();

const data = await sdk.getKlineWithIndicators('sz000858', {
  startDate: '20240101',
  indicators: {
    ma: { periods: [5, 10, 20] },
    macd: true,
    boll: true,
  }
});

data.forEach(k => {
  console.log(`${k.date}: Close ${k.close}`);
  console.log(`  MA: 5=${k.ma?.ma5}, 10=${k.ma?.ma10}, 20=${k.ma?.ma20}`);
  console.log(`  MACD: DIF=${k.macd?.dif}, DEA=${k.macd?.dea}`);
  console.log(`  BOLL: Upper=${k.boll?.upper}, Mid=${k.boll?.mid}`);
});

Released under the ISC License.