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.1.0.tar.gz (35.9 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.1.0-py3-none-any.whl (50.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zenotc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe59e09eb8f65ed7d796c365d2bab9c186d25090c13c79d504624fbeee49efd5
MD5 447c8a0ac711872d152840f18cf6f163
BLAKE2b-256 1b97df6cfd59d1e42e76965ef5504dd8d952c25e85af2cde98fa45a5fa7fc13c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zenotc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.7 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 480af70b3f0c2d8ea23e7aaff8491e06e7bba5c21f69d694985e0df4beaced80
MD5 e150c1c3c683311c9fae5c3bcdf7f66f
BLAKE2b-256 5472c2c81b72121b878b1993856cfc87f35d632d248b2b809a8b958a476217bd

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