Skip to main content

DESK Python SDK

Project description

DESK Python SDK

A Python client for interacting with DESK Exchange API, featuring JWT authentication and EVM wallet integration.

Features

  • EVM wallet integration
  • JWT-based authentication
  • Subaccount management
  • Type-safe API interactions
  • Real-time WebSocket support
  • Comprehensive error handling

Installation

pip install desk-python-sdk
# or
poetry add desk-python-sdk

Usage

Initialize the Client

from desk.auth import Auth
from desk.exchange import Exchange
from desk.info import Info

# Initialize authentication
auth = Auth(
    api_url="https://api.happytrading.global/",
    private_key="YOUR_PRIVATE_KEY",
    rpc_url="https://base-rpc.publicnode.com",
    chain_id=8453,  # Base Mainnet
    account="YOUR_ACCOUNT_ADDRESS",
    sub_account_id=0
)

# Initialize exchange client
exchange = Exchange(api_url="https://api.happytrading.global/", auth=auth)

# Initialize info client
info = Info(
    api_url="https://api.happytrading.global/",
    ws_url="wss://ws-api.happytrading.global/ws",
    skip_ws=False
)

Account Management

# Get account information
account_summary = info.get_subaccount_summary(account="YOUR_ACCOUNT", sub_account_id=0)

Trading Operations

from desk.enum import OrderSide, OrderType, TimeInForce, MarketSymbol

# Place a limit order
limit_order = exchange.place_order(
    symbol=MarketSymbol.BTCUSD,
    amount="0.001",
    price="99714.4",
    side=OrderSide.LONG,
    order_type=OrderType.LIMIT,
    time_in_force=TimeInForce.GTC,
    wait_for_reply=True
)

# Place a market order
market_order = exchange.place_order(
    symbol=MarketSymbol.BTCUSD,
    amount="0.001",
    price="92123.4",
    side=OrderSide.SHORT,
    order_type=OrderType.MARKET,
    wait_for_reply=True
)

# Cancel an order
exchange.cancel_order(
    symbol=MarketSymbol.BTCUSD,
    order_digest="ORDER_DIGEST",
    is_conditional_order=False,
    wait_for_reply=True
)

# Batch manage orders
exchange.batch_place_orders(
    orders=[
        {
            "symbol": "BTCUSD",
            "amount": "0.001",
            "price": "92123.4",
            "side": OrderSide.LONG,
            "order_type": OrderType.LIMIT,
            "time_in_force": TimeInForce.GTC
        },
        {
            "symbol": "BTCUSD",
            "amount": "0.001",
            "price": "92123.4",
            "side": OrderSide.SHORT,
            "order_type": OrderType.LIMIT,
            "time_in_force": TimeInForce.GTC
        }
    ]
)

# Batch Cancel Specific Orders
exchange.batch_cancel_order(
    orders=[
        {
            "symbol": "BTCUSD",
        },
        {
            "symbol": "ETHUSD",
            "order_digest": "ORDER_DIGEST"
        }
    ]
)

# Cancel all orders
exchange.cancel_all_orders(
    symbol=MarketSymbol.BTCUSD,
    is_conditional_order=False,
    wait_for_reply=True
)

WebSocket Streams

from datetime import datetime

# Subscribe to mark prices
info.subscribe(
    {"type": "markPricesV2"}, 
    lambda x: print("markprice: ", x['data'])
)

# Subscribe to orderbook
info.subscribe(
    {"type": "l2BookV2", "symbol": "BTCUSD"},
    lambda x: print("orderbook: ", x['data'])
)

Running examples

python examples/manage_order.py
python examples/get_info.py
python examples/deposit_withdraw.py

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

See the Contributor Guide for more details.

License

MIT License - see the LICENSE file for details.

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

desk_python_sdk-0.0.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

desk_python_sdk-0.0.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file desk_python_sdk-0.0.1.tar.gz.

File metadata

  • Download URL: desk_python_sdk-0.0.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0

File hashes

Hashes for desk_python_sdk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a9757b13561cec5991c24cb24a58d6b9845547866065b6810f3f1d85a1170529
MD5 67ed77efff3a78d57cb3cfa62e76ffb8
BLAKE2b-256 ba8bfd2918a9bef68c3c27ff0c0e0b3102cad80a4e3411fcfa43e74760dc51b8

See more details on using hashes here.

File details

Details for the file desk_python_sdk-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: desk_python_sdk-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0

File hashes

Hashes for desk_python_sdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da1aa4f967e8fa765de9aa385faa776d2b9e37c4120971db08fe839fff3c9f0d
MD5 4573a58b5fefd0ce97cb1f43e6f42f0f
BLAKE2b-256 8b2152c4b083c968386193c2a9ac0480f09bcd1cdcf2ef7a25945d4a08e15f87

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