Configurations
The Bjarkan SOR SDK uses two main configurations: Orderbook Configuration and Trades Configuration. These configurations define the exchanges, trading pairs, and other essential parameters for your trading activities.
Setting Configurations
You configure the SDK using the set_config
method:
This method returns a dictionary with the status and a message:
Orderbook Configuration
The orderbook configuration defines parameters for fetching and processing orderbook data.
Orderbook Config Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
aggregated | bool | No | False | Whether to aggregate orderbooks across exchanges |
exchanges | List[str] | Yes | - | List of exchange IDs to connect to |
sandbox_mode | Dict[str, bool] | No | {} | Dictionary of exchange IDs to sandbox mode flags |
symbols | List[str] | Yes | - | List of symbols to monitor |
depth | int | Yes | - | Number of price levels to include |
fees_bps | Dict[str, Union[float, Dict[str, float]]] | No | None | Exchange fee rates in basis points |
weighting | Dict[str, Dict[str, float]] | No | None | VWAP weighting configuration |
group | Dict[str, str] | No | None | Symbol grouping configuration |
Example Orderbook Config
Fee-Aware Orderbooks
The fees_bps
parameter allows you to account for exchange fees in orderbook prices. This is essential for accurate cross-exchange price comparisons and arbitrage detection.
Fees are specified in basis points (1 bp = 0.01%). You can set:
- A single fee for all symbols on an exchange:
"binance": 9.8
- Different fees per symbol:
"okx": {"BTC/USDT": 7, "ETH/USDT": 8}
The SDK applies these fees to the orderbook data as follows:
- For buy orders (bids), the fee-adjusted price is decreased:
adjusted_price = original_price / (1 + fee)
- For sell orders (asks), the fee-adjusted price is increased:
adjusted_price = original_price * (1 + fee)
If the fees_bps
parameter is omitted, no fee adjustments will be applied.
Symbol Grouping
The group
parameter allows you to treat different but related symbols as equivalent. This is useful for stablecoins or similar assets where you want to combine liquidity.
This will combine orderbooks for BTC/USDT and BTC/USDC into a single view.
VWAP Weighting
The weighting
parameter enables Volume Weighted Average Price (VWAP) calculations. This calculates what price you would pay/receive when executing a specific order size, accounting for slippage.
VWAP is calculated by taking the sum of the price times the volume for each order up to the specified target amount, then dividing by the total volume.
VWAP Calculation Example
Let’s consider a simplified order book for BTC/USDT with a target of 1 BTC:
The VWAP calculation for each exchange would be:
-
Binance VWAP (1 BTC target):
- Use 0.5 BTC at 57,900
- Use 0.4 BTC at 57,800
- Use 0.1 BTC at 57,600 VWAP = (57900 * 0.5 + 57800 * 0.4 + 57600 * 0.1) / 1 = 57,830
-
Coinbase VWAP (1 BTC target):
- Use 0.7 BTC at 57,700
- Use 0.3 BTC at 57,500 VWAP = (57700 * 0.7 + 57500 * 0.3) / 1 = 57,640
The resulting VWAP orderbook would look like:
Trades Configuration
The trades configuration defines parameters for streaming real-time trade data.
Trades Config Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
exchanges | List[str] | Yes | - | List of exchange IDs to connect to |
sandbox_mode | Dict[str, bool] | No | {} | Dictionary of exchange IDs to sandbox mode flags |
symbols | List[str] | Yes | - | List of symbols to monitor |
fees_bps | Dict[str, Union[float, Dict[str, float]]] | No | None | Exchange fee rates in basis points |
size | Dict[str, Dict[str, float]] | No | None | Minimum trade size filters |
Example Trades Config
Trade Size Filtering
The size
parameter allows you to filter trades by minimum size. This is particularly useful for:
- Reducing noise from small trades
- Focusing on institutional/whale activity
- Monitoring significant market moves
- Reducing processing overhead
You can specify minimum sizes in two ways:
- Base currency:
"BTC/USDT": {"BTC": 0.1}
(only trades ≥ 0.1 BTC) - Quote currency:
"ETH/USDT": {"USDT": 10000}
(only trades with value ≥ $10,000)
Sandbox Mode
For testing without using real funds, you can enable sandbox/testnet mode for specific exchanges:
This setting applies to both orderbook data collection and order execution. Make sure your API keys are configured for the respective exchange testnet environments when using sandbox mode.
Starting and Stopping Streams
After setting your configurations, you need to explicitly start the data streams:
To stop a running stream:
Important Notes
- The SDK will validate the configurations when you call
set_config()
- For order execution, the orderbook configuration must have
aggregated=True
and contain only one symbol - You must start the orderbook stream before attempting to execute orders
- When using both orderbook and trades configurations, you need to call
set_config()
for each type - If you need different configurations for the same type, you should create separate SDK instances
By properly configuring the Bjarkan SOR SDK, you can customize its behavior to suit your specific trading strategies and requirements. The flexibility of the configuration system allows you to fine-tune data collection, filtering, and execution parameters across multiple exchanges.