avantis-trader-sdk 0.6.0__py3-none-any.whl → 0.7.0__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.
@@ -2,25 +2,25 @@ from .client import TraderClient
2
2
  from .feed.feed_client import FeedClient
3
3
  from .signers.base import BaseSigner
4
4
 
5
- __version__ = "0.6.0"
5
+ __version__ = "0.7.0"
6
6
 
7
- # print(
8
- # f"""
9
- # ---------------------------------------------------------------------------------
10
- # ⚠️ IMPORTANT: Avantis Contracts v1.5 Upgrade
7
+ print(
8
+ f"""
9
+ ---------------------------------------------------------------------------------
10
+ ⚠️ IMPORTANT: Avantis Contracts v1.5 Upgrade
11
11
 
12
- # Breaking changes are being introduced as part of the v1.5 Contracts Upgrade.
13
- # If you're using this SDK, please review the details to ensure compatibility.
12
+ Breaking changes are being introduced as part of the v1.5 Contracts Upgrade.
13
+ If you're using this SDK, please review the details to ensure compatibility.
14
14
 
15
- # Details: https://avantisfi.notion.site/avantis-contracts-v1-5-upgrade
15
+ Details: https://avantisfi.notion.site/avantis-contracts-v1-5-upgrade
16
16
 
17
- # Milestone 1: Scheduled for 24th January 2025
18
- # - Updates to PairStorage, PairInfos, and Multicall contracts.
17
+ Milestone 1: Completed on 24th January 2025
18
+ - Updates to PairStorage, PairInfos, and Multicall contracts.
19
19
 
20
- # Milestone 2: Date TBD
21
- # - Updates to Trading, Referral, TradingStorage, TradingCallbacks, and more.
20
+ Milestone 2: Scheduled for 21th February 2025
21
+ - Updates to Trading, Referral, TradingStorage, TradingCallbacks, and more.
22
22
 
23
- # Ensure your integration is updated to avoid disruptions.
24
- # ---------------------------------------------------------------------------------
25
- # """
26
- # )
23
+ Ensure your integration is updated to avoid disruptions.
24
+ ---------------------------------------------------------------------------------
25
+ """
26
+ )
@@ -150,9 +150,8 @@ class TraderClient:
150
150
  if not self.has_signer():
151
151
  return transaction
152
152
 
153
- signed_txn = await self.sign_transaction(transaction)
154
- tx_hash = await self.send_and_get_transaction_hash(signed_txn)
155
- return tx_hash
153
+ receipt = await self.sign_and_get_receipt(transaction)
154
+ return receipt
156
155
 
157
156
  def set_signer(self, signer: BaseSigner):
158
157
  """
@@ -290,7 +289,8 @@ class TraderClient:
290
289
  """
291
290
  if address is None:
292
291
  address = self.get_signer().get_ethereum_address()
293
- return await self.async_web3.eth.get_balance(address)
292
+ balance = await self.async_web3.eth.get_balance(address)
293
+ return balance / 10**18
294
294
 
295
295
  async def get_usdc_balance(self, address=None):
296
296
  """
@@ -9,4 +9,6 @@ MAINNET_ADDRESSES = {
9
9
  "Referral": "0xA96f577821933d127B491D0F91202405B0dbB1bd",
10
10
  }
11
11
 
12
+ AVANTIS_SOCKET_API = "https://socket-api.avantisfi.com/v1/data"
13
+
12
14
  CONTRACT_ADDRESSES = MAINNET_ADDRESSES
@@ -1,9 +1,12 @@
1
1
  import json
2
2
  import websockets
3
- from pathlib import Path
4
- from ..types import PriceFeedResponse, PriceFeedUpdatesResponse
5
- from typing import List
3
+ from ..types import PriceFeedResponse, PriceFeedUpdatesResponse, PairInfoFeed
4
+ from typing import List, Callable
6
5
  import requests
6
+ from pydantic import ValidationError
7
+ from ..config import AVANTIS_SOCKET_API
8
+ import asyncio
9
+ from concurrent.futures import ThreadPoolExecutor
7
10
 
8
11
 
9
12
  class FeedClient:
@@ -17,6 +20,7 @@ class FeedClient:
17
20
  on_error=None,
18
21
  on_close=None,
19
22
  hermes_url="https://hermes.pyth.network/v2/updates/price/latest",
23
+ pair_fetcher: Callable = None,
20
24
  ):
21
25
  """
22
26
  Constructor for the FeedClient class.
@@ -42,6 +46,7 @@ class FeedClient:
42
46
  self._connected = False
43
47
  self._on_error = on_error
44
48
  self._on_close = on_close
49
+ self.pair_fetcher = pair_fetcher or self.default_pair_fetcher
45
50
  self._load_pair_feeds()
46
51
 
47
52
  async def listen_for_price_updates(self):
@@ -95,14 +100,65 @@ class FeedClient:
95
100
  else:
96
101
  raise e
97
102
 
103
+ async def default_pair_fetcher(self) -> List[dict]:
104
+ """
105
+ Default pair fetcher that retrieves data from the Avantis API.
106
+ Returns:
107
+ A list of validated trading pairs.
108
+ Raises:
109
+ ValueError if API response is invalid.
110
+ """
111
+ if not AVANTIS_SOCKET_API:
112
+ raise ValueError("AVANTIS_SOCKET_API is not set")
113
+ try:
114
+ response = requests.get(AVANTIS_SOCKET_API)
115
+ response.raise_for_status()
116
+
117
+ result = response.json()
118
+ pairs = result["data"]["pairInfos"].values()
119
+
120
+ return pairs
121
+ except (requests.RequestException, ValidationError) as e:
122
+ print(f"Error fetching pair feeds: {e}")
123
+ return []
124
+
98
125
  def _load_pair_feeds(self):
99
126
  """
100
- Loads the pair feeds from the json file.
127
+ Loads the pair feeds dynamically using the provided pair_fetcher function.
101
128
  """
102
- feed_path = Path(__file__).parent / "feedIds.json"
103
- with open(feed_path) as feed_file:
104
- self.pair_feeds = json.load(feed_file)
105
- self.feed_pairs = {v["id"]: k for k, v in self.pair_feeds.items()}
129
+
130
+ try:
131
+ try:
132
+ asyncio.get_running_loop()
133
+ except RuntimeError:
134
+ asyncio.set_event_loop(asyncio.new_event_loop())
135
+
136
+ with ThreadPoolExecutor() as executor:
137
+ future = executor.submit(lambda: asyncio.run(self.pair_fetcher()))
138
+ pairs = future.result()
139
+
140
+ if not pairs:
141
+ raise ValueError("Fetched pair feed data is empty or invalid.")
142
+
143
+ if isinstance(pairs, dict):
144
+ pairs = list(pairs.values())
145
+ else:
146
+ pairs = list(pairs)
147
+
148
+ if hasattr(pairs[0], "model_dump_json"):
149
+ pairs = [json.loads(pair.model_dump_json()) for pair in pairs]
150
+
151
+ validated_pairs = [PairInfoFeed.model_validate(pair) for pair in pairs]
152
+
153
+ self.pair_feeds = {
154
+ f"{pair.from_}/{pair.to}": {"id": pair.feed.feed_id}
155
+ for pair in validated_pairs
156
+ }
157
+ self.feed_pairs = {
158
+ pair.feed.feed_id: f"{pair.from_}/{pair.to}" for pair in validated_pairs
159
+ }
160
+ except Exception as e:
161
+ print(f"Failed to load pair feeds: {e}")
106
162
 
107
163
  def get_pair_from_feed_id(self, feed_id):
108
164
  """
@@ -36,6 +36,9 @@ class PairInfoBackupFeed(BaseModel):
36
36
  def convert_max_deviation(cls, v):
37
37
  return v / 10**10
38
38
 
39
+ class Config:
40
+ populate_by_name = True
41
+
39
42
 
40
43
  class PairInfoLeverages(BaseModel):
41
44
  min_leverage: float = Field(..., alias="minLeverage")
@@ -110,8 +113,19 @@ class PairInfoWithData(PairInfo, PairData):
110
113
  from_attributes = True
111
114
 
112
115
 
116
+ class PairInfoFeed(BaseModel):
117
+ from_: str = Field(..., alias="from")
118
+ to: str
119
+ feed: PairInfoFeed
120
+ backup_feed: PairInfoBackupFeed = Field(..., alias="backupFeed")
121
+
122
+ class Config:
123
+ populate_by_name = True
124
+
125
+
113
126
  class OpenInterest(BaseModel):
114
127
  long: Dict[str, float]
128
+
115
129
  short: Dict[str, float]
116
130
 
117
131
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: avantis-trader-sdk
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: SDK for interacting with Avantis trading contracts.
5
5
  Home-page: https://avantisfi.com/
6
6
  Author: Avantis Labs
@@ -1,7 +1,7 @@
1
- avantis_trader_sdk/__init__.py,sha256=JUFO-X_UKaXCpgw3D34f1vlKoiykNf3eRBkYkeb9slg,917
2
- avantis_trader_sdk/client.py,sha256=OPyVhE6g41_Uek1C95PT6h1YJRjDnsQ6cGZZ-1XV2XM,11271
3
- avantis_trader_sdk/config.py,sha256=3nubC4ClH15JJ71Z3MJuvEwkBP5R-paIhHOEfQ9WFnM,585
4
- avantis_trader_sdk/types.py,sha256=aJRfFESmcqcgSRQ8B_9zzXalOChSlsC5K5HfkZvwzlg,13958
1
+ avantis_trader_sdk/__init__.py,sha256=QSySCM3stHw3scigwfo2rG29XXKDFGiklzq9ZPTbRww,910
2
+ avantis_trader_sdk/client.py,sha256=dYGrSH5m1QesyMXEGvoLQihBQTRm_nJF22t46JeZirk,11236
3
+ avantis_trader_sdk/config.py,sha256=jFLspHAWgLWVv5VdyS25aBtiQLLcHqJJ11jkT6ubSgY,652
4
+ avantis_trader_sdk/types.py,sha256=9PNDt4nhEDxDEGsN_bYC7MOHK0w9UYwI6BSwvpFVdxY,14254
5
5
  avantis_trader_sdk/utils.py,sha256=JE3hiDA8a9KHW08u0lVsuXi6Npl8GcuUdvrSkwohvDc,2909
6
6
  avantis_trader_sdk/abis/AggregatorV3Interface.json,sha256=0sTEMeK5PfVfJM0ZoLkWkxme_PgcOKoYhxz5cQNo728,26850
7
7
  avantis_trader_sdk/abis/Sanctions.json,sha256=2FFgtlHZEXTOYtFWNjPlV56b7WSiwuY92VR9Jkik1uc,4047
@@ -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=fnATL8bCNzteZZolMgrycXHNK25_TI4Lg_Y4oVN9ep8,7423
198
+ avantis_trader_sdk/feed/feed_client.py,sha256=kzn3XSbYU68R18JUB2GUN70SuyuILyGVSd65onJLsPk,9473
199
199
  avantis_trader_sdk/rpc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
200
200
  avantis_trader_sdk/rpc/asset_parameters.py,sha256=OkGyfSmiCUl7fgJaUJFQekpQ8o2_JbbSwh1gWAXdZKY,19717
201
201
  avantis_trader_sdk/rpc/blended.py,sha256=UHgrPEvkJwQJRxTrVG03Ir8IjJRGenQFov1bJvbuGi4,2512
@@ -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.6.0.dist-info/METADATA,sha256=T5o1GDxF_mjZE3_N77alBZ9QbRQGg6U6YGqozkPbVmw,4916
216
- avantis_trader_sdk-0.6.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
217
- avantis_trader_sdk-0.6.0.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
218
- avantis_trader_sdk-0.6.0.dist-info/RECORD,,
215
+ avantis_trader_sdk-0.7.0.dist-info/METADATA,sha256=SWtPCpMJXC0pR7QNTT9PmxLGFB16WmH1QKnGo5ZSwOI,4916
216
+ avantis_trader_sdk-0.7.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
217
+ avantis_trader_sdk-0.7.0.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
218
+ avantis_trader_sdk-0.7.0.dist-info/RECORD,,