Repository navigation
coinbase watch ohlcv
github-actions[bot] edited this page Aug 21, 2026
·
1 revision
# -*- coding: utf-8 -*-
# Prefer watchOHLCV over polling fetchOHLCV in a loop: the candles WebSocket
# channel streams the forming candle and closed buckets instead of repeatedly
# re-fetching the candles endpoint over REST.
#
# Note: coinbase watchOHLCV currently supports only the 5m timeframe.
import ccxt.pro
from importlib import import_module
from importlib.util import find_spec
run = import_module(next(filter(find_spec, ('uvloop', 'winloop', 'asyncio')))).run
async def main():
exchange = ccxt.pro.coinbase()
method = 'watchOHLCV'
symbol = 'BTC/USD'
timeframe = '5m'
print('CCXT Pro version', ccxt.pro.__version__)
if exchange.has[method]:
while True:
try:
candles = await exchange.watch_ohlcv(symbol, timeframe)
candle = candles[-1]
print(exchange.iso8601(candle[0]), symbol, timeframe, 'O', candle[1], 'H', candle[2], 'L', candle[3], 'C', candle[4], 'V', candle[5])
except Exception as e:
# stop
await exchange.close()
raise e
# or retry
# pass
else:
raise Exception(exchange.id + ' ' + method + ' is not supported or not implemented yet')
run(main())(If the page is not being rendered for you, you can refer to the mirror at https://docs.ccxt.com/)
- Install
- Examples
- Manual
- CCXT Pro
- Contributing
- Supported Exchanges
- Exchanges By Country
- API Spec By Method
- Order Router
- FAQ
- Changelog
- Awesome
- API Spec by Exchange
- alpaca
- apex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- btse
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinmate
- coinone
- coinsph
- coinspot
- cryptocom
- cryptomus
- deepcoin
- delta
- deribit
- derive
- digifinex
- dydx
- extended
- foxbit
- gate
- gemini
- grvt
- hashkey
- hibachi
- hitbtc
- hollaex
- htx
- hyperliquid
- independentreserve
- indodax
- kraken
- krakenfutures
- kucoin
- kucoinfutures
- latoken
- lbank
- lighter
- luno
- mercado
- mexc
- modetrade
- mudrex
- nado
- ndax
- okx
- onetrading
- p2b
- pacifica
- paradex
- paymium
- phemex
- poloniex
- polymarket
- revolutx
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- zebpay
- API Spec by Prediction Exchange