babel_exchange library

A unified multi-exchange API client for cryptocurrency trading.

This library provides a consistent interface across different exchanges (Binance, MEXC, Kraken) allowing you to switch exchanges without changing your trading logic.

Quick Start

import 'package:babel_exchange/babel_exchange.dart';

void main() async {
  // Create an exchange instance
  final exchange = BabelExchange.create(
    Exchange.mexc,
    apiKey: 'your-api-key',
    secretKey: 'your-secret-key',
  );

  // Get market data
  final ticker = await exchange.getTicker('BTCUSDT');
  print('BTC Price: ${ticker.lastPrice}');

  // Place an order
  final order = await exchange.placeMarketOrder(
    symbol: 'BTCUSDT',
    side: OrderSide.buy,
    quantity: 0.001,
  );
  print('Order placed: ${order.orderId}');

  // Subscribe to real-time data
  exchange.subscribeToTrades('BTCUSDT').listen((trade) {
    print('Trade: ${trade.price} x ${trade.quantity}');
  });

  // Clean up
  exchange.dispose();
}

Supported Exchanges

  • Binance: Full support for Spot trading
  • MEXC: Full support for Spot trading with B2B fees
  • Kraken: Planned for MiCA compliance

Classes

AccountInfo
Account information.
AggTrade
Aggregated trade data.
BabelDebug
Debug logging utilities for babel_exchange.
BabelExchange
Factory for creating exchange instances.
Balance
Account balance.
BinanceExchange
Binance Spot API implementation of ExchangeApi.
Candle
Candlestick/OHLCV data.
ExchangeApi
Abstract interface for all exchange implementations.
ExchangeErrorCode
Common exchange error codes.
ExchangeFees
Fee structure for an exchange.
ExchangeInfo
Exchange information.
Fill
Individual fill within an order.
FundingData
Funding rate data (futures).
KrakenExchange
Kraken Spot API implementation of ExchangeApi.
MexcExchange
MEXC Spot API implementation of ExchangeApi.
Order
Order representation.
OrderBook
Order book snapshot.
OrderBookLevel
Order book price level.
SymbolInfo
Symbol/trading pair information.
Ticker
24hr ticker statistics.
Trade
Trade history entry.
TradingPair
A type-safe trading pair.

Enums

AccountType
Account type enumeration.
Coin
Common cryptocurrency assets (coins).
DebugLevel
Debug log level.
Exchange
Supported exchanges enumeration.
KlineInterval
Kline/Candlestick interval enumeration.
OrderSide
Order side enumeration.
OrderStatus
Order status enumeration.
OrderType
Order type enumeration.
SymbolStatus
Symbol trading status enumeration.
TimeInForce
Time in force enumeration.

Exceptions / Errors

ExchangeApiException
API error returned by the exchange.
ExchangeAuthException
Authentication error.
ExchangeException
Base exception for all exchange errors.
ExchangeNetworkException
Network/connection error.
ExchangeParameterException
Invalid parameter error.
ExchangeRateLimitException
Rate limit exceeded.
ExchangeWebSocketException
WebSocket error.
InsufficientBalanceException
Insufficient balance error.
IpBannedException
IP banned error.
OrderNotFoundException
Order not found error.