Skip to main content

A Python SDK for accessing the Historical Market Data API of Bjarkan

Project description

Bjarkan Market Data SDK

A Python SDK for accessing the Historical Market Data API of Bjarkan.

Installation

You can install the Bjarkan Market Data SDK using pip:

pip install bjarkan-sdk

Usage

Here's a quick example of how to use the SDK:

from bjarkan_client import BjarkanClient
from datetime import datetime, timedelta

# Initialize the client
client = BjarkanClient("https://data.bjarkan.io")

# Authenticate
client.authenticate("your_username", "your_password")

# Get available tables
tables = client.get_tables()
print("Available tables:", tables)

# Get history for a specific table
result = 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("Data:", result['data'][:5])  # Print first 5 entries
print(f"Query performance: {result['query_performance_seconds']:.4f} seconds")

API Reference

BjarkanClient

The BjarkanClient class is the main interface for interacting with the Bjarkan Historical Market Data API.

__init__(base_url: str)

Initialize the client with the base URL of the Bjarkan Market Data API.

authenticate(username: str, password: str)

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

get_tables() -> List[Dict[str, any]]

Get a list of available tables and their configurations.

get_history(table_name: str, start_time: datetime, end_time: datetime, exchange: str = None, symbol: str = None, sort_descending: bool = False, bucket_period: str = None, limit: int = None, offset: int = None) -> Dict[str, any]

Retrieve historical data for a specific table.

Parameters:

  • table_name: Name of the table to query
  • start_time: Start time for the query (inclusive)
  • end_time: End time for the query (inclusive)
  • exchange: (Optional) Filter by exchange
  • symbol: (Optional) Filter by symbol
  • sort_descending: (Optional) Sort results in descending order if True
  • bucket_period: (Optional) Aggregation bucket period
  • limit: (Optional) Maximum number of records to return
  • offset: (Optional) Number of records to skip

Returns a dictionary containing:

  • data: List of historical data entries
  • query_performance_seconds: Time taken to execute the query in seconds

get_paginated_history(table_name: str, start_time: datetime, end_time: datetime, exchange: str = None, symbol: str = None, sort_descending: bool = False, bucket_period: str = None, page_size: int = 1000) -> Iterator[Dict[str, any]]

Retrieve historical data in pages. This method is useful for handling large datasets.

Parameters are the same as get_history, with the addition of:

  • page_size: Number of records to retrieve per page

Returns an iterator, where each iteration yields a dictionary containing:

  • data: List of historical data entries for the current page
  • query_performance_seconds: Time taken to execute the query for the current page in seconds

validate_bucket_period(bucket_period: str) -> bool

Validate if the given bucket period is valid. Valid periods are: ['100ms', '1s', '30s', '1 minute', '5 minutes', '15 minutes', '30 minutes', '1 hour'].

Examples

Fetching Available Tables

client = BjarkanClient("https://data.bjarkan.io")
client.authenticate("your_username", "your_password")

tables = client.get_tables()
for table in tables:
    print(f"Table: {table['table_name']}")
    print(f"Config: {table['config']}")
    print("---")

Fetching Historical Data with Pagination

from datetime import datetime, timedelta

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

for page in 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.1.14.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

bjarkan_sdk-0.1.14-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bjarkan_sdk-0.1.14.tar.gz
  • Upload date:
  • Size: 3.0 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.1.14.tar.gz
Algorithm Hash digest
SHA256 b75666a1dfdd5126a757e1894194e9a2bddebada1665943f6385f29434e1759a
MD5 f40c1b8df01fed267473ab90cd86c11e
BLAKE2b-256 718641cd8e3f0dd9a6562f2998106753f9098ca697062d68b81f94ac3093a47b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bjarkan_sdk-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 7cc55c9f24e43595d9dbbeb3c1fb4da7298facbee8209512f3884ec1fedc9bb0
MD5 b985be33c40df8d11224087ff887c56d
BLAKE2b-256 8312965214d15b03c91929efdf56c4c713f1dcdbc3c5c9beaeea3ced8189ccbe

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