Skip to main content

Python SDK for the True Markets public API.

Project description

truemarkets

Python SDK for the True Markets public API.

Install

pip install truemarkets

Requires Python 3.10+.

Quickstart

Sign up for and fund your TrueMarkets account on https://truemarkets.co/. Follow our onboarding documentation to get started.

Set TM_KEY_FILE (and optionally TM_ENV=prod) in a .env file or your shell environment:

# .env
TM_ENV=prod
TM_KEY_FILE=/path/to/truemarkets-api-key-XXXXXXXX.json

Then call any operation on c.gateway or c.defi. Methods are generated from the OpenAPI spec and named after the spec's operationIds, so the full surface is discoverable via dir(c.gateway):

from truemarkets import Client
from truemarkets._generated.gateway.models import (
    OrderSide,
    QuoteRequest,
    QuoteRequestQtyUnit,
)

with Client() as c:
    q = c.gateway.compute_quote(body=QuoteRequest(
        base_asset="BTC", quote_asset="USDC",
        qty="25", qty_unit=QuoteRequestQtyUnit.QUOTE, side=OrderSide.BUY,
    ))

print(f"{q.qty} BTC @ {q.price} USDC/BTC")

Client() auto-loads .env from the current working directory (walking up).

API surface

  • c.gateway.<operation_id>compute_quote, create_order, execute_order, cancel_order, get_order_status, list_orders, create_transfer, execute_transfer, list_transfers, get_transfer, list_assets, list_balances, get_balances.
  • c.defi.<operation_id>get_assets, get_asset_by_chain_and_address, get_balances, get_history, get_profile, create_quote, execute_trade, prepare_transfer, execute_transfer, create_wallet, prepare_wallet_export, execute_wallet_export, get_watchlists, get_watchlist_by_id.
  • c.sign_turnkey(payload) — stamp a Turnkey activity payload with the cached API key.
  • truemarkets.auth.{load_key_file, mint_token, refresh_token, sign_challenge, turnkey_stamp} — low-level helpers.

Models live under truemarkets._generated.{gateway,defi,authapi}.models. Operations return the parsed response model directly.

Telemetry

The SDK ships with opt-out telemetry so we can prioritize features against real usage. The data is intentionally narrow: operation, status, latency, SDK version. We never see request bodies, response bodies, headers, API keys, or anything identifying a wallet/asset/human.

Events

Event When Properties
sdk_initialized Client() sdk_lang, sdk_version, runtime
sdk_authenticated c.authenticate() succeeds sdk_lang, sdk_version, is_refresh
sdk_request Each HTTP response sdk_lang, sdk_version, method, path, status, latency_ms, ok

Identity

distinct_id is derived in priority order:

  1. The JWT's raw uid claim — a stable user UUID, set after the first successful authenticate().
  2. sha256(api_key_id)[:16] — once the key file is loaded, before first auth.
  3. A per-process UUID — fully anonymous (e.g. read-only Marketdata calls).

On successful auth, the SDK sends an identify event attaching two properties to the user: the raw uid and hashed_email = sha256(jwt.sub)[:16] — the email is one-way hashed before leaving the SDK and is never sent in raw form.

Alias events bridge the pre-auth identities under the user uid as identity gets promoted, so the same human counts as one user across key rotations and token refreshes.

Disable

Either env var disables telemetry before any analytics code initializes:

TM_TELEMETRY=0       # 0|false|no|off
DO_NOT_TRACK=1       # 1|true|yes|on — industry convention

Flushing

Events are buffered and flushed asynchronously from a daemon thread. with Client() as c: ... flushes on __exit__; for ad-hoc scripts that don't use the context manager, call c.close() before exit.

DeFi trades

DeFi orders return Turnkey activity payloads that the SDK signs locally with your API key:

from truemarkets import Client
from truemarkets._generated.gateway.models import (
    Chain,
    CreateOrderRequest,
    CreateOrderRequestQtyUnit,
    ExecuteOrderRequest,
    OrderSide,
    OrderType,
    SigningMethod,
)

with Client() as c:
    order = c.gateway.create_order(body=CreateOrderRequest(
        base_asset="0xbaa5...",      # MORPHO
        quote_asset="0x8335...",     # USDC
        qty="0.5", qty_unit=CreateOrderRequestQtyUnit.BASE,
        side=OrderSide.SELL, type_=OrderType.MARKET, chain=Chain.BASE,
    ))
    stamps = [c.sign_turnkey(p.payload) for p in (order.payloads or [])]
    c.gateway.execute_order(
        id=order.order_id,
        body=ExecuteOrderRequest(signatures=stamps, auth_type=SigningMethod.API_KEY),
    )

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

truemarkets-0.2.3.tar.gz (87.4 kB view details)

Uploaded Source

Built Distribution

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

truemarkets-0.2.3-py3-none-any.whl (239.6 kB view details)

Uploaded Python 3

File details

Details for the file truemarkets-0.2.3.tar.gz.

File metadata

  • Download URL: truemarkets-0.2.3.tar.gz
  • Upload date:
  • Size: 87.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for truemarkets-0.2.3.tar.gz
Algorithm Hash digest
SHA256 f9cbeee30c7d7bf2af6cd01e8ccf705b6edd2836b271713c1830f3f35e8366e9
MD5 4b1bd38fbdeba033910344a37f1205f9
BLAKE2b-256 202b967adbe6f128b5c23414497af7b667aec6f7171bce7e713da4bfd4a2971f

See more details on using hashes here.

File details

Details for the file truemarkets-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: truemarkets-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 239.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for truemarkets-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0164b4c1b75bc3c3fea14e4b9171267158f2b8e1d09cbcc9c53df36f8727993b
MD5 5c50eb27f331cc8e2271ffadd17ae723
BLAKE2b-256 094ac735a3859b396d96ee2f31d28c65ef87d14514cc6c07235d51227d612256

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