Skip to content

0xBennie/binance-smart-money-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binance-smart-money-tracker

Production-grade scraper for Binance Smart Signal (the "Smart Money" tab on binance.com Futures) — pulls the full 17-field whale overview that the public fapi API does not expose, with a 7-layer defense against 418 / 429 / 403 rate-limit bans.

This is the URL that binance.com/zh-CN/smart-money/signal/<symbol> calls behind the scenes:

https://www.binance.com/bapi/futures/v1/public/future/smart-money/signal/overview?symbol=BTCUSDT

No API key required. No proxy required (works directly from most VPS regions). But Binance enforces an undocumented per-IP weight budget, and a single careless burst can cost you a 4-hour Retry-After. This repo solves that.


What you get vs. public fapi

Field Public fapi/data This repo
longShortRatio ✅ via topLongShortPositionRatio
Top 20% account/position long-short ratios ✅ (bonus: also pulled)
Taker buy/sell ratio ✅ (bonus: also pulled)
Total Open Interest (USD) + 5m/15m/1h/4h velocity ✅ (bonus: also pulled)
longWhalesAvgEntryPrice / shortWhalesAvgEntryPrice
longProfitTraders / shortProfitTraders (in-profit count)
longProfitWhales / shortProfitWhales
Smart Money's share of total market OI (derived)

The four ★ fields are what makes Smart Signal useful — they tell you not just which side has more positions, but which side is actually making money right now, and at what average entry. Public fapi can't tell you any of that.

Example interpretation

Symbol            Long Profit%   Short Profit%   Whale Avg L/S    Verdict
1000RATSUSDT      5%             92%             0.034 / 0.042    🔴 shorts winning big (price has dropped)
1000LUNCUSDT      71%            41%             0.085 / 0.092    🟢 longs winning big (price has run)

When Short Whale Avg Entry > Long Whale Avg Entry by >5%, it usually means shorts entered too late and are about to get squeezed.


Architecture

┌─────────────────┐         ┌──────────────────────────────┐
│ smart-money-tick│ cron 60m├──► binance bapi smart-money  │
└────────┬────────┘         └──────────────────────────────┘
         │                                │
         │ writes ob_smart_money_snapshots│
         ▼                                ▼
┌─────────────────────────────────────────────┐
│           sqlite (data/snapshots.db)         │
│   ob_smart_money_snapshots (21 columns)      │
│   ob_top_trader_snapshots  (12 columns)      │
└────────────────────┬─────────────────────────┘
                     │ read-only
                     ▼
            ┌──────────────────┐
            │ Express dashboard │   http://your-host:3001/
            │ + JSON API        │
            └──────────────────┘

┌─────────────────┐         ┌──────────────────────────────┐
│ top-trader-tick │ cron 30m├──► binance fapi/futures/data │
└─────────────────┘         └──────────────────────────────┘
  • One sqlite file, two tables, 30-day retention
  • One Express dashboard with server-side rendering (no JS framework)
  • Two cron entry points (smart-money 60min, top-trader 30min) — staggered
  • Library mode: import { getSmartMoneyOverview } from 'binance-smart-money-tracker'

7 layers of 418/429 protection

The Smart Signal endpoint lives on Binance's web bapi gateway, which is more aggressive than fapi. A single uncoordinated burst can earn a 3.85-hour Retry-After (verified empirically). All seven layers below are wired up by default:

  1. Real Retry-After parsing — uses the exact seconds Binance returns, not a guess. parseInt(response.headers['retry-after']).
  2. Weight budget tracker — reads X-MBX-USED-WEIGHT-1M from every fapi response; when utilization > 70%, the next call sleeps to the next minute window before firing.
  3. Pre-flight ping — every cron entry pings /fapi/v1/ping once before the batch; on 418/403 it aborts immediately, no further requests fired.
  4. Jittered spacing — smart-money batches use 12s ± 3s, top-trader uses 1s ± 200ms. Avoids forming a predictable cadence that WAFs flag.
  5. Exponential backoff — consecutive soft hits within 1 hour escalate the cooldown 5min → 15min → 60min.
  6. Process-wide circuit breakerisBinanceApiBlocked() short-circuits all downstream calls in the same process; getSmartMoneyOverview() and getTopTraderSnapshot() return cached or null without firing.
  7. Memory cache — 10min for smart-money, 5min for top-trader. Repeated calls to the same symbol within the window don't hit Binance at all.

There is no retry-on-failure path that ignores Retry-After. That is intentional. The single fastest way to escalate a 5-minute soft block into a multi-hour hard block is to retry-loop a 418 — don't.


