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 (read scope)

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.1.tar.gz (41.1 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.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: liquidtrading_python-0.1.1.tar.gz
  • Upload date:
  • Size: 41.1 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.1.tar.gz
Algorithm Hash digest
SHA256 a32f80849314809e6b9ce6e8ed1cfef84cec2a564f652be2ac5adc7482132f93
MD5 037e1241e43fc6c020d74053fcae876d
BLAKE2b-256 d55aec8050e2d60f11c25cc560d67971d2d25f773f15e29694d605f8256d147e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: liquidtrading_python-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3a11144555a03dfdc3cc2a8d3fb84e8fca3d09b99463ec443913566c2daf51c
MD5 0da51026e99639036de347b42116376c
BLAKE2b-256 886ae32d4c8183841eedfcc8bf889e4ca861831684b1058bdaaaf99c7067e127

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