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
  • Multi-chain support

Installation

pip install desk-python-sdk

or

poetry add desk-python-sdk

Supported Chain

List of all supported chain.

Mainnet

  • Base (mainnet, mainnetBase, base)
  • Arbitrum One (mainnetArbitrum, arbitrum)
  • BNB Smart Chain (mainnetBsc, bsc)

Supported Tokens

  • USDC
  • cbBTC (base)
  • WETH (base)

List of functions

Info

    subscribe
    disconnect_websocket
    get_market_info
    get_mark_price
    get_collaterals_info
    get_last_trades
    get_subaccount_summary
    get_current_funding_rate
    get_historical_funding_rates
    get_trade_history

Exchange

    place_order
    batch_place_order
    cancel_order
    batch_cancel_order
    cancel_all_orders
    deposit_collateral
    withdraw_collateral

Usage

Initialize the Client

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

# Initialize authentication
auth = Auth(
    network="mainnet", # mainnet
    private_key="YOUR_PRIVATE_KEY",
    rpc_url="https://base-rpc.publicnode.com",
    account="YOUR_ACCOUNT_ADDRESS",
    sub_account_id=0
)

# Initialize exchange client
exchange = Exchange(
    network="mainnet", # mainnet, mainnetArbitrum
    auth=auth
)

# Initialize info client
info = Info(
    network="mainnet", # mainnet, mainnetArbitrum
    skip_ws=False
)

Account Management

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

# Get funding rates info
funding_rates = info.get_current_funding_rate("BTCUSD")

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 desk.enum import Subscription, MarketSymbol

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

# Subscribe to orderbook
info.subscribe(
    {"type": Subscription.ORDERBOOK, "symbol": MarketSymbol.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-1.1.0.tar.gz (16.6 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-1.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for desk_python_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 58477345e344c8215fed6df8e05d14c65f62ffe7d5d5d32cb4aee69f7b675196
MD5 5dfac5e9a9da5dbeb770da9f6538c7ac
BLAKE2b-256 4f50e943523ef33c30fc653fbf8d434ac74210f158651566b1d2abcff1508c8a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for desk_python_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12434af3a859179b5474488e8b67f4cf57371767124a3a96ba169c794d3e4646
MD5 796e7adf773f0118dfe4d38632e22357
BLAKE2b-256 aaf477dd830f327c9291c35b22e3d6eb1b9ac4b2cdaf7d2ce939a329188bbea8

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