106 lines
6.1 KiB
Markdown
106 lines
6.1 KiB
Markdown
# Meme Matcher
|
||
|
||
Finds the same memecoins on **CEX perpetual futures** and on **DEX spot**, and compares their prices.
|
||
|
||
```
|
||
py -3 meme_matcher.py # window
|
||
py -3 meme_matcher.py --once # console table + meme_matches.csv
|
||
```
|
||
|
||
Python 3.10+ standard library only; all APIs are public (no keys).
|
||
|
||
## Sources
|
||
|
||
| What | Where |
|
||
|---|---|
|
||
| USDT perpetuals: price, 24h volume, funding | Bybit, Binance, OKX, Gate, MEXC, Bitget, BingX |
|
||
| Which coins are memecoins, market cap, contract addresses | CoinGecko, category `meme-token` (top 1000 by default, 4 pages × 250) |
|
||
| DEX pools: price, liquidity, 24h volume | DexScreener (Solana, Ethereum, BSC, Base, Arbitrum, TON, …) |
|
||
| DEX spot order book | HyperLiquid spot (USDC pairs) |
|
||
|
||
The CoinGecko contract list (~4 MB) is cached in `cache/` for 24 h.
|
||
|
||
## How a coin is identified
|
||
|
||
A ticker alone is not enough: CoinGecko lists 21 different "PEPE" tokens, and one exchange can list `CAT` and
|
||
`1000CAT` as two different coins. So:
|
||
|
||
1. Contract size prefixes and suffixes are removed and the price is converted to one coin (`1000PEPE`, `1MBABYDOGE`,
|
||
`SHIB1000`).
|
||
2. Each CEX contract is tied to the CoinGecko meme token with the same symbol **whose price agrees** with it (within
|
||
±50%); contracts that agree with no meme token are skipped (not a memecoin, or an unknown one).
|
||
3. For that token's contract addresses every DexScreener pool is fetched; the token must be the pool's base asset.
|
||
The chosen pool is the deepest one whose price is within ±25% of the CEX price; HyperLiquid spot is added by
|
||
token name with the same price check.
|
||
4. Status by the DEX − CEX price gap: **совпадает** ≤ 5%, **проверить** ≤ 25%, **разные монеты?** above that (only
|
||
pools at a very different price exist — usually a copycat token on another chain), **нет на DEX**.
|
||
|
||
## Window
|
||
|
||
Exchange checkboxes, minimum DEX liquidity and CEX volume, number of CoinGecko pages, "only on DEX" and
|
||
"only matching" filters. Columns sort on click; a double click opens the pool on DexScreener / HyperLiquid;
|
||
"Сохранить CSV" saves what is shown. `(+N)` after the DEX means the coin also trades on N more chains at the same
|
||
price. Funding is the largest absolute funding rate over the listed exchanges.
|
||
|
||
## Lead-lag: does the DEX move before the futures?
|
||
|
||
```
|
||
py -3 leadlag.py --minutes 30 --coins 12 # scan, record, analyse
|
||
py -3 leadlag.py --analyze recordings\leadlag_….jsonl.gz
|
||
```
|
||
|
||
Also the «Опережение DEX…» button in the window. Coins: status «совпадает», a pool on **Solana, BSC or Base**
|
||
(blocks ≤ 2 s; a 12 s Ethereum block cannot show a 1 s lead) with at least 120 swaps an hour (the most active pool
|
||
is used), and a perpetual on Binance, Bybit, Gate or MEXC (in that order of preference).
|
||
|
||
Recorded at the same time:
|
||
* futures trades over WebSockets with exchange timestamps in ms (Binance `fstream…/market/stream` aggTrade, Bybit
|
||
publicTrade, Gate futures.trades, MEXC push.deal);
|
||
* DEX swaps from GeckoTerminal (`/pools/{pool}/trades`, last 300 swaps, polled every 30 s, ≤ 26 requests a minute)
|
||
with **on-chain block timestamps** — so the lead is measured on chain time, not on when the API showed the swap.
|
||
|
||
Recordings go to `recordings/`, verdicts to `leadlag_results.csv`.
|
||
|
||
Analysis on a 1-second grid (DEX: volume-weighted price of the block second; futures: last trade of the second):
|
||
* correlation of 1-s returns at lags −10…+10 s (+ = futures after the DEX);
|
||
* events — seconds where the DEX moved ≥ 0.15%: the futures move in the same direction in that second, and **from
|
||
t+1 to t+3/5/10** — i.e. after the DEX second and the next one, so a sub-second reaction that merely lands in the
|
||
next second does not count as a lead. Block times are whole seconds, so a lead under ~1 s cannot be told apart
|
||
from "simultaneous".
|
||
* verdicts: **DEX опережает ≥1 с** (t+1→t+5 move the DEX way, t ≥ 2, hit rate ≥ 60%, ≥ 10 events), **фьючерс
|
||
опережает** (best correlation at a negative lag), **после DEX фьючерс откатывает**, **одновременно / нет
|
||
опережения**, **мало движений DEX / мало данных**.
|
||
|
||
**Live use:** GeckoTerminal publishes swaps 1–2 minutes late (column «Задержка данных DEX»). The tool can find
|
||
which coins lead; acting on a lead needs a direct chain feed (Solana RPC WebSocket on the pool), not this API.
|
||
|
||
## Autonomous search (autoscan)
|
||
|
||
```
|
||
py -3 autoscan.py --minutes 15 --coins 12 # or autoscan.bat, or «Автопоиск…» → «Запустить» in the window
|
||
```
|
||
|
||
Runs on its own in a loop: scan → up to 12 coins (earlier leaders are re-checked first, the rest rotate through all
|
||
candidates) → 15 min recording → lead analysis → next cycle (one cycle ≈ 20 min). Every result is appended to
|
||
`autoscan_history.csv`, the log to `autoscan.log`. A coin with «DEX опережает ≥1 с» whose pool is on Solana and of a
|
||
type the simulator reads live (Raydium AMM v4 / CPMM, PumpSwap, Meteora DLMM — checked through the pool account's
|
||
owner program) and whose futures are on Binance, Bybit or MEXC is added to the simulator's `../lead_connections.json`
|
||
(never removed; the simulator's active connection is not changed; the simulator picks the new entry up within 30 s).
|
||
Only one autoscan runs at a time (`autoscan.lock`); the manual «Опережение DEX…» recording shares GeckoTerminal's
|
||
rate limit with it. «Автопоиск…» in the window shows the history (leaders highlighted, what was added) and starts or
|
||
stops the background process, which keeps running when the windows are closed.
|
||
|
||
## Limits
|
||
|
||
* The meme universe is CoinGecko's `meme-token` category: memecoins that CoinGecko has not tagged, or that are
|
||
outside the scanned pages, are not found.
|
||
* The CoinGecko free API allows a few requests per minute; the scanner waits between pages and retries on HTTP 429.
|
||
* Prices come from different moments (each API is polled once); small gaps are timing, not arbitrage. DEX prices
|
||
do not include swap fees, slippage or gas.
|
||
|
||
## Tests
|
||
|
||
```
|
||
py -3 -m unittest discover -s tests
|
||
```
|