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.2.tar.gz (203.3 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.2-py3-none-any.whl (331.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kaleidoswap_sdk-0.5.2.tar.gz
  • Upload date:
  • Size: 203.3 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.2.tar.gz
Algorithm Hash digest
SHA256 5d123f25b3427471d81b3fe0116aace1d51a56f05f1676edbe57180cb8d47607
MD5 93b3a0b7a46af980026d6d00d36a6fa1
BLAKE2b-256 7e7e69b2967b4de5906e34cad0d76639f17db6f43955e76609b2dc4c252ff479

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kaleidoswap_sdk-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 331.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d0ccd8111880a400efbae6bb7705ce4171e7cd06e84d1f4a9d1b58836a745e0c
MD5 3794b7814d6de3a3e8c407c0c4c2373f
BLAKE2b-256 1487b197e900421f8b0a98293ce5761a76de1751ab5910fda2dfd8ca727093c6

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