avantis-trader-sdk 0.8.2__py3-none-any.whl → 0.8.3__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/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.3.dist-info}/METADATA +124 -113
- {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.3.dist-info}/RECORD +38 -39
- {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.3.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.3.dist-info}/top_level.txt +0 -0
|
@@ -1,237 +1,237 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
from .rpc_helpers import map_output_to_pairs
|
|
3
|
-
from ..types import MarginFee, PairSpread, Fee, TradeInput
|
|
4
|
-
from typing import Optional
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class FeeParametersRPC:
|
|
8
|
-
"""
|
|
9
|
-
This class provides methods to retrieve and calculate various fee parameters
|
|
10
|
-
related to trades.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
def __init__(self, client):
|
|
14
|
-
"""
|
|
15
|
-
Constructor for the FeeParametersRPC class.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
client: The TraderClient object.
|
|
19
|
-
"""
|
|
20
|
-
self.client = client
|
|
21
|
-
|
|
22
|
-
async def get_margin_fee(self):
|
|
23
|
-
"""
|
|
24
|
-
Retrieves the margin fee for all trading pairs.
|
|
25
|
-
|
|
26
|
-
Returns:
|
|
27
|
-
A MarginFee instance containing the margin fee for each trading pair in bps.
|
|
28
|
-
"""
|
|
29
|
-
Multicall = self.client.contracts.get("Multicall")
|
|
30
|
-
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
31
|
-
raw_data = await Multicall.functions.getMargins().call()
|
|
32
|
-
decoded = self.client.utils["decoder"](Multicall, "getMargins", raw_data)
|
|
33
|
-
|
|
34
|
-
for key, value in decoded.items():
|
|
35
|
-
decoded[key] = [val * 30 * 60 / 10**10 * 100 for val in value]
|
|
36
|
-
|
|
37
|
-
return MarginFee(
|
|
38
|
-
hourly_base_fee_parameter=map_output_to_pairs(
|
|
39
|
-
pairs_info, decoded["rolloverFeePerBlockP"]
|
|
40
|
-
),
|
|
41
|
-
hourly_margin_fee_long_bps=map_output_to_pairs(
|
|
42
|
-
pairs_info, decoded["rolloverFeePerBlockLong"]
|
|
43
|
-
),
|
|
44
|
-
hourly_margin_fee_short_bps=map_output_to_pairs(
|
|
45
|
-
pairs_info, decoded["rolloverFeePerBlockShort"]
|
|
46
|
-
),
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
async def constant_spread_parameter(self):
|
|
50
|
-
"""
|
|
51
|
-
Retrieves the spread for all trading pairs.
|
|
52
|
-
|
|
53
|
-
Returns:
|
|
54
|
-
A PairSpread instance containing the spread for each trading pair in bps.
|
|
55
|
-
"""
|
|
56
|
-
PairStorage = self.client.contracts.get("PairStorage")
|
|
57
|
-
Multicall = self.client.contracts.get("Multicall")
|
|
58
|
-
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
59
|
-
calls = []
|
|
60
|
-
for pair_index in range(len(pairs_info)):
|
|
61
|
-
call_data = PairStorage.encodeABI(fn_name="pairSpreadP", args=[pair_index])
|
|
62
|
-
calls.append((PairStorage.address, call_data))
|
|
63
|
-
|
|
64
|
-
response = await Multicall.functions.aggregate(calls).call()
|
|
65
|
-
decoded_response = [
|
|
66
|
-
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
67
|
-
for value in response[1]
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
return PairSpread(spread=map_output_to_pairs(pairs_info, decoded_response))
|
|
71
|
-
|
|
72
|
-
async def get_opening_fee(
|
|
73
|
-
self,
|
|
74
|
-
position_size: float = 0,
|
|
75
|
-
is_long: Optional[bool] = None,
|
|
76
|
-
pair_index: int = None,
|
|
77
|
-
pair: str = None,
|
|
78
|
-
):
|
|
79
|
-
"""
|
|
80
|
-
Retrieves the opening fee for all trading pairs in bps.
|
|
81
|
-
|
|
82
|
-
Args:
|
|
83
|
-
is_long: A boolean indicating if the position is a buy or sell. Defaults to None. If None, the opening fee for both buy and sell will be returned.
|
|
84
|
-
position_size: The size of the position (collateral * leverage). Supports upto 6 decimals. Defaults to 0.
|
|
85
|
-
pair_index: The pair index for which the opening fee is to be calculated. Defaults to None. If None, the opening fee for all trading pairs will be returned.
|
|
86
|
-
pair: The trading pair for which the opening fee is to be calculated. Defaults to None. If None, the opening fee for all trading pairs will be returned.
|
|
87
|
-
|
|
88
|
-
Returns:
|
|
89
|
-
A Fee instance containing the opening Fee for each trading pair in bps.
|
|
90
|
-
"""
|
|
91
|
-
position_size = int(position_size * 10**6)
|
|
92
|
-
|
|
93
|
-
Multicall = self.client.contracts.get("Multicall")
|
|
94
|
-
|
|
95
|
-
calls = []
|
|
96
|
-
response = None
|
|
97
|
-
|
|
98
|
-
if pair is not None or pair_index is not None:
|
|
99
|
-
if pair_index is None:
|
|
100
|
-
pair_index = await self.client.pairs_cache.get_pair_index(pair)
|
|
101
|
-
if pair is None:
|
|
102
|
-
pair = await self.client.pairs_cache.get_pair_name_from_index(
|
|
103
|
-
pair_index
|
|
104
|
-
)
|
|
105
|
-
PriceAggregator = self.client.contracts.get("PriceAggregator")
|
|
106
|
-
if is_long is None:
|
|
107
|
-
calls.extend(
|
|
108
|
-
[
|
|
109
|
-
(
|
|
110
|
-
PriceAggregator.address,
|
|
111
|
-
PriceAggregator.encodeABI(
|
|
112
|
-
fn_name="openFeeP",
|
|
113
|
-
args=[pair_index, position_size, True],
|
|
114
|
-
),
|
|
115
|
-
),
|
|
116
|
-
(
|
|
117
|
-
PriceAggregator.address,
|
|
118
|
-
PriceAggregator.encodeABI(
|
|
119
|
-
fn_name="openFeeP",
|
|
120
|
-
args=[pair_index, position_size, False],
|
|
121
|
-
),
|
|
122
|
-
),
|
|
123
|
-
]
|
|
124
|
-
)
|
|
125
|
-
else:
|
|
126
|
-
response = await PriceAggregator.functions.openFeeP(
|
|
127
|
-
pair_index, position_size, is_long
|
|
128
|
-
).call()
|
|
129
|
-
else:
|
|
130
|
-
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
131
|
-
PriceAggregator = self.client.contracts.get("PriceAggregator")
|
|
132
|
-
for pair_index in range(len(pairs_info)):
|
|
133
|
-
if is_long is None:
|
|
134
|
-
calls.extend(
|
|
135
|
-
[
|
|
136
|
-
(
|
|
137
|
-
PriceAggregator.address,
|
|
138
|
-
PriceAggregator.encodeABI(
|
|
139
|
-
fn_name="openFeeP",
|
|
140
|
-
args=[pair_index, position_size, True],
|
|
141
|
-
),
|
|
142
|
-
),
|
|
143
|
-
(
|
|
144
|
-
PriceAggregator.address,
|
|
145
|
-
PriceAggregator.encodeABI(
|
|
146
|
-
fn_name="openFeeP",
|
|
147
|
-
args=[pair_index, position_size, False],
|
|
148
|
-
),
|
|
149
|
-
),
|
|
150
|
-
]
|
|
151
|
-
)
|
|
152
|
-
else:
|
|
153
|
-
calls.append(
|
|
154
|
-
(
|
|
155
|
-
PriceAggregator.address,
|
|
156
|
-
PriceAggregator.encodeABI(
|
|
157
|
-
fn_name="openFeeP",
|
|
158
|
-
args=[pair_index, position_size, is_long],
|
|
159
|
-
),
|
|
160
|
-
)
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
if response is None:
|
|
164
|
-
response = await Multicall.functions.aggregate(calls).call()
|
|
165
|
-
if is_long is None:
|
|
166
|
-
decoded_response = [
|
|
167
|
-
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
168
|
-
for value in response[1]
|
|
169
|
-
]
|
|
170
|
-
if pair is None:
|
|
171
|
-
return Fee(
|
|
172
|
-
long=map_output_to_pairs(pairs_info, decoded_response[::2]),
|
|
173
|
-
short=map_output_to_pairs(pairs_info, decoded_response[1::2]),
|
|
174
|
-
)
|
|
175
|
-
else:
|
|
176
|
-
return Fee(
|
|
177
|
-
long={pair: decoded_response[0]},
|
|
178
|
-
short={pair: decoded_response[1]},
|
|
179
|
-
)
|
|
180
|
-
elif is_long:
|
|
181
|
-
decoded_response = map_output_to_pairs(
|
|
182
|
-
pairs_info,
|
|
183
|
-
[
|
|
184
|
-
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
185
|
-
for value in response[1]
|
|
186
|
-
],
|
|
187
|
-
)
|
|
188
|
-
return Fee(long=decoded_response)
|
|
189
|
-
else:
|
|
190
|
-
decoded_response = map_output_to_pairs(
|
|
191
|
-
pairs_info,
|
|
192
|
-
[
|
|
193
|
-
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
194
|
-
for value in response[1]
|
|
195
|
-
],
|
|
196
|
-
)
|
|
197
|
-
return Fee(short=decoded_response)
|
|
198
|
-
elif is_long:
|
|
199
|
-
return Fee(long={pair: response / 10**10 * 100})
|
|
200
|
-
else:
|
|
201
|
-
return Fee(short={pair: response / 10**10 * 100})
|
|
202
|
-
|
|
203
|
-
async def get_new_trade_opening_fee(
|
|
204
|
-
self,
|
|
205
|
-
trade_input: TradeInput,
|
|
206
|
-
):
|
|
207
|
-
"""
|
|
208
|
-
Retrieves the opening fee for a trade with referral rebate in USDC.
|
|
209
|
-
|
|
210
|
-
Args:
|
|
211
|
-
trade_input: The trade input object.
|
|
212
|
-
|
|
213
|
-
Returns:
|
|
214
|
-
Final opening fee in USDC
|
|
215
|
-
"""
|
|
216
|
-
position_size = (
|
|
217
|
-
trade_input.positionSizeUSDC / 10**6 * trade_input.leverage / 10**10
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
position_size = int(position_size * 10**6)
|
|
221
|
-
|
|
222
|
-
PriceAggregator = self.client.contracts.get("PriceAggregator")
|
|
223
|
-
|
|
224
|
-
response = await PriceAggregator.functions.openFeeP(
|
|
225
|
-
trade_input.pairIndex, position_size, trade_input.buy
|
|
226
|
-
).call()
|
|
227
|
-
|
|
228
|
-
referral_rebate_percentage = (
|
|
229
|
-
await self.client.trading_parameters.get_trade_referral_rebate_percentage(
|
|
230
|
-
trade_input.trader
|
|
231
|
-
)
|
|
232
|
-
)
|
|
233
|
-
referral_rebate_percentage = 1 - (referral_rebate_percentage / 100)
|
|
234
|
-
return round(
|
|
235
|
-
response / 10**12 * position_size / 10**6 * referral_rebate_percentage,
|
|
236
|
-
18,
|
|
237
|
-
)
|
|
1
|
+
import asyncio
|
|
2
|
+
from .rpc_helpers import map_output_to_pairs
|
|
3
|
+
from ..types import MarginFee, PairSpread, Fee, TradeInput
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FeeParametersRPC:
|
|
8
|
+
"""
|
|
9
|
+
This class provides methods to retrieve and calculate various fee parameters
|
|
10
|
+
related to trades.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, client):
|
|
14
|
+
"""
|
|
15
|
+
Constructor for the FeeParametersRPC class.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
client: The TraderClient object.
|
|
19
|
+
"""
|
|
20
|
+
self.client = client
|
|
21
|
+
|
|
22
|
+
async def get_margin_fee(self):
|
|
23
|
+
"""
|
|
24
|
+
Retrieves the margin fee for all trading pairs.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
A MarginFee instance containing the margin fee for each trading pair in bps.
|
|
28
|
+
"""
|
|
29
|
+
Multicall = self.client.contracts.get("Multicall")
|
|
30
|
+
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
31
|
+
raw_data = await Multicall.functions.getMargins().call()
|
|
32
|
+
decoded = self.client.utils["decoder"](Multicall, "getMargins", raw_data)
|
|
33
|
+
|
|
34
|
+
for key, value in decoded.items():
|
|
35
|
+
decoded[key] = [val * 30 * 60 / 10**10 * 100 for val in value]
|
|
36
|
+
|
|
37
|
+
return MarginFee(
|
|
38
|
+
hourly_base_fee_parameter=map_output_to_pairs(
|
|
39
|
+
pairs_info, decoded["rolloverFeePerBlockP"]
|
|
40
|
+
),
|
|
41
|
+
hourly_margin_fee_long_bps=map_output_to_pairs(
|
|
42
|
+
pairs_info, decoded["rolloverFeePerBlockLong"]
|
|
43
|
+
),
|
|
44
|
+
hourly_margin_fee_short_bps=map_output_to_pairs(
|
|
45
|
+
pairs_info, decoded["rolloverFeePerBlockShort"]
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
async def constant_spread_parameter(self):
|
|
50
|
+
"""
|
|
51
|
+
Retrieves the spread for all trading pairs.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
A PairSpread instance containing the spread for each trading pair in bps.
|
|
55
|
+
"""
|
|
56
|
+
PairStorage = self.client.contracts.get("PairStorage")
|
|
57
|
+
Multicall = self.client.contracts.get("Multicall")
|
|
58
|
+
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
59
|
+
calls = []
|
|
60
|
+
for pair_index in range(len(pairs_info)):
|
|
61
|
+
call_data = PairStorage.encodeABI(fn_name="pairSpreadP", args=[pair_index])
|
|
62
|
+
calls.append((PairStorage.address, call_data))
|
|
63
|
+
|
|
64
|
+
response = await Multicall.functions.aggregate(calls).call()
|
|
65
|
+
decoded_response = [
|
|
66
|
+
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
67
|
+
for value in response[1]
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
return PairSpread(spread=map_output_to_pairs(pairs_info, decoded_response))
|
|
71
|
+
|
|
72
|
+
async def get_opening_fee(
|
|
73
|
+
self,
|
|
74
|
+
position_size: float = 0,
|
|
75
|
+
is_long: Optional[bool] = None,
|
|
76
|
+
pair_index: int = None,
|
|
77
|
+
pair: str = None,
|
|
78
|
+
):
|
|
79
|
+
"""
|
|
80
|
+
Retrieves the opening fee for all trading pairs in bps.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
is_long: A boolean indicating if the position is a buy or sell. Defaults to None. If None, the opening fee for both buy and sell will be returned.
|
|
84
|
+
position_size: The size of the position (collateral * leverage). Supports upto 6 decimals. Defaults to 0.
|
|
85
|
+
pair_index: The pair index for which the opening fee is to be calculated. Defaults to None. If None, the opening fee for all trading pairs will be returned.
|
|
86
|
+
pair: The trading pair for which the opening fee is to be calculated. Defaults to None. If None, the opening fee for all trading pairs will be returned.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
A Fee instance containing the opening Fee for each trading pair in bps.
|
|
90
|
+
"""
|
|
91
|
+
position_size = int(position_size * 10**6)
|
|
92
|
+
|
|
93
|
+
Multicall = self.client.contracts.get("Multicall")
|
|
94
|
+
|
|
95
|
+
calls = []
|
|
96
|
+
response = None
|
|
97
|
+
|
|
98
|
+
if pair is not None or pair_index is not None:
|
|
99
|
+
if pair_index is None:
|
|
100
|
+
pair_index = await self.client.pairs_cache.get_pair_index(pair)
|
|
101
|
+
if pair is None:
|
|
102
|
+
pair = await self.client.pairs_cache.get_pair_name_from_index(
|
|
103
|
+
pair_index
|
|
104
|
+
)
|
|
105
|
+
PriceAggregator = self.client.contracts.get("PriceAggregator")
|
|
106
|
+
if is_long is None:
|
|
107
|
+
calls.extend(
|
|
108
|
+
[
|
|
109
|
+
(
|
|
110
|
+
PriceAggregator.address,
|
|
111
|
+
PriceAggregator.encodeABI(
|
|
112
|
+
fn_name="openFeeP",
|
|
113
|
+
args=[pair_index, position_size, True],
|
|
114
|
+
),
|
|
115
|
+
),
|
|
116
|
+
(
|
|
117
|
+
PriceAggregator.address,
|
|
118
|
+
PriceAggregator.encodeABI(
|
|
119
|
+
fn_name="openFeeP",
|
|
120
|
+
args=[pair_index, position_size, False],
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
]
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
response = await PriceAggregator.functions.openFeeP(
|
|
127
|
+
pair_index, position_size, is_long
|
|
128
|
+
).call()
|
|
129
|
+
else:
|
|
130
|
+
pairs_info = await self.client.pairs_cache.get_pairs_info()
|
|
131
|
+
PriceAggregator = self.client.contracts.get("PriceAggregator")
|
|
132
|
+
for pair_index in range(len(pairs_info)):
|
|
133
|
+
if is_long is None:
|
|
134
|
+
calls.extend(
|
|
135
|
+
[
|
|
136
|
+
(
|
|
137
|
+
PriceAggregator.address,
|
|
138
|
+
PriceAggregator.encodeABI(
|
|
139
|
+
fn_name="openFeeP",
|
|
140
|
+
args=[pair_index, position_size, True],
|
|
141
|
+
),
|
|
142
|
+
),
|
|
143
|
+
(
|
|
144
|
+
PriceAggregator.address,
|
|
145
|
+
PriceAggregator.encodeABI(
|
|
146
|
+
fn_name="openFeeP",
|
|
147
|
+
args=[pair_index, position_size, False],
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
calls.append(
|
|
154
|
+
(
|
|
155
|
+
PriceAggregator.address,
|
|
156
|
+
PriceAggregator.encodeABI(
|
|
157
|
+
fn_name="openFeeP",
|
|
158
|
+
args=[pair_index, position_size, is_long],
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
if response is None:
|
|
164
|
+
response = await Multicall.functions.aggregate(calls).call()
|
|
165
|
+
if is_long is None:
|
|
166
|
+
decoded_response = [
|
|
167
|
+
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
168
|
+
for value in response[1]
|
|
169
|
+
]
|
|
170
|
+
if pair is None:
|
|
171
|
+
return Fee(
|
|
172
|
+
long=map_output_to_pairs(pairs_info, decoded_response[::2]),
|
|
173
|
+
short=map_output_to_pairs(pairs_info, decoded_response[1::2]),
|
|
174
|
+
)
|
|
175
|
+
else:
|
|
176
|
+
return Fee(
|
|
177
|
+
long={pair: decoded_response[0]},
|
|
178
|
+
short={pair: decoded_response[1]},
|
|
179
|
+
)
|
|
180
|
+
elif is_long:
|
|
181
|
+
decoded_response = map_output_to_pairs(
|
|
182
|
+
pairs_info,
|
|
183
|
+
[
|
|
184
|
+
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
185
|
+
for value in response[1]
|
|
186
|
+
],
|
|
187
|
+
)
|
|
188
|
+
return Fee(long=decoded_response)
|
|
189
|
+
else:
|
|
190
|
+
decoded_response = map_output_to_pairs(
|
|
191
|
+
pairs_info,
|
|
192
|
+
[
|
|
193
|
+
int.from_bytes(value, byteorder="big") / 10**10 * 100
|
|
194
|
+
for value in response[1]
|
|
195
|
+
],
|
|
196
|
+
)
|
|
197
|
+
return Fee(short=decoded_response)
|
|
198
|
+
elif is_long:
|
|
199
|
+
return Fee(long={pair: response / 10**10 * 100})
|
|
200
|
+
else:
|
|
201
|
+
return Fee(short={pair: response / 10**10 * 100})
|
|
202
|
+
|
|
203
|
+
async def get_new_trade_opening_fee(
|
|
204
|
+
self,
|
|
205
|
+
trade_input: TradeInput,
|
|
206
|
+
):
|
|
207
|
+
"""
|
|
208
|
+
Retrieves the opening fee for a trade with referral rebate in USDC.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
trade_input: The trade input object.
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
Final opening fee in USDC
|
|
215
|
+
"""
|
|
216
|
+
position_size = (
|
|
217
|
+
trade_input.positionSizeUSDC / 10**6 * trade_input.leverage / 10**10
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
position_size = int(position_size * 10**6)
|
|
221
|
+
|
|
222
|
+
PriceAggregator = self.client.contracts.get("PriceAggregator")
|
|
223
|
+
|
|
224
|
+
response = await PriceAggregator.functions.openFeeP(
|
|
225
|
+
trade_input.pairIndex, position_size, trade_input.buy
|
|
226
|
+
).call()
|
|
227
|
+
|
|
228
|
+
referral_rebate_percentage = (
|
|
229
|
+
await self.client.trading_parameters.get_trade_referral_rebate_percentage(
|
|
230
|
+
trade_input.trader
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
referral_rebate_percentage = 1 - (referral_rebate_percentage / 100)
|
|
234
|
+
return round(
|
|
235
|
+
response / 10**12 * position_size / 10**6 * referral_rebate_percentage,
|
|
236
|
+
18,
|
|
237
|
+
)
|