avantis-trader-sdk 0.4.0__py3-none-any.whl → 0.6.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.
- avantis_trader_sdk/__init__.py +22 -1
- avantis_trader_sdk/abis/PairStorage.sol/PairStorage.json +1 -1
- avantis_trader_sdk/client.py +6 -0
- avantis_trader_sdk/config.py +2 -2
- avantis_trader_sdk/rpc/pairs_cache.py +22 -6
- avantis_trader_sdk/rpc/trade.py +60 -2
- avantis_trader_sdk/types.py +71 -9
- {avantis_trader_sdk-0.4.0.dist-info → avantis_trader_sdk-0.6.0.dist-info}/METADATA +1 -1
- {avantis_trader_sdk-0.4.0.dist-info → avantis_trader_sdk-0.6.0.dist-info}/RECORD +11 -11
- {avantis_trader_sdk-0.4.0.dist-info → avantis_trader_sdk-0.6.0.dist-info}/WHEEL +0 -0
- {avantis_trader_sdk-0.4.0.dist-info → avantis_trader_sdk-0.6.0.dist-info}/top_level.txt +0 -0
avantis_trader_sdk/client.py
CHANGED
|
@@ -137,6 +137,12 @@ class TraderClient:
|
|
|
137
137
|
if self.has_signer() and "from" not in kwargs:
|
|
138
138
|
kwargs["from"] = self.get_signer().get_ethereum_address()
|
|
139
139
|
|
|
140
|
+
if "chainId" not in kwargs:
|
|
141
|
+
kwargs["chainId"] = self.chain_id
|
|
142
|
+
|
|
143
|
+
if "nonce" not in kwargs:
|
|
144
|
+
kwargs["nonce"] = await self.get_transaction_count(kwargs["from"])
|
|
145
|
+
|
|
140
146
|
transaction = await contract.functions[function_name](*args).build_transaction(
|
|
141
147
|
kwargs
|
|
142
148
|
)
|
avantis_trader_sdk/config.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
MAINNET_ADDRESSES = {
|
|
2
2
|
"TradingStorage": "0x8a311D7048c35985aa31C131B9A13e03a5f7422d",
|
|
3
|
-
"PairStorage": "
|
|
3
|
+
"PairStorage": "0x5db3772136e5557EFE028Db05EE95C84D76faEC4",
|
|
4
4
|
"PairInfos": "0x81F22d0Cc22977c91bEfE648C9fddf1f2bd977e5",
|
|
5
5
|
"PriceAggregator": "0x64e2625621970F8cfA17B294670d61CB883dA511",
|
|
6
6
|
"USDC": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
7
7
|
"Trading": "0x5FF292d70bA9cD9e7CCb313782811b3D7120535f",
|
|
8
|
-
"Multicall": "
|
|
8
|
+
"Multicall": "0xD4693314460d6fb598C1124aeC40C03e2Aa0A8a4",
|
|
9
9
|
"Referral": "0xA96f577821933d127B491D0F91202405B0dbB1bd",
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from ..types import
|
|
1
|
+
from ..types import PairInfoWithData
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class PairsCache:
|
|
@@ -35,15 +35,31 @@ class PairsCache:
|
|
|
35
35
|
|
|
36
36
|
calls = []
|
|
37
37
|
for pair_index in range(pairs_count):
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
core_call_data = PairStorage.encodeABI(
|
|
39
|
+
fn_name="pairs", args=[pair_index]
|
|
40
|
+
)
|
|
41
|
+
pair_data_call_data = PairStorage.encodeABI(
|
|
42
|
+
fn_name="getPairData", args=[pair_index]
|
|
43
|
+
)
|
|
44
|
+
calls.extend(
|
|
45
|
+
[
|
|
46
|
+
(PairStorage.address, core_call_data),
|
|
47
|
+
(PairStorage.address, pair_data_call_data),
|
|
48
|
+
]
|
|
49
|
+
)
|
|
40
50
|
|
|
41
51
|
_, raw_data = await Multicall.functions.aggregate(calls).call()
|
|
42
52
|
|
|
43
53
|
decoded_data = []
|
|
44
|
-
for
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
for i in range(0, len(raw_data), 2):
|
|
55
|
+
pair_info = self.client.utils["decoder"](
|
|
56
|
+
PairStorage, "pairs", raw_data[i]
|
|
57
|
+
)
|
|
58
|
+
pair_data = self.client.utils["decoder"](
|
|
59
|
+
PairStorage, "getPairData", raw_data[i + 1]
|
|
60
|
+
)
|
|
61
|
+
pair_info.update(pair_data)
|
|
62
|
+
decoded_data.append(PairInfoWithData(**pair_info))
|
|
47
63
|
|
|
48
64
|
for index, pair_info in enumerate(decoded_data):
|
|
49
65
|
if not pair_info.from_:
|
avantis_trader_sdk/rpc/trade.py
CHANGED
|
@@ -236,6 +236,8 @@ class TradeRPC:
|
|
|
236
236
|
if trader is None:
|
|
237
237
|
trader = self.client.get_signer().get_ethereum_address()
|
|
238
238
|
|
|
239
|
+
collateral_to_close = int(collateral_to_close * 10**6)
|
|
240
|
+
|
|
239
241
|
execution_fee = await self.get_trade_execution_fee()
|
|
240
242
|
|
|
241
243
|
transaction = await Trading.functions.closeTradeMarket(
|
|
@@ -308,7 +310,6 @@ class TradeRPC:
|
|
|
308
310
|
trader = self.client.get_signer().get_ethereum_address()
|
|
309
311
|
|
|
310
312
|
collateral_change = int(collateral_change * 10**6)
|
|
311
|
-
fee_in_wei = 1 * 10**18
|
|
312
313
|
|
|
313
314
|
feed_client = self.FeedClient()
|
|
314
315
|
|
|
@@ -328,8 +329,65 @@ class TradeRPC:
|
|
|
328
329
|
{
|
|
329
330
|
"from": trader,
|
|
330
331
|
"chainId": self.client.chain_id,
|
|
331
|
-
"value":
|
|
332
|
+
"value": 1,
|
|
333
|
+
"nonce": await self.client.get_transaction_count(trader),
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
return transaction
|
|
338
|
+
|
|
339
|
+
async def build_trade_tp_sl_update_tx(
|
|
340
|
+
self,
|
|
341
|
+
pair_index: int,
|
|
342
|
+
trade_index: int,
|
|
343
|
+
take_profit_price: float,
|
|
344
|
+
stop_loss_price: float,
|
|
345
|
+
trader: str = None,
|
|
346
|
+
):
|
|
347
|
+
"""
|
|
348
|
+
Builds a transaction to update the stop loss and take profit of a trade.
|
|
349
|
+
|
|
350
|
+
Args:
|
|
351
|
+
pair_index: The pair index.
|
|
352
|
+
trade_index: The trade index.
|
|
353
|
+
take_profit_price: The take profit price.
|
|
354
|
+
stop_loss_price: The stop loss price. Pass 0 if you want to remove the stop loss.
|
|
355
|
+
trader (optional): The trader's wallet address.
|
|
356
|
+
Returns:
|
|
357
|
+
A transaction object.
|
|
358
|
+
"""
|
|
359
|
+
Trading = self.client.contracts.get("Trading")
|
|
360
|
+
|
|
361
|
+
if take_profit_price == 0:
|
|
362
|
+
raise ValueError("Take profit price cannot be 0")
|
|
363
|
+
|
|
364
|
+
if trader is None:
|
|
365
|
+
trader = self.client.get_signer().get_ethereum_address()
|
|
366
|
+
|
|
367
|
+
feed_client = self.FeedClient()
|
|
368
|
+
|
|
369
|
+
pair_name = await self.client.pairs_cache.get_pair_name_from_index(pair_index)
|
|
370
|
+
|
|
371
|
+
price_data = await feed_client.get_latest_price_updates([pair_name])
|
|
372
|
+
|
|
373
|
+
price_update_data = "0x" + price_data.binary.data[0]
|
|
374
|
+
|
|
375
|
+
take_profit_price = int(take_profit_price * 10**10)
|
|
376
|
+
stop_loss_price = int(stop_loss_price * 10**10)
|
|
377
|
+
|
|
378
|
+
transaction = await Trading.functions.updateTpAndSl(
|
|
379
|
+
pair_index,
|
|
380
|
+
trade_index,
|
|
381
|
+
stop_loss_price,
|
|
382
|
+
take_profit_price,
|
|
383
|
+
[price_update_data],
|
|
384
|
+
).build_transaction(
|
|
385
|
+
{
|
|
386
|
+
"from": trader,
|
|
387
|
+
"chainId": self.client.chain_id,
|
|
388
|
+
"value": 1,
|
|
332
389
|
"nonce": await self.client.get_transaction_count(trader),
|
|
390
|
+
"gas": 1_000_000,
|
|
333
391
|
}
|
|
334
392
|
)
|
|
335
393
|
|
avantis_trader_sdk/types.py
CHANGED
|
@@ -13,6 +13,22 @@ import re
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class PairInfoFeed(BaseModel):
|
|
16
|
+
max_open_deviation_percentage: float = Field(..., alias="maxOpenDeviationP")
|
|
17
|
+
max_close_deviation_percentage: float = Field(..., alias="maxCloseDeviationP")
|
|
18
|
+
|
|
19
|
+
feed_id: str = Field(..., alias="feedId")
|
|
20
|
+
|
|
21
|
+
@field_validator(
|
|
22
|
+
"max_open_deviation_percentage", "max_close_deviation_percentage", mode="before"
|
|
23
|
+
)
|
|
24
|
+
def convert_max_deviation(cls, v):
|
|
25
|
+
return v / 10**10
|
|
26
|
+
|
|
27
|
+
class Config:
|
|
28
|
+
populate_by_name = True
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class PairInfoBackupFeed(BaseModel):
|
|
16
32
|
max_deviation_percentage: float = Field(..., alias="maxDeviationP")
|
|
17
33
|
feed_id: str = Field(..., alias="feedId")
|
|
18
34
|
|
|
@@ -21,26 +37,52 @@ class PairInfoFeed(BaseModel):
|
|
|
21
37
|
return v / 10**10
|
|
22
38
|
|
|
23
39
|
|
|
40
|
+
class PairInfoLeverages(BaseModel):
|
|
41
|
+
min_leverage: float = Field(..., alias="minLeverage")
|
|
42
|
+
max_leverage: float = Field(..., alias="maxLeverage")
|
|
43
|
+
pnl_min_leverage: float = Field(..., alias="pnlMinLeverage")
|
|
44
|
+
pnl_max_leverage: float = Field(..., alias="pnlMaxLeverage")
|
|
45
|
+
|
|
46
|
+
@field_validator(
|
|
47
|
+
"min_leverage",
|
|
48
|
+
"max_leverage",
|
|
49
|
+
"pnl_min_leverage",
|
|
50
|
+
"pnl_max_leverage",
|
|
51
|
+
mode="before",
|
|
52
|
+
)
|
|
53
|
+
def convert_max_deviation(cls, v):
|
|
54
|
+
return v / 10**10
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class PairInfoValues(BaseModel):
|
|
58
|
+
max_gain_percentage: float = Field(..., alias="maxGainP")
|
|
59
|
+
max_sl_percentage: float = Field(..., alias="maxSlP")
|
|
60
|
+
max_long_oi_percentage: float = Field(..., alias="maxLongOiP")
|
|
61
|
+
max_short_oi_percentage: float = Field(..., alias="maxShortOiP")
|
|
62
|
+
group_open_interest_percentage: float = Field(
|
|
63
|
+
..., alias="groupOpenInterestPecentage"
|
|
64
|
+
)
|
|
65
|
+
max_wallet_oi_percentage: float = Field(..., alias="maxWalletOI")
|
|
66
|
+
is_usdc_aligned: bool = Field(..., alias="isUSDCAligned")
|
|
67
|
+
|
|
68
|
+
|
|
24
69
|
class PairInfo(BaseModel):
|
|
25
|
-
from_: str = Field(..., alias="from")
|
|
26
|
-
to: str
|
|
27
70
|
feed: PairInfoFeed
|
|
28
|
-
backup_feed:
|
|
71
|
+
backup_feed: PairInfoBackupFeed = Field(..., alias="backupFeed")
|
|
29
72
|
constant_spread_bps: float = Field(..., alias="spreadP")
|
|
73
|
+
constant_pnl_spread_bps: float = Field(..., alias="pnlSpreadP")
|
|
74
|
+
leverages: PairInfoLeverages = Field(..., alias="leverages")
|
|
30
75
|
price_impact_parameter: float = Field(..., alias="priceImpactMultiplier")
|
|
31
76
|
skew_impact_parameter: float = Field(..., alias="skewImpactMultiplier")
|
|
32
77
|
group_index: int = Field(..., alias="groupIndex")
|
|
33
78
|
fee_index: int = Field(..., alias="feeIndex")
|
|
34
|
-
|
|
35
|
-
..., alias="groupOpenInterestPecentage"
|
|
36
|
-
)
|
|
37
|
-
max_wallet_oi: float = Field(..., alias="maxWalletOI")
|
|
79
|
+
values: PairInfoValues = Field(..., alias="values")
|
|
38
80
|
|
|
39
81
|
@field_validator("price_impact_parameter", "skew_impact_parameter", mode="before")
|
|
40
82
|
def convert_to_float_10(cls, v):
|
|
41
83
|
return v / 10**10
|
|
42
84
|
|
|
43
|
-
@field_validator("constant_spread_bps", mode="before")
|
|
85
|
+
@field_validator("constant_spread_bps", "constant_pnl_spread_bps", mode="before")
|
|
44
86
|
def convert_to_float_10_bps(cls, v):
|
|
45
87
|
return v / 10**10 * 100
|
|
46
88
|
|
|
@@ -48,6 +90,26 @@ class PairInfo(BaseModel):
|
|
|
48
90
|
populate_by_name = True
|
|
49
91
|
|
|
50
92
|
|
|
93
|
+
class PairData(BaseModel):
|
|
94
|
+
from_: str = Field(..., alias="from")
|
|
95
|
+
to: str
|
|
96
|
+
num_tiers: int = Field(..., alias="numTiers")
|
|
97
|
+
tier_thresholds: Dict[str, float] = Field(..., alias="tierThresholds")
|
|
98
|
+
tier_timers: Dict[str, float] = Field(..., alias="timer")
|
|
99
|
+
|
|
100
|
+
@field_validator("tier_thresholds", "tier_timers", mode="before")
|
|
101
|
+
def convert_tuple_to_dict(cls, v):
|
|
102
|
+
if isinstance(v, tuple):
|
|
103
|
+
return {str(i): j for i, j in enumerate(v)}
|
|
104
|
+
return v
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class PairInfoWithData(PairInfo, PairData):
|
|
108
|
+
class Config:
|
|
109
|
+
populate_by_name = True
|
|
110
|
+
from_attributes = True
|
|
111
|
+
|
|
112
|
+
|
|
51
113
|
class OpenInterest(BaseModel):
|
|
52
114
|
long: Dict[str, float]
|
|
53
115
|
short: Dict[str, float]
|
|
@@ -82,7 +144,7 @@ class DepthSingle(BaseModel):
|
|
|
82
144
|
below: float
|
|
83
145
|
|
|
84
146
|
|
|
85
|
-
class PairInfoExtended(
|
|
147
|
+
class PairInfoExtended(PairInfoWithData):
|
|
86
148
|
asset_open_interest_limit: float
|
|
87
149
|
asset_open_interest: Dict[str, float]
|
|
88
150
|
asset_utilization: float
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
avantis_trader_sdk/__init__.py,sha256=
|
|
2
|
-
avantis_trader_sdk/client.py,sha256=
|
|
3
|
-
avantis_trader_sdk/config.py,sha256=
|
|
4
|
-
avantis_trader_sdk/types.py,sha256=
|
|
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
|
|
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
|
|
@@ -88,7 +88,7 @@ avantis_trader_sdk/abis/Multicall.t.sol/MulticallGroup.json,sha256=AZVoGuVs__JE-
|
|
|
88
88
|
avantis_trader_sdk/abis/Multicall3.sol/Multicall3.json,sha256=7-38-beNTW3Jo9ZHvpgp8JzI5ylN6llcV_fzw9syF_s,176224
|
|
89
89
|
avantis_trader_sdk/abis/Ownable.sol/Ownable.json,sha256=aBFacbduOM9MRjoTB71SNiMWIytBc2t0BRcU7u-GrNk,31008
|
|
90
90
|
avantis_trader_sdk/abis/PairInfos.sol/PairInfos.json,sha256=i9sWFDHIDJAlwuC0M0Y9w7Z2rhOcWDGyKYUrobI2SdI,712989
|
|
91
|
-
avantis_trader_sdk/abis/PairStorage.sol/PairStorage.json,sha256=
|
|
91
|
+
avantis_trader_sdk/abis/PairStorage.sol/PairStorage.json,sha256=Lcrh8PfZusTQr_ZWpSU96PBEKebb0rQrMhzge6BsjoA,305493
|
|
92
92
|
avantis_trader_sdk/abis/PausableUpgradeable.sol/PausableUpgradeable.json,sha256=_STYbJg_yX9kU7He-sQjkwVo8uHTs0jotpHoi-8DYWY,31799
|
|
93
93
|
avantis_trader_sdk/abis/PositionMath.sol/PositionMath.json,sha256=WouZkR-00Avs16LvtMUdWitehNKKiuiQUWr4O0I6DJM,11823
|
|
94
94
|
avantis_trader_sdk/abis/PriceAggregator.sol/PriceAggregator.json,sha256=_IhAyWO2pzFu-TJg0OJRxnF8s9xE_w9khrkq7R3ztdc,393087
|
|
@@ -201,10 +201,10 @@ avantis_trader_sdk/rpc/asset_parameters.py,sha256=OkGyfSmiCUl7fgJaUJFQekpQ8o2_Jb
|
|
|
201
201
|
avantis_trader_sdk/rpc/blended.py,sha256=UHgrPEvkJwQJRxTrVG03Ir8IjJRGenQFov1bJvbuGi4,2512
|
|
202
202
|
avantis_trader_sdk/rpc/category_parameters.py,sha256=yw-6Ib1kS25JTmZQzH7Xyn1dehUqGYBoZM_bO7G4lEE,8181
|
|
203
203
|
avantis_trader_sdk/rpc/fee_parameters.py,sha256=EhJY7I66MAP_sClVhSy6KBiicpeEip5EXrIlpfbVSDM,9369
|
|
204
|
-
avantis_trader_sdk/rpc/pairs_cache.py,sha256=
|
|
204
|
+
avantis_trader_sdk/rpc/pairs_cache.py,sha256=gjdfdIr8BGhGDIBv-PZQnJZEKeDHSt1DJZVzecCN7yY,4689
|
|
205
205
|
avantis_trader_sdk/rpc/rpc_helpers.py,sha256=d3dzwEaAUVo700qK7S-bBSVX3UtrOKbPEGPqgxHS5sk,292
|
|
206
206
|
avantis_trader_sdk/rpc/snapshot.py,sha256=2EMtNqfeB37dr4EsuSMBm0CAYbwWMv9evML8MZocNFw,5494
|
|
207
|
-
avantis_trader_sdk/rpc/trade.py,sha256=
|
|
207
|
+
avantis_trader_sdk/rpc/trade.py,sha256=jq3bYWPZqAaFjDlbs42mhbQFb8dKiGLxGYyDAsqNv8Y,13154
|
|
208
208
|
avantis_trader_sdk/rpc/trading_parameters.py,sha256=ZvEJ-kjrogENIhPsETRIp-FdVaIdd2mT2fyM84SuFJk,4702
|
|
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.
|
|
216
|
-
avantis_trader_sdk-0.
|
|
217
|
-
avantis_trader_sdk-0.
|
|
218
|
-
avantis_trader_sdk-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,,
|
|
File without changes
|
|
File without changes
|