Skip to main content
SDK 2.0 is a ground-up rewrite for Avantis v2 and the 0.x/1.x API is removed; there is no compatibility layer. The good news: almost every 0.x flow collapses into a single call, and the things 0.x made you manage (RPC node, ABIs, gas, transaction receipts, USDC allowances before every session, trade indexes) are handled for you. The package name is unchanged (avantis-trader-sdk on PyPI); 2.0.0 is the v2 release. Pinning the old client is only a stopgap — Avantis v1 is superseded on-chain, so the 0.x SDK no longer trades:

The shape of the change

Client setup

Before (0.x):
After (2.x):
Two decisions to make once:
  1. Key type. The closest thing to 0.x is using your trader key directly (set AVANTIS_PRIVATE_KEY to it, leave AVANTIS_TRADER_ADDRESS unset). The recommended setup is an API key: a delegate key created with the Avantis API Key Generator that can trade but never withdraw. See Delegates.
  2. Execution route. The default relayer route is gasless (signed intents, no ETH, no node). AVANTIS_EXECUTION=direct with AVANTIS_RPC_URL reproduces 0.x behavior: the SDK signs EIP-1559 transactions and broadcasts them through your RPC. See Execution modes.
Signers: set_local_signer(key) is now just the env var; set_aws_kms_signer(...) became the KmsSigner class (pip install "avantis-trader-sdk[kms]"), passed to the client instead of a private key.

Trading methods

Every 0.x write was a build_*_tx + sign_and_get_receipt pair (plus a *_delegate twin). Each maps to one 2.x call on client.trade / client.account: Semantics that changed along the way:
  • No TradeInput struct. Orders are keyword arguments; pairs are symbols or indexes interchangeably ("ETH/USD" or 1), so there is no get_pair_index round-trip.
  • No manual trade index. 0.x made you pick the per-pair slot (index=0); 2.x assigns it. You only pass an index to target an existing position (close, margin, TP/SL), and it comes from account.positions().
  • Receipts are fill-aware on market orders. 0.x returned a transaction receipt and you slept 30 seconds hoping the keeper filled it. The 2.x batched-market route streams the order lifecycle: when trade.market_open(...) returns with wait=True (default), the order executed. A declined fill (slippage etc.) raises RelayError instead. See Core concepts.
  • Typed errors. Pre-trade validation failures raise ValidationError with a human-readable reason instead of reverting on-chain.
  • Units are unchanged: human units in, human units out (100 = 100 USDC).

Before / after: open and close

0.x (abridged from the old 10_example_open_and_close_market_trade.py):
2.x:

Market data and parameter reads

The 0.x read namespaces (pairs_cache, snapshot, asset_parameters, category_parameters, fee_parameters, trading_parameters, blended) were RPC multicall fan-outs. In 2.x, one snapshot call carries the full 100+ pair catalog, and the UI-parity math lives in pure functions under avantis_trader_sdk.compute: New in 2.x with no 0.x equivalent: compute.estimate_liquidation_price, compute.validate_order (full pre-trade validation, UI parity), compute.available_liquidity / max_position_size, TP/SL bounds helpers, markets.candles(...), and the whole client.info namespace (trade/order history with fee breakdowns, portfolio analytics, vault APY).

Price feeds

New v2 surface worth adopting

These have no 0.x equivalent and are the reason to migrate beyond compatibility:
  • Position increases: trade.increase_position(...) adds size to an open position instead of opening a parallel trade.
  • Partial TP/SL triggers: trade.partial_tp_sl(...) closes a slice at a trigger price (stored off-chain, executed by keepers). See TP/SL.
  • Coin-sized orders: trade.market_open_coin(...) / market_close_coin(...) size in base-asset units instead of USDC.
  • TWAP: trade.twap_open(...) / twap_close(...) / twap_cancel(...). See TWAP.
  • Builder codes: account.register_builder_code(...) for order-flow attribution and fees.

Market makers

If your 0.x integration bypassed build_*_tx for speed (raw transactions, custom signing), the 2.x equivalent is the local intent builder: client.local_intents() builds and signs EIP-712 order intents in microseconds with no I/O on the hot path, byte-for-byte verified against the on-chain hashing library. Combined with a nonce pool and wait=False submission, this is the intended MM hot path. See Market-maker fast path.