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):- Key type. The closest thing to 0.x is using your trader key directly
(set
AVANTIS_PRIVATE_KEYto it, leaveAVANTIS_TRADER_ADDRESSunset). 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. - Execution route. The default relayer route is gasless (signed
intents, no ETH, no node).
AVANTIS_EXECUTION=directwithAVANTIS_RPC_URLreproduces 0.x behavior: the SDK signs EIP-1559 transactions and broadcasts them through your RPC. See Execution modes.
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 abuild_*_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
TradeInputstruct. Orders are keyword arguments; pairs are symbols or indexes interchangeably ("ETH/USD"or1), so there is noget_pair_indexround-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 fromaccount.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 withwait=True(default), the order executed. A declined fill (slippage etc.) raisesRelayErrorinstead. See Core concepts. - Typed errors. Pre-trade validation failures raise
ValidationErrorwith 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 old10_example_open_and_close_market_trade.py):
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 bypassedbuild_*_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.