avantis-trader-sdk 0.8.12__py3-none-any.whl → 0.8.13__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,4 +2,4 @@ from .client import TraderClient
2
2
  from .feed.feed_client import FeedClient
3
3
  from .signers.base import BaseSigner
4
4
 
5
- __version__ = "0.8.12"
5
+ __version__ = "0.8.13"
@@ -10,5 +10,6 @@ MAINNET_ADDRESSES = {
10
10
  }
11
11
 
12
12
  AVANTIS_SOCKET_API = "https://socket-api-pub.avantisfi.com/socket-api/v1/data"
13
+ AVANTIS_CORE_API_BASE_URL = "https://core.avantisfi.com"
13
14
 
14
15
  CONTRACT_ADDRESSES = MAINNET_ADDRESSES
@@ -122,7 +122,7 @@ class FeedClient:
122
122
  return pairs
123
123
  except (requests.RequestException, ValidationError) as e:
124
124
  print(f"Error fetching pair feeds: {e}")
125
- return []
125
+ return []
126
126
 
127
127
  def load_pair_feeds(self):
128
128
  """
@@ -130,6 +130,9 @@ class FeedClient:
130
130
  """
131
131
 
132
132
  try:
133
+ if self.pair_feeds:
134
+ return
135
+
133
136
  try:
134
137
  asyncio.get_running_loop()
135
138
  except RuntimeError:
@@ -231,6 +234,9 @@ class FeedClient:
231
234
  Returns:
232
235
  A PriceFeedUpdatesResponse object containing the latest price updates.
233
236
  """
237
+ if not self.pair_feeds:
238
+ self.load_pair_feeds()
239
+
234
240
  url = self.hermes_url
235
241
 
236
242
  feedIds = []
@@ -28,6 +28,7 @@ class PairsCache:
28
28
  self._pair_mapping = {}
29
29
 
30
30
  self._pair_info_from_socket_cache = {}
31
+ self._socket_info_cache = {}
31
32
 
32
33
  async def get_pairs_info(self, force_update=False):
33
34
  """
@@ -87,10 +88,13 @@ class PairsCache:
87
88
 
88
89
  return self._pair_info_cache
89
90
 
90
- async def get_pair_info_from_socket(self, pair_index=None):
91
+ async def get_pair_info_from_socket(self, pair_index=None, use_cache=False):
91
92
  """
92
93
  Retrieves the pair information from the socket.
93
94
  """
95
+ if not use_cache and self._pair_info_from_socket_cache:
96
+ return self._pair_info_from_socket_cache[str(pair_index)]
97
+
94
98
  if not self.socket_api:
95
99
  raise ValueError("socket_api is not set")
96
100
  try:
@@ -98,7 +102,8 @@ class PairsCache:
98
102
  response.raise_for_status()
99
103
 
100
104
  result = response.json()
101
- pairs = result["data"]["pairInfos"]
105
+ self._socket_info_cache = result["data"]
106
+ pairs = self._socket_info_cache["pairInfos"]
102
107
  self._pair_info_from_socket_cache = pairs
103
108
  except (requests.RequestException, ValidationError) as e:
104
109
  print(f"Error fetching pair feeds: {e}")
@@ -108,6 +113,28 @@ class PairsCache:
108
113
  return self._pair_info_from_socket_cache[str(pair_index)]
109
114
  return self._pair_info_from_socket_cache
110
115
 
116
+ async def get_info_from_socket(self, force_update=False):
117
+ """
118
+ Retrieves the socket information.
119
+ """
120
+ if not force_update and self._socket_info_cache:
121
+ return self._socket_info_cache
122
+
123
+ if not self.socket_api:
124
+ raise ValueError("socket_api is not set")
125
+ try:
126
+ response = requests.get(self.socket_api)
127
+ response.raise_for_status()
128
+
129
+ result = response.json()
130
+ self._socket_info_cache = result["data"]
131
+ self._pair_info_from_socket_cache = self._socket_info_cache["pairInfos"]
132
+ except (requests.RequestException, ValidationError) as e:
133
+ print(f"Error fetching pair feeds: {e}")
134
+ return {}
135
+
136
+ return self._socket_info_cache
137
+
111
138
  async def get_pairs_count(self):
