Skip to main content

Official Python client library for the Blocky Crypto Exchange API

Project description

Blocky Python SDK

Official Python client library for the Blocky Crypto Exchange API.

Features

  • 🔄 Sync & Async Support - Choose between synchronous (requests) or asynchronous (httpx) clients
  • 🌐 WebSocket Streams - Real-time orderbook and transaction updates
  • 🔒 Type-Safe - Full type annotations for better IDE support
  • Lightweight - Minimal dependencies
  • 📚 Well Documented - Comprehensive docstrings and examples

Installation

# Basic installation (sync client only)
pip install blockypy

# With async support
pip install blockypy[async]

# With WebSocket support
pip install blockypy[ws]

# Full installation (async + websocket + dev tools)
pip install blockypy[all]

Quick Start

Synchronous Client

from blocky import Blocky

# Public API (no authentication required)
client = Blocky()
markets = client.get_markets()
print(markets)

# Private API (requires API key)
client = Blocky(api_key="your-api-key")
wallets = client.get_wallets()
print(wallets)

Asynchronous Client

import asyncio
from blocky import AsyncBlocky

async def main():
    # Using context manager (recommended)
    async with AsyncBlocky(api_key="your-api-key") as client:
        markets = await client.get_markets()
        wallets = await client.get_wallets()
        print(markets, wallets)

asyncio.run(main())

WebSocket Client

import asyncio
from blocky import BlockyWebSocket

async def on_orderbook(data):
    print(f"Orderbook spread: {data['spread']}")

async def on_trade(data):
    print(f"Trade: {data['price']} x {data['quantity']}")

async def main():
    async with BlockyWebSocket() as ws:
        # Subscribe using convenience methods
        await ws.subscribe_orderbook("xno_xbrl", on_orderbook)
        await ws.subscribe_transactions("xno_xbrl", on_trade)
        
        # Or use generic subscribe with channel string
        # await ws.subscribe("xno_xbrl:orderbook", on_orderbook)
        
        # Run until cancelled (Ctrl+C)
        await ws.run_forever()

asyncio.run(main())

API Reference

Public Endpoints

These endpoints don't require authentication:

# Get all markets
markets = client.get_markets(get_tickers=True)

# Get specific market
market = client.get_market("xno_xbrl")

# Get 24h ticker
ticker = client.get_ticker("xno_xbrl")

# Get recent trades
transactions = client.get_transactions("xno_xbrl", count=100)

# Get orderbook
orderbook = client.get_orderbook("xno_xbrl", depth=50)

# Get OHLCV/candlestick data
ohlcv = client.get_ohlcv("xno_xbrl", timeframe="1H")

Private Endpoints

These endpoints require an API key:

Wallets

# Get all wallets
wallets = client.get_wallets()

# Get specific wallet
wallet = client.get_wallet("xbrl")

# Get wallet with frozen balance
wallet = client.get_wallet("xbrl", get_frozen=True)

Orders

# Create limit order
order = client.create_order(
    type_="limit",
    market="xno_xbrl",
    side="buy",
    price="100.00",
    quantity="1.5"
)

# Create market order
order = client.create_order(
    type_="market",
    market="xno_xbrl",
    side="buy",
    total="100.00"  # Amount to spend
)

# Get orders
orders = client.get_orders(limit=50, statuses=["open"])

# Cancel order
client.cancel_order(order_id=123)

# Cancel all orders
client.cancel_orders()

Trades

# Get trade history
trades = client.get_trades(limit=100, markets=["xno_xbrl"])

Transfers

# Transfer between sub-wallets
transfer = client.create_transfer(
    instrument="xbrl",
    quantity="100",
    source_sub_wallet_id=0,
    destination_sub_wallet_id=1,
    memo="Savings"
)

# Get transfer history
transfers = client.get_transfers()

Deposits & Withdrawals

# Get deposit history
deposits = client.get_deposits(instruments=["xbrl"])

# Get withdrawal history
withdrawals = client.get_withdrawals()

# Get combined history
history = client.get_deposits_and_withdrawals()

Error Handling

The SDK provides custom exceptions for different error types:

from blocky import (
    Blocky,
    BlockyError,
    BlockyAPIError,
    BlockyAuthenticationError,
    BlockyNetworkError,
    BlockyValidationError,
)

try:
    client = Blocky(api_key="invalid-key")
    client.get_wallets()
except BlockyAuthenticationError as e:
    print(f"Auth failed: {e}")
except BlockyAPIError as e:
    print(f"API error [{e.status_code}]: {e.message}")
except BlockyNetworkError as e:
    print(f"Network error: {e}")
except BlockyValidationError as e:
    print(f"Validation error: {e}")
except BlockyError as e:
    print(f"General error: {e}")

Configuration

Custom Endpoint

client = Blocky(
    api_key="your-api-key",
    endpoint="https://custom.blocky.com.br/api/v1"
)

Custom Timeout

client = Blocky(
    api_key="your-api-key",
    timeout=60.0  # seconds
)

Timeframes

For OHLCV data, the following timeframe strings are supported:

Timeframe Description
1m 1 minute
3m 3 minutes
5m 5 minutes
15m 15 minutes
30m 30 minutes
1H 1 hour
2H 2 hours
4H 4 hours
6H 6 hours
8H 8 hours
12H 12 hours
1D 1 day
3D 3 days
1W 1 week
1M 1 month

License

MIT License - see LICENSE for details.

Links

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

blockypy-0.2.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blockypy-0.2.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file blockypy-0.2.1.tar.gz.

File metadata

  • Download URL: blockypy-0.2.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for blockypy-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e79f9c20ecbc96870afcd77b298b917bb59d3b8251e8a263679598d6c30d5296
MD5 e9a2d1a4811ed1beaee1a84c1126f6ba
BLAKE2b-256 a857a585954cf4a6833991cad73d2d1c5e1a44d00c180f2f621a36c508fae0ab

See more details on using hashes here.

File details

Details for the file blockypy-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: blockypy-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for blockypy-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 98f2e2c4a37d164a59f333f5875c1db756f64d189d7d636f70df9c709bf8ee24
MD5 a95c62090cc3acbd8d3b370adacb07be
BLAKE2b-256 efa5864e1fbef42fb9de5ad5f0bb06cbbe51bf2aa4288bbc4a8b420c9a9f4a01

See more details on using hashes here.

Supported by

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