Skip to main content

A Python SDK for accessing the Historical Market Data API and Smart Order Router API of Bjarkan

Project description

Bjarkan SDK

A Python SDK for accessing both the Smart Order Router (SOR) API and Historical Market Data services of Bjarkan.

Installation

You can install the Bjarkan SDK using pip:

pip install bjarkan-sdk

Usage

The SDK provides two main client classes:

  1. BjarkanDataClient: For interacting with the Historical Market Data API (data.bjarkan.io)
  2. BjarkanSORClient: For interacting with the Smart Order Router API (api.bjarkan.io)

Here's a quick example of how to use both clients:

from bjarkan_sdk import BjarkanDataClient, BjarkanSORClient
from datetime import datetime, timedelta

# Initialize the clients
data_client = BjarkanDataClient()
sor_client = BjarkanSORClient()

# Authenticate
data_client.authenticate("your_username", "your_password")
sor_client.authenticate("your_username", "your_password")

# Using the SOR API
orderbook_config = {
    "aggregated": True,
    "exchanges": ["binance", "okx", "htx"],
    "symbols": ["BTC/USDT", "ETH/USDT"],
    "depth": 10
}
result = sor_client.set_orderbook_config(orderbook_config)
print("Orderbook config set:", result)

latest_orderbook = sor_client.get_latest_orderbook()
print("Latest orderbook:", latest_orderbook)

# Using the Data API
tables = data_client.get_tables()
print("Available tables:", tables)

result = data_client.get_history(
    table_name="example_table",
    start_time=datetime.now() - timedelta(hours=1),
    end_time=datetime.now(),
    exchange='binance',
    symbol="BTC/USDT",
    bucket_period="1 minute",
    sort_descending=False,
    limit=100
)
print("Historical data:", result['data'][:5])  # Print first 5 entries
print(f"Query performance: {result['query_performance_seconds']:.4f} seconds")

API Reference

BjarkanDataClient

The BjarkanDataClient class is used for interacting with the Bjarkan Historical Market Data service.

__init__(base_url: str = 'https://data.bjarkan.io')

Initialize the client with the base URL of the Bjarkan Data service.

authenticate(username: str, password: str)

Authenticate with the Data service using your username and password. This method must be called before making any other API calls.

Methods

  • get_tables() -> List[Dict[str, any]]
  • get_history(table_name: str, start_time: datetime, end_time: datetime, ...) -> Dict[str, any]
  • get_paginated_history(table_name: str, start_time: datetime, end_time: datetime, ...) -> Iterator[Dict[str, any]]
  • validate_bucket_period(bucket_period: str) -> bool

BjarkanSORClient

The BjarkanSORClient class is used for interacting with the Bjarkan Smart Order Router API.

__init__(base_url: str = 'https://api.bjarkan.io')

Initialize the client with the base URL of the Bjarkan SOR API service.

authenticate(username: str, password: str)

Authenticate with the SOR API service using your username and password. This method must be called before making any other API calls.

Methods

  • set_orderbook_config(config: Dict) -> Dict
  • get_orderbook_config() -> Dict
  • set_trades_config(config: Dict) -> Dict
  • get_trades_config() -> Dict
  • set_api_keys(api_configs: List[Dict]) -> Dict
  • get_api_keys() -> Dict
  • get_latest_orderbook() -> Dict
  • execute_order(order: Dict) -> Dict
  • get_balances() -> Dict

For detailed information on each method, please refer to the docstrings in the source code.

Examples

Setting Orderbook Configuration (SOR API)

sor_client = BjarkanSORClient()
sor_client.authenticate("your_username", "your_password")

orderbook_config = {
    "aggregated": True,
    "exchanges": ["binance", "okx", "htx"],
    "symbols": ["BTC/USDT", "ETH/USDT"],
    "depth": 10
}
result = sor_client.set_orderbook_config(orderbook_config)
print("Orderbook config set:", result)

Fetching Historical Data with Pagination (Data API)

from datetime import datetime, timedelta

data_client = BjarkanDataClient()
data_client.authenticate("your_username", "your_password")

start_time = datetime.now() - timedelta(days=1)
end_time = datetime.now()

for page in data_client.get_paginated_history(
    table_name="example_table",
    start_time=start_time,
    end_time=end_time,
    exchange="binance",
    symbol="BTC/USDT",
    bucket_period="5 minutes",
    page_size=500
):
    print(f"Retrieved {len(page['data'])} records")
    print(f"Query performance: {page['query_performance_seconds']:.4f} seconds")
    # Process the data in the current page
    for record in page['data']:
        # Do something with each record
        pass

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bjarkan_sdk-0.2.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

bjarkan_sdk-0.2.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file bjarkan_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: bjarkan_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for bjarkan_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a4c68a0b9aa42b8b83b40cac98a6915b9137f5b56a66a495a87a6d2f955354af
MD5 c67623c2cd0dd1b3bffa064ea006dc7f
BLAKE2b-256 ad785621d6d4e4f6d752efc07272fbc7822115a30f4299b45cdc9ec45b4d0282

See more details on using hashes here.

File details

Details for the file bjarkan_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: bjarkan_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for bjarkan_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d10be0748cfe26b6a5ff7fb3c4933cfbd6bc39b09cc8d234363ee8c59bd2297
MD5 9d524638e7fc96d2aacf506af4769ab4
BLAKE2b-256 1011f154906b16775a0b51907eb2c762323b98bc3a096a18b6ff4f6d2d121b04

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page