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.2.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.2-py3-none-any.whl (51.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zenotc-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 1696afffb8ac0c35310dcc04b011ea1b5b7751ad46e48fb363a044929fa6a308
MD5 44a0bada45f7852ee760c14e36bc2886
BLAKE2b-256 729349963391339d95319d8bc6688495e9cd076001292aa82a7c0494da11f531

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zenotc-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 51.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fc1f8b86403a8b41f4d7e7c6cb661c4fbc0bc924d3e5101f6b0944aa45d00b50
MD5 698d5592fa26b58dc095e6e1b934a6c6
BLAKE2b-256 fa0a2d646c7470cb50804877e0e177aacb3007a9a031084903130ed3b2622384

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