Sub topic 7
Exchange inflows, outflows, and netflow
This chapter assumes you know how transfers appear on an account-based or UTXO ledger, that an address is not the same as a person, and that you can read short Python functions. It builds on the earlier chapters on entities and transfer volume.
Why exchange flows get so much attention
Centralized exchanges are where most coins are bought and sold for fiat currency or other assets. A coin that sits in an exchange's wallet can be sold quickly. A coin that sits in a private wallet needs one extra step before it can be sold: a deposit to an exchange. Analysts use this to build a rough signal. Coins moving into exchanges might mean selling is coming. Coins moving out might mean holders are taking custody and plan to keep them.
The signal is weak and often wrong, as later sections show. But the calculation is simple, and learning it well teaches you most of the labeling and counting problems in on-chain analysis.
Definitions
Take a set of addresses labeled as belonging to exchanges. For a chosen time window:
- Inflow is the total value sent from addresses outside the set to addresses inside the set.
- Outflow is the total value sent from addresses inside the set to addresses outside the set.
- Netflow is inflow minus outflow.
A positive netflow means more value entered exchanges than left. A negative netflow means more value left. Netflow is measured in the asset's own units (for example, coins), or converted to a currency value.
The phrase "outside the set to inside the set" matters. Transfers between two exchange addresses are not inflows or outflows. They are internal reshuffling, such as an exchange moving funds from a deposit address to its main wallet. If you counted them, you would inflate both inflow and outflow, and the totals would say nothing about money entering or leaving the exchange ecosystem.
Computing netflow
The function below follows those definitions. It takes a list of transfers and a set of exchange addresses.
def exchange_netflow(transfers, exchange_addresses):
inflow = 0
outflow = 0
for t in transfers:
from_exchange = t["from"] in exchange_addresses
to_exchange = t["to"] in exchange_addresses
if to_exchange and not from_exchange:
inflow += t["value"]
elif from_exchange and not to_exchange:
outflow += t["value"]
return {"inflow": inflow, "outflow": outflow, "netflow": inflow - outflow}
exchanges = {"0xb"}
transfers = [
{"from": "0xa", "to": "0xb", "value": 10},
{"from": "0xb", "to": "0xc", "value": 4},
{"from": "0xb", "to": "0xb2", "value": 3},
]
print(exchange_netflow(transfers, exchanges))The output is {'inflow': 10, 'outflow': 7, 'netflow': 3}. Walk through the three transfers:
0xato0xb:0xbis an exchange and0xais not, so 10 counts as inflow.0xbto0xc: the exchange sends to a non-exchange address, so 4 counts as outflow.0xbto0xb2:0xb2is not in the labeled set, so the function counts 3 as outflow, giving 7 in total.
The third transfer shows the main weakness. If 0xb2 is actually another wallet of the same exchange, the 3 is not a real outflow. The code is correct, and the result is still wrong, because the label set is incomplete. Labeling quality sets the ceiling for the whole metric.
Adding a time window
The function above treats its input as one window. In practice you group transfers by time, usually by UTC day or hour, and compute one netflow per bucket. Two choices affect what you see:
- Window length. Hourly netflow is noisy. Daily netflow is smoother but hides intraday swings. Weekly or 30-day sums show trends but react slowly.
- Block time versus processing time. Use the block timestamp, not the time your pipeline saw the transaction. Otherwise a delayed indexer shifts value into the wrong bucket.
Where the exchange labels come from
Exchange labels are not recorded on the chain. They come from a few sources:
- Public disclosures, where an exchange publishes its wallet addresses, often as part of a proof-of-reserves report.
- Heuristics, such as clustering deposit addresses that all sweep funds into the same hot wallet.
- Commercial data providers, who combine heuristics with their own investigation and sell the resulting label sets.
- Community-maintained lists, which vary in quality.
Each source has errors. The two kinds of error push your result in different directions.
| Error | Example | Effect on the metric |
|---|---|---|
| Missing exchange address (false negative) | An exchange wallet is not in your set | Inflow and outflow are undercounted. Internal moves to that wallet appear as outflow. |
| Wrong exchange address (false positive) | A private wallet is labeled as an exchange | Ordinary transfers appear as inflow or outflow. |
| Stale label | An exchange retires a wallet and the address is reused or becomes inactive | Old data looks fine, new data drifts. |
| Shared custody | An address belongs to a custodian that serves many firms, not only an exchange | Flows mix trading activity with long-term custody. |
Because labels change over time, store the label set with a date, and rerun a historical metric with the labels that were known at the time as well as with the latest labels. The two series can differ a lot.
Deposit addresses and the double hop
Many exchanges give each customer a unique deposit address. When a customer deposits, the coins arrive at that address, and later the exchange sweeps them to a main wallet. If your label set includes only the main wallet, the customer's deposit appears as a transfer between two non-exchange addresses, and only the later sweep shows up. The sweep is a transfer from an unlabeled address to a labeled one, so you count an inflow. The inflow is correct in amount but delayed, and the timing is the exchange's, not the customer's.
If your label set includes the deposit addresses but the exchange later sweeps funds between them and the hot wallet, your internal-transfer rule must handle both sides. This is why the exclusion of exchange-to-exchange transfers is part of the definition, not an optional cleanup.
On UTXO chains such as Bitcoin, a single transaction can have several inputs and outputs, and change outputs return value to the sender. A withdrawal from an exchange often includes a change output back to an exchange address. If you treat each output separately, you must not count the change as an inflow. A safer method is to compute, per transaction, the value that left exchange-controlled inputs and the value that reached non-exchange outputs.
Reading the numbers
Suppose daily netflow for an asset is strongly positive for a week. Possible explanations include:
- Holders are moving coins to exchanges to sell.
- Holders are moving coins to exchanges to use them as collateral for loans or derivatives margin, with no plan to sell.
- A market maker is repositioning inventory between venues.
- An exchange has changed its wallet structure and your labels have not caught up.
- A single large holder made one deposit.
The metric alone cannot separate these. Treat netflow as a prompt to investigate, not a forecast. Some practical habits help:
- Normalize. A netflow of 5,000 coins means something different for an asset with 20 million coins in circulation than for one with 200 million. Divide by circulating supply, by exchange balance, or by total transfer volume.
- Check concentration. Look at the largest few transfers in the window. If one deposit makes up most of the netflow, the signal is one actor, not a crowd.
- Look at the stock too. Netflow is a change. Exchange balance, the sum of all coins held in labeled exchange addresses, is the running total. A large balance with small netflow differs from a small balance with the same netflow.
- Compare across stablecoins and the base asset. Stablecoin inflows to exchanges are sometimes read as buying power arriving, but the same caveats about labels and purpose apply.
Edge cases to handle in code
- Zero-value and failed transactions. On account-based chains, failed transactions still appear in some data sources. Filter them out, or you will count value that never moved.
- Contract-mediated transfers. On chains with smart contracts, a token deposit may be a contract call that emits an event, not a plain transfer. Use token transfer events for token flows, and internal transaction traces for native-coin transfers made by contracts.
- Wrapped and bridged assets. A wrapped version of a coin is a different token. Decide whether to combine them, and state the decision.
- Self-transfers. A user moving coins from one of their wallets to another is outside the exchange set on both ends and is ignored, which is correct.
- Double counting in multi-hop paths. A coin that moves from a user to exchange A, then to exchange B, counts as an inflow once, at the first hop. The A to B move is internal only if both are labeled as the same entity. If your labels treat A and B as separate exchanges, decide whether you are measuring flows per exchange or across all exchanges, and keep that consistent.
Per-exchange versus aggregate flows
Per-exchange flows tell you which venue receives the coins. Aggregate flows tell you whether coins entered the exchange system as a whole. Aggregate flows must exclude transfers between exchanges, while per-exchange flows must include them, because from one exchange's point of view, a transfer from another exchange is an inflow. A reliable pipeline stores the transfers once and computes both views from the same data, so the numbers reconcile.
A grouped version
This extension buckets transfers by UTC day and returns a netflow series. It reuses the same rule as before.
from collections import defaultdict
from datetime import datetime, timezone
def daily_netflow(transfers, exchange_addresses):
days = defaultdict(lambda: {"inflow": 0, "outflow": 0})
for t in transfers:
from_ex = t["from"] in exchange_addresses
to_ex = t["to"] in exchange_addresses
if from_ex == to_ex:
continue
day = datetime.fromtimestamp(t["ts"], tz=timezone.utc).date()
if to_ex:
days[day]["inflow"] += t["value"]
else:
days[day]["outflow"] += t["value"]
return {
day: {**v, "netflow": v["inflow"] - v["outflow"]}
for day, v in sorted(days.items())
}
transfers = [
{"ts": 1700000000, "from": "0xa", "to": "0xb", "value": 10},
{"ts": 1700003600, "from": "0xb", "to": "0xc", "value": 4},
{"ts": 1700090000, "from": "0xd", "to": "0xb", "value": 6},
]
print(daily_netflow(transfers, {"0xb"}))The condition from_ex == to_ex skips both internal transfers (both true) and transfers that do not touch an exchange (both false). Only transfers where exactly one side is an exchange are counted. This is a compact way to express the same rule as the earlier function.
Summary of the model
- Inflow, outflow, and netflow depend on a label set. Change the labels and you change the metric.
- Exclude exchange-to-exchange transfers from aggregate figures.
- Pick the window, the unit, and the normalization before comparing periods.
- Treat the result as one input to a broader reading, which a later chapter on combining metrics develops.
Exercise
An analyst sees a large positive daily netflow for an asset and writes that holders are preparing to sell. Name two other explanations the data cannot rule out, and one check that would help narrow it down.
Show answer
Possible alternatives: the coins were deposited as collateral or margin and will not be sold, or a single large holder or a market maker moved coins between venues, or the exchange moved coins to a wallet missing from the label set. A useful check is to look at the largest transfers in the window. If one or two deposits make up most of the netflow, the signal reflects one actor, not broad selling. Comparing the netflow with the exchange balance and the circulating supply also helps size it.
Exercise
In the function exchange_netflow, a transfer goes from 0xb (an exchange) to 0xb2, a second wallet that belongs to the same exchange but is missing from the label set. What does the function report, and how would you fix it?
Show answer
It counts the value as outflow, because 0xb2 is not in the set, so outflow is overstated and netflow is understated. The fix is to add 0xb2 to the exchange label set, ideally by clustering it with 0xb or by using the exchange's published addresses, then recompute. The function logic is fine, since the error is in the labels.
Exercise
Why must aggregate exchange flows exclude transfers between two labeled exchange addresses, while per-exchange flows should include transfers from one exchange to another?
Show answer
In the aggregate view, an exchange-to-exchange transfer moves value within the exchange ecosystem, so it is neither new money entering nor money leaving, and counting it would inflate both inflow and outflow. In a per-exchange view, a transfer from exchange A to exchange B is a real inflow for B and a real outflow for A, because it changes how much each venue holds.