SDK for interacting with Avantis trading contracts.
Project description
Avantis Trader SDK
Python SDK for trading on Avantis - a perpetual trading platform on Base.
Installation
pip install avantis-trader-sdk
Quick Start
import asyncio
from avantis_trader_sdk import TraderClient
from avantis_trader_sdk.types import TradeInput, TradeInputOrderType
async def main():
# Initialize client
trader_client = TraderClient("https://mainnet.base.org")
trader_client.set_local_signer("0xYOUR_PRIVATE_KEY")
trader = trader_client.get_signer().get_ethereum_address()
# Check and approve USDC allowance
allowance = await trader_client.get_usdc_allowance_for_trading(trader)
if allowance < 100:
await trader_client.approve_usdc_for_trading(100)
# Open a 10x long ETH position with $100 collateral
trade_input = TradeInput(
trader=trader,
pair_index=1, # ETH/USD
collateral_in_trade=100,
is_long=True,
leverage=10,
tp=5000, # take profit
sl=2500, # stop loss
)
tx = await trader_client.trade.build_trade_open_tx(
trade_input, TradeInputOrderType.MARKET, slippage_percentage=1
)
receipt = await trader_client.sign_and_get_receipt(tx)
print("Trade opened!", receipt.transactionHash.hex())
asyncio.run(main())
Get Open Trades
trades, pending_orders = await trader_client.trade.get_trades(trader)
for trade in trades:
print(f"Pair: {trade.trade.pair_index}, Leverage: {trade.trade.leverage}x")
print(f"Entry: {trade.trade.open_price}, Liq: {trade.liquidation_price}")
Close a Trade
trade = trades[0]
close_tx = await trader_client.trade.build_trade_close_tx(
pair_index=trade.trade.pair_index,
trade_index=trade.trade.trade_index,
collateral_to_close=trade.trade.collateral_in_trade,
trader=trader,
)
await trader_client.sign_and_get_receipt(close_tx)
AI-Assisted Development
Building with AI tools? We provide optimized documentation:
- AGENT.md - Comprehensive guide for AI agents. Copy to your project or paste into AI chat.
- .cursorrules - Auto-loaded by Cursor IDE.
curl -o AGENT.md https://raw.githubusercontent.com/Avantis-Labs/avantis_trader_sdk/main/AGENT.md
Resources
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file avantis_trader_sdk-0.8.16.tar.gz.
File metadata
- Download URL: avantis_trader_sdk-0.8.16.tar.gz
- Upload date:
- Size: 8.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5449462af705cfe3ed9ca981f098d1eb58d1f64e3d32ad023c97c02d1e6bfb11
|
|
| MD5 |
b6f0dee9cd9c0e13d1167e1781185c52
|
|
| BLAKE2b-256 |
68170f03dba1842108167135f267e99bc449601d921e61cc52f11a7b22c3b919
|
File details
Details for the file avantis_trader_sdk-0.8.16-py3-none-any.whl.
File metadata
- Download URL: avantis_trader_sdk-0.8.16-py3-none-any.whl
- Upload date:
- Size: 9.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2757502a757927d8530a8871b68fe55608eb07c376ca0f91353b9ea23266ff6
|
|
| MD5 |
c5d254db93ec91689a5db87aa04a961d
|
|
| BLAKE2b-256 |
e22ddc4477686587038296399af4312c0e4ff67a744ecdd7e3109ccb90431499
|