avantis-trader-sdk 0.7.0__py3-none-any.whl → 0.8.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 +1 -22
- avantis_trader_sdk/abis/PairInfos.sol/PairInfos.json +1 -1
- avantis_trader_sdk/abis/PriceAggregator.sol/PriceAggregator.json +1 -1
- avantis_trader_sdk/abis/Referral.sol/Referral.json +1 -1
- avantis_trader_sdk/abis/Trading.sol/Trading.json +1 -1
- avantis_trader_sdk/abis/TradingCallbacks.sol/TradingCallbacks.json +1 -1
- avantis_trader_sdk/abis/TradingStorage.sol/TradingStorage.json +1 -1
- avantis_trader_sdk/config.py +3 -3
- avantis_trader_sdk/rpc/asset_parameters.py +15 -15
- avantis_trader_sdk/rpc/trade.py +320 -4
- avantis_trader_sdk/rpc/trading_parameters.py +7 -4
- avantis_trader_sdk/types.py +1 -0
- {avantis_trader_sdk-0.7.0.dist-info → avantis_trader_sdk-0.8.0.dist-info}/METADATA +1 -1
- {avantis_trader_sdk-0.7.0.dist-info → avantis_trader_sdk-0.8.0.dist-info}/RECORD +16 -16
- {avantis_trader_sdk-0.7.0.dist-info → avantis_trader_sdk-0.8.0.dist-info}/WHEEL +0 -0
- {avantis_trader_sdk-0.7.0.dist-info → avantis_trader_sdk-0.8.0.dist-info}/top_level.txt +0 -0
avantis_trader_sdk/config.py
CHANGED
|
@@ -4,9 +4,9 @@ MAINNET_ADDRESSES = {
|
|
|
4
4
|
"PairInfos": "0x81F22d0Cc22977c91bEfE648C9fddf1f2bd977e5",
|
|
5
5
|
"PriceAggregator": "0x64e2625621970F8cfA17B294670d61CB883dA511",
|
|
6
6
|
"USDC": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
7
|
-
"Trading": "
|
|
8
|
-
"Multicall": "
|
|
9
|
-
"Referral": "
|
|
7
|
+
"Trading": "0x44914408af82bC9983bbb330e3578E1105e11d4e",
|
|
8
|
+
"Multicall": "0x7A829c5C97A2Bf8BeFB4b01d96A282E4763848d8",
|
|
9
|
+
"Referral": "0x1A110bBA13A1f16cCa4b79758BD39290f29De82D",
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
AVANTIS_SOCKET_API = "https://socket-api.avantisfi.com/v1/data"
|
|
@@ -161,21 +161,21 @@ class AssetParametersRPC:
|
|
|
161
161
|
PairInfos.address,
|
|
162
162
|
PairInfos.encodeABI(
|
|
163
163
|
fn_name="getPriceImpactSpread",
|
|
164
|
-
args=[pair_index, True, position_size],
|
|
164
|
+
args=[pair_index, True, position_size, False],
|
|
165
165
|
),
|
|
166
166
|
),
|
|
167
167
|
(
|
|
168
168
|
PairInfos.address,
|
|
169
169
|
PairInfos.encodeABI(
|
|
170
170
|
fn_name="getPriceImpactSpread",
|
|
171
|
-
args=[pair_index, False, position_size],
|
|
171
|
+
args=[pair_index, False, position_size, False],
|
|
172
172
|
),
|
|
173
173
|
),
|
|
174
174
|
]
|
|
175
175
|
)
|
|
176
176
|
else:
|
|
177
177
|
response = await PairInfos.functions.getPriceImpactSpread(
|
|
178
|
-
pair_index, is_long, position_size
|
|
178
|
+
pair_index, is_long, position_size, False
|
|
179
179
|
).call()
|
|
180
180
|
else:
|
|
181
181
|
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
@@ -189,14 +189,14 @@ class AssetParametersRPC:
|
|
|
189
189
|
PairInfos.address,
|
|
190
190
|
PairInfos.encodeABI(
|
|
191
191
|
fn_name="getPriceImpactSpread",
|
|
192
|
-
args=[pair_index, True, position_size],
|
|
192
|
+
args=[pair_index, True, position_size, False],
|
|
193
193
|
),
|
|
194
194
|
),
|
|
195
195
|
(
|
|
196
196
|
PairInfos.address,
|
|
197
197
|
PairInfos.encodeABI(
|
|
198
198
|
fn_name="getPriceImpactSpread",
|
|
199
|
-
args=[pair_index, False, position_size],
|
|
199
|
+
args=[pair_index, False, position_size, False],
|
|
200
200
|
),
|
|
201
201
|
),
|
|
202
202
|
]
|
|
@@ -207,7 +207,7 @@ class AssetParametersRPC:
|
|
|
207
207
|
PairInfos.address,
|
|
208
208
|
PairInfos.encodeABI(
|
|
209
209
|
fn_name="getPriceImpactSpread",
|
|
210
|
-
args=[pair_index, is_long, position_size],
|
|
210
|
+
args=[pair_index, is_long, position_size, False],
|
|
211
211
|
),
|
|
212
212
|
)
|
|
213
213
|
)
|
|
@@ -295,21 +295,21 @@ class AssetParametersRPC:
|
|
|
295
295
|
PairInfos.address,
|
|
296
296
|
PairInfos.encodeABI(
|
|
297
297
|
fn_name="getSkewImpactSpread",
|
|
298
|
-
args=[pair_index, True, position_size],
|
|
298
|
+
args=[pair_index, True, position_size, False],
|
|
299
299
|
),
|
|
300
300
|
),
|
|
301
301
|
(
|
|
302
302
|
PairInfos.address,
|
|
303
303
|
PairInfos.encodeABI(
|
|
304
304
|
fn_name="getSkewImpactSpread",
|
|
305
|
-
args=[pair_index, False, position_size],
|
|
305
|
+
args=[pair_index, False, position_size, False],
|
|
306
306
|
),
|
|
307
307
|
),
|
|
308
308
|
]
|
|
309
309
|
)
|
|
310
310
|
else:
|
|
311
311
|
response = await PairInfos.functions.getSkewImpactSpread(
|
|
312
|
-
pair_index, is_long, position_size
|
|
312
|
+
pair_index, is_long, position_size, False
|
|
313
313
|
).call()
|
|
314
314
|
else:
|
|
315
315
|
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
@@ -322,14 +322,14 @@ class AssetParametersRPC:
|
|
|
322
322
|
PairInfos.address,
|
|
323
323
|
PairInfos.encodeABI(
|
|
324
324
|
fn_name="getSkewImpactSpread",
|
|
325
|
-
args=[pair_index, True, position_size],
|
|
325
|
+
args=[pair_index, True, position_size, False],
|
|
326
326
|
),
|
|
327
327
|
),
|
|
328
328
|
(
|
|
329
329
|
PairInfos.address,
|
|
330
330
|
PairInfos.encodeABI(
|
|
331
331
|
fn_name="getSkewImpactSpread",
|
|
332
|
-
args=[pair_index, False, position_size],
|
|
332
|
+
args=[pair_index, False, position_size, False],
|
|
333
333
|
),
|
|
334
334
|
),
|
|
335
335
|
]
|
|
@@ -340,7 +340,7 @@ class AssetParametersRPC:
|
|
|
340
340
|
PairInfos.address,
|
|
341
341
|
PairInfos.encodeABI(
|
|
342
342
|
fn_name="getSkewImpactSpread",
|
|
343
|
-
args=[pair_index, is_long, position_size],
|
|
343
|
+
args=[pair_index, is_long, position_size, False],
|
|
344
344
|
),
|
|
345
345
|
)
|
|
346
346
|
)
|
|
@@ -423,21 +423,21 @@ class AssetParametersRPC:
|
|
|
423
423
|
PairInfos.address,
|
|
424
424
|
PairInfos.encodeABI(
|
|
425
425
|
fn_name="getTradePriceImpact",
|
|
426
|
-
args=[open_price, pair_index, True, position_size],
|
|
426
|
+
args=[open_price, pair_index, True, position_size, False],
|
|
427
427
|
),
|
|
428
428
|
),
|
|
429
429
|
(
|
|
430
430
|
PairInfos.address,
|
|
431
431
|
PairInfos.encodeABI(
|
|
432
432
|
fn_name="getTradePriceImpact",
|
|
433
|
-
args=[open_price, pair_index, False, position_size],
|
|
433
|
+
args=[open_price, pair_index, False, position_size, False],
|
|
434
434
|
),
|
|
435
435
|
),
|
|
436
436
|
]
|
|
437
437
|
)
|
|
438
438
|
else:
|
|
439
439
|
response = await PairInfos.functions.getTradePriceImpact(
|
|
440
|
-
open_price, pair_index, is_long, position_size
|
|
440
|
+
open_price, pair_index, is_long, position_size, False
|
|
441
441
|
).call()
|
|
442
442
|
|
|
443
443
|
if response is None:
|
avantis_trader_sdk/rpc/trade.py
CHANGED
|
@@ -60,9 +60,10 @@ class TradeRPC:
|
|
|
60
60
|
|
|
61
61
|
if (
|
|
62
62
|
trade_input_order_type == TradeInputOrderType.MARKET
|
|
63
|
-
|
|
64
|
-
):
|
|
63
|
+
or trade_input_order_type == TradeInputOrderType.MARKET_PNL
|
|
64
|
+
) and not trade_input.openPrice:
|
|
65
65
|
feed_client = self.FeedClient()
|
|
66
|
+
|
|
66
67
|
pair_name = await self.client.pairs_cache.get_pair_name_from_index(
|
|
67
68
|
trade_input.pairIndex
|
|
68
69
|
)
|
|
@@ -80,7 +81,6 @@ class TradeRPC:
|
|
|
80
81
|
trade_input.model_dump(),
|
|
81
82
|
trade_input_order_type.value,
|
|
82
83
|
slippage_percentage * 10**10,
|
|
83
|
-
0,
|
|
84
84
|
).build_transaction(
|
|
85
85
|
{
|
|
86
86
|
"from": trade_input.trader,
|
|
@@ -92,6 +92,86 @@ class TradeRPC:
|
|
|
92
92
|
|
|
93
93
|
return transaction
|
|
94
94
|
|
|
95
|
+
async def build_trade_open_tx_delegate(
|
|
96
|
+
self,
|
|
97
|
+
trade_input: TradeInput,
|
|
98
|
+
trade_input_order_type: TradeInputOrderType,
|
|
99
|
+
slippage_percentage: int,
|
|
100
|
+
execution_fee: Optional[float] = None,
|
|
101
|
+
):
|
|
102
|
+
"""
|
|
103
|
+
Builds a transaction to open a trade.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
trade: The trade input object.
|
|
107
|
+
trade_input_order_type: The trade input order type.
|
|
108
|
+
slippage_percentage: The slippage percentage.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
A transaction object.
|
|
112
|
+
"""
|
|
113
|
+
Trading = self.client.contracts.get("Trading")
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
trade_input.trader == "0x1234567890123456789012345678901234567890"
|
|
117
|
+
and self.client.get_signer() is not None
|
|
118
|
+
):
|
|
119
|
+
trade_input.trader = await self.client.get_signer().get_ethereum_address()
|
|
120
|
+
|
|
121
|
+
if execution_fee is not None:
|
|
122
|
+
execution_fee_wei = int(execution_fee * 10**18)
|
|
123
|
+
else:
|
|
124
|
+
execution_fee_wei = await self.get_trade_execution_fee()
|
|
125
|
+
|
|
126
|
+
if (
|
|
127
|
+
trade_input_order_type == TradeInputOrderType.MARKET
|
|
128
|
+
or trade_input_order_type == TradeInputOrderType.MARKET_PNL
|
|
129
|
+
) and not trade_input.openPrice:
|
|
130
|
+
feed_client = self.FeedClient()
|
|
131
|
+
|
|
132
|
+
pair_name = await self.client.pairs_cache.get_pair_name_from_index(
|
|
133
|
+
trade_input.pairIndex
|
|
134
|
+
)
|
|
135
|
+
price_data = await feed_client.get_latest_price_updates([pair_name])
|
|
136
|
+
price = int(price_data.parsed[0].converted_price * 10**10)
|
|
137
|
+
trade_input.openPrice = price
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
trade_input_order_type == TradeInputOrderType.LIMIT
|
|
141
|
+
or trade_input_order_type == TradeInputOrderType.STOP_LIMIT
|
|
142
|
+
) and not trade_input.openPrice:
|
|
143
|
+
raise Exception("Open price is required for LIMIT/STOP LIMIT order type")
|
|
144
|
+
|
|
145
|
+
transaction = await Trading.functions.openTrade(
|
|
146
|
+
trade_input.model_dump(),
|
|
147
|
+
trade_input_order_type.value,
|
|
148
|
+
slippage_percentage * 10**10,
|
|
149
|
+
).build_transaction(
|
|
150
|
+
{
|
|
151
|
+
"from": trade_input.trader,
|
|
152
|
+
"value": 0,
|
|
153
|
+
"chainId": self.client.chain_id,
|
|
154
|
+
"nonce": await self.client.get_transaction_count(trade_input.trader),
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
print("transaction: ", trade_input.trader)
|
|
159
|
+
|
|
160
|
+
delegate_transaction = await Trading.functions.delegatedAction(
|
|
161
|
+
trade_input.trader, transaction["data"]
|
|
162
|
+
).build_transaction(
|
|
163
|
+
{
|
|
164
|
+
"from": self.client.get_signer().get_ethereum_address(),
|
|
165
|
+
"value": execution_fee_wei,
|
|
166
|
+
"chainId": self.client.chain_id,
|
|
167
|
+
"nonce": await self.client.get_transaction_count(
|
|
168
|
+
self.client.get_signer().get_ethereum_address()
|
|
169
|
+
),
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
return delegate_transaction
|
|
174
|
+
|
|
95
175
|
async def get_trade_execution_fee(self):
|
|
96
176
|
"""
|
|
97
177
|
Gets the correct trade execution fee.
|
|
@@ -241,7 +321,9 @@ class TradeRPC:
|
|
|
241
321
|
execution_fee = await self.get_trade_execution_fee()
|
|
242
322
|
|
|
243
323
|
transaction = await Trading.functions.closeTradeMarket(
|
|
244
|
-
pair_index,
|
|
324
|
+
pair_index,
|
|
325
|
+
trade_index,
|
|
326
|
+
collateral_to_close,
|
|
245
327
|
).build_transaction(
|
|
246
328
|
{
|
|
247
329
|
"from": trader,
|
|
@@ -253,6 +335,62 @@ class TradeRPC:
|
|
|
253
335
|
|
|
254
336
|
return transaction
|
|
255
337
|
|
|
338
|
+
async def build_trade_close_tx_delegate(
|
|
339
|
+
self,
|
|
340
|
+
pair_index: int,
|
|
341
|
+
trade_index: int,
|
|
342
|
+
collateral_to_close: float,
|
|
343
|
+
trader: Optional[str] = None,
|
|
344
|
+
):
|
|
345
|
+
"""
|
|
346
|
+
Builds a transaction to close a trade.
|
|
347
|
+
|
|
348
|
+
Args:
|
|
349
|
+
pair_index: The pair index.
|
|
350
|
+
trade_index: The trade index.
|
|
351
|
+
collateral_to_close: The collateral to close.
|
|
352
|
+
trader (optional): The trader's wallet address.
|
|
353
|
+
|
|
354
|
+
Returns:
|
|
355
|
+
A transaction object.
|
|
356
|
+
"""
|
|
357
|
+
Trading = self.client.contracts.get("Trading")
|
|
358
|
+
|
|
359
|
+
if trader is None:
|
|
360
|
+
trader = self.client.get_signer().get_ethereum_address()
|
|
361
|
+
|
|
362
|
+
collateral_to_close = int(collateral_to_close * 10**6)
|
|
363
|
+
|
|
364
|
+
execution_fee = await self.get_trade_execution_fee()
|
|
365
|
+
|
|
366
|
+
transaction = await Trading.functions.closeTradeMarket(
|
|
367
|
+
pair_index,
|
|
368
|
+
trade_index,
|
|
369
|
+
collateral_to_close,
|
|
370
|
+
).build_transaction(
|
|
371
|
+
{
|
|
372
|
+
"from": trader,
|
|
373
|
+
"chainId": self.client.chain_id,
|
|
374
|
+
"nonce": await self.client.get_transaction_count(trader),
|
|
375
|
+
"value": 0,
|
|
376
|
+
}
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
delegate_transaction = await Trading.functions.delegatedAction(
|
|
380
|
+
trader, transaction["data"]
|
|
381
|
+
).build_transaction(
|
|
382
|
+
{
|
|
383
|
+
"from": self.client.get_signer().get_ethereum_address(),
|
|
384
|
+
"value": execution_fee,
|
|
385
|
+
"chainId": self.client.chain_id,
|
|
386
|
+
"nonce": await self.client.get_transaction_count(
|
|
387
|
+
self.client.get_signer().get_ethereum_address()
|
|
388
|
+
),
|
|
389
|
+
}
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
return delegate_transaction
|
|
393
|
+
|
|
256
394
|
async def build_order_cancel_tx(
|
|
257
395
|
self, pair_index: int, trade_index: int, trader: Optional[str] = None
|
|
258
396
|
):
|
|
@@ -284,6 +422,49 @@ class TradeRPC:
|
|
|
284
422
|
|
|
285
423
|
return transaction
|
|
286
424
|
|
|
425
|
+
async def build_order_cancel_tx_delegate(
|
|
426
|
+
self, pair_index: int, trade_index: int, trader: Optional[str] = None
|
|
427
|
+
):
|
|
428
|
+
"""
|
|
429
|
+
Builds a transaction to cancel an order.
|
|
430
|
+
|
|
431
|
+
Args:
|
|
432
|
+
pair_index: The pair index.
|
|
433
|
+
trade_index: The trade/order index.
|
|
434
|
+
trader (optional): The trader's wallet address.
|
|
435
|
+
|
|
436
|
+
Returns:
|
|
437
|
+
A transaction object.
|
|
438
|
+
"""
|
|
439
|
+
Trading = self.client.contracts.get("Trading")
|
|
440
|
+
|
|
441
|
+
if trader is None:
|
|
442
|
+
trader = self.client.get_signer().get_ethereum_address()
|
|
443
|
+
|
|
444
|
+
transaction = await Trading.functions.cancelOpenLimitOrder(
|
|
445
|
+
pair_index, trade_index
|
|
446
|
+
).build_transaction(
|
|
447
|
+
{
|
|
448
|
+
"from": trader,
|
|
449
|
+
"chainId": self.client.chain_id,
|
|
450
|
+
"nonce": await self.client.get_transaction_count(trader),
|
|
451
|
+
}
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
delegate_transaction = await Trading.functions.delegatedAction(
|
|
455
|
+
trader, transaction["data"]
|
|
456
|
+
).build_transaction(
|
|
457
|
+
{
|
|
458
|
+
"from": self.client.get_signer().get_ethereum_address(),
|
|
459
|
+
"chainId": self.client.chain_id,
|
|
460
|
+
"nonce": await self.client.get_transaction_count(
|
|
461
|
+
self.client.get_signer().get_ethereum_address()
|
|
462
|
+
),
|
|
463
|
+
}
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
return delegate_transaction
|
|
467
|
+
|
|
287
468
|
async def build_trade_margin_update_tx(
|
|
288
469
|
self,
|
|
289
470
|
pair_index: int,
|
|
@@ -336,6 +517,71 @@ class TradeRPC:
|
|
|
336
517
|
|
|
337
518
|
return transaction
|
|
338
519
|
|
|
520
|
+
async def build_trade_margin_update_tx_delegate(
|
|
521
|
+
self,
|
|
522
|
+
pair_index: int,
|
|
523
|
+
trade_index: int,
|
|
524
|
+
margin_update_type: MarginUpdateType,
|
|
525
|
+
collateral_change: float,
|
|
526
|
+
trader: Optional[str] = None,
|
|
527
|
+
):
|
|
528
|
+
"""
|
|
529
|
+
Builds a transaction to update the margin of a trade.
|
|
530
|
+
|
|
531
|
+
Args:
|
|
532
|
+
pair_index: The pair index.
|
|
533
|
+
trade_index: The trade index.
|
|
534
|
+
margin_update_type: The margin update type.
|
|
535
|
+
collateral_change: The collateral change.
|
|
536
|
+
trader (optional): The trader's wallet address.
|
|
537
|
+
Returns:
|
|
538
|
+
A transaction object.
|
|
539
|
+
"""
|
|
540
|
+
Trading = self.client.contracts.get("Trading")
|
|
541
|
+
|
|
542
|
+
if trader is None:
|
|
543
|
+
trader = self.client.get_signer().get_ethereum_address()
|
|
544
|
+
|
|
545
|
+
collateral_change = int(collateral_change * 10**6)
|
|
546
|
+
|
|
547
|
+
feed_client = self.FeedClient()
|
|
548
|
+
|
|
549
|
+
pair_name = await self.client.pairs_cache.get_pair_name_from_index(pair_index)
|
|
550
|
+
|
|
551
|
+
price_data = await feed_client.get_latest_price_updates([pair_name])
|
|
552
|
+
|
|
553
|
+
price_update_data = "0x" + price_data.binary.data[0]
|
|
554
|
+
|
|
555
|
+
transaction = await Trading.functions.updateMargin(
|
|
556
|
+
pair_index,
|
|
557
|
+
trade_index,
|
|
558
|
+
margin_update_type.value,
|
|
559
|
+
collateral_change,
|
|
560
|
+
[price_update_data],
|
|
561
|
+
).build_transaction(
|
|
562
|
+
{
|
|
563
|
+
"from": trader,
|
|
564
|
+
"chainId": self.client.chain_id,
|
|
565
|
+
"value": 0,
|
|
566
|
+
"nonce": await self.client.get_transaction_count(trader),
|
|
567
|
+
}
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
delegate_transaction = await Trading.functions.delegatedAction(
|
|
571
|
+
trader, transaction["data"]
|
|
572
|
+
).build_transaction(
|
|
573
|
+
{
|
|
574
|
+
"from": self.client.get_signer().get_ethereum_address(),
|
|
575
|
+
"chainId": self.client.chain_id,
|
|
576
|
+
"nonce": await self.client.get_transaction_count(
|
|
577
|
+
self.client.get_signer().get_ethereum_address()
|
|
578
|
+
),
|
|
579
|
+
"value": 1,
|
|
580
|
+
}
|
|
581
|
+
)
|
|
582
|
+
|
|
583
|
+
return delegate_transaction
|
|
584
|
+
|
|
339
585
|
async def build_trade_tp_sl_update_tx(
|
|
340
586
|
self,
|
|
341
587
|
pair_index: int,
|
|
@@ -392,3 +638,73 @@ class TradeRPC:
|
|
|
392
638
|
)
|
|
393
639
|
|
|
394
640
|
return transaction
|
|
641
|
+
|
|
642
|
+
async def build_trade_tp_sl_update_tx_delegate(
|
|
643
|
+
self,
|
|
644
|
+
pair_index: int,
|
|
645
|
+
trade_index: int,
|
|
646
|
+
take_profit_price: float,
|
|
647
|
+
stop_loss_price: float,
|
|
648
|
+
trader: str = None,
|
|
649
|
+
):
|
|
650
|
+
"""
|
|
651
|
+
Builds a transaction to update the stop loss and take profit of a trade.
|
|
652
|
+
|
|
653
|
+
Args:
|
|
654
|
+
pair_index: The pair index.
|
|
655
|
+
trade_index: The trade index.
|
|
656
|
+
take_profit_price: The take profit price.
|
|
657
|
+
stop_loss_price: The stop loss price. Pass 0 if you want to remove the stop loss.
|
|
658
|
+
trader (optional): The trader's wallet address.
|
|
659
|
+
Returns:
|
|
660
|
+
A transaction object.
|
|
661
|
+
"""
|
|
662
|
+
Trading = self.client.contracts.get("Trading")
|
|
663
|
+
|
|
664
|
+
if take_profit_price == 0:
|
|
665
|
+
raise ValueError("Take profit price cannot be 0")
|
|
666
|
+
|
|
667
|
+
if trader is None:
|
|
668
|
+
trader = self.client.get_signer().get_ethereum_address()
|
|
669
|
+
|
|
670
|
+
feed_client = self.FeedClient()
|
|
671
|
+
|
|
672
|
+
pair_name = await self.client.pairs_cache.get_pair_name_from_index(pair_index)
|
|
673
|
+
|
|
674
|
+
price_data = await feed_client.get_latest_price_updates([pair_name])
|
|
675
|
+
|
|
676
|
+
price_update_data = "0x" + price_data.binary.data[0]
|
|
677
|
+
|
|
678
|
+
take_profit_price = int(take_profit_price * 10**10)
|
|
679
|
+
stop_loss_price = int(stop_loss_price * 10**10)
|
|
680
|
+
|
|
681
|
+
transaction = await Trading.functions.updateTpAndSl(
|
|
682
|
+
pair_index,
|
|
683
|
+
trade_index,
|
|
684
|
+
stop_loss_price,
|
|
685
|
+
take_profit_price,
|
|
686
|
+
[price_update_data],
|
|
687
|
+
).build_transaction(
|
|
688
|
+
{
|
|
689
|
+
"from": trader,
|
|
690
|
+
"chainId": self.client.chain_id,
|
|
691
|
+
"value": 0,
|
|
692
|
+
"nonce": await self.client.get_transaction_count(trader),
|
|
693
|
+
"gas": 1_000_000,
|
|
694
|
+
}
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
delegate_transaction = await Trading.functions.delegatedAction(
|
|
698
|
+
trader, transaction["data"]
|
|
699
|
+
).build_transaction(
|
|
700
|
+
{
|
|
701
|
+
"from": self.client.get_signer().get_ethereum_address(),
|
|
702
|
+
"chainId": self.client.chain_id,
|
|
703
|
+
"nonce": await self.client.get_transaction_count(
|
|
704
|
+
self.client.get_signer().get_ethereum_address()
|
|
705
|
+
),
|
|
706
|
+
"value": 1,
|
|
707
|
+
"gas": 1_000_000,
|
|
708
|
+
}
|
|
709
|
+
)
|
|
710
|
+
return delegate_transaction
|
|
@@ -16,7 +16,7 @@ class TradingParametersRPC:
|
|
|
16
16
|
"""
|
|
17
17
|
self.client = client
|
|
18
18
|
|
|
19
|
-
async def get_loss_protection_tier(self, trade: TradeInput):
|
|
19
|
+
async def get_loss_protection_tier(self, trade: TradeInput, is_pnl: bool = False):
|
|
20
20
|
"""
|
|
21
21
|
Retrieves the loss protection tier for a trade. Read more about loss protection tiers here: https://docs.avantisfi.com/rewards/loss-protection
|
|
22
22
|
|
|
@@ -33,7 +33,7 @@ class TradingParametersRPC:
|
|
|
33
33
|
trade.trader,
|
|
34
34
|
trade.pairIndex,
|
|
35
35
|
trade.index,
|
|
36
|
-
trade.
|
|
36
|
+
trade.positionSizeUSDC,
|
|
37
37
|
trade.positionSizeUSDC,
|
|
38
38
|
trade.openPrice,
|
|
39
39
|
trade.buy,
|
|
@@ -41,7 +41,8 @@ class TradingParametersRPC:
|
|
|
41
41
|
trade.tp,
|
|
42
42
|
trade.sl,
|
|
43
43
|
trade.timestamp,
|
|
44
|
-
)
|
|
44
|
+
),
|
|
45
|
+
is_pnl,
|
|
45
46
|
).call()
|
|
46
47
|
return response
|
|
47
48
|
|
|
@@ -131,6 +132,8 @@ class TradingParametersRPC:
|
|
|
131
132
|
referrer_tier = await Referral.functions.referrerTiers(
|
|
132
133
|
trader_referral_info[1]
|
|
133
134
|
).call() # trader_referral_info[1] is the referrer address
|
|
134
|
-
tier_info = await self.client.read_contract(
|
|
135
|
+
tier_info = await self.client.read_contract(
|
|
136
|
+
"Referral", "referralTiers", referrer_tier
|
|
137
|
+
)
|
|
135
138
|
discount_percentage = tier_info["feeDiscountPct"] / 100
|
|
136
139
|
return discount_percentage
|
avantis_trader_sdk/types.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
avantis_trader_sdk/__init__.py,sha256=
|
|
1
|
+
avantis_trader_sdk/__init__.py,sha256=FmWQjoPw5BkWAB3u8zTjQRZSaVXP9XdimPwCSEtC7Hs,139
|
|
2
2
|
avantis_trader_sdk/client.py,sha256=dYGrSH5m1QesyMXEGvoLQihBQTRm_nJF22t46JeZirk,11236
|
|
3
|
-
avantis_trader_sdk/config.py,sha256=
|
|
4
|
-
avantis_trader_sdk/types.py,sha256=
|
|
3
|
+
avantis_trader_sdk/config.py,sha256=a6LvCQFD1693zg_vqUh4TJn0RWzR9VQqY6B4BEpHgJE,652
|
|
4
|
+
avantis_trader_sdk/types.py,sha256=J4tam39MaWSz0fFGAB8Jfvsl90c5jKCdiFdaGP8fkUU,14274
|
|
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
|
|
@@ -87,17 +87,17 @@ avantis_trader_sdk/abis/Multicall.sol/Multicall.json,sha256=tMI3BQG6VY04Ng-MydNP
|
|
|
87
87
|
avantis_trader_sdk/abis/Multicall.t.sol/MulticallGroup.json,sha256=AZVoGuVs__JE-bvm87tyLimln8CrN-mXcr85JWQAXgU,1451433
|
|
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
|
-
avantis_trader_sdk/abis/PairInfos.sol/PairInfos.json,sha256=
|
|
90
|
+
avantis_trader_sdk/abis/PairInfos.sol/PairInfos.json,sha256=UBw_KaBzncLGNiNYaXmqULMvFEQPIbDW00OKo_2gANc,248441
|
|
91
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
|
-
avantis_trader_sdk/abis/PriceAggregator.sol/PriceAggregator.json,sha256=
|
|
94
|
+
avantis_trader_sdk/abis/PriceAggregator.sol/PriceAggregator.json,sha256=mFQsxikrJysn9QqfzI3jvVGwliAmeyYf54eEpFSiINU,163589
|
|
95
95
|
avantis_trader_sdk/abis/Proxy.sol/Proxy.json,sha256=ueXd2LE9xOaodZh24iAnxEDpcVlBT3NqaYCGgrU45cc,17487
|
|
96
96
|
avantis_trader_sdk/abis/ProxyAdmin.sol/ProxyAdmin.json,sha256=WtsllWLFPFagyN6iNtiLT5KJPKADvORpUX-9GrcB68o,62016
|
|
97
97
|
avantis_trader_sdk/abis/PythErrors.sol/PythErrors.json,sha256=ZGC_RsX18RPpAM7LoBQ4U1rDmkNaJgul_qx7z59d-R4,9299
|
|
98
98
|
avantis_trader_sdk/abis/PythStructs.sol/PythStructs.json,sha256=wL-Sb5BnuEfVbz65xDFTosQZaVHPcMf8Kw9WvVeeDyM,7973
|
|
99
99
|
avantis_trader_sdk/abis/ReentrancyGuardUpgradeable.sol/ReentrancyGuardUpgradeable.json,sha256=76gQ_UcX-HImLlGiKfTPj7PREJp6A9zJE5gD_grHb8k,22858
|
|
100
|
-
avantis_trader_sdk/abis/Referral.sol/Referral.json,sha256=
|
|
100
|
+
avantis_trader_sdk/abis/Referral.sol/Referral.json,sha256=VsYQysyHRGrraxBsqiZK3BFQTQDmBxkQkfVQDf7Qpqs,123372
|
|
101
101
|
avantis_trader_sdk/abis/Referral.sol/ReferralStorage.json,sha256=_CYslSdS0XydcmGPOIjkYeFGe8a5daka-bypIpLkCxg,305854
|
|
102
102
|
avantis_trader_sdk/abis/Referral.t.sol/Referral.json,sha256=iUqfkOMmOTq0CcgS7raEXOHeJWffyY5jUs7VJ5UEZL8,1367955
|
|
103
103
|
avantis_trader_sdk/abis/SafeERC20.sol/SafeERC20.json,sha256=pjE25IFPDjQQmW2ndGZyGL9cylit6O9IOcq1JsQV-UQ,99908
|
|
@@ -128,9 +128,9 @@ 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=
|
|
132
|
-
avantis_trader_sdk/abis/TradingCallbacks.sol/TradingCallbacks.json,sha256=
|
|
133
|
-
avantis_trader_sdk/abis/TradingStorage.sol/TradingStorage.json,sha256=
|
|
131
|
+
avantis_trader_sdk/abis/Trading.sol/Trading.json,sha256=of7jgJrvdr4FF9TcZNVvY6YePSmJFamhpyLxr9AFGnM,227469
|
|
132
|
+
avantis_trader_sdk/abis/TradingCallbacks.sol/TradingCallbacks.json,sha256=m_tO-wHtc5hXMky0wbLj6lqFt12SgtjlBQZQnmShECU,199077
|
|
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
|
|
135
135
|
avantis_trader_sdk/abis/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json,sha256=JzZ9LTpg6rTkQtwimdWaP-_gBg4yXC_iGyc9P4vdMBs,86405
|
|
136
136
|
avantis_trader_sdk/abis/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json,sha256=Q3BrFLOIPxuzg3gobI9Tlbg9axQJONQ7xj0R84WK5Jg,109628
|
|
@@ -197,22 +197,22 @@ avantis_trader_sdk/feed/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
|
197
197
|
avantis_trader_sdk/feed/feedIds.json,sha256=T77nww3eRiQt8rqZBDpdxA49USGyfI0dQBPnzo-H1dE,6697
|
|
198
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
|
-
avantis_trader_sdk/rpc/asset_parameters.py,sha256=
|
|
200
|
+
avantis_trader_sdk/rpc/asset_parameters.py,sha256=KfrJ61j3B-S76xidWYKW404eBy1Kccy4pCVYdfCc-Kk,19822
|
|
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
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=
|
|
208
|
-
avantis_trader_sdk/rpc/trading_parameters.py,sha256=
|
|
207
|
+
avantis_trader_sdk/rpc/trade.py,sha256=kbMval4suEZggtoz229omzkmQfRUyqDf7xJIErH4Pis,24044
|
|
208
|
+
avantis_trader_sdk/rpc/trading_parameters.py,sha256=DulLhgdlt12w6zYi9LYoF-jTAGtw9QdSQRtpWKyD37E,4779
|
|
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.
|
|
216
|
-
avantis_trader_sdk-0.
|
|
217
|
-
avantis_trader_sdk-0.
|
|
218
|
-
avantis_trader_sdk-0.
|
|
215
|
+
avantis_trader_sdk-0.8.0.dist-info/METADATA,sha256=CXXNcL8uIUtmx5tQvtDDJcUjdpZ0CHihWUiS7JiNets,4916
|
|
216
|
+
avantis_trader_sdk-0.8.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
217
|
+
avantis_trader_sdk-0.8.0.dist-info/top_level.txt,sha256=XffaQJ68SGT1KUz2HHXSGSEsmNy8-AGjgtO127xhzQA,25
|
|
218
|
+
avantis_trader_sdk-0.8.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|