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.0.tar.gz (36.4 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.0-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zenotc-0.2.0.tar.gz
  • Upload date:
  • Size: 36.4 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.0.tar.gz
Algorithm Hash digest
SHA256 829691c8c5aa966efd3c36e4971d00c84bb69b1e8c891823641bfe1bedef0633
MD5 129ff0b9f37123f48a500778a4a09d67
BLAKE2b-256 245bf4e739b3075392a2b07da7b1d2ce7f81d846dff3f1911c86da36ba461587

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zenotc-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e51f875e35fc5a482c430037d7d2a8250c818e4c0da659173338cd1cca4ab14
MD5 f40a8a7343c4219aeeb8248964d64952
BLAKE2b-256 b1c16e1cc648cba056597a1d87d9db165be3a6805cb124196d401f06bd9f4f49

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