-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
async orderbooks
github-actions[bot] edited this page Jul 4, 2026
·
4 revisions
# -*- coding: utf-8 -*-
import asyncio
from importlib import import_module
from importlib.util import find_spec
run = import_module(next(filter(find_spec, ('uvloop', 'winloop', 'asyncio')))).run
import ccxt
import ccxt.async_support as ccxta # noqa: E402
import time
import os
import sys
async def async_client(exchange, symbol):
client = getattr(ccxta, exchange)()
await client.load_markets()
if symbol not in client.symbols:
raise Exception(exchange + ' does not support symbol ' + symbol)
while True:
try:
orderbook = await client.fetch_order_book(symbol)
datetime = client.iso8601(client.milliseconds())
print(datetime, client.id, symbol, orderbook['bids'][0], orderbook['asks'][0])
except Exception as e:
print(type(e).__name__, e.args, str(e)) # comment if not needed
# break # uncomment to break it
# pass # uncomment to do nothing and just retry again on next iteration
# or add your own reaction according to the purpose of your app
await client.close()
async def multi_orderbooks(exchanges, symbol):
input_coroutines = [async_client(exchange, symbol) for exchange in exchanges]
await asyncio.gather(*input_coroutines, return_exceptions=True)
if __name__ == '__main__':
# Consider review request rate limit in the methods you call
exchanges = ["kucoin", "bitfinex", "poloniex"]
symbol = 'ETH/BTC'
run(multi_orderbooks(exchanges, symbol))(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
- FAQ
- Changelog
- Awesome
- API Spec by Exchange
- alpaca
- apex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitmex
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- btse
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinex
- 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
- revolutx
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- zebpay
- API Spec by Prediction Exchange