112
139
  """
113
140
  Retrieves the number of pairs from the blockchain.
@@ -1,4 +1,5 @@
1
1
  from ..feed.feed_client import FeedClient
2
+ from ..config import AVANTIS_CORE_API_BASE_URL
2
3
  from ..types import (
3
4
  TradeInput,
4
5
  TradeInputOrderType,
@@ -8,8 +9,10 @@ from ..types import (
8
9
  PendingLimitOrderExtendedResponse,
9
10
  MarginUpdateType,
10
11
  )
11
- from typing import Optional
12
+ from typing import Optional, List, Tuple
12
13
  import math
14
+ import asyncio
15
+ import requests
13
16
 
14
17
 
15
18
  class TradeRPC:
@@ -17,16 +20,23 @@ class TradeRPC:
17
20
  The TradeRPC class contains methods for retrieving trading parameters from the Avantis Protocol.
18
21
  """
19
22
 
20
- def __init__(self, client, feed_client: FeedClient):
23
+ def __init__(
24
+ self,
25
+ client,
26
+ feed_client: FeedClient,
27
+ core_api_base_url: Optional[str] = None,
28
+ ):
21
29
  """
22
30
  Constructor for the TradeRPC class.
23
31
 
24
32
  Args:
25
33
  client: The TraderClient object.
26
34
  feed_client: The FeedClient object.
35
+ core_api_base_url: Optional override for the API base URL.
27
36
  """
28
37
  self.client = client
29
38
  self.feed_client = feed_client
39
+ self.core_api_base_url = core_api_base_url or AVANTIS_CORE_API_BASE_URL
30
40
 