Quick start

git clone https://github.com/0xBennie/binance-smart-money-tracker.git
cd binance-smart-money-tracker
npm install

# 1. One-shot pull (writes to data/snapshots.db)
npx tsx src/scripts/smart-money-tick.ts

# 2. Start the dashboard (reads from the same db)
PORT=3001 npx tsx src/scripts/smart-money-dashboard.ts
# → http://localhost:3001/

# 3. Optional: also pull top-trader supplement (Taker ratio + 5min LSR)
npx tsx src/scripts/top-trader-tick.ts

Env vars

Var Default What
SMART_MONEY_POOL_MAX 0 Cap of symbols. 0 = all USDT-PERPETUAL (~500). Set to e.g. 100 to limit
SMART_MONEY_SHARD_INDEX 0 0-based shard index when sharding (see below)
SMART_MONEY_SHARD_TOTAL 1 Total shards. 1 = no sharding
TOP_TRADER_POOL_MAX / _SHARD_INDEX / _SHARD_TOTAL same Same semantics for top-trader cron
OI_POOL_MAX / _SHARD_INDEX / _SHARD_TOTAL same Same for open-interest cron
SMART_MONEY_DASHBOARD_PORT / PORT 3001 Dashboard listen port

As a library

import {
  getSmartMoneyOverview,
  getTopTraderSnapshot,
  getOpenInterest,
  smartMoneyNotionalUsd,
  smartMoneyShareOfOI,
} from 'binance-smart-money-tracker';

const sym = 'BTCUSDT';
const [sm, tt, oi] = await Promise.all([
  getSmartMoneyOverview(sym),         // 17 whale fields
  getTopTraderSnapshot(sym, '5m'),    // top-account/position LSR + Taker BSR
  getOpenInterest(sym),               // total market OI + 5m/15m/1h/4h velocity
]);

if (sm && oi) {
  console.log(`${sm.longWhales} long whales @ avg ${sm.longWhalesAvgEntryPrice}`);
  console.log(`${sm.longProfitTraders}/${sm.longTraders} longs in profit`);
  console.log(`Total OI: $${(oi.oiNowUsd / 1e6).toFixed(2)}M, 4h chg ${oi.oiChg4h.toFixed(2)}%`);

  // Smart Money USD notional, derived from qty × avg-entry (NOT from the
  // undocumented `totalPositions` field whose unit is inconsistent).
  const smUsd = smartMoneyNotionalUsd(sm);
  const share = smartMoneyShareOfOI(sm, oi.oiNowUsd);
  console.log(`Smart Money notional: $${(smUsd / 1e6).toFixed(2)}M`);
  console.log(`Smart Money share of total OI: ${share == null ? 'n/a' : (share * 100).toFixed(1) + '%'}`);
}

Why a helper? Binance's undocumented totalPositions field has inconsistent units across symbols (sometimes base-coin units, sometimes USD). smartMoneyNotionalUsd(sm) computes it deterministically from longTradersQty × longTradersAvgEntryPrice + shortTradersQty × shortTradersAvgEntryPrice — both fields have known units (base-coin × USD = USD). Don't divide totalPositions by anything; use the helper.

The library re-exports all rate-limit helpers (isBinanceApiBlocked, preflightBinanceFapi, waitForBinanceWeightHeadroom) so you can integrate the same circuit breaker into your other Binance calls and share one weight budget across modules.


Pool sizing & cron cadence

Default behavior is all USDT-PERPETUAL symbols (~500 contracts as of 2026). Pick a deployment mode that matches your tolerance for data freshness:

Mode Symbols smart-money cron top-trader cron OI cron Sharding
Light 100 cap 7 * * * * (1×/h) */30 * * * * 15,45 * * * * None
Standard 200 cap 7 * * * * (1×/h) */30 * * * * 15,45 * * * * None
Full, 2h refresh ~500 all 0 */2 * * * (1×/2h) */30 * * * * 15,45 * * * * None
Full, 1h refresh ~500 all 7,37 * * * * (2×/h, each does half) */30 * * * * 15,45 * * * * 2 shards

Read "1h refresh" as every symbol gets a fresh snapshot within 1h, achieved by two cron entries at :07 and :37 each pulling half (shard 0/2 and 1/2).

The math: smart-money runs at 12s ± 3s spacing (web bapi is rate-sensitive). 500 symbols ≈ 100 min, so it cannot finish inside an hour without sharding. Top-trader and OI both use fapi/data at 1s spacing — 500 symbols ≈ 8 min, fits anywhere.

