Skip to main content

Typed Margin Trade

A fully typed, validated async client for the Margin Trade API.

PyPI version Python versions Docs License



from typed_margin_trade import MarginTrade

async with MarginTrade.new(public=True) as client:
  book = await client.info.l2_book('BTC')
  bids, asks = book['levels'] or ([], [])  # an empty book answers `levels: []`
  if bids and asks:
    print(bids[0]['px'], asks[0]['px'])

Why Typed Margin Trade?

  • 🎯 Precise Types: Typed requests and responses for every info, exchange, user, solana, public and CoinGecko call and WebSocket channel the client supports, not dict/Any; only a few nested lists the venue has only ever sent empty (fee tiers, order children) stay loosely typed.
  • ✅ Runtime Validation: Responses and stream pushes validated by default, with prices and sizes parsed to Decimal and timestamps to datetime.
  • ⚡ Async First: Async HTTP and WebSocket streaming over one shared connection each, with Ed25519 signing built in.
  • 📚 Full Surface: Market data, trading, agent wallets, transfers, withdrawals, account history, referrals and the testnet faucet, not just the popular calls.

Installation

pip install typed-margin_trade

Testnet And Mainnet

The client talks to mainnet by default. Pass mainnet=False for testnet: it picks the testnet host and signs every request for testnet, so a signed request is only valid on the network you chose. Testnet accounts can claim test USDC daily with user.faucet_claim(). The examples in these docs use testnet and read the key from MARGIN_TRADE_TESTNET_PRIVATE_KEY; see Authenticated Setup.

from typed_margin_trade import MarginTrade

async with MarginTrade.new(public=True, mainnet=False) as client:
  mids = await client.info.all_mids()  # testnet prices

How To

Reference

License

MIT — see LICENSE.

Metadata

Release files for typed-margin-trade 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for typed-margin-trade 0.1.2
File Size Uploaded Provenance Actions
typed_margin_trade-0.1.2.tar.gz 58.6 kB With provenance Details for typed_margin_trade-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for typed-margin-trade 0.1.2
File Interpreter ABI Platform Actions
typed_margin_trade-0.1.2-py3-none-any.whl Python 3 none any Details for typed_margin_trade-0.1.2-py3-none-any.whl

Total release size: 174.4 kB

Release files / typed_margin_trade-0.1.2.tar.gz

Download URL typed_margin_trade-0.1.2.tar.gz
Size 58.6 kB
Tags Source
SHA-256 checksum
How to use checksums
51a5f916f3a95c96fe15ef8ccc5f4a61901a3dd5dbf8e5c98114381071954137
BLAKE2b-256 checksum
How to use checksums
36caf0197661832eeb3dd11e366c0934b622e3b326fff08f12a3dc29c95a8cc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / typed_margin_trade-0.1.2-py3-none-any.whl

Download URL typed_margin_trade-0.1.2-py3-none-any.whl
Size 115.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70a8fd9f6a1084e3299da31b112cf0e1d1a990d7a265cdc387a6fc31136ebb0e
BLAKE2b-256 checksum
How to use checksums
92a86240bfab5a0826970a9c4957ffdbf1893edadded4549e38c3aa16f91e5d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for typed-margin-trade 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for typed_margin_trade-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page