npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@firstthumb/tefas-api

v2.0.0

Published

TypeScript client library for TEFAS (Turkish Electronic Fund Information System) API

Downloads

252

Readme

TEFAS API Client

A TypeScript client library for TEFAS (Turkish Electronic Fund Information System). Works in both browsers and Node.js.

Features

  • Search funds by code or name prefix
  • Fetch merged fund data (history + allocation + optional fund details)
  • Fuzzy date support (today, yesterday, last week, last month)
  • Built-in performance metrics calculator
  • Pluggable async cache adapters (memory, Cloudflare KV, custom)
  • Full TypeScript support

Install

npm install @firstthumb/tefas-api

Quick Start

import { TefasClient, FundType } from '@firstthumb/tefas-api';

const client = new TefasClient();

// Search (ApiResponse<SearchResult>)
const searchResponse = await client.searchFund('IPB', { limit: 5 });
const matches = searchResponse.results;

// Get merged fund data (ApiResponse<FundResponse>)
const fundResponse = await client.getFund('2024-01-01', '2024-01-31', 'IPB', FundType.YAT);
const funds = fundResponse.results;

Public API

searchFund(query, options?)

const response = await client.searchFund('IPB', {
  fundType: FundType.YAT,
  limit: 10
});

for (const result of response.results) {
  console.log(result.fundCode, result.fundName, result.fundType);
}
  • Returns: Promise<ApiResponse<SearchResult>>
  • SearchResult includes: fundCode, fundName, fundType

getFund(startDate, endDate, fundCode?, fundType?, skipFundDetails = false)

// Specific fund, auto-detects fundType when omitted
const r1 = await client.getFund('2024-01-01', '2024-01-31', 'TGE');

// Explicit fund type filter
const r2 = await client.getFund('2024-01-01', '2024-01-31', undefined, FundType.EMK);

// Skip Fundfy detail fetch for faster bulk retrieval
const r3 = await client.getFund('2024-01-01', '2024-12-31', undefined, FundType.YAT, true);
  • Returns: Promise<ApiResponse<FundResponse>>
  • getFund is the primary public data method.
  • If fundCode is provided and fundType is omitted, the client resolves the type automatically via search.

Fuzzy Dates

const response = await client.getFund('yesterday', 'today');
console.log(response.results.length);

Supported examples: today, yesterday, last week, last month.

setMaxDaysPerRequest(maxDays)

Control internal chunk size for date-range requests.

client.setMaxDaysPerRequest(30); // valid: integer 1..365

Validation rules:

  • Must be an integer
  • Must be between 1 and 365

Use this when tuning request chunking for long date ranges.

Response Fields (FundResponse)

FundResponse includes merged values from TEFAS history/content and Fundfy details.

Example fields:

const record = (await client.getFund('2024-01-01', '2024-01-01', 'TGE')).results[0];

console.log(record.fundCode, record.fundName, record.fundType, record.date);
console.log(record.price, record.volume, record.assets, record.investorCount);
console.log(record.totalValue, record.stocks, record.bonds);

// Fundfy-enriched detail fields
console.log(record.auditFirm, record.founder, record.risk, record.yearlyManagementFee);
console.log(record.fundCategory, record.fundBenchmarks);

Performance Metrics

import { PerformanceCalculator, FundType } from '@firstthumb/tefas-api';

const response = await client.getFund('2024-01-01', '2024-12-31', undefined, FundType.YAT, true);
const metrics = PerformanceCalculator.calculateMetrics(response.results, {
  riskFreeRate: 0.10,
  frequency: 'daily',
  method: 'simple'
});

Caching

The client uses async cache operations and supports custom adapters.

Default Memory Cache

const client = new TefasClient({
  cache: {
    enabled: true,
    ttl: 15 * 60 * 1000,
    maxSize: 1000
  }
});

await client.clearCache();
await client.invalidateCache('2024-01-01', '2024-01-31', 'TGE', FundType.EMK);
const stats = await client.getCacheStats();
const removed = await client.pruneCache();

Cloudflare Workers KV

import { TefasClient, CloudflareKVCacheAdapter } from '@firstthumb/tefas-api';

const cache = new CloudflareKVCacheAdapter({
  namespace: env.TEFAS_CACHE,
  ttl: 15 * 60 * 1000,
  prefix: 'tefas:'
});

const client = new TefasClient({ cacheAdapter: cache });
const response = await client.getFund('2024-01-01', '2024-01-31');

Custom Cache Adapter

import { CacheAdapter } from '@firstthumb/tefas-api';

class RedisCacheAdapter implements CacheAdapter<any> {
  async get(key: string) {
    const value = await redis.get(key);
    return value ? JSON.parse(value) : undefined;
  }

  async set(key: string, value: any, ttl?: number) {
    await redis.setEx(key, Math.floor((ttl ?? 900000) / 1000), JSON.stringify(value));
  }

  async delete(key: string) {
    return (await redis.del(key)) > 0;
  }

  async clear() {
    // implement for your backend
  }

  async has(key: string) {
    return (await redis.exists(key)) === 1;
  }
}

Error Handling

import {
  ValidationError,
  TefasApiError,
  NetworkError,
  FundNotFoundError,
  isValidationError,
  isNetworkError,
  isTefasApiError
} from '@firstthumb/tefas-api';

try {
  const response = await client.getFund('2024-01-01', '2024-01-31', 'TGE');
  console.log(response.results.length);
} catch (error) {
  if (isValidationError(error) || error instanceof ValidationError) {
    console.error('Validation error:', error.message);
  } else if (error instanceof FundNotFoundError) {
    console.error('Fund not found:', error.message);
  } else if (isTefasApiError(error) || error instanceof TefasApiError) {
    console.error('TEFAS API error:', error.message);
  } else if (isNetworkError(error) || error instanceof NetworkError) {
    console.error('Network error:', error.message);
  }
}

Requirements

  • Node.js 18+
  • Modern browser with fetch support

Development

npm install
npm test
npm run build

License

MIT