Skip to main content

ZenOTC Python SDK for Algorithmic Trading

Project description

ZenOTC Python SDK

Official Python SDK for the ZenOTC OTC Trading Platform. Build and deploy algorithmic trading strategies with a clean, production-ready interface.

Open In Colab

Try the API interactively - Open the notebook in Google Colab to test REST API calls without any local setup.

Installation

pip install zenotc

Quick Start

from zenotc import ZenOTCClient

# Initialize the client
client = ZenOTCClient(
    api_key="your_api_key",
    api_secret="your_api_secret",
    environment="production"  # or "sandbox"
)

# Create an order
order = await client.execution.create_order(
    side="buy",
    asset="BTC",
    quantity=1.0,
    price=50000.00,
    order_type="limit"
)

print(f"Order created: {order.id}")

# Check order status
status = await client.execution.get_status(order.id)
print(f"Order status: {status.state}")

Features

ExecutionClient

Execute and manage orders.

# Create order
order = await client.execution.create_order(
    side="buy",
    asset="BTC",
    quantity=1.0,
    price=50000.00
)

# Cancel order
await client.execution.cancel_order(order.id)

# Get execution status
status = await client.execution.get_status(order.id)

# Batch orders
orders = await client.execution.create_batch([
    {"side": "buy", "asset": "BTC", "quantity": 0.5, "price": 49000},
    {"side": "buy", "asset": "ETH", "quantity": 5.0, "price": 3000},
])

MarketMakingClient

Submit and manage quotes for market makers.

# Submit a two-way quote
quote = await client.market_making.submit_quote(
    asset="BTC",
    bid_price=49900.00,
    ask_price=50100.00,
    bid_size=5.0,
    ask_size=5.0,
    valid_for_seconds=30
)

# Update quote
await client.market_making.update_quote(
    quote_id=quote.id,
    bid_price=49950.00,
    ask_price=50050.00
)

# Cancel quote
await client.market_making.cancel_quote(quote.id)

# Get active quotes
quotes = await client.market_making.get_active_quotes()

MarketDataClient

Access market data and real-time prices.

# Get current prices
prices = await client.market_data.get_prices(["BTC", "ETH"])

# Get order book
orderbook = await client.market_data.get_orderbook("BTC", depth=10)

# Subscribe to real-time prices (async)
async def on_price_update(price):
    print(f"{price.asset}: bid={price.bid}, ask={price.ask}")

await client.market_data.subscribe_prices(["BTC", "ETH"], on_price_update)

PortfolioClient

Track balances, positions, and exposure.

# Get all balances
balances = await client.portfolio.get_balances()

# Get specific asset balance
btc_balance = await client.portfolio.get_balance("BTC")

# Get positions
positions = await client.portfolio.get_positions()

# Get exposure summary
exposure = await client.portfolio.get_exposure()

# Get portfolio summary
summary = await client.portfolio.get_summary()

RiskClient

Pre-trade checks and risk management.

# Get current risk limits
limits = await client.risk.get_limits()

# Pre-trade risk check
check = await client.risk.pre_trade_check(
    side="buy",
    asset="BTC",
    quantity=10.0,
    price=50000.00
)

if check.approved:
    order = await client.execution.create_order(...)
else:
    print(f"Rejected: {check.reason}")
    print(f"Available: {check.available_quantity}")

# Get current exposure
exposure = await client.risk.get_exposure()

Configuration

Environment Variables

ZENOTC_API_KEY=your_api_key
ZENOTC_API_SECRET=your_api_secret
ZENOTC_ENVIRONMENT=production  # or sandbox
ZENOTC_BASE_URL=https://api.zenotc.com  # optional override

Client Configuration

from zenotc import ZenOTCClient, Config

config = Config(
    api_key="your_api_key",
    api_secret="your_api_secret",
    environment="production",
    timeout=30.0,
    max_retries=3,
    rate_limit_per_second=10,
)

client = ZenOTCClient(config=config)

Error Handling

from zenotc.exceptions import (
    ZenOTCError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    InsufficientFundsError,
    OrderNotFoundError,
)

try:
    order = await client.execution.create_order(...)
except AuthenticationError:
    print("Invalid API credentials")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except InsufficientFundsError as e:
    print(f"Insufficient funds. Available: {e.available}")
except ValidationError as e:
    print(f"Invalid request: {e.details}")
except ZenOTCError as e:
    print(f"API error: {e}")

Async Support

All clients support async operations:

import asyncio
from zenotc import AsyncZenOTCClient

async def main():
    client = AsyncZenOTCClient(
        api_key="your_api_key",
        api_secret="your_api_secret"
    )

    # Async order creation
    order = await client.execution.create_order(
        side="buy",
        asset="BTC",
        quantity=1.0,
        price=50000.00
    )

    # Async market data
    prices = await client.market_data.get_prices(["BTC", "ETH"])

    await client.close()

asyncio.run(main())

Development

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Type checking
mypy src

# Linting
ruff check .

License

Proprietary - ZenOTC

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

zenotc-0.2.1.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

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

zenotc-0.2.1-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zenotc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2effbb8f7e142649c9abbb6a460a05e5b7ea8e21894206a4b862d1492c4f5678
MD5 d544d6d006a7816e4af98a4f55fbbdb3
BLAKE2b-256 345b34a342eda7d28f7b368e4ad1959a555defb0fda9675f449b00b530c47d68

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for zenotc-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 691af1818f3627b1a168ef1954b5dcfa9e71375415ed904cf6f9518004a8abad
MD5 c27668e7ce28977ae3d5b05dc084c819
BLAKE2b-256 3d2f896c0c4d92b41e79f3497801fcc91d695b1a4acb51e399673135a13e811d

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