Sharding

Symbols are split deterministically by index % SHARD_TOTAL == SHARD_INDEX, so each shard always pulls the same set (good for cache locality, and means shards don't collide on the same symbol within a window).

Data Retention

The sqlite tables (ob_smart_money_snapshots, ob_top_trader_snapshots, ob_oi_snapshots) are pruned to 30 days by the storage.cleanup() call that runs at the end of every smart-money-tick execution. If you need longer history, increase RETENTION_DAYS in src/storage.ts and rebuild, or back the table up before the daily cron runs.

Disk usage estimate at default cadence (500 symbols, hourly smart-money + 30min top-trader + 30min OI): roughly 30–80 MB / month with WAL enabled.

Production deployment (pm2)

A. Standard — cap at 200, hourly

// ecosystem.config.js
module.exports = {
  apps: [
    {
      name: 'smart-money-tick',
      script: 'node_modules/.bin/tsx',
      args: 'src/scripts/smart-money-tick.ts',
      cron_restart: '7 * * * *',        // :07 every hour
      autorestart: false,
      env: { SMART_MONEY_POOL_MAX: '200' },
    },
    {
      name: 'top-trader-tick',
      script: 'node_modules/.bin/tsx',
      args: 'src/scripts/top-trader-tick.ts 5m',
      cron_restart: '*/30 * * * *',
      autorestart: false,
    },
    {
      name: 'oi-tick',
      script: 'node_modules/.bin/tsx',
      args: 'src/scripts/oi-tick.ts',
      cron_restart: '15,45 * * * *',    // offset from top-trader
      autorestart: false,
    },
    {
      name: 'smart-money-dashboard',
      script: 'node_modules/.bin/tsx',
      args: 'src/scripts/smart-money-dashboard.ts',
      autorestart: true,
      env: { PORT: '3001' },
    },
  ],
};

B. Full coverage with 1h refresh — 2-way sharding

Two pm2 entries, each pulls half the symbols at staggered times:

module.exports = {
  apps: [
    {
      name: 'smart-money-tick-a',
      script: 'node_modules/.bin/tsx',
      args: 'src/scripts/smart-money-tick.ts',
      cron_restart: '7 * * * *',        // :07
      autorestart: false,
      env: { SMART_MONEY_SHARD_INDEX: '0', SMART_MONEY_SHARD_TOTAL: '2' },
    },
    {
      name: 'smart-money-tick-b',
      script: 'node_modules/.bin/tsx',
      args: 'src/scripts/smart-money-tick.ts',
      cron_restart: '37 * * * *',       // :37 — 30 min offset from A
      autorestart: false,
      env: { SMART_MONEY_SHARD_INDEX: '1', SMART_MONEY_SHARD_TOTAL: '2' },
    },
    // ... top-trader-tick and dashboard same as Mode A
  ],
};

C. Full coverage, slower refresh — 2-hour cron, no sharding

Cheapest option if hourly freshness isn't required:

{
  name: 'smart-money-tick',
  args: 'src/scripts/smart-money-tick.ts',
  cron_restart: '0 */2 * * *',          // every 2 hours
  autorestart: false,
  // no env vars needed — defaults to all symbols
}

Why staggering matters

The circuit breaker lives in per-process module state. Two cron processes running simultaneously cannot share isBinanceApiBlocked() state directly, but each one ping-tests via preflightBinanceFapi() before issuing any data requests — so if process A just got a 418, process B's preflight will catch it and abort cleanly. Stagger the times anyway to give the IP weight window time to drain between bursts.


What's not in this repo

  • ❌ No trading. This is data only.
  • ❌ No proxy. If your IP gets a hard 403 (CloudFront WAF), the only fix is to wait it out or change IP. The whole point of the protection layers is to never get there.
  • ❌ No on-chain data, no order book, no aggregated trades. For that, see the projects in Credits.

Credits

  • andychien555/binance-smart-money-tracker — original reverse-engineering of the bapi/futures/v1/public/future/smart-money/signal/overview endpoint. Their version is built on Cloudflare Workers + R2 with a static SPA frontend; this repo is the Node + sqlite + express version with stronger rate-limit protection. Different architecture, same source insight.
  • y18929284608-byte/BNSmartMoneyMonitor and 6551Team/opentrade — parallel implementations that confirmed the endpoint contract.

License

MIT — see LICENSE.

About

Production-grade Binance Smart Signal tracker. 17 whale fields incl. longWhalesAvgEntryPrice + profitTraders that public fapi can't give you. 7-layer 418/429 defense.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors