avantis-trader-sdk 0.8.14__py3-none-any.whl → 0.8.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,4 +3,4 @@ from .feed.feed_client import FeedClient
3
3
  from .signers.base import BaseSigner
4
4
  from .types import PriceSourcing
5
5
 
6
- __version__ = "0.8.14"
6
+ __version__ = "0.8.15"
@@ -308,6 +308,28 @@ class FeedClient:
308
308
  data = response.json()
309
309
  return FeedV3PriceResponse(**data)
310
310
 
311
+ async def get_latest_lazer_price(
312
+ self, lazer_feed_ids: List[int]
313
+ ) -> LazerPriceFeedResponse:
314
+ """
315
+ Retrieves the latest prices from the Pyth Lazer API.
316
+
317
+ Args:
318
+ lazer_feed_ids: List of Lazer feed IDs to get prices for.
319
+
320
+ Returns:
321
+ A LazerPriceFeedResponse containing the latest prices.
322
+
323
+ Raises:
324
+ requests.HTTPError: If the API request fails.
325
+ """
326
+ params = "&".join([f"price_feed_ids={fid}" for fid in lazer_feed_ids])
327
+ url = f"{self.lazer_sse_url.replace('/stream', '/latest_price')}?{params}"
328
+ response = requests.get(url, timeout=10)
329
+ response.raise_for_status()
330
+ data = response.json()
331
+ return LazerPriceFeedResponse(**data)
332
+
311
333
  async def listen_for_lazer_price_updates(
312
334
  self,
313
335
  lazer_feed_ids: List[int],
@@ -74,11 +74,15 @@ class TradeRPC:
74
74
  trade_input_order_type == TradeInputOrderType.MARKET
75
75
  or trade_input_order_type == TradeInputOrderType.MARKET_ZERO_FEE
76
76
  ) and not trade_input.openPrice:
