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

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.1
File Size Uploaded Provenance
typed_margin_trade-0.1.1.tar.gz 58.4 kB With provenance Details

Built distribution (wheel)

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

Total release size: 174.2 kB

Release files / typed_margin_trade-0.1.1.tar.gz

Download URL typed_margin_trade-0.1.1.tar.gz
Size 58.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ffd2ec0f3529de65e2905ffca270f1d7542b64202b4cf5bd3a6c98c434a62c2f
BLAKE2b-256 checksum
How to use checksums
63783de84b33768ab5471eb75624dbb57270df23588b6e8909ec4250a6558f30
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.1-py3-none-any.whl

Download URL typed_margin_trade-0.1.1-py3-none-any.whl
Size 115.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a952a2eab3db0c7678f009d2a86e30ec7249cf311d953df4abd4fbed1e08452
BLAKE2b-256 checksum
How to use checksums
cce4473ea33bc9620e8a61349872b844a8a4f6944ff29d07cd225cee016838aa
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.1

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