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.0

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.0
File Size Uploaded Provenance
typed_margin_trade-0.1.0.tar.gz 58.2 kB With provenance Details

Built distribution (wheel)

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

Total release size: 173.6 kB

Release files / typed_margin_trade-0.1.0.tar.gz

Download URL typed_margin_trade-0.1.0.tar.gz
Size 58.2 kB
Tags Source
SHA-256 checksum
How to use checksums
efeeeff575784db819618afe7ebfb071d305144aca7c21c8ae55f631e298c592
BLAKE2b-256 checksum
How to use checksums
53a7f676874bff5659b44f37a748e10420e25536bdea755a27425a49ca898380
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 Oct 21, 2026.

Transparency log

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

Download URL typed_margin_trade-0.1.0-py3-none-any.whl
Size 115.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e79acba8a045215f9f5b02553d698fc55cdbc5c58d865cb1c2c63ffef1077c8a
BLAKE2b-256 checksum
How to use checksums
128eea94b4bec646aed29a65c2901a671c408e9f2c487a2042fc8ec7857de940
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 Oct 21, 2026.

Transparency log

Security for typed-margin-trade 0.1.0

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for typed_margin_trade-0.1.0.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 Oct 21, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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