77
- pair_name = await self.client.pairs_cache.get_pair_name_from_index(
77
+ lazer_feed_id = await self.client.pairs_cache.get_lazer_feed_id(
78
78
  trade_input.pairIndex
79
79
  )
80
- price_data = await self.feed_client.get_latest_price_updates([pair_name])
81
- price = int(price_data.parsed[0].converted_price * 10**10)
80
+ price_data = await self.feed_client.get_latest_lazer_price([lazer_feed_id])
81
+ price_feed = next(
82
+ (f for f in price_data.price_feeds if f.price_feed_id == lazer_feed_id),
83
+ price_data.price_feeds[0],
84
+ )
85
+ price = int(price_feed.converted_price * 10**10)
82
86
  trade_input.openPrice = price
83
87
 
84
88
  if (
@@ -137,11 +141,15 @@ class TradeRPC:
137
141
  trade_input_order_type == TradeInputOrderType.MARKET
138
142
  or trade_input_order_type == TradeInputOrderType.MARKET_ZERO_FEE
139
143
  ) and not trade_input.openPrice:
140
- pair_name = await self.client.pairs_cache.get_pair_name_from_index(
144
+ lazer_feed_id = await self.client.pairs_cache.get_lazer_feed_id(
141
145
  trade_input.pairIndex
142
146
  )
143
- price_data = await self.feed_client.get_latest_price_updates([pair_name])
144
- price = int(price_data.parsed[0].converted_price * 10**10)
147
+ price_data = await self.feed_client.get_latest_lazer_price([lazer_feed_id])
148
+ price_feed = next(
149
+ (f for f in price_data.price_feeds if f.price_feed_id == lazer_feed_id),
150
+ price_data.price_feeds[0],
151
+ )
152
+ price = int(price_feed.converted_price * 10**10)
145
153
  trade_input.openPrice = price
146
154
 
147
155
  if (
@@ -163,8 +171,6 @@ class TradeRPC:
163
171
  }
164
172
  )
165
173
 
166
- print("transaction: ", trade_input.trader)
167
-
168
174
  delegate_transaction = await Trading.functions.delegatedAction(
169
175
  trade_input.trader, transaction["data"]
170
176
  ).build_transaction(
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: avantis_trader_sdk
3
+ Version: 0.8.15
4
+ Summary: SDK for interacting with Avantis trading contracts.
5
+ Home-page: https://avantisfi.com/
6
+ Author: Avantis Labs
7
+ Author-email: yug@avantisfi.com
8
+ License: MIT
9
+ Keywords: trading sdk blockchain ethereum web3 avantis
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: web3<7,>=6.15.1
16
+ Requires-Dist: pydantic<3,>=2.8.2
17
+ Requires-Dist: websockets<14,>=12.0
18
+ Requires-Dist: boto3<2,>=1.35.44
19
+ Requires-Dist: eth_account<0.14,>=0.10.0
20
+ Requires-Dist: toolz<1,>=0.12.1
21
+ Requires-Dist: eth_utils<5,>=2.1.0
22
+ Requires-Dist: pyasn1<1,>=0.6.1
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: keywords
30
+ Dynamic: license
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ # Avantis Trader SDK
36
+
37
+ Python SDK for trading on [Avantis](https://avantisfi.com/) - a perpetual trading platform on Base.
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install avantis-trader-sdk
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ```python
48
+ import asyncio
49
+ from avantis_trader_sdk import TraderClient
50
+ from avantis_trader_sdk.types import TradeInput, TradeInputOrderType
51
+
52
+ async def main():
53
+ # Initialize client
54
+ trader_client = TraderClient("https://mainnet.base.org")
55
+ trader_client.set_local_signer("0xYOUR_PRIVATE_KEY")
56
+
57
+ trader = trader_client.get_signer().get_ethereum_address()
58
+
59
+ # Check and approve USDC allowance
60
+ allowance = await trader_client.get_usdc_allowance_for_trading(trader)
61
+ if allowance < 100:
62
+ await trader_client.approve_usdc_for_trading(100)
63
+
64
+ # Open a 10x long ETH position with $100 collateral
65
+ trade_input = TradeInput(
66
+ trader=trader,
67
+ pair_index=1, # ETH/USD
68
+ collateral_in_trade=100,
69
+ is_long=True,
70
+ leverage=10,
71
+ tp=5000, # take profit
72
+ sl=2500, # stop loss
73
+ )
74
+
75
+ tx = await trader_client.trade.build_trade_open_tx(
76
+ trade_input, TradeInputOrderType.MARKET, slippage_percentage=1
77
+ )
78
+ receipt = await trader_client.sign_and_get_receipt(tx)
79
+ print("Trade opened!", receipt.transactionHash.hex())
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ ## Get Open Trades
85
+
86
+ ```python
87
+ trades, pending_orders = await trader_client.trade.get_trades(trader)
88
+
89
+ for trade in trades:
90
+ print(f"Pair: {trade.trade.pair_index}, Leverage: {trade.trade.leverage}x")
91
+ print(f"Entry: {trade.trade.open_price}, Liq: {trade.liquidation_price}")
92
+ ```
93
+
94
+ ## Close a Trade
95
+
96
+ ```python
97
+ trade = trades[0]
98
+ close_tx = await trader_client.trade.build_trade_close_tx(
99
+ pair_index=trade.trade.pair_index,
100
+ trade_index=trade.trade.trade_index,
101
+ collateral_to_close=trade.trade.collateral_in_trade,
102
+ trader=trader,
103
+ )
104
+ await trader_client.sign_and_get_receipt(close_tx)
105
+ ```
106
+
107
+ ## AI-Assisted Development
108
+
109
+ Building with AI tools? We provide optimized documentation:
110
+
111
+ - [AGENT.md](./AGENT.md) - Comprehensive guide for AI agents. Copy to your project or paste into AI chat.
112
+ - [.cursorrules](./.cursorrules) - Auto-loaded by Cursor IDE.
113
+
114
+ ```bash
115
+ curl -o AGENT.md https://raw.githubusercontent.com/Avantis-Labs/avantis_trader_sdk/main/AGENT.md
116
+ ```
117
+
118
+ ## Resources
119
+
120
+ - [Documentation](https://sdk.avantisfi.com/)
121
+ - [Examples](https://github.com/Avantis-Labs/avantis_trader_sdk/tree/main/examples)
122
+ - [Avantis Docs](https://docs.avantisfi.com/)
123
+
124
+ ## License
125
+
126
+ MIT
@@ -1,4 +1,4 @@
1
- avantis_trader_sdk/__init__.py,sha256=piAMiNqSagDn1nQUlJ2y5v_egZfg11Aui8ly04gjbKQ,168
1
+ avantis_trader_sdk/__init__.py,sha256=qpix2Zruoll9hF1RrY9b0Z2na5gVuibZalTuAHJX_04,168
2
2
  avantis_trader_sdk/client.py,sha256=M01uwXIdxJjmPEcFr1MsDuoxU9YGddxcGMTPucOOssA,10903
3
3
  avantis_trader_sdk/config.py,sha256=sE9y9R1ql1UwpFSs-qTbNfvO5iffRRUdYtx_JVOaWyA,838
4
4
  avantis_trader_sdk/types.py,sha256=spp3n7UedgVM-w9JyCzQuqi8JiJmSjm24j4cxg0-gx8,17274
@@ -195,7 +195,7 @@ avantis_trader_sdk/crypto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
195
195
  avantis_trader_sdk/crypto/spki.py,sha256=CNy7A8TTwBHiNSzIj7uqiHKAeLcn1Q9MbszW_2mdXgI,3080
196
196
  avantis_trader_sdk/feed/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
197
197
  avantis_trader_sdk/feed/feedIds.json,sha256=T77nww3eRiQt8rqZBDpdxA49USGyfI0dQBPnzo-H1dE,6697
198
- avantis_trader_sdk/feed/feed_client.py,sha256=sMlf6XaMoAiJ4DSxim-Bd81kPlM2laT0QmLbMfR6P9Q,12989
198
+ avantis_trader_sdk/feed/feed_client.py,sha256=fwdmS_9b6N-CAbmu2Lq_26uKahMLsYKNglg6XF8xZHQ,13755
199
199
  avantis_trader_sdk/rpc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
200
200
  avantis_trader_sdk/rpc/asset_parameters.py,sha256=ESx4eg0K3W9EigsEmN0a7Pym2hL4iJgMWmzhHmmWXyY,19323
201
201
  avantis_trader_sdk/rpc/blended.py,sha256=tRWfO7XreY_YahL9ACpss7ylWz5fdk6G3bv4QpLpGms,2441
@@ -204,7 +204,7 @@ avantis_trader_sdk/rpc/fee_parameters.py,sha256=0UCf4FZQp26777o8aA75oOO-b3xFK88c
204
204
  avantis_trader_sdk/rpc/pairs_cache.py,sha256=wtxkvaemVbJclCSiOcyelbBcQzwJbIOP0JF0rfyE56M,7234
205
205
  avantis_trader_sdk/rpc/rpc_helpers.py,sha256=Sywz6BIj4y2gkudkOhPEND2r2ILvtfq502A_pSEUDv8,284
206
206
  avantis_trader_sdk/rpc/snapshot.py,sha256=hfLRfCbOqnqcuZncaiTmm0BJ2pgLFOEHgsgQ-92Xlcs,5352
207
- avantis_trader_sdk/rpc/trade.py,sha256=QZCc0wU_7tPzC_Bo32JlSxcDZZF7NK-udqNG54myizM,31940
207
+ avantis_trader_sdk/rpc/trade.py,sha256=EB9JEAih2s0y3h2Y1VnYboc7-gQQe-aQa3RBoseAiwk,32220
208
208
  avantis_trader_sdk/rpc/trading_parameters.py,sha256=_tpzgyMO_I-XebVWtiWSlmedtbr66elUxCRgegd1aao,4626
209
209
  avantis_trader_sdk/signers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
210
210
  avantis_trader_sdk/signers/base.py,sha256=QaOu0CxFq60oR4LegCp1XwONMQx8ZShXyiLZvfcbCPM,260
@@ -212,7 +212,7 @@ avantis_trader_sdk/signers/kms_signer.py,sha256=lxK3f9KQsdCDAvOE1SHleKjI8zD_3PTv
212
212
  avantis_trader_sdk/signers/local_signer.py,sha256=kUx5vExiBfvFGmoMCFR6b7_4cXx2mvYOJNqZQDIEcG8,505
213
213
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
214
214
  tests/test_client.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
215
- avantis_trader_sdk-0.8.14.dist-info/METADATA,sha256=l4vQYzfNXuKcECXL-Y1xHmDdrwvm5s_eok3AZmAJOwo,5032
216
- avantis_trader_sdk-0.8.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
217
- avantis_trader_sdk-0.8.14.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
218
- avantis_trader_sdk-0.8.14.dist-info/RECORD,,
215
+ avantis_trader_sdk-0.8.15.dist-info/METADATA,sha256=1XhW8Ak1oBkrDgb2UBASGfWIV2et7Pnt6tAliqbnUUo,3514
216
+ avantis_trader_sdk-0.8.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
217
+ avantis_trader_sdk-0.8.15.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
218
+ avantis_trader_sdk-0.8.15.dist-info/RECORD,,
@@ -1,124 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: avantis_trader_sdk
3
- Version: 0.8.14
4
- Summary: SDK for interacting with Avantis trading contracts.
5
- Home-page: https://avantisfi.com/
6
- Author: Avantis Labs
7
- Author-email: yug@avantisfi.com
8
- License: MIT
9
- Keywords: trading sdk blockchain ethereum web3 avantis
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Requires-Python: >=3.6
14
- Description-Content-Type: text/markdown
15
- Requires-Dist: web3<7,>=6.15.1
16
- Requires-Dist: pydantic<3,>=2.8.2
17
- Requires-Dist: websockets<14,>=12.0
18
- Requires-Dist: boto3<2,>=1.35.44
19
- Requires-Dist: eth_account<0.14,>=0.10.0
20
- Requires-Dist: toolz<1,>=0.12.1
21
- Requires-Dist: eth_utils<5,>=2.1.0
22
- Requires-Dist: pyasn1<1,>=0.6.1
23
- Dynamic: author
24
- Dynamic: author-email
25
- Dynamic: classifier
26
- Dynamic: description
27
- Dynamic: description-content-type
28
- Dynamic: home-page
29
- Dynamic: keywords
30
- Dynamic: license
31
- Dynamic: requires-dist
32
- Dynamic: requires-python
33
- Dynamic: summary
34
-
35
- # Welcome to Avantis Trader SDK’s documentation!
36
-
37
- Avantis Trader SDK is a powerful and flexible toolkit for trading on the Avantis platform. This documentation will guide you through the installation process, basic usage, and advanced features of the SDK.
38
-
39
- ## 📚 [Read the Full Documentation Here](https://sdk.avantisfi.com/)
40
-
41
- Contents:
42
-
43
- - [Introduction](#introduction)
44
- - [About Avantis](#about-avantis)
45
- - [Purpose of the Avantis Trader SDK](#purpose-of-the-avantis-trader-sdk)
46
- - [Getting Started](#getting_started)
47
- - [Installation](#installation)
48
- - [Next Steps](#next-steps)
49
- - [Examples](#examples)
50
-
51
- # Introduction
52
-
53
- Welcome to the Avantis Trader SDK, a powerful tool designed to interact with the Avantis decentralized exchange (DEX) and leverage its advanced features for trading and market-making in cryptocurrencies, forex, and commodities.
54
-
55
- ## About Avantis
56
-
57
- [Avantis](https://avantisfi.com/) is at the forefront of decentralized leveraged trading platforms, offering users the ability to take long or short positions in synthetic crypto, forex, and commodities using perpetuals—a financial instrument that provides leverage without an expiration date. With synthetic leverage and a USDC stablecoin liquidity pool, Avantis achieves high capital efficiency, enabling a diverse selection of tradable assets and leverage up to 100x.
58
-
59
- The platform also introduces fine-grained risk management for liquidity providers (LPs) through time and risk parameters. This innovation allows any LP to become a sophisticated market maker for a wide range of derivatives, starting with perpetuals.
60
-
61
- Read more about Avantis at [https://docs.avantisfi.com/](https://docs.avantisfi.com/).
62
-
63
- ## Purpose of the Avantis Trader SDK
64
-
65
- The Avantis Trader SDK is designed to simplify and enhance the experience of interacting with the Avantis DEX. It provides developers and traders with a set of tools to:
66
-
67
- - Access real-time price feeds for supported trading pairs.
68
- - Retrieve and analyze key parameters for assets, categories, and trading strategies.
69
- - Integrate live price updates into applications or trading algorithms.
70
- - Execute trades and manage positions on the Avantis platform.
71
-
72
- Whether you are a developer building decentralized finance (DeFi) applications, a trader seeking to automate your strategies, or a market maker looking to optimize your operations, the Avantis Trader SDK offers the functionality you need to succeed in the rapidly evolving world of decentralized trading.
73
-
74
- # Getting Started
75
-
76
- ## Installation
77
-
78
- To get started with the Avantis Trader SDK, follow these steps to install the package:
79
-
80
- 1. Ensure you have Python 3.6 or later installed on your system.
81
- 2. Install the SDK using pip:
82
-
83
- ```bash
84
- pip install avantis-trader-sdk
85
- ```
86
-
87
- or
88
-
89
- ```bash
90
- pip install git+https://github.com/Avantis-Labs/avantis_trader_sdk.git
91
- ```
92
-
93
- Alternatively, if you have a local copy of the source:
94
-
95
- ```bash
96
- git clone https://github.com/yourusername/avantis-trader-sdk.git
97
- cd avantis-trader-sdk
98
- pip install .
99
- ```
100
-
101
- 3. Verify the installation:
102
-
103
- ```python
104
- import avantis_trader_sdk
105
- print(avantis_trader_sdk.__version__)
106
- ```
107
-
108
- If the installation was successful, this command should print the version number of the Avantis Trader SDK.
109
-
110
- ## Next Steps
111
-
112
- Once you have installed the Avantis Trader SDK, you can start using it to interact with the Avantis platform. Here are some things you might want to do next:
113
-
114
- - Explore the SDK’s features and capabilities.
115
- - Access real-time price feeds for various trading pairs.
116
- - Integrate the SDK into your trading algorithms or DeFi applications.
117
-
118
- ## Examples
119
-
120
- You can find practical examples and sample code for using the Avantis Trader SDK in our GitHub repository. These examples are designed to help you get started quickly and explore the capabilities of the SDK.
121
-
122
- 📂 [Browse the Examples on GitHub](https://github.com/Avantis-Labs/avantis_trader_sdk/tree/main/examples)
123
-
124
- ## 📚 [Read the Full Documentation Here](https://sdk.avantisfi.com/)