Cross-exchange arbitrage
Query
WITH
'2024-12-31' AS day,
p AS (
SELECT start, exchange, toFloat64(close) AS close
FROM api.ohlcv(candle_duration_in_minutes = 1)
WHERE market = 'BTC-USDT'
AND exchange IN ('binance', 'okx', 'kucoin', 'gateio')
AND start >= toDateTime(day)
AND start < toDateTime(day) + INTERVAL 1 DAY
)
SELECT a.start,
a.exchange AS buy_ex,
b.exchange AS sell_ex,
a.close AS buy_price,
b.close AS sell_price,
(b.close - a.close) / a.close * 100 AS spread_pct
FROM p a
JOIN p b ON a.start = b.start
WHERE a.exchange < b.exchange
ORDER BY a.start, buy_ex, sell_exOutput (2024-12-31)
start
buy_ex
sell_ex
buy_price
sell_price
spread_pct
pair
mean
std
min
max
Extending it
Last updated