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

btg-mfo-api-client

v1.0.2

Published

TypeScript client for the BTG Pactual MFO APIs (Auth, Position, and Operation).

Readme

btg-mfo-api-client

npm version License: MIT Node GitHub Issues GitHub Stars Buy Me A Coffee

Table of Contents

💡 Description

btg-mfo-api-client is a TypeScript client for the BTG Pactual MFO (Multi Family Office) APIs, covering Auth, Position, and Operation endpoints. It handles OAuth2 client_credentials authentication with token caching, typed requests, and strongly-typed responses so you can consume BTG data directly from Node.js without wrangling HTTP details.

✨ Features

  • 🔑 OAuth2 authentication with automatic token caching
  • 📊 Position endpoints (by account, by date, by partner, unit price history, V2 variants)
  • 💸 Operation / movement endpoints (account and partner, full/monthly/weekly windows)
  • 🧾 Full TypeScript types for every response payload
  • 🪶 Zero runtime dependencies — uses the native fetch in Node 20+
  • 🛑 Typed error classes (BtgAuthError, BtgApiError) with status code and body

📌 Requirements

  • Node.js 20+
  • BTG Pactual API credentials (BTG_CLIENT_ID, BTG_CLIENT_SECRET)

🚀 Installation

npm install btg-mfo-api-client
yarn add btg-mfo-api-client
pnpm add btg-mfo-api-client

🔐 Authentication

Set your credentials as environment variables before calling any API:

export BTG_CLIENT_ID="your-client-id"
export BTG_CLIENT_SECRET="your-client-secret"

The package does not bundle dotenv — load .env yourself (e.g. import "dotenv/config") if you use one.

Tokens are cached in-memory for ~14 minutes. Call clearTokenCache() to force a refresh.

📚 Usage & Examples

Get a position for a specific date

import { getPositionByAccountAndDate } from "btg-mfo-api-client";

const position = await getPositionByAccountAndDate("000123456", "2025-11-28");
console.log(position);

Get weekly movements for the partner

import { getMovementsByPartnerWeekly } from "btg-mfo-api-client";

const movements = await getMovementsByPartnerWeekly();
console.log(movements);

Get full movement history for an account

import { getMovementsByAccountFull } from "btg-mfo-api-client";

const history = await getMovementsByAccountFull("000987654");
console.log(history);

Handle typed errors

import { getPositionByAccountAndDate, BtgApiError, BtgAuthError } from "btg-mfo-api-client";

try {
  await getPositionByAccountAndDate("000123456", "2025-11-28");
} catch (err) {
  if (err instanceof BtgAuthError) {
    console.error("Auth failed", err.statusCode, err.responseBody);
  } else if (err instanceof BtgApiError) {
    console.error("API error", err.statusCode, err.responseBody);
  } else {
    throw err;
  }
}

🧱 API

Auth

  • getAccessToken(options?) — returns a cached or fresh access token
  • clearTokenCache() — clears the cached token

Position

  • getPositionByAccount(account)
  • getPositionByAccountAndDate(account, date)
  • getPositionUnitPriceByAccount(account)
  • getPositionUnitPriceHistoryByAccount(account, filter)
  • getPartnerPosition()
  • getPositionRefresh(account)
  • getPositionUnitPriceByAccountV2(account)
  • getPositionUnitPriceHistoryByAccountV2(account, filter)
  • getPositionUnitPriceHistoryByPartnerV2(filter)
  • getPositionUnitPriceHistoryByAccountsV2(accounts, filter)

Operation

  • getMovementsByAccountFull(account)
  • getMovementsByAccountMonthly(account)
  • getMovementsByAccountWeekly(account)
  • getMovementsByPartnerAndPeriod(request)
  • getMovementsByPartnerMonthly()
  • getMovementsByPartnerWeekly()

Every response is fully typed — see the exported types in btgApiPositionTypes (e.g. Position, PositionData, InvestmentFund, FixedIncome, Equities, Derivative, CryptoAsset, and many more).

💛 Support

If you find this project helpful, please give it a star on GitHub!

GitHub stars

If you find this package useful, consider buying me a beer!

👤 Author

Bruno Lobo

GitHub X (Twitter)

🔗 Links

📄 License

MIT License — see the LICENSE file for details.


Made with :heart: in Brazil