Welcome to the documentation for the Bjarkan Smart Order Router (SOR) SDK. This project provides a powerful and flexible solution for getting aggregated or non-aggregated market data, streaming real-time trades, and executing orders across multiple cryptocurrency exchanges, optimizing for the best possible execution price.

What is Bjarkan SOR?

Bjarkan SOR is a comprehensive Market Data provider and Smart Order Router designed to:

  1. Provide both aggregated and non-aggregated orderbook data views with fees and VWAP calculations available.
  2. Stream real-time trade data from multiple exchanges.
  3. Intelligently split and route orders to achieve the best overall execution price.

Key Features

  • Multi-Exchange Support: Connect to and trade on multiple exchanges simultaneously (30+ exchanges supported).
  • Configurable: Set up your own configurations to define which exchanges and symbols you want to work with.
  • Real-time Order Book Data: Get a comprehensive view of the market across all connected exchanges, with options for aggregated or non-aggregated data.
  • Live Trade Streaming: Receive real-time trade data from multiple exchanges with customizable filtering.
  • Smart Order Execution: Automatically split and route orders for optimal execution.
  • Customizable Strategies: Leverage our open market data, execution and SOR to create your own advanced trading strategies and execution models.
  • Flexible Configuration: Easily set up and modify your orderbook and trades configurations, as well as API keys.
  • Sandbox Mode: Test your strategies in a safe environment using exchange sandbox modes.
  • Fee-Aware Orderbooks: Incorporate exchange fees directly into price levels to view the real orderbook of crypto.
  • VWAP Calculations: Utilize Volume Weighted Average Price calculations for more accurate pricing and better execution strategies.
  • Async Architecture: Built with Python’s asyncio for high-performance and non-blocking operations.
  • Resource Management: Clean resource handling with async context managers.

Getting Started

  1. Install the Bjarkan SDK:

    pip install bjarkan-sdk
    
  2. Import and initialize the SDK:

    import asyncio
    from bjarkan import BjarkanSDK
    
    async def main():
        async with BjarkanSDK() as sdk:
            # Your code here
    
    if __name__ == "__main__":
        asyncio.run(main())
    
  3. Set your orderbook and/or trades configurations:

    # Configure orderbook
    await sdk.set_config(
        type="orderbook",
        aggregated=True,
        exchanges=["binance", "okx", "bybit"],
        symbols=["BTC/USDT"],
        depth=20
    )
    
  4. Start the required data streams:

    # Define a callback for orderbook updates
    async def process_orderbook(orderbook):
        print(f"Best bid: {orderbook['bids'][0][0]}, Best ask: {orderbook['asks'][0][0]}")
    
    # Start the orderbook stream
    await sdk.start_stream("orderbook", callback=process_orderbook)
    
  5. Execute orders or implement your custom trading strategies:

    from bjarkan.models import OrderConfig
    
    # Create an order
    order = OrderConfig(
        side="buy",
        amount=0.001  # BTC amount
    )
    
    # Execute the order
    result = await sdk.execute_order(order)
    print(f"Order status: {result['status']}")
    

Built on CCXT Pro

Bjarkan SOR SDK is built on top of CCXT Pro, providing a standardized interface to access cryptocurrency exchanges. This foundation ensures robust exchange connectivity while Bjarkan adds smart order routing and advanced market data capabilities.

Core Components

The SDK consists of several key components:

  1. BjarkanSDK Client: The main entry point for all functionality
  2. OrderbookManager: Handles orderbook data collection and processing
  3. TradesManager: Manages real-time trade data
  4. OrderExecutor: Routes and executes orders across exchanges

We’re excited to see what you’ll build with the Bjarkan SOR. Happy trading!