CCXT Async vs Sync: Which One Should You Use?
Sync CCXT is easy but slow. Async CCXT is faster but needs setup. Learn which fits your trading bot and how to switch.
Sync CCXT is easy but slow. Async CCXT is faster but needs setup. Learn which fits your trading bot and how to switch.
If you've been building a trading bot with CCXT, you've probably hit the moment where it feels slow. You're fetching order books from Binance, checking balances, placing orders — and everything happens one after another like customers in a single checkout line. That's synchronous CCXT. Async CCXT is the express lane with ten registers open at once. Knowing which one to use — and when — can be the difference between a bot that lags behind the market and one that actually catches the move.
Synchronous code runs one task at a time. When your bot calls `exchange.fetch_ticker('BTC/USDT')`, the entire program stops and waits for Binance's server to respond before doing anything else. Only after that response arrives does your code move to the next line. Think of it like calling a restaurant to place a delivery order — you stay on hold until someone picks up, you give your order, and only then can you do something else.
For simple scripts — checking a price once, placing a manual order, pulling historical data for backtesting — synchronous CCXT is perfectly fine. It's easier to read, easier to debug, and the mental overhead is near zero. Beginners almost always start here, and for many use cases, they never need to leave.
import ccxt
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
})
# This blocks until Binance responds
ticker = exchange.fetch_ticker('BTC/USDT')
print(ticker['last'])
# Only runs AFTER the above finishes
balance = exchange.fetch_balance()
print(balance['USDT']['free'])
Key Takeaway: Synchronous CCXT is simpler and totally valid for single-exchange bots, one-time data pulls, and scripts that don't need to monitor multiple markets at once.
Asynchronous CCXT uses Python's `asyncio` library under the hood. Instead of blocking while waiting for a response, your program can fire off multiple API requests at the same time and handle each response as it arrives. Same restaurant analogy — except now you've sent ten text orders simultaneously and you're reading replies as they come in.
CCXT exposes async versions of its exchange classes. So `ccxt.binance` becomes `ccxt.pro.binance` (for WebSocket streams) or `ccxt.async_support.binance` for async REST calls. The API methods look identical — `fetch_ticker`, `create_order`, `fetch_balance` — but you prefix them with `await` and wrap everything in `async def` functions.
import ccxt.async_support as ccxt
import asyncio
async def fetch_prices():
exchange = ccxt.bybit({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
})
# Fire all three requests at once
btc, eth, sol = await asyncio.gather(
exchange.fetch_ticker('BTC/USDT'),
exchange.fetch_ticker('ETH/USDT'),
exchange.fetch_ticker('SOL/USDT'),
)
print(btc['last'], eth['last'], sol['last'])
await exchange.close()
asyncio.run(fetch_prices())
The `asyncio.gather()` call is where the magic happens. All three ticker requests go out simultaneously. If each one takes 200ms to respond, synchronous code would take 600ms total. Async code finishes in roughly 200ms — as fast as the slowest single request. On platforms like Bybit and OKX where rate limits are strict, this efficiency matters enormously.
Raw benchmarks depend on your network, the exchange, and what you're fetching — but the pattern is consistent. Async wins whenever you're making multiple API calls in the same time window. Here's a realistic comparison for a bot monitoring five trading pairs on Binance:
| Approach | Total Time | CPU Usage | Complexity |
|---|---|---|---|
| Synchronous | ~750ms | Low | Simple |
| Async (gather) | ~150-200ms | Low-Medium | Moderate |
| Async + WebSocket | ~1-5ms updates | Medium | Higher |
That 750ms vs 150ms difference looks small on paper. But run that loop every second for a scalping bot on OKX, and you're either keeping up with the market or constantly working with stale data. For signal-based strategies where timing matters — like acting on alerts from VoiceOfChain before a price move completes — that 600ms gap is significant.
Key Takeaway: Async doesn't make individual requests faster. It makes your bot faster by running multiple requests in parallel instead of sequentially.
Async isn't always worth the added complexity. Here are situations where synchronous CCXT is the smarter pick:
The rule of thumb: if your bot only needs one API call at a time, use sync. If it needs two or more calls before making a decision, async pays off immediately. A bot that checks the order book AND current position AND open orders before placing a trade on Bitget — that's a perfect async candidate.
There's a third option most guides skip: CCXT Pro with WebSocket connections. REST API calls (both sync and async) are request-response — your bot asks, the exchange answers. WebSockets are persistent connections where the exchange pushes updates to you continuously. No polling, no repeated HTTP handshakes.
For bots that need real-time order book data or live trade streams — say, monitoring large whale orders on Binance or tracking liquidation cascades on Bybit — WebSocket via CCXT Pro is the right tool. You subscribe to a stream once and receive updates in milliseconds as they happen.
import ccxt.pro as ccxtpro
import asyncio
async def watch_orderbook():
exchange = ccxtpro.binance()
while True:
orderbook = await exchange.watch_order_book('BTC/USDT')
best_bid = orderbook['bids'][0][0]
best_ask = orderbook['asks'][0][0]
spread = best_ask - best_bid
print(f'Spread: {spread:.2f} USDT')
asyncio.run(watch_orderbook())
This is how professional market-making bots and high-frequency strategies work. Platforms like VoiceOfChain use similar real-time data pipelines to generate order flow signals — tracking where big money is moving before the price reflects it. If your strategy depends on knowing the exact moment a level breaks, REST polling (even async) introduces unnecessary lag compared to a WebSocket feed.
Key Takeaway: REST async = good for parallel requests. WebSocket = good for continuous real-time data. Use both together in sophisticated bots: WebSockets for market data, async REST for order management.
Async CCXT is powerful but has a few sharp edges that trip up developers coming from synchronous code:
Synchronous CCXT gets you started fast. Async CCXT gets your bot running fast. The choice isn't about one being better — it's about matching the tool to the job. If you're fetching from a single exchange, doing research, or prototyping a strategy, sync is perfectly fine. If you're monitoring multiple pairs across Binance and OKX simultaneously, managing positions while watching signals, or trying to react to market conditions in near real-time, async is essential.
The professional path usually looks like this: start with sync to validate the logic, switch to async REST as complexity grows, and add WebSocket streams via CCXT Pro when latency becomes the bottleneck. Pair that with a real-time signal layer — like what VoiceOfChain provides for order flow analysis — and you have a stack that can actually compete with institutional flow rather than just react to it after the fact.
Key Takeaway: Don't prematurely optimize. Start sync, profile where the slowdowns are, then switch those specific parts to async. Over-engineering your architecture before the strategy is proven is how bots never ship.