Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/rest/stock/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RestStockTechnicalBbParams, bb } from './technical/bb';
import { RestStockCorporateActionsCapitalChangesParams, capitalChanges } from './corporate-actions/capital-changes';
import { RestStockCorporateActionsDividendsParams, dividends } from './corporate-actions/dividends';
import { RestStockCorporateActionsListingApplicantsParams, listingApplicants } from './corporate-actions/listing-applicants';
import { RestStockOwnershipEtfHoldingsParams, etfHoldings } from './ownership/etf-holdings';

export class RestStockClient extends RestClient {
get intraday() {
Expand Down Expand Up @@ -68,4 +69,11 @@ export class RestStockClient extends RestClient {
listingApplicants: (params?: RestStockCorporateActionsListingApplicantsParams) => listingApplicants(request, params),
};
}

get ownership() {
const request = this.request;
return {
etfHoldings: (params: RestStockOwnershipEtfHoldingsParams) => etfHoldings(request, params),
};
}
}
34 changes: 34 additions & 0 deletions src/rest/stock/ownership/etf-holdings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RestClientRequest } from '../../client';

export interface RestStockOwnershipEtfHoldingsParams {
symbol: string;
from?: string;
to?: string;
sort?: 'asc' | 'desc';
code?: string;
}

export interface RestStockOwnershipEtfHoldingsComponent {
symbol: string;
name: string;
quantity: number;
weight: number;
quantityChange?: number;
weightChange?: number;
}

export interface RestStockOwnershipEtfHoldingsResponse {
type?: string;
exchange?: string;
market?: string;
symbol: string;
data: Array<{
date: string;
components: RestStockOwnershipEtfHoldingsComponent[];
}>;
}

export const etfHoldings = (request: RestClientRequest, params: RestStockOwnershipEtfHoldingsParams) => {
const { symbol, ...options } = params;
return request(`ownership/etf-holdings/${symbol}`, options) as Promise<RestStockOwnershipEtfHoldingsResponse>;
}
41 changes: 41 additions & 0 deletions test/rest-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,47 @@ describe('RestClient', () => {
});
});

describe('.ownership', () => {
it('should contain stock ownership api endpoints', () => {
const client = new RestClient({ apiKey: 'api-key' });
const stock = client.stock as RestStockClient;
expect(stock.ownership).toBeDefined();
expect(stock.ownership).toHaveProperty('etfHoldings');
});

describe('.etfHoldings()', () => {
it('should request with api key', async () => {
const client = new RestClient({ apiKey: 'api-key' });
const stock = client.stock as RestStockClient;
await stock.ownership.etfHoldings({ symbol: '0050' });
expect(fetch).toBeCalledWith(
'https://api.fugle.tw/marketdata/v1.0/stock/ownership/etf-holdings/0050',
{ headers: { 'X-API-KEY': 'api-key' } },
);
});

it('should request with bearer token', async () => {
const client = new RestClient({ bearerToken: 'bearer-token' });
const stock = client.stock as RestStockClient;
await stock.ownership.etfHoldings({ symbol: '0050' });
expect(fetch).toBeCalledWith(
'https://api.fugle.tw/marketdata/v1.0/stock/ownership/etf-holdings/0050',
{ headers: { 'Authorization': 'Bearer bearer-token' } },
);
});

it('should request with query params', async () => {
const client = new RestClient({ apiKey: 'api-key' });
const stock = client.stock as RestStockClient;
await stock.ownership.etfHoldings({ symbol: '0050', from: '2026-05-01', to: '2026-05-21', sort: 'desc', code: '2330' });
expect(fetch).toBeCalledWith(
'https://api.fugle.tw/marketdata/v1.0/stock/ownership/etf-holdings/0050?code=2330&from=2026-05-01&sort=desc&to=2026-05-21',
{ headers: { 'X-API-KEY': 'api-key' } },
);
});
});
});

describe('.snapshot', () => {
it('should contain stock intraday api endpoints', () => {
const client = new RestClient({ apiKey: 'api-key' });
Expand Down
Loading