-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
async basic callchain
github-actions[bot] edited this page Jun 11, 2026
·
2 revisions
# -*- coding: utf-8 -*-
import asyncio
import os
import sys
import ccxt.async_support as ccxt # noqa: E402
async def run_all_exchanges(exchange_ids):
results = {}
for exchange_id in exchange_ids:
exchange = getattr(ccxt, exchange_id)({
'options': {
'useWebapiForFetchingFees': False,
}
})
symbol = 'ETH/BTC'
print('Exchange:', exchange_id)
print(exchange_id, 'symbols:')
markets = await load_markets(exchange, symbol) # ←----------- STEP 1
print(list(markets.keys()))
print(symbol, 'ticker:')
ticker = await fetch_ticker(exchange, symbol) # ←------------ STEP 2
print(ticker)
print(symbol, 'orderbook:')
orderbook = await fetch_orderbook(exchange, symbol) # ←------ STEP 3
print(orderbook)
await exchange.close() # ←----------- LAST STEP GOES AFTER ALL CALLS
results[exchange_id] = ticker
return results
async def load_markets(exchange, symbol):
try:
result = await exchange.load_markets()
return result
except ccxt.BaseError as e:
print(type(e).__name__, str(e), str(e.args))
raise e
async def fetch_ticker(exchange, symbol):
try:
result = await exchange.fetch_ticker(symbol)
return result
except ccxt.BaseError as e:
print(type(e).__name__, str(e), str(e.args))
raise e
async def fetch_orderbook(exchange, symbol):
try:
result = await exchange.fetch_order_book(symbol)
return result
except ccxt.BaseError as e:
print(type(e).__name__, str(e), str(e.args))
raise e
if __name__ == '__main__':
exchange_ids = ['bitfinex', 'okex', 'exmo']
exchanges = []
results = asyncio.run(run_all_exchanges(exchange_ids))
print([(exchange_id, ticker) for exchange_id, ticker in results.items()])(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
- fetchCurrencies
- alpaca
- apex
- ascendex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitmart
- bitmex
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinex
- coinmate
- coinmetro
- coinone
- coinsph
- coinspot
- cryptocom
- cryptomus
- deepcoin
- delta
- deribit
- derive
- digifinex
- dydx
- exmo
- extended
- foxbit
- gate
- gemini
- grvt
- hashkey
- hibachi
- hitbtc
- hollaex
- htx
- hyperliquid
- independentreserve
- indodax
- kraken
- krakenfutures
- kucoin
- fetchBidsAsks
- latoken
- lbank
- lighter
- luno
- mercado
- mexc
- modetrade
- ndax
- novadax
- okx
- onetrading
- p2b
- pacifica
- paradex
- paymium
- phemex
- poloniex
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- fetchStatus