avantis-trader-sdk 0.8.12__py3-none-any.whl → 0.8.14__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.
- avantis_trader_sdk/__init__.py +2 -1
- avantis_trader_sdk/abis/Trading.sol/Trading.json +1347 -1
- avantis_trader_sdk/config.py +3 -0
- avantis_trader_sdk/feed/feed_client.py +103 -7
- avantis_trader_sdk/rpc/pairs_cache.py +48 -2
- avantis_trader_sdk/rpc/trade.py +307 -86
- avantis_trader_sdk/rpc/trading_parameters.py +3 -1
- avantis_trader_sdk/types.py +144 -26
- {avantis_trader_sdk-0.8.12.dist-info → avantis_trader_sdk-0.8.14.dist-info}/METADATA +1 -1
- {avantis_trader_sdk-0.8.12.dist-info → avantis_trader_sdk-0.8.14.dist-info}/RECORD +12 -12
- {avantis_trader_sdk-0.8.12.dist-info → avantis_trader_sdk-0.8.14.dist-info}/WHEEL +0 -0
- {avantis_trader_sdk-0.8.12.dist-info → avantis_trader_sdk-0.8.14.dist-info}/top_level.txt +0 -0
avantis_trader_sdk/types.py
CHANGED
|
@@ -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(
|
|
338
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
384
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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):
|
|
@@ -441,6 +487,78 @@ class MarginUpdateType(Enum):
|
|
|
441
487
|
WITHDRAW = 1
|
|
442
488
|
|
|
443
489
|
|
|
490
|
+
class PriceSourcing(Enum):
|
|
491
|
+
"""Price sourcing options for contract calls."""
|
|
492
|
+
|
|
493
|
+
HERMES = 0 # Pyth Hermes (legacy)
|
|
494
|
+
PRO = 1 # Pyth Pro / Lazer
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
class LazerPriceFeed(BaseModel):
|
|
498
|
+
"""Single price feed from Pyth Lazer SSE stream."""
|
|
499
|
+
|
|
500
|
+
price_feed_id: int = Field(..., alias="priceFeedId")
|
|
501
|
+
price: str
|
|
502
|
+
best_bid_price: str = Field(..., alias="bestBidPrice")
|
|
503
|
+
best_ask_price: str = Field(..., alias="bestAskPrice")
|
|
504
|
+
publisher_count: int = Field(..., alias="publisherCount")
|
|
505
|
+
exponent: int
|
|
506
|
+
confidence: int
|
|
507
|
+
|
|
508
|
+
@property
|
|
509
|
+
def converted_price(self) -> float:
|
|
510
|
+
return int(self.price) / 10 ** -self.exponent
|
|
511
|
+
|
|
512
|
+
class Config:
|
|
513
|
+
populate_by_name = True
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
class LazerPriceFeedResponse(BaseModel):
|
|
517
|
+
"""Response from Pyth Lazer SSE stream."""
|
|
518
|
+
|
|
519
|
+
timestamp_us: str = Field(..., alias="timestampUs")
|
|
520
|
+
price_feeds: List[LazerPriceFeed] = Field(..., alias="priceFeeds")
|
|
521
|
+
|
|
522
|
+
@property
|
|
523
|
+
def timestamp_ms(self) -> int:
|
|
524
|
+
return int(self.timestamp_us) // 1000
|
|
525
|
+
|
|
526
|
+
class Config:
|
|
527
|
+
populate_by_name = True
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
class FeedV3CorePriceData(BaseModel):
|
|
531
|
+
"""Core price data from feed-v3 API (Pyth Hermes)."""
|
|
532
|
+
|
|
533
|
+
price_update_data: str = Field(..., alias="priceUpdateData")
|
|
534
|
+
price: float
|
|
535
|
+
publish_timestamp_ms: int = Field(..., alias="publishTimestampMs")
|
|
536
|
+
|
|
537
|
+
class Config:
|
|
538
|
+
populate_by_name = True
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
class FeedV3ProPriceData(BaseModel):
|
|
542
|
+
"""Pro price data from feed-v3 API (Pyth Pro/Lazer)."""
|
|
543
|
+
|
|
544
|
+
price_update_data: str = Field(..., alias="priceUpdateData")
|
|
545
|
+
price: float
|
|
546
|
+
publish_timestamp_ms: int = Field(..., alias="publishTimestampMs")
|
|
547
|
+
|
|
548
|
+
class Config:
|
|
549
|
+
populate_by_name = True
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
class FeedV3PriceResponse(BaseModel):
|
|
553
|
+
"""Response from feed-v3 API containing both core and pro price data."""
|
|
554
|
+
|
|
555
|
+
core: FeedV3CorePriceData
|
|
556
|
+
pro: FeedV3ProPriceData
|
|
557
|
+
|
|
558
|
+
class Config:
|
|
559
|
+
populate_by_name = True
|
|
560
|
+
|
|
561
|
+
|
|
444
562
|
class LossProtectionInfo(BaseModel):
|
|
445
563
|
percentage: float
|
|
446
564
|
amount: float
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
avantis_trader_sdk/__init__.py,sha256=
|
|
1
|
+
avantis_trader_sdk/__init__.py,sha256=piAMiNqSagDn1nQUlJ2y5v_egZfg11Aui8ly04gjbKQ,168
|
|
2
2
|
avantis_trader_sdk/client.py,sha256=M01uwXIdxJjmPEcFr1MsDuoxU9YGddxcGMTPucOOssA,10903
|
|
3
|
-
avantis_trader_sdk/config.py,sha256=
|
|
4
|
-
avantis_trader_sdk/types.py,sha256=
|
|
3
|
+
avantis_trader_sdk/config.py,sha256=sE9y9R1ql1UwpFSs-qTbNfvO5iffRRUdYtx_JVOaWyA,838
|
|
4
|
+
avantis_trader_sdk/types.py,sha256=spp3n7UedgVM-w9JyCzQuqi8JiJmSjm24j4cxg0-gx8,17274
|
|
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
|
|
@@ -128,7 +128,7 @@ avantis_trader_sdk/abis/Timelock.t.sol/Timelock.json,sha256=N58EBp-LRYuIUvs5s0ze
|
|
|
128
128
|
avantis_trader_sdk/abis/TimelockBase.t.sol/TimelockBase.json,sha256=Bx-U5If_X5Dd49-GBDQTst3gDp8hG1YptPxoDyw3auw,1111293
|
|
129
129
|
avantis_trader_sdk/abis/TimelockController.sol/TimelockController.json,sha256=k6uk3eErrOFWCIaSBno0aqziOi744NEdxnK8vG-ohrA,333379
|
|
130
130
|
avantis_trader_sdk/abis/TradeBase.t.sol/TradeBase.json,sha256=w3sGtHzPkd45TLRhRxQzlUPmwYfjay7_4rU6CyuFu9M,1328584
|
|
131
|
-
avantis_trader_sdk/abis/Trading.sol/Trading.json,sha256=
|
|
131
|
+
avantis_trader_sdk/abis/Trading.sol/Trading.json,sha256=IM8Uv4SSXq23L8W-eJSzPtmz_h10WaRWao5ks0uiOLo,41789
|
|
132
132
|
avantis_trader_sdk/abis/TradingCallbacks.sol/TradingCallbacks.json,sha256=m_tO-wHtc5hXMky0wbLj6lqFt12SgtjlBQZQnmShECU,199077
|
|
133
133
|
avantis_trader_sdk/abis/TradingStorage.sol/TradingStorage.json,sha256=ImaFCa_a4htBOw99ITGzfuWlUeN3CvIROv0f4KH-hqw,313012
|
|
134
134
|
avantis_trader_sdk/abis/Tranche.sol/Tranche.json,sha256=AZX5KxzyXI6ao93UrZsqQE9FpNZAArOqReJX0OzoT2E,392082
|
|
@@ -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=
|
|
198
|
+
avantis_trader_sdk/feed/feed_client.py,sha256=sMlf6XaMoAiJ4DSxim-Bd81kPlM2laT0QmLbMfR6P9Q,12989
|
|
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=
|
|
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=
|
|
208
|
-
avantis_trader_sdk/rpc/trading_parameters.py,sha256=
|
|
207
|
+
avantis_trader_sdk/rpc/trade.py,sha256=QZCc0wU_7tPzC_Bo32JlSxcDZZF7NK-udqNG54myizM,31940
|
|
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.
|
|
216
|
-
avantis_trader_sdk-0.8.
|
|
217
|
-
avantis_trader_sdk-0.8.
|
|
218
|
-
avantis_trader_sdk-0.8.
|
|
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,,
|
|
File without changes
|
|
File without changes
|