Bjarkan SDK
A sophisticated cryptocurrency trading SDK that provides real-time market data aggregation, smart order routing (SOR), and execution capabilities across multiple exchanges.
Features
For Users
Installation
pip install bjarkan-sdk
Quick Start
Market Data Monitoring
import asyncio
from bjarkan import BjarkanSDK
async def orderbook_callback(orderbook):
print(f"\nOrderbook Update for {orderbook['symbol']}:")
print("Top 5 Bids:")
for price, amount, exchange in orderbook['bids'][:5]:
print(f" {exchange}: {price:.2f} @ {amount:.4f}")
async def main():
sdk = BjarkanSDK()
await sdk.set_config(
type="orderbook",
aggregated=True,
exchanges=["binance", "bybit", "okx"],
symbols=["BTC/USDT", "ETH/USDT"],
depth=20
)
await sdk.start_stream("orderbook", callback=orderbook_callback)
await asyncio.sleep(60)
await sdk.stop_stream("orderbook")
await sdk.close()
if __name__ == "__main__":
asyncio.run(main())
Trade Execution
import asyncio
from bjarkan import BjarkanSDK
from bjarkan.models import OrderConfig
async def main():
sdk = BjarkanSDK()
await sdk.set_config(
type="orderbook",
aggregated=True,
exchanges=["binance", "bybit", "okx", "kraken"],
symbols=["BTC/USDT"],
depth=20
)
api_configs = [
{
"exchange": "binance",
"api_key": "your_api_key",
"api_secret": "your_secret"
},
{
"exchange": "bybit",
"api_key": "your_api_key",
"api_secret": "your_api_secret"
}
]
await sdk.initialize_executor(api_configs)
order = OrderConfig(
side="buy",
amount=0.01
)
result = await sdk.execute_order(order)
print(f"Order execution result: {result}")
await sdk.close()
if __name__ == "__main__":
asyncio.run(main())
Configuration
API configurations can be passed directly as the api_configs
dictionary or added to your .env
file and accessed using the get_api_config
function.
from bjarkan.utils.helpers import get_api_configs
Environment Variables
Create a .env
file in your project root:
# Exchange API Keys
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_secret
BYBIT_API_KEY=your_api_key
BYBIT_API_SECRET=your_secret
OKX_API_KEY=your_api_key
OKX_API_SECRET=your_secret
OKX_API_PASSWORD=your_password
# Optional Logging
BETTERSTACK_TOKEN=your_token
Orderbook Configuration
The SDK supports various orderbook configuration options:
await sdk.set_config(
type="orderbook",
aggregated=True,
exchanges=["binance", "bybit", "coinbase", "okx"],
symbols=["BTC/USDT", "BTC/USDC"],
depth=100,
fees_bps={
"binance": 10,
"bybit": {"BTC/USDT": 10}
},
group={
"BTC/USDT": "BTC/USDC"
},
weighting={"BTC/USDT":
{"USDT": 1000}
}
)
Trade Monitor Configuration
For monitoring trades across exchanges:
await sdk.set_config(
type="trades",
exchanges=["binance", "bybit", "okx"],
symbols=["BTC/USDT", "ETH/USDT"],
size={
"BTC/USDT": {"USDT": 10000}
}
)
Advanced Usage
Sandbox Testing
Enable sandbox/testnet mode for testing. Note that you will need to pass the testnet API keys, and only Binance and Bybit are currently supported for sandbox mode:
await sdk.set_config(
type="orderbook",
aggregated=True,
exchanges=["binance", "bybit"],
sandbox_mode={
"binance": True,
"bybit": True
},
symbols=["BTC/USDT"],
depth=20
)
Margin Trading
Enable spot margin trading mode:
await sdk.initialize_executor(api_configs, margin_mode=True)
For developers
Deployment
python bump_version.py patch
./deploy.sh
License
This project is licensed under the MIT License - see the LICENSE file for details.