avantis-trader-sdk 0.8.11__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.
@@ -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,96 +203,208 @@ 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
218
- (trade, trade_info, margin_fee, liquidation_price) = aggregated_trade
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:
343
+ (trade, trade_info, margin_fee, liquidation_price, is_zfp) = (
344
+ aggregated_trade
345
+ )
219
346
 
220
347
  if trade[7] <= 0:
221
348
  continue
222
349
 
223
- # Extract and format the trade data
224
- trade_details = {
225
- "trade": {
226
- "trader": trade[0],
227
- "pairIndex": trade[1],
228
- "index": trade[2],
229
- "initialPosToken": trade[3],
230
- "positionSizeUSDC": trade[4],
231
- "openPrice": trade[5],
232
- "buy": trade[6],
233
- "leverage": trade[7],
234
- "tp": trade[8],
235
- "sl": trade[9],
236
- "timestamp": trade[10],
237
- },
238
- "additional_info": {
239
- "openInterestUSDC": trade_info[0],
240
- "tpLastUpdated": trade_info[1],
241
- "slLastUpdated": trade_info[2],
242
- "beingMarketClosed": trade_info[3],
243
- "lossProtectionPercentage": await self.client.trading_parameters.get_loss_protection_percentage_by_tier(
244
- trade_info[4], trade[1]
245
- ),
246
- },
247
- "margin_fee": margin_fee,
248
- "liquidationPrice": liquidation_price,
249
- }
350
+ loss_protection = await self.client.trading_parameters.get_loss_protection_percentage_by_tier(
351
+ trade_info[4], trade[1]
352
+ )
353
+
250
354
  trades.append(
251
355
  TradeExtendedResponse(
252
- trade=TradeResponse(**trade_details["trade"]),
253
- additional_info=TradeInfo(**trade_details["additional_info"]),
254
- margin_fee=trade_details["margin_fee"],
255
- liquidation_price=trade_details["liquidationPrice"],
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,
256
375
  )
257
376
  )
258
-
259
- 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:
260
385
  (order, liquidation_price) = aggregated_order
261
386
 
262
387
  if order[5] <= 0:
263
388
  continue
264
389
 
265
- # Extract and format the order data
266
- order_details = {
267
- "trader": order[0],
268
- "pairIndex": order[1],
269
- "index": order[2],
270
- "positionSize": order[3],
271
- "buy": order[4],
272
- "leverage": order[5],
273
- "tp": order[6],
274
- "sl": order[7],
275
- "price": order[8],
276
- "slippageP": order[9],
277
- "block": order[10],
278
- # 'executionFee': order[11],
279
- "liquidation_price": liquidation_price,
280
- }
281
- pendingOpenLimitOrders.append(
282
- 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
+ )
283
406
  )
284
-
285
- return trades, pendingOpenLimitOrders
407
+ return orders
286
408
 
287
409
  async def build_trade_close_tx(
288
410
  self,
@@ -662,8 +784,6 @@ class TradeRPC:
662
784
  if trader is None:
663
785
  trader = self.client.get_signer().get_ethereum_address()
664
786
 
665
- feed_client = self.FeedClient()
666
-
667
787
  pair_name = await self.client.pairs_cache.get_pair_name_from_index(pair_index)
668
788
 
669
789
  price_data = await self.feed_client.get_latest_price_updates([pair_name])
@@ -703,3 +823,79 @@ class TradeRPC:
703
823
  }
704
824
  )
705
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,44 +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
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"))
384
394
 
385
395
  @field_validator("margin_fee", mode="before")
386
396
  def convert_to_float_6(cls, v):
387
- return v / 10**6
397
+ if v is None:
398
+ return 0
399
+ return int(v) / 10**6
388
400
 
389
401
  @field_validator("liquidation_price", mode="before")
390
402
  def convert_to_float_10(cls, v):
391
- 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
392
432
 
393
433
  class Config:
394
434
  populate_by_name = True
@@ -398,7 +438,9 @@ class PendingLimitOrderResponse(BaseModel):
398
438
  trader: str
399
439
  pair_index: int = Field(..., alias="pairIndex")
400
440
  trade_index: int = Field(0, alias="index")
401
- open_collateral: float = Field(..., alias="positionSize")
441
+ open_collateral: float = Field(
442
+ ..., validation_alias=AliasChoices("collateral", "positionSize")
443
+ )
402
444
  buy: bool
403
445
  leverage: int
404
446
  tp: float
@@ -406,6 +448,7 @@ class PendingLimitOrderResponse(BaseModel):
406
448
  price: float
407
449
  slippage_percentage: float = Field(..., alias="slippageP")
408
450
  block: int
451
+ execution_fee: float = Field(0, alias="executionFee")
409
452
 
410
453
  @field_validator("trader")
411
454
  def validate_eth_address(cls, v):
@@ -417,22 +460,26 @@ class PendingLimitOrderResponse(BaseModel):
417
460
  "price", "tp", "sl", "leverage", "slippage_percentage", mode="before"
418
461
  )
419
462
  def convert_to_float_10(cls, v):
420
- return v / 10**10
463
+ return int(v) / 10**10
421
464
 
422
- @field_validator("open_collateral", mode="before")
465
+ @field_validator("open_collateral", "execution_fee", mode="before")
423
466
  def convert_to_float_6(cls, v):
424
- return v / 10**6
467
+ if v is None:
468
+ return 0
469
+ return int(v) / 10**6
425
470
 
426
471
  class Config:
427
472
  populate_by_name = True
428
473
 
429
474
 
430
475
  class PendingLimitOrderExtendedResponse(PendingLimitOrderResponse):
431
- liquidation_price: float
476
+ liquidation_price: float = Field(
477
+ ..., validation_alias=AliasChoices("liquidation_price", "liquidationPrice")
478
+ )
432
479
 
433
480
  @field_validator("liquidation_price", mode="before")
434
481
  def convert_liq_to_float_10(cls, v):
435
- return v / 10**10
482
+ return int(v) / 10**10
436
483
 
437
484
 
438
485
  class MarginUpdateType(Enum):