avantis-trader-sdk 0.8.2__py3-none-any.whl → 0.8.4__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 +5 -5
- avantis_trader_sdk/abis/AggregatorV3Interface.json +606 -606
- avantis_trader_sdk/abis/IPyth.sol/IPyth.dbg.json +4 -4
- avantis_trader_sdk/abis/Referral.sol/ReferralStorage.json +7132 -7132
- avantis_trader_sdk/abis/Sanctions.json +190 -190
- avantis_trader_sdk/abis/Trading.sol/Trading.json +1 -1
- avantis_trader_sdk/abis/USDC.sol/USDC.dbg.json +4 -4
- avantis_trader_sdk/abis/interfaces/ICallbacks.sol/ICallbacks.json +2637 -2637
- avantis_trader_sdk/abis/interfaces/IExecute.sol/IExecute.json +1628 -1628
- avantis_trader_sdk/abis/interfaces/IPairInfos.sol/IPairInfos.json +2781 -2781
- avantis_trader_sdk/abis/interfaces/IPairStorage.sol/IPairStorage.json +3729 -3729
- avantis_trader_sdk/abis/interfaces/IPriceAggregator.sol/IPriceAggregator.json +2330 -2330
- avantis_trader_sdk/abis/interfaces/IReferral.sol/IReferral.json +1890 -1890
- avantis_trader_sdk/abis/interfaces/ITradingStorage.sol/ITradingStorage.json +7022 -7022
- avantis_trader_sdk/abis/interfaces/ITranche.sol/ITranche.json +1283 -1283
- avantis_trader_sdk/abis/interfaces/IVaultManager.sol/IVaultManager.json +2424 -2424
- avantis_trader_sdk/abis/interfaces/IVeTranche.sol/IVeTranche.json +855 -855
- avantis_trader_sdk/abis/library/PositionMath.sol/PositionMath.dbg.json +4 -4
- avantis_trader_sdk/abis/library/PositionMath.sol/PositionMath.json +10 -10
- avantis_trader_sdk/abis/testnet/USDC.sol/USDC.dbg.json +4 -4
- avantis_trader_sdk/abis/testnet/USDC.sol/USDC.json +320 -320
- avantis_trader_sdk/client.py +369 -367
- avantis_trader_sdk/config.py +14 -14
- avantis_trader_sdk/feed/feed_client.py +263 -261
- avantis_trader_sdk/rpc/asset_parameters.py +499 -499
- avantis_trader_sdk/rpc/blended.py +71 -71
- avantis_trader_sdk/rpc/category_parameters.py +216 -216
- avantis_trader_sdk/rpc/fee_parameters.py +237 -237
- avantis_trader_sdk/rpc/pairs_cache.py +130 -130
- avantis_trader_sdk/rpc/rpc_helpers.py +8 -8
- avantis_trader_sdk/rpc/snapshot.py +142 -142
- avantis_trader_sdk/rpc/trade.py +701 -710
- avantis_trader_sdk/rpc/trading_parameters.py +139 -139
- avantis_trader_sdk/types.py +462 -462
- avantis_trader_sdk/utils.py +78 -78
- {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/METADATA +124 -113
- {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/RECORD +39 -40
- {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/WHEEL +1 -1
- avantis_trader_sdk/feed/feedIds.json +0 -214
- {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/top_level.txt +0 -0
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
from ..types import TradeInput, LossProtectionInfo
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class TradingParametersRPC:
|
|
6
|
-
"""
|
|
7
|
-
The TradingParametersRPC class contains methods for retrieving trading parameters from the Avantis Protocol.
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
def __init__(self, client):
|
|
11
|
-
"""
|
|
12
|
-
Constructor for the TradingParametersRPC class.
|
|
13
|
-
|
|
14
|
-
Args:
|
|
15
|
-
client: The TraderClient object.
|
|
16
|
-
"""
|
|
17
|
-
self.client = client
|
|
18
|
-
|
|
19
|
-
async def get_loss_protection_tier(self, trade: TradeInput, is_pnl: bool = False):
|
|
20
|
-
"""
|
|
21
|
-
Retrieves the loss protection tier for a trade. Read more about loss protection tiers here: https://docs.avantisfi.com/rewards/loss-protection
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
trade: A TradeInput instance containing the trade details.
|
|
25
|
-
|
|
26
|
-
Returns:
|
|
27
|
-
The loss protection tier as an integer.
|
|
28
|
-
"""
|
|
29
|
-
PairInfos = self.client.contracts.get("PairInfos")
|
|
30
|
-
|
|
31
|
-
response = await PairInfos.functions.lossProtectionTier(
|
|
32
|
-
(
|
|
33
|
-
trade.trader,
|
|
34
|
-
trade.pairIndex,
|
|
35
|
-
trade.index,
|
|
36
|
-
trade.positionSizeUSDC,
|
|
37
|
-
trade.positionSizeUSDC,
|
|
38
|
-
trade.openPrice,
|
|
39
|
-
trade.buy,
|
|
40
|
-
trade.leverage,
|
|
41
|
-
trade.tp,
|
|
42
|
-
trade.sl,
|
|
43
|
-
trade.timestamp,
|
|
44
|
-
),
|
|
45
|
-
is_pnl,
|
|
46
|
-
).call()
|
|
47
|
-
return response
|
|
48
|
-
|
|
49
|
-
async def get_loss_protection_percentage_by_tier(self, tier: int, pair_index: int):
|
|
50
|
-
"""
|
|
51
|
-
Gets the loss protection tier.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
tier: The tier.
|
|
55
|
-
pair_index: The pair index.
|
|
56
|
-
|
|
57
|
-
Returns:
|
|
58
|
-
The loss protection percentage.
|
|
59
|
-
"""
|
|
60
|
-
PairStorage = self.client.contracts.get("PairStorage")
|
|
61
|
-
data = await PairStorage.functions.lossProtectionMultiplier(
|
|
62
|
-
pair_index, tier
|
|
63
|
-
).call()
|
|
64
|
-
return 100 - data
|
|
65
|
-
|
|
66
|
-
async def get_loss_protection_percentage(self, trade: TradeInput):
|
|
67
|
-
"""
|
|
68
|
-
Retrieves the loss protection percentage for a trade.
|
|
69
|
-
|
|
70
|
-
Args:
|
|
71
|
-
trade: A TradeInput instance containing the trade details.
|
|
72
|
-
|
|
73
|
-
Returns:
|
|
74
|
-
The loss protection percentage.
|
|
75
|
-
"""
|
|
76
|
-
tier = await self.get_loss_protection_tier(trade)
|
|
77
|
-
return await self.get_loss_protection_percentage_by_tier(tier, trade.pairIndex)
|
|
78
|
-
|
|
79
|
-
async def get_loss_protection_for_trade_input(
|
|
80
|
-
self, trade: TradeInput, opening_fee_usdc: Optional[float] = None
|
|
81
|
-
):
|
|
82
|
-
"""
|
|
83
|
-
Retrieves the loss protection for a trade.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
trade: A TradeInput instance containing the trade details.
|
|
87
|
-
|
|
88
|
-
Returns:
|
|
89
|
-
A LossProtectionInfo instance containing the loss protection percentage and amount in USDC.
|
|
90
|
-
"""
|
|
91
|
-
loss_protection_percentage = await self.get_loss_protection_percentage(trade)
|
|
92
|
-
|
|
93
|
-
if loss_protection_percentage == 0:
|
|
94
|
-
return LossProtectionInfo(percentage=0, amount=0)
|
|
95
|
-
|
|
96
|
-
if opening_fee_usdc is None:
|
|
97
|
-
opening_fee_usdc = await self.client.fee_parameters.get_opening_fee(
|
|
98
|
-
trade_input=trade
|
|
99
|
-
)
|
|
100
|
-
collateral_after_opening_fee = trade.positionSizeUSDC / 10**6 - opening_fee_usdc
|
|
101
|
-
loss_protection_usdc = (
|
|
102
|
-
collateral_after_opening_fee * loss_protection_percentage / 100
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
return LossProtectionInfo(
|
|
106
|
-
percentage=loss_protection_percentage, amount=loss_protection_usdc
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
async def get_trade_referral_rebate_percentage(self, trader: Optional[str] = None):
|
|
110
|
-
"""
|
|
111
|
-
Retrieves the trade referral rebate percentage for a trader.
|
|
112
|
-
|
|
113
|
-
Args:
|
|
114
|
-
trader (optional): The trader's wallet address.
|
|
115
|
-
|
|
116
|
-
Returns:
|
|
117
|
-
The trade referral rebate percentage.
|
|
118
|
-
"""
|
|
119
|
-
Referral = self.client.contracts.get("Referral")
|
|
120
|
-
|
|
121
|
-
if trader is None:
|
|
122
|
-
trader = self.client.get_signer().get_ethereum_address()
|
|
123
|
-
|
|
124
|
-
trader_referral_info = await Referral.functions.getTraderReferralInfo(
|
|
125
|
-
trader
|
|
126
|
-
).call()
|
|
127
|
-
if (
|
|
128
|
-
len(trader_referral_info) == 0
|
|
129
|
-
or trader_referral_info[1] == "0x0000000000000000000000000000000000000000"
|
|
130
|
-
):
|
|
131
|
-
return 0
|
|
132
|
-
referrer_tier = await Referral.functions.referrerTiers(
|
|
133
|
-
trader_referral_info[1]
|
|
134
|
-
).call() # trader_referral_info[1] is the referrer address
|
|
135
|
-
tier_info = await self.client.read_contract(
|
|
136
|
-
"Referral", "referralTiers", referrer_tier
|
|
137
|
-
)
|
|
138
|
-
discount_percentage = tier_info["feeDiscountPct"] / 100
|
|
139
|
-
return discount_percentage
|
|
1
|
+
from ..types import TradeInput, LossProtectionInfo
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TradingParametersRPC:
|
|
6
|
+
"""
|
|
7
|
+
The TradingParametersRPC class contains methods for retrieving trading parameters from the Avantis Protocol.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, client):
|
|
11
|
+
"""
|
|
12
|
+
Constructor for the TradingParametersRPC class.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
client: The TraderClient object.
|
|
16
|
+
"""
|
|
17
|
+
self.client = client
|
|
18
|
+
|
|
19
|
+
async def get_loss_protection_tier(self, trade: TradeInput, is_pnl: bool = False):
|
|
20
|
+
"""
|
|
21
|
+
Retrieves the loss protection tier for a trade. Read more about loss protection tiers here: https://docs.avantisfi.com/rewards/loss-protection
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
trade: A TradeInput instance containing the trade details.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
The loss protection tier as an integer.
|
|
28
|
+
"""
|
|
29
|
+
PairInfos = self.client.contracts.get("PairInfos")
|
|
30
|
+
|
|
31
|
+
response = await PairInfos.functions.lossProtectionTier(
|
|
32
|
+
(
|
|
33
|
+
trade.trader,
|
|
34
|
+
trade.pairIndex,
|
|
35
|
+
trade.index,
|
|
36
|
+
trade.positionSizeUSDC,
|
|
37
|
+
trade.positionSizeUSDC,
|
|
38
|
+
trade.openPrice,
|
|
39
|
+
trade.buy,
|
|
40
|
+
trade.leverage,
|
|
41
|
+
trade.tp,
|
|
42
|
+
trade.sl,
|
|
43
|
+
trade.timestamp,
|
|
44
|
+
),
|
|
45
|
+
is_pnl,
|
|
46
|
+
).call()
|
|
47
|
+
return response
|
|
48
|
+
|
|
49
|
+
async def get_loss_protection_percentage_by_tier(self, tier: int, pair_index: int):
|
|
50
|
+
"""
|
|
51
|
+
Gets the loss protection tier.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
tier: The tier.
|
|
55
|
+
pair_index: The pair index.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
The loss protection percentage.
|
|
59
|
+
"""
|
|
60
|
+
PairStorage = self.client.contracts.get("PairStorage")
|
|
61
|
+
data = await PairStorage.functions.lossProtectionMultiplier(
|
|
62
|
+
pair_index, tier
|
|
63
|
+
).call()
|
|
64
|
+
return 100 - data
|
|
65
|
+
|
|
66
|
+
async def get_loss_protection_percentage(self, trade: TradeInput):
|
|
67
|
+
"""
|
|
68
|
+
Retrieves the loss protection percentage for a trade.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
trade: A TradeInput instance containing the trade details.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
The loss protection percentage.
|
|
75
|
+
"""
|
|
76
|
+
tier = await self.get_loss_protection_tier(trade)
|
|
77
|
+
return await self.get_loss_protection_percentage_by_tier(tier, trade.pairIndex)
|
|
78
|
+
|
|
79
|
+
async def get_loss_protection_for_trade_input(
|
|
80
|
+
self, trade: TradeInput, opening_fee_usdc: Optional[float] = None
|
|
81
|
+
):
|
|
82
|
+
"""
|
|
83
|
+
Retrieves the loss protection for a trade.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
trade: A TradeInput instance containing the trade details.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
A LossProtectionInfo instance containing the loss protection percentage and amount in USDC.
|
|
90
|
+
"""
|
|
91
|
+
loss_protection_percentage = await self.get_loss_protection_percentage(trade)
|
|
92
|
+
|
|
93
|
+
if loss_protection_percentage == 0:
|
|
94
|
+
return LossProtectionInfo(percentage=0, amount=0)
|
|
95
|
+
|
|
96
|
+
if opening_fee_usdc is None:
|
|
97
|
+
opening_fee_usdc = await self.client.fee_parameters.get_opening_fee(
|
|
98
|
+
trade_input=trade
|
|
99
|
+
)
|
|
100
|
+
collateral_after_opening_fee = trade.positionSizeUSDC / 10**6 - opening_fee_usdc
|
|
101
|
+
loss_protection_usdc = (
|
|
102
|
+
collateral_after_opening_fee * loss_protection_percentage / 100
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return LossProtectionInfo(
|
|
106
|
+
percentage=loss_protection_percentage, amount=loss_protection_usdc
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
async def get_trade_referral_rebate_percentage(self, trader: Optional[str] = None):
|
|
110
|
+
"""
|
|
111
|
+
Retrieves the trade referral rebate percentage for a trader.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
trader (optional): The trader's wallet address.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
The trade referral rebate percentage.
|
|
118
|
+
"""
|
|
119
|
+
Referral = self.client.contracts.get("Referral")
|
|
120
|
+
|
|
121
|
+
if trader is None:
|
|
122
|
+
trader = self.client.get_signer().get_ethereum_address()
|
|
123
|
+
|
|
124
|
+
trader_referral_info = await Referral.functions.getTraderReferralInfo(
|
|
125
|
+
trader
|
|
126
|
+
).call()
|
|
127
|
+
if (
|
|
128
|
+
len(trader_referral_info) == 0
|
|
129
|
+
or trader_referral_info[1] == "0x0000000000000000000000000000000000000000"
|
|
130
|
+
):
|
|
131
|
+
return 0
|
|
132
|
+
referrer_tier = await Referral.functions.referrerTiers(
|
|
133
|
+
trader_referral_info[1]
|
|
134
|
+
).call() # trader_referral_info[1] is the referrer address
|
|
135
|
+
tier_info = await self.client.read_contract(
|
|
136
|
+
"Referral", "referralTiers", referrer_tier
|
|
137
|
+
)
|
|
138
|
+
discount_percentage = tier_info["feeDiscountPct"] / 100
|
|
139
|
+
return discount_percentage
|