Skip to main content

Python SDK for the Kaleidoswap protocol - Trade RGB assets on Lightning Network

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Kaleidoswap Python SDK

Pure Python SDK for interacting with the Kaleidoswap protocol. Trade RGB assets on Lightning Network with ease.

Installation

pip install kaleidoswap-sdk

Or with development dependencies:

pip install kaleidoswap-sdk[dev]

Quick Start

import asyncio
from kaleidoswap_sdk import KaleidoClient

async def main():
    # Create client
    client = KaleidoClient.create(
        base_url="https://api.kaleidoswap.com"
    )

    async with client:
        # List available assets
        assets = await client.maker.list_assets()
        for asset in assets.assets:
            print(f"{asset.ticker}: {asset.name}")

        # Get trading pairs
        pairs = await client.maker.list_pairs()
        for pair in pairs.pairs:
            print(f"{pair.base.ticker}/{pair.quote.ticker}")

asyncio.run(main())

Features

  • Async-first design - All API methods are async using asyncio
  • Type-safe - Full type hints with Pydantic models
  • Feature parity - Matches the TypeScript SDK 1-to-1

MakerClient (Market Operations)

# List assets
assets = await client.maker.list_assets()

# List trading pairs
pairs = await client.maker.list_pairs()

# Get a quote
quote = await client.maker.get_quote(PairQuoteRequest(...))

# Create swap order
order = await client.maker.create_swap_order(CreateSwapOrderRequest(...))

# Get order status
status = await client.maker.get_swap_order_status(SwapOrderStatusRequest(...))

# LSP operations
lsp_info = await client.maker.get_lsp_info()

RlnClient (RGB Lightning Node Operations)

Requires node_url configuration:

client = KaleidoClient.create(
    base_url="https://api.kaleidoswap.com",
    node_url="http://localhost:3000"
)

# Node info
info = await client.rln.get_node_info()

# BTC operations
balance = await client.rln.get_btc_balance()
address = await client.rln.get_address()

# RGB asset operations
assets = await client.rln.list_assets()
await client.rln.send_rgb(SendRgbRequest(...))

# Lightning channels
channels = await client.rln.list_channels()
await client.rln.open_channel(OpenChannelRequest(...))

# Payments
await client.rln.send_payment(SendPaymentRequest(...))

WebSocket Streaming

# Enable WebSocket
ws = client.maker.enable_websocket("wss://api.kaleidoswap.com/ws")

# Stream quotes
unsubscribe = await client.maker.stream_quotes(
    from_asset="BTC",
    to_asset="USDT",
    from_amount=100000,
    from_layer=Layer.BTC_LN,
    to_layer=Layer.RGB_LN,
    on_update=lambda quote: print(quote),
)

# Later: stop streaming
unsubscribe()
ws.disconnect()

Utility Functions

from kaleidoswap_sdk import to_smallest_units, to_display_units

# Convert BTC to satoshis
sats = to_smallest_units(1.5, 8)  # 150000000

# Convert satoshis to BTC
btc = to_display_units(150000000, 8)  # 1.5

Error Handling

from kaleidoswap_sdk import (
    KaleidoError,
    APIError,
    ValidationError,
    NotFoundError,
    NodeNotConfiguredError,
)

try:
    quote = await client.maker.get_quote(request)
except ValidationError as e:
    print(f"Invalid request: {e}")
except NotFoundError as e:
    print(f"Resource not found: {e}")
except APIError as e:
    print(f"API error ({e.status_code}): {e}")
except KaleidoError as e:
    print(f"SDK error: {e}")

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=kaleidoswap_sdk

# Type checking
mypy kaleidoswap_sdk

# Linting
ruff check kaleidoswap_sdk

License

MIT

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

kaleidoswap_sdk-0.5.1.tar.gz (202.8 kB view details)

Uploaded Source

Built Distribution

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

kaleidoswap_sdk-0.5.1-py3-none-any.whl (330.9 kB view details)

Uploaded Python 3

File details

Details for the file kaleidoswap_sdk-0.5.1.tar.gz.

File metadata

  • Download URL: kaleidoswap_sdk-0.5.1.tar.gz
  • Upload date:
  • Size: 202.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for kaleidoswap_sdk-0.5.1.tar.gz
Algorithm Hash digest
SHA256 9cf33b6665b962869462de64ce6397ef397b67438c4942aa05170d1505e535c3
MD5 8982040b94412359c8b51bff9ddd4a24
BLAKE2b-256 6a4aa020bc91602d5c12ddd988f6d0bf719f951294bcb1f479ad13f58b342f69

See more details on using hashes here.

File details

Details for the file kaleidoswap_sdk-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: kaleidoswap_sdk-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 330.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for kaleidoswap_sdk-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14dff54cd8676968c606955446eb49dfc0154c5614ece635422f85f5335a8354
MD5 2784e74dfa207060e48c5b93fe2acda9
BLAKE2b-256 75c57119acdbb7492142cfd5a9e4fd7a4f7e24fe3a78d59661de1ea0faa73a36

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