Skip to main content

Python SDK for the Liquid trading API

Project description

liquidtrading-python

Official Python SDK for the Liquid trading API.

Installation

pip install liquidtrading-python
uv add liquidtrading-python

Quick Start

from liquidtrading import LiquidClient

client = LiquidClient(api_key="lq_...", api_secret="sk_...")
ticker = client.get_ticker("BTC-PERP")
print(f"BTC: {ticker.mark_price}")

Legacy compatibility import:

from liquid import Client

Authentication

client = LiquidClient(api_key="lq_...", api_secret="sk_...")

Hosted Liquid API requests currently require credentials:

client = LiquidClient(api_key="lq_...", api_secret="sk_...")
markets = client.get_markets()

Quick connectivity check after install:

liquidtrading-demo --base-url http://localhost:8001 --api-key lq_... --api-secret sk_...

If you also want to query open orders:

liquidtrading-demo --base-url http://localhost:8001 --api-key lq_... --api-secret sk_... --include-open-orders

Easiest local repo smoke test:

bash scripts/run_smoke_demo.sh --base-url http://localhost:8001 --api-key lq_... --api-secret sk_...

Alternative local repo smoke test:

uv run python examples/smoke_demo.py --base-url http://localhost:8001 --api-key lq_... --api-secret sk_...

Publishing guide:

See PUBLISHING.md

Methods

Market Data (public)

client.get_markets()                                    # list[dict]
client.get_ticker("BTC-PERP")                           # Ticker
client.get_orderbook("BTC-PERP", depth=20)              # Orderbook
client.get_candles("BTC-PERP", interval="1h", limit=100) # list[Candle]

Account (read scope)

client.get_account()      # Account
client.get_balances()     # Balance
client.get_positions()    # list[Position]

Orders (trade scope)

client.place_order("BTC-PERP", "buy", size=100, leverage=10)                    # Order
client.place_order("ETH-PERP", "sell", type="limit", size=500, leverage=5,
                   price=4000, tp=3800, sl=4200, time_in_force="gtc")           # Order
client.get_open_orders()                                                         # list[OpenOrder]
client.get_order("order-id")                                                     # Order
client.cancel_order("order-id")                                                  # bool
client.cancel_all_orders()                                                       # int

Positions (trade scope)

client.close_position("BTC-PERP")                       # CloseResult
client.set_tp_sl("BTC-PERP", tp=70000, sl=60000)        # TpSlResult
client.update_leverage("BTC-PERP", leverage=20)         # LeverageResult
client.update_margin("BTC-PERP", amount=50)             # MarginResult

Error Handling

from liquidtrading import (
    LiquidClient,
    AuthenticationError,
    InvalidSignatureError,
    InvalidApiKeyError,
    RateLimitError,
    InsufficientBalanceError,
    InsufficientScopeError,
)

try:
    order = client.place_order("BTC-PERP", "buy", size=100, leverage=10)
except InvalidApiKeyError:
    print("API key is invalid or revoked")
except InvalidSignatureError:
    print("Check your API secret")
except InsufficientScopeError:
    print("API key needs trade permissions")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except InsufficientBalanceError:
    print("Not enough balance")
except AuthenticationError:
    print("Other auth error")

All errors inherit from LiquidError. Auth errors: AuthenticationError, InvalidApiKeyError, InvalidSignatureError, ExpiredTimestampError, ReplayedNonceError. Permission errors: ForbiddenError, IpForbiddenError, InsufficientScopeError. Others: RateLimitError, ValidationError, InsufficientBalanceError, OrderRejectedError, SymbolNotFoundError, TimeoutError, ConnectionError, ServiceUnavailableError.

Client-side validation raises ValueError before the request is sent.

Rate Limits

Tier Requests/sec Orders/sec
free 10 2
trader 30 10
pro 100 50

Enable retries for transient 429s (GET only, exponential backoff):

client = LiquidClient(api_key="lq_...", api_secret="sk_...", max_retries=3)

MCP Server

The MCP server lives in the sibling ../liquidtrading-mcp/ repo and depends on this SDK as a published package.

Requirements

Python 3.9+ · httpx >= 0.25.0

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

liquidtrading_python-0.1.0.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

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

liquidtrading_python-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: liquidtrading_python-0.1.0.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for liquidtrading_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89417df261057bab4ed08e786dd604cda79dd6ab4dc84239cd7d9b1386102b64
MD5 d73dba1e6ff6eb4c739b31df4faa9bc0
BLAKE2b-256 8814ff168c68c4d300ef25629e8398f02d6a26456d9191a4d3ddfe8f2f97e7f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: liquidtrading_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for liquidtrading_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d0fc278c1b834e1012f56d072ac04b804d7ff5804d71379d85f1e43cf4be0e5
MD5 47ad3f14790473bb37a723a83dc8d7a0
BLAKE2b-256 6e4e3463835c4771869d0ebe47167b2b3efff4d5f8c43d2620580410f8d14b9b

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