Fintech: Wash Trading

10pts
Coinbase, Binance

Problem Statement

Market integrity is crucial in crypto. Wash trading occurs when traders create artificial volume by buying and selling the same asset between two controlled accounts.

Write a query to detect "Wash Trade Pairs." A wash trade is defined as:

  1. Trade 1: Account A sells a specific amount of a crypto ticker to Account B.
  2. Trade 2: Account B sells the exact same amount of the same crypto ticker back to Account A.
  3. Trade 2 occurs within 60 minutes after Trade 1.

Rules:

  • Only consider trades where Trade 2 happens after Trade 1.
  • Output columns: account_1, account_2, crypto_ticker, wash_trade_count.
  • account_1 should always be the smaller ID of the pair (to ensure unique pairs).
  • wash_trade_count is the number of times this specific back-and-forth occurred.
  • Result must be sorted by wash_trade_count descending, then account_1 ascending.
Tests your understanding of
Self Joins, Time Series and Conditional Logic

Input Tables

trades
trade_id(INTEGER)seller_id(INTEGER)buyer_id(INTEGER)crypto_ticker(VARCHAR)amount(DECIMAL)trade_timestamp(TIMESTAMP)
1101202BTC0.52026-03-04 10:00:00
2202101BTC0.52026-03-04 10:15:00
3101202BTC0.52026-03-04 11:30:00
4202101BTC0.52026-03-04 11:45:00
5303404ETH102026-03-04 12:00:00
6404303ETH102026-03-04 12:10:00
7505606SOL1002026-03-04 13:00:00
8606505SOL992026-03-04 13:05:00

Expected Output

account_1(INTEGER)account_2(INTEGER)crypto_ticker(VARCHAR)wash_trade_count(INTEGER)
101202BTC2
303404ETH1

Tags

HardSelf JoinsTime SeriesConditional Logic
40-50 min
24%

Hints