31
41
  async def build_trade_open_tx(
32
42
  self,
@@ -193,28 +203,143 @@ class TradeRPC:
193
203
  print("Error getting correct trade execution fee. Using fallback: ", e)
194
204
  return execution_fee_wei
195
205
 
196
- async def get_trades(self, trader: Optional[str] = None):
206
+ async def get_trades(
207
+ self,
208
+ trader: Optional[str] = None,
209
+ use_api: bool = True,
210
+ ) -> Tuple[List[TradeExtendedResponse], List[PendingLimitOrderExtendedResponse]]:
197
211
  """
198
- Gets the trades.
212
+ Gets the trades and pending limit orders for a trader.
213
+
214
+ Attempts to fetch from API first for better performance. Falls back to
215
+ paginated smart contract calls if API is unavailable or disabled.
199
216
 
200
217
  Args:
201
218
  trader: The trader's wallet address.
219
+ use_api: Whether to attempt API fetch first. Defaults to True.
202
220
 
203
221
  Returns:
204
- The trades.
222
+ A tuple of (trades, pending_limit_orders).
205
223
  """
206
224
  if trader is None:
207
225
  trader = self.client.get_signer().get_ethereum_address()
208
226
 
227
+ if use_api:
228
+ api_enabled = await self._check_api_enabled(trader)
229
+ if api_enabled:
230
+ try:
231
+ return await self._fetch_trades_from_api(trader)
232
+ except Exception:
233
+ pass
234
+
235
+ return await self._fetch_trades_from_contracts(trader)
236
+
237
+ async def _check_api_enabled(self, trader: str) -> bool:
238
+ """Checks if the API is enabled for the given trader."""
239
+ try:
240
+ response = requests.get(
241
+ f"{self.core_api_base_url}/user-data/config",
242
+ params={"wallet": trader},
243
+ timeout=5,
244
+ )
245
+ response.raise_for_status()
246
+ data = response.json()
247
+ return data.get("globallyEnabled", False) or data.get(
248
+ "enabledForWallet", False
249
+ )
250
+ except Exception:
251
+ return False
252
+
253
+ async def _fetch_trades_from_api(
254
+ self, trader: str
255
+ ) -> Tuple[List[TradeExtendedResponse], List[PendingLimitOrderExtendedResponse]]:
256
+ """Fetches trades from the API."""
257
+ response = requests.get(
258
+ f"{self.core_api_base_url}/user-data",
259
+ params={"trader": trader},
260
+ timeout=10,
261
+ )
262
+ response.raise_for_status()
263
+ data = response.json()
264
+
265
+ trades = []
266
+ for position in data.get("positions", []):
267
+ loss_protection_tier = int(position.get("lossProtection", 0))
268
+ pair_index = int(position.get("pairIndex", 0))
269
+ loss_protection_pct = await self.client.trading_parameters.get_loss_protection_percentage_by_tier(
270
+ loss_protection_tier, pair_index
271
+ )
272
+ position["lossProtectionPercentage"] = loss_protection_pct
273
+ trades.append(TradeExtendedResponse(**position))
274
+
275
+ limit_orders = [
276
+ PendingLimitOrderExtendedResponse(**order)
277
+ for order in data.get("limitOrders", [])
278
+ ]
279
+
280
+ return trades, limit_orders
281
+
282
+ async def _fetch_trades_from_contracts(
283
+ self,
284
+ trader: str,
285
+ max_pairs_per_call: int = 12,
286
+ ) -> Tuple[List[TradeExtendedResponse], List[PendingLimitOrderExtendedResponse]]:
287
+ """Fetches trades from smart contracts with paginated calls."""
288
+ socket_info = await self.client.pairs_cache.get_info_from_socket()
289
+ max_trades_per_pair = socket_info.get("maxTradesPerPair", 40)
290
+
291
+ pairs_count = await self.client.pairs_cache.get_pairs_count()
292
+ pair_ranges = self._build_pair_ranges(pairs_count, max_pairs_per_call)
293
+
294
+ tasks = [
295
+ self._fetch_positions_for_range(trader, start, end, max_trades_per_pair)
296
+ for start, end in pair_ranges
297
+ ]
298
+ results = await asyncio.gather(*tasks)
299
+
300
+ raw_trades = []
301
+ raw_orders = []
302
+ for trades_batch, orders_batch in results:
303
+ raw_trades.extend(trades_batch)
304
+ raw_orders.extend(orders_batch)
305
+
306
+ trades = await self._parse_raw_trades(raw_trades)
307
+ limit_orders = self._parse_raw_limit_orders(raw_orders)
308
+
309
+ return trades, limit_orders
310
+
311
+ def _build_pair_ranges(
312
+ self, pairs_count: int, max_pairs_per_call: int
313
+ ) -> List[Tuple[int, int]]:
314
+ """Builds pair index ranges for paginated fetching."""
315
+ ranges = []
316
+ for i in range(0, pairs_count, max_pairs_per_call):
317
+ start = i
318
+ end = min(i + max_pairs_per_call, pairs_count)
319
+ ranges.append((start, end))
320
+ return ranges
321
+
322
+ async def _fetch_positions_for_range(
323
+ self,
324
+ trader: str,
325
+ start_pair: int,
326
+ end_pair: int,
327
+ max_trades_per_pair: int,
328
+ ) -> Tuple[list, list]:
329
+ """Fetches positions for a range of pair indexes."""
209
330
  result = (
210
331
  await self.client.contracts.get("Multicall")
211
- .functions.getPositions(trader)
332
+ .functions.getPositionsForPairIndexes(
333
+ trader, start_pair, end_pair, max_trades_per_pair
334
+ )
212
335
  .call()
213
336
  )
214
- trades = []
215
- pendingOpenLimitOrders = []
337
+ return result[0], result[1]
216
338
 
217
- for aggregated_trade in result[0]: # Access the list of aggregated trades
339
+ async def _parse_raw_trades(self, raw_trades: list) -> List[TradeExtendedResponse]:
340
+ """Parses raw contract trade data into TradeExtendedResponse objects."""
341
+ trades = []
342
+ for aggregated_trade in raw_trades:
218
343
  (trade, trade_info, margin_fee, liquidation_price, is_zfp) = (
219
344
  aggregated_trade
220
345
  )
@@ -222,71 +347,64 @@ class TradeRPC:
222
347
  if trade[7] <= 0:
223
348
  continue
224
349
 
225
- # Extract and format the trade data
226
- trade_details = {
227
- "trade": {
228
- "trader": trade[0],
229
- "pairIndex": trade[1],
230
- "index": trade[2],
231
- "initialPosToken": trade[3],
232
- "positionSizeUSDC": trade[4],
233
- "openPrice": trade[5],
234
- "buy": trade[6],
235
- "leverage": trade[7],
236
- "tp": trade[8],
237
- "sl": trade[9],
238
- "timestamp": trade[10],
239
- },
240
- "additional_info": {
241
- "openInterestUSDC": trade_info[0],
242
- "tpLastUpdated": trade_info[1],
243
- "slLastUpdated": trade_info[2],
244
- "beingMarketClosed": trade_info[3],
245
- "lossProtectionPercentage": await self.client.trading_parameters.get_loss_protection_percentage_by_tier(
246
- trade_info[4], trade[1]
247
- ),
248
- },
249
- "margin_fee": margin_fee,
250
- "liquidationPrice": liquidation_price,
251
- "is_zfp": is_zfp,
252
- }
350
+ loss_protection = await self.client.trading_parameters.get_loss_protection_percentage_by_tier(
351
+ trade_info[4], trade[1]
352
+ )
353
+
253
354
  trades.append(
254
355
  TradeExtendedResponse(
255
- trade=TradeResponse(**trade_details["trade"]),
256
- additional_info=TradeInfo(**trade_details["additional_info"]),
257
- margin_fee=trade_details["margin_fee"],
258
- liquidation_price=trade_details["liquidationPrice"],
259
- is_zfp=trade_details["is_zfp"],
356
+ trade=TradeResponse(
357
+ trader=trade[0],
358
+ pairIndex=trade[1],
359
+ index=trade[2],
360
+ initialPosToken=trade[3],
361
+ positionSizeUSDC=trade[3],
362
+ openPrice=trade[5],
363
+ buy=trade[6],
364
+ leverage=trade[7],
365
+ tp=trade[8],
366
+ sl=trade[9],
367
+ timestamp=trade[10],
368
+ ),
369
+ additional_info=TradeInfo(
370
+ lossProtectionPercentage=loss_protection,
371
+ ),
372
+ margin_fee=margin_fee,
373
+ liquidation_price=liquidation_price,
374
+ is_zfp=is_zfp,
260
375
  )
261
376
  )
262
-
263
- for aggregated_order in result[1]: # Access the list of aggregated orders
377
+ return trades
378
+
379
+ def _parse_raw_limit_orders(
380
+ self, raw_orders: list
381
+ ) -> List[PendingLimitOrderExtendedResponse]:
382
+ """Parses raw contract order data into PendingLimitOrderExtendedResponse objects."""
383
+ orders = []
384
+ for aggregated_order in raw_orders:
264
385
  (order, liquidation_price) = aggregated_order
265
386
 
266
387
  if order[5] <= 0:
267
388
  continue
268
389
 
269
- # Extract and format the order data
270
- order_details = {
271
- "trader": order[0],
272
- "pairIndex": order[1],
273
- "index": order[2],
274
- "positionSize": order[3],
275
- "buy": order[4],
276
- "leverage": order[5],
277
- "tp": order[6],
278
- "sl": order[7],
279
- "price": order[8],
280
- "slippageP": order[9],
281
- "block": order[10],
282
- # 'executionFee': order[11],
283
- "liquidation_price": liquidation_price,
284
- }
285
- pendingOpenLimitOrders.append(
286
- PendingLimitOrderExtendedResponse(**order_details)
390
+ orders.append(
391
+ PendingLimitOrderExtendedResponse(
392
+ trader=order[0],
393
+ pairIndex=order[1],
394
+ index=order[2],
395
+ positionSize=order[3],
396
+ buy=order[4],
397
+ leverage=order[5],
398
+ tp=order[6],
399
+ sl=order[7],
400
+ price=order[8],
401
+ slippageP=order[9],
402
+ block=order[10],
403
+ executionFee=order[11],
404
+ liquidation_price=liquidation_price,
405
+ )
287
406
  )
288
-
289
- return trades, pendingOpenLimitOrders
407
+ return orders
290
408
 
291
409
  async def build_trade_close_tx(
292
410
  self,
@@ -666,8 +784,6 @@ class TradeRPC:
666
784
  if trader is None:
667
785
  trader = self.client.get_signer().get_ethereum_address()
668
786
 
669
- feed_client = self.FeedClient()
670
-
671
787
  pair_name = await self.client.pairs_cache.get_pair_name_from_index(pair_index)
672
788
 
673
789
  price_data = await self.feed_client.get_latest_price_updates([pair_name])
@@ -707,3 +823,79 @@ class TradeRPC:
707
823
  }
708
824
  )
709
825
  return delegate_transaction
826
+
827
+ async def get_delegate(self, trader: Optional[str] = None) -> str:
828
+ """
829
+ Gets the delegate address for a trader.
830
+
831
+ Args:
832
+ trader: The trader's wallet address. Defaults to signer's address.
833
+
834
+ Returns:
835
+ The delegate address, or zero address if no delegate is set.
836
+ """
837
+ Trading = self.client.contracts.get("Trading")
838
+
839
+ if trader is None:
840
+ trader = self.client.get_signer().get_ethereum_address()
841
+
842
+ delegate = await Trading.functions.delegations(trader).call()
843
+ return delegate
844
+
845
+ async def build_set_delegate_tx(
846
+ self,
847
+ delegate: str,
848
+ trader: Optional[str] = None,
849
+ ):
850
+ """
851
+ Builds a transaction to set a delegate for trading.
852
+
853
+ The delegate can perform all trade-related actions on behalf of the trader.
854
+ Each wallet can have at most one delegate.
855
+
856
+ Args:
857
+ delegate: The delegate's wallet address.
858
+ trader: The trader's wallet address. Defaults to signer's address.
859
+
860
+ Returns:
861
+ A transaction object.
862
+ """
863
+ Trading = self.client.contracts.get("Trading")
864
+
865
+ if trader is None:
866
+ trader = self.client.get_signer().get_ethereum_address()
867
+
868
+ transaction = await Trading.functions.setDelegate(delegate).build_transaction(
869
+ {
870
+ "from": trader,
871
+ "chainId": self.client.chain_id,
872
+ "nonce": await self.client.get_transaction_count(trader),
873
+ }
874
+ )
875
+
876
+ return transaction
877
+
878
+ async def build_remove_delegate_tx(self, trader: Optional[str] = None):
879
+ """
880
+ Builds a transaction to remove the current delegate.
881
+
882
+ Args:
883
+ trader: The trader's wallet address. Defaults to signer's address.
884
+
885
+ Returns:
886
+ A transaction object.
887
+ """
888
+ Trading = self.client.contracts.get("Trading")
889
+
890
+ if trader is None:
891
+ trader = self.client.get_signer().get_ethereum_address()
892
+
893
+ transaction = await Trading.functions.removeDelegate().build_transaction(
894
+ {
895
+ "from": trader,
896
+ "chainId": self.client.chain_id,
897
+ "nonce": await self.client.get_transaction_count(trader),
898
+ }
899
+ )
900
+
901
+ return transaction
@@ -57,7 +57,9 @@ class TradingParametersRPC:
57
57
  Returns:
58
58
  The loss protection percentage.
59
59
  """
60
- pair_info = await self.client.pairs_cache.get_pair_info_from_socket(pair_index)
60
+ pair_info = await self.client.pairs_cache.get_pair_info_from_socket(
61
+ pair_index, use_cache=True
62
+ )
61
63
  return pair_info["lossProtectionMultiplier"][str(tier)]
62
64
 
63
65
  async def get_loss_protection_percentage(self, trade: TradeInput):
@@ -1,6 +1,7 @@
1
1
  from pydantic import (
2
2
  BaseModel,
3
3
  Field,
4
+ AliasChoices,
4
5
  conint,
5
6
  field_validator,
6
7
  ValidationError,
@@ -334,14 +335,16 @@ class TradeResponse(BaseModel):
334
335
  trader: str
335
336
  pair_index: int = Field(..., alias="pairIndex")
336
337
  trade_index: int = Field(0, alias="index")
337
- open_collateral: float = Field(None, alias="initialPosToken")
338
- collateral_in_trade: float = Field(None, alias="positionSizeUSDC")
338
+ open_collateral: float = Field(
339
+ None, validation_alias=AliasChoices("collateral", "initialPosToken")
340
+ )
341
+ collateral_in_trade: Optional[float] = Field(None, alias="positionSizeUSDC")
339
342
  open_price: float = Field(0, alias="openPrice")
340
343
  is_long: bool = Field(..., alias="buy")
341
344
  leverage: float
342
345
  tp: float
343
346
  sl: float
344
- timestamp: int
347
+ timestamp: int = Field(..., validation_alias=AliasChoices("timestamp", "openedAt"))
345
348
 
346
349
  @field_validator("trader")
347
350
  def validate_eth_address(cls, v):
@@ -351,45 +354,81 @@ class TradeResponse(BaseModel):
351
354
 
352
355
  @field_validator("open_price", "tp", "sl", "leverage", mode="before")
353
356
  def convert_to_float_10(cls, v):
354
- return v / 10**10
357
+ if v is None:
358
+ return 0
359
+ return int(v) / 10**10
355
360
 
356
361
  @field_validator("open_collateral", "collateral_in_trade", mode="before")
357
362
  def convert_to_float_6(cls, v):
358
- return v / 10**6
363
+ if v is None:
364
+ return None
365
+ return int(v) / 10**6
366
+
367
+ @model_validator(mode="after")
368
+ def set_collateral_in_trade(self):
369
+ if self.collateral_in_trade is None:
370
+ self.collateral_in_trade = self.open_collateral
371
+ return self
359
372
 
360
373
  class Config:
361
374
  populate_by_name = True
362
375
 
363
376
 
364
377
  class TradeInfo(BaseModel):
365
- open_interest_usdc: float = Field(..., alias="openInterestUSDC")
366
- tp_last_updated: float = Field(..., alias="tpLastUpdated")
367
- sl_last_updated: float = Field(..., alias="slLastUpdated")
368
- being_market_closed: bool = Field(..., alias="beingMarketClosed")
369
378
  loss_protection_percentage: float = Field(..., alias="lossProtectionPercentage")
370
379
 
371
- @field_validator("open_interest_usdc", mode="before")
372
- def convert_to_float_6(cls, v):
373
- return v / 10**6
374
-
375
380
  class Config:
376
381
  populate_by_name = True
377
382
 
378
383
 
379
384
  class TradeExtendedResponse(BaseModel):
380
- trade: TradeResponse
381
- additional_info: TradeInfo
382
- margin_fee: float
383
- liquidation_price: float
384
- is_zfp: bool
385
+ trade: Optional[TradeResponse] = None
386
+ additional_info: Optional[TradeInfo] = None
387
+ margin_fee: float = Field(
388
+ 0, validation_alias=AliasChoices("margin_fee", "rolloverFee")
389
+ )
390
+ liquidation_price: float = Field(
391
+ ..., validation_alias=AliasChoices("liquidation_price", "liquidationPrice")
392
+ )
393
+ is_zfp: bool = Field(False, validation_alias=AliasChoices("is_zfp", "isPnl"))
385
394
 
386
395
  @field_validator("margin_fee", mode="before")
387
396
  def convert_to_float_6(cls, v):
388
- return v / 10**6
397
+ if v is None:
398
+ return 0
399
+ return int(v) / 10**6
389
400
 
390
401
  @field_validator("liquidation_price", mode="before")
391
402
  def convert_to_float_10(cls, v):
392
- return v / 10**10
403
+ return int(v) / 10**10
404
+
405
+ @model_validator(mode="before")
406
+ def build_from_flat(cls, values):
407
+ if "trade" not in values and "trader" in values:
408
+ trade_fields = [
409
+ "trader",
410
+ "pairIndex",
411
+ "index",
412
+ "initialPosToken",
413
+ "collateral",
414
+ "positionSizeUSDC",
415
+ "openPrice",
416
+ "buy",
417
+ "leverage",
418
+ "tp",
419
+ "sl",
420
+ "timestamp",
421
+ "openedAt",
422
+ ]
423
+ trade_data = {k: values.get(k) for k in trade_fields if k in values}
424
+ values["trade"] = trade_data
425
+
426
+ info_data = {
427
+ "lossProtectionPercentage": values.get("lossProtectionPercentage", 0),
428
+ }
429
+ values["additional_info"] = info_data
430
+
431
+ return values
393
432
 
394
433
  class Config:
395
434
  populate_by_name = True
@@ -399,7 +438,9 @@ class PendingLimitOrderResponse(BaseModel):
399
438
  trader: str
400
439
  pair_index: int = Field(..., alias="pairIndex")
401
440
  trade_index: int = Field(0, alias="index")
402
- open_collateral: float = Field(..., alias="positionSize")
441
+ open_collateral: float = Field(
442
+ ..., validation_alias=AliasChoices("collateral", "positionSize")
443
+ )
403
444
  buy: bool
404
445
  leverage: int
405
446
  tp: float
@@ -407,6 +448,7 @@ class PendingLimitOrderResponse(BaseModel):
407
448
  price: float
408
449
  slippage_percentage: float = Field(..., alias="slippageP")
409
450
  block: int
451
+ execution_fee: float = Field(0, alias="executionFee")
410
452
 
411
453
  @field_validator("trader")
412
454
  def validate_eth_address(cls, v):
@@ -418,22 +460,26 @@ class PendingLimitOrderResponse(BaseModel):
418
460
  "price", "tp", "sl", "leverage", "slippage_percentage", mode="before"
419
461
  )
420
462
  def convert_to_float_10(cls, v):
421
- return v / 10**10
463
+ return int(v) / 10**10
422
464
 
423
- @field_validator("open_collateral", mode="before")
465
+ @field_validator("open_collateral", "execution_fee", mode="before")
424
466
  def convert_to_float_6(cls, v):
425
- return v / 10**6
467
+ if v is None:
468
+ return 0
469
+ return int(v) / 10**6
426
470
 
427
471
  class Config:
428
472
  populate_by_name = True
429
473
 
430
474
 
431
475
  class PendingLimitOrderExtendedResponse(PendingLimitOrderResponse):
432
- liquidation_price: float
476
+ liquidation_price: float = Field(
477
+ ..., validation_alias=AliasChoices("liquidation_price", "liquidationPrice")
478
+ )
433
479
 
434
480
  @field_validator("liquidation_price", mode="before")
435
481
  def convert_liq_to_float_10(cls, v):
436
- return v / 10**10
482
+ return int(v) / 10**10
437
483
 
438
484
 
439
485
  class MarginUpdateType(Enum):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: avantis_trader_sdk
3
- Version: 0.8.12
3
+ Version: 0.8.13
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=L4axdHNq1qOLCsIA5cLkhAi7E-uzMUUTpx3Xg4L6ZvQ,135
1
+ avantis_trader_sdk/__init__.py,sha256=yDgKgOYEOlq-pVM-QqjmrO_UFl0aObe5ZjcgtRf4y7w,135
2
2
  avantis_trader_sdk/client.py,sha256=M01uwXIdxJjmPEcFr1MsDuoxU9YGddxcGMTPucOOssA,10903
3
- avantis_trader_sdk/config.py,sha256=anwq2ynMurYna24ABbhtAyfpDg4NtPI2lubFuzHkJ9A,653
4
- avantis_trader_sdk/types.py,sha256=dvKj2xRYLq2Wq0ugJlDewDNiM-KaKhTbDe6b6hZ-sK8,13834
3
+ avantis_trader_sdk/config.py,sha256=ffmArpqwoXEupCt5aG8Q22da58Eye3jV1-f-PegTjiw,710
4
+ avantis_trader_sdk/types.py,sha256=8UjPERXxVJ-zthDHZ4YlYU3goaXzMbZenTB8nQDQGwA,15379
5
5
  avantis_trader_sdk/utils.py,sha256=gTYgNVVd5rLZEUf2eyJftjKYxn55wRm09xAXIF_xjXM,2831
6
6
  avantis_trader_sdk/abis/AggregatorV3Interface.json,sha256=qUeDGZ55Akgu8zOv_Wzf21sTREEyZXF47K_TdPcliBM,26244
7
7
  avantis_trader_sdk/abis/Sanctions.json,sha256=Fsn67jEGW4GdS15icrtxN_sur4e8-06SoijL7K79vAE,3857
@@ -195,24 +195,24 @@ 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=SsCX5CJfrXjN5rl8hMqED-kebHnM3AMRDkdCKeMV5DI,9283
198
+ avantis_trader_sdk/feed/feed_client.py,sha256=Qnx-RAFd9pzYK7GY6IKzon20_ioI3OuSvFWxlhMnzrY,9403
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
202
202
  avantis_trader_sdk/rpc/category_parameters.py,sha256=ofsKct23E8DThCKqP627ol-_YPIdN5HAn09eLqyf6WM,7965
203
203
  avantis_trader_sdk/rpc/fee_parameters.py,sha256=0UCf4FZQp26777o8aA75oOO-b3xFK88c-_glbqQ2-8M,9132
204
- avantis_trader_sdk/rpc/pairs_cache.py,sha256=tSDfPaBcqtVHj0yyUEHXfD5OAgFgq6_JneNjUxIsbzg,5580
204
+ avantis_trader_sdk/rpc/pairs_cache.py,sha256=Cts7EqblH6WQ2Gc2OwYGkLtxlzu33-T4cd7hQCuNkcw,6610
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=D3OQGVRK0Bib2oc3ouyMU-jmEywlG3UqqwdDZm8k870,23565
208
- avantis_trader_sdk/rpc/trading_parameters.py,sha256=KMLR0RTU82Q9UzSmjnBhUrVn8AaRvG09MovPQs-yXaA,4588
207
+ avantis_trader_sdk/rpc/trade.py,sha256=Aw_YJ5WGAfpleTISl7xyZw_6sVj4EBRSXHLuG_qzPSk,30141
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
211
211
  avantis_trader_sdk/signers/kms_signer.py,sha256=lxK3f9KQsdCDAvOE1SHleKjI8zD_3PTvywDjDVQGDKg,4448
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.12.dist-info/METADATA,sha256=zk7GPC15Wt1bIF1G4fQdnPkljUvrmJFc9fCiNSxMJuU,5032
216
- avantis_trader_sdk-0.8.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
217
- avantis_trader_sdk-0.8.12.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
218
- avantis_trader_sdk-0.8.12.dist-info/RECORD,,
215
+ avantis_trader_sdk-0.8.13.dist-info/METADATA,sha256=50-W4zc-CnQ5WxvF4WsTDNaRjPm0YIQuBV0ubMEqpFg,5032
216
+ avantis_trader_sdk-0.8.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
217
+ avantis_trader_sdk-0.8.13.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
218
+ avantis_trader_sdk-0.8.13.dist-info/RECORD,,