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 querystart_time
: Start time for the query (inclusive)end_time
: End time for the query (inclusive)exchange
: (Optional) Filter by exchangesymbol
: (Optional) Filter by symbolsort_descending
: (Optional) Sort results in descending order if Truebucket_period
: (Optional) Aggregation bucket periodlimit
: (Optional) Maximum number of records to returnoffset
: (Optional) Number of records to skip
Returns a dictionary containing:
data
: List of historical data entriesquery_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 pagequery_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b75666a1dfdd5126a757e1894194e9a2bddebada1665943f6385f29434e1759a |
|
MD5 | f40c1b8df01fed267473ab90cd86c11e |
|
BLAKE2b-256 | 718641cd8e3f0dd9a6562f2998106753f9098ca697062d68b81f94ac3093a47b |
File details
Details for the file bjarkan_sdk-0.1.14-py3-none-any.whl
.
File metadata
- Download URL: bjarkan_sdk-0.1.14-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc55c9f24e43595d9dbbeb3c1fb4da7298facbee8209512f3884ec1fedc9bb0 |
|
MD5 | b985be33c40df8d11224087ff887c56d |
|
BLAKE2b-256 | 8312965214d15b03c91929efdf56c4c713f1dcdbc3c5c9beaeea3ced8189ccbe |