nado-protocol 0.1.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.
- nado_protocol/__init__.py +0 -0
- nado_protocol/client/__init__.py +200 -0
- nado_protocol/client/apis/__init__.py +26 -0
- nado_protocol/client/apis/base.py +42 -0
- nado_protocol/client/apis/market/__init__.py +23 -0
- nado_protocol/client/apis/market/execute.py +192 -0
- nado_protocol/client/apis/market/query.py +310 -0
- nado_protocol/client/apis/perp/__init__.py +18 -0
- nado_protocol/client/apis/perp/query.py +30 -0
- nado_protocol/client/apis/rewards/__init__.py +6 -0
- nado_protocol/client/apis/rewards/execute.py +131 -0
- nado_protocol/client/apis/rewards/query.py +12 -0
- nado_protocol/client/apis/spot/__init__.py +23 -0
- nado_protocol/client/apis/spot/base.py +32 -0
- nado_protocol/client/apis/spot/execute.py +117 -0
- nado_protocol/client/apis/spot/query.py +79 -0
- nado_protocol/client/apis/subaccount/__init__.py +24 -0
- nado_protocol/client/apis/subaccount/execute.py +54 -0
- nado_protocol/client/apis/subaccount/query.py +145 -0
- nado_protocol/client/context.py +90 -0
- nado_protocol/contracts/__init__.py +377 -0
- nado_protocol/contracts/abis/Endpoint.json +636 -0
- nado_protocol/contracts/abis/FQuerier.json +1909 -0
- nado_protocol/contracts/abis/IClearinghouse.json +876 -0
- nado_protocol/contracts/abis/IERC20.json +185 -0
- nado_protocol/contracts/abis/IEndpoint.json +250 -0
- nado_protocol/contracts/abis/IFoundationRewardsAirdrop.json +76 -0
- nado_protocol/contracts/abis/IOffchainBook.json +536 -0
- nado_protocol/contracts/abis/IPerpEngine.json +931 -0
- nado_protocol/contracts/abis/IProductEngine.json +352 -0
- nado_protocol/contracts/abis/ISpotEngine.json +813 -0
- nado_protocol/contracts/abis/IStaking.json +288 -0
- nado_protocol/contracts/abis/IVrtxAirdrop.json +138 -0
- nado_protocol/contracts/abis/MockERC20.json +311 -0
- nado_protocol/contracts/deployments/deployment.test.json +18 -0
- nado_protocol/contracts/eip712/__init__.py +16 -0
- nado_protocol/contracts/eip712/domain.py +36 -0
- nado_protocol/contracts/eip712/sign.py +79 -0
- nado_protocol/contracts/eip712/types.py +154 -0
- nado_protocol/contracts/loader.py +55 -0
- nado_protocol/contracts/types.py +141 -0
- nado_protocol/engine_client/__init__.py +35 -0
- nado_protocol/engine_client/execute.py +416 -0
- nado_protocol/engine_client/query.py +481 -0
- nado_protocol/engine_client/types/__init__.py +113 -0
- nado_protocol/engine_client/types/execute.py +680 -0
- nado_protocol/engine_client/types/models.py +247 -0
- nado_protocol/engine_client/types/query.py +516 -0
- nado_protocol/engine_client/types/stream.py +6 -0
- nado_protocol/indexer_client/__init__.py +28 -0
- nado_protocol/indexer_client/query.py +466 -0
- nado_protocol/indexer_client/types/__init__.py +122 -0
- nado_protocol/indexer_client/types/models.py +364 -0
- nado_protocol/indexer_client/types/query.py +819 -0
- nado_protocol/trigger_client/__init__.py +17 -0
- nado_protocol/trigger_client/execute.py +118 -0
- nado_protocol/trigger_client/query.py +61 -0
- nado_protocol/trigger_client/types/__init__.py +7 -0
- nado_protocol/trigger_client/types/execute.py +89 -0
- nado_protocol/trigger_client/types/models.py +44 -0
- nado_protocol/trigger_client/types/query.py +77 -0
- nado_protocol/utils/__init__.py +37 -0
- nado_protocol/utils/backend.py +111 -0
- nado_protocol/utils/bytes32.py +159 -0
- nado_protocol/utils/enum.py +6 -0
- nado_protocol/utils/exceptions.py +58 -0
- nado_protocol/utils/execute.py +403 -0
- nado_protocol/utils/expiration.py +45 -0
- nado_protocol/utils/interest.py +66 -0
- nado_protocol/utils/math.py +67 -0
- nado_protocol/utils/model.py +79 -0
- nado_protocol/utils/nonce.py +33 -0
- nado_protocol/utils/subaccount.py +18 -0
- nado_protocol/utils/time.py +21 -0
- nado_protocol-0.1.0.dist-info/METADATA +157 -0
- nado_protocol-0.1.0.dist-info/RECORD +78 -0
- nado_protocol-0.1.0.dist-info/WHEEL +4 -0
- nado_protocol-0.1.0.dist-info/entry_points.txt +11 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from nado_protocol.engine_client import EngineClientOpts
|
|
5
|
+
from nado_protocol.engine_client.types.models import (
|
|
6
|
+
MarketType,
|
|
7
|
+
Orderbook,
|
|
8
|
+
ResponseStatus,
|
|
9
|
+
SubaccountPosition,
|
|
10
|
+
)
|
|
11
|
+
from nado_protocol.engine_client.types.query import (
|
|
12
|
+
AllProductsData,
|
|
13
|
+
ContractsData,
|
|
14
|
+
FeeRatesData,
|
|
15
|
+
HealthGroupsData,
|
|
16
|
+
LinkedSignerData,
|
|
17
|
+
MarketLiquidityData,
|
|
18
|
+
MarketPriceData,
|
|
19
|
+
MaxLpMintableData,
|
|
20
|
+
MaxOrderSizeData,
|
|
21
|
+
MaxWithdrawableData,
|
|
22
|
+
NoncesData,
|
|
23
|
+
ProductSymbolsData,
|
|
24
|
+
SubaccountOpenOrdersData,
|
|
25
|
+
SubaccountMultiProductsOpenOrdersData,
|
|
26
|
+
OrderData,
|
|
27
|
+
QueryAllProductsParams,
|
|
28
|
+
QueryContractsParams,
|
|
29
|
+
QueryFeeRatesParams,
|
|
30
|
+
QueryHealthGroupsParams,
|
|
31
|
+
QueryLinkedSignerParams,
|
|
32
|
+
QueryMarketLiquidityParams,
|
|
33
|
+
QueryMarketPriceParams,
|
|
34
|
+
QueryMaxLpMintableParams,
|
|
35
|
+
QueryMaxOrderSizeParams,
|
|
36
|
+
QueryMaxWithdrawableParams,
|
|
37
|
+
QueryNoncesParams,
|
|
38
|
+
QuerySubaccountOpenOrdersParams,
|
|
39
|
+
QuerySubaccountMultiProductOpenOrdersParams,
|
|
40
|
+
QueryOrderParams,
|
|
41
|
+
QueryIsolatedPositionsParams,
|
|
42
|
+
QueryRequest,
|
|
43
|
+
QueryResponse,
|
|
44
|
+
QueryStatusParams,
|
|
45
|
+
QuerySubaccountInfoParams,
|
|
46
|
+
QuerySubaccountInfoTx,
|
|
47
|
+
StatusData,
|
|
48
|
+
SubaccountInfoData,
|
|
49
|
+
SymbolsData,
|
|
50
|
+
QuerySymbolsParams,
|
|
51
|
+
AssetsData,
|
|
52
|
+
MarketPairsData,
|
|
53
|
+
SpotsAprData,
|
|
54
|
+
IsolatedPositionsData,
|
|
55
|
+
)
|
|
56
|
+
from nado_protocol.utils.exceptions import (
|
|
57
|
+
BadStatusCodeException,
|
|
58
|
+
QueryFailedException,
|
|
59
|
+
)
|
|
60
|
+
from nado_protocol.utils.model import ensure_data_type
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class EngineQueryClient:
|
|
64
|
+
"""
|
|
65
|
+
Client class for querying the off-chain engine.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(self, opts: EngineClientOpts):
|
|
69
|
+
"""
|
|
70
|
+
Initialize EngineQueryClient with provided options.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
opts (EngineClientOpts): Options for the client.
|
|
74
|
+
"""
|
|
75
|
+
self._opts: EngineClientOpts = EngineClientOpts.parse_obj(opts)
|
|
76
|
+
self.url: str = self._opts.url
|
|
77
|
+
self.url_v2: str = self.url.replace("/v1", "") + "/v2"
|
|
78
|
+
self.session = requests.Session() # type: ignore
|
|
79
|
+
|
|
80
|
+
def query(self, req: QueryRequest) -> QueryResponse:
|
|
81
|
+
"""
|
|
82
|
+
Send a query to the engine.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
req (QueryRequest): The query request parameters.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
QueryResponse: The response from the engine.
|
|
89
|
+
|
|
90
|
+
Raises:
|
|
91
|
+
BadStatusCodeException: If the response status code is not 200.
|
|
92
|
+
QueryFailedException: If the query status is not "success".
|
|
93
|
+
"""
|
|
94
|
+
res = self.session.post(f"{self.url}/query", json=req.dict())
|
|
95
|
+
if res.status_code != 200:
|
|
96
|
+
raise BadStatusCodeException(res.text)
|
|
97
|
+
try:
|
|
98
|
+
query_res = QueryResponse(**res.json())
|
|
99
|
+
except Exception:
|
|
100
|
+
raise QueryFailedException(res.text)
|
|
101
|
+
if query_res.status != "success":
|
|
102
|
+
raise QueryFailedException(res.text)
|
|
103
|
+
return query_res
|
|
104
|
+
|
|
105
|
+
def _query_v2(self, url):
|
|
106
|
+
res = self.session.get(url)
|
|
107
|
+
if res.status_code != 200:
|
|
108
|
+
raise Exception(res.text)
|
|
109
|
+
return res.json()
|
|
110
|
+
|
|
111
|
+
def get_product_symbols(self) -> ProductSymbolsData:
|
|
112
|
+
"""
|
|
113
|
+
Retrieves symbols for all available products.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
ProductSymbolsData: Symbols for all available products.
|
|
117
|
+
"""
|
|
118
|
+
res = self.session.get(f"{self.url}/symbols?")
|
|
119
|
+
if res.status_code != 200:
|
|
120
|
+
raise BadStatusCodeException(res.text)
|
|
121
|
+
try:
|
|
122
|
+
query_res = QueryResponse(
|
|
123
|
+
status=ResponseStatus.SUCCESS,
|
|
124
|
+
data=res.json(),
|
|
125
|
+
error=None,
|
|
126
|
+
error_code=None,
|
|
127
|
+
request_type=None,
|
|
128
|
+
)
|
|
129
|
+
except Exception:
|
|
130
|
+
raise QueryFailedException(res.text)
|
|
131
|
+
return ensure_data_type(query_res.data, list)
|
|
132
|
+
|
|
133
|
+
def get_status(self) -> StatusData:
|
|
134
|
+
"""
|
|
135
|
+
Query the engine for its status.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
StatusData: The status of the engine.
|
|
139
|
+
"""
|
|
140
|
+
return ensure_data_type(self.query(QueryStatusParams()).data, StatusData)
|
|
141
|
+
|
|
142
|
+
def get_contracts(self) -> ContractsData:
|
|
143
|
+
"""
|
|
144
|
+
Query the engine for Nado contract addresses.
|
|
145
|
+
|
|
146
|
+
Use this to fetch verifying contracts needed for signing executes.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
ContractsData: Nado contracts info.
|
|
150
|
+
"""
|
|
151
|
+
return ensure_data_type(self.query(QueryContractsParams()).data, ContractsData)
|
|
152
|
+
|
|
153
|
+
def get_nonces(self, address: str) -> NoncesData:
|
|
154
|
+
"""
|
|
155
|
+
Query the engine for nonces of a specific address.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
address (str): Wallet address to fetch nonces for.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
NoncesData: The nonces of the address.
|
|
162
|
+
"""
|
|
163
|
+
return ensure_data_type(
|
|
164
|
+
self.query(QueryNoncesParams(address=address)).data, NoncesData
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
def get_order(self, product_id: int, digest: str) -> OrderData:
|
|
168
|
+
"""
|
|
169
|
+
Query the engine for an order with a specific product id and digest.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
product_id (int): The id of the product.
|
|
173
|
+
|
|
174
|
+
digest (str): The digest of the order.
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
OrderData: The order data.
|
|
178
|
+
"""
|
|
179
|
+
return ensure_data_type(
|
|
180
|
+
self.query(QueryOrderParams(product_id=product_id, digest=digest)).data,
|
|
181
|
+
OrderData,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def get_subaccount_info(
|
|
185
|
+
self, subaccount: str, txs: Optional[list[QuerySubaccountInfoTx]] = None
|
|
186
|
+
) -> SubaccountInfoData:
|
|
187
|
+
"""
|
|
188
|
+
Query the engine for the state of a subaccount, including balances.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
subaccount (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
192
|
+
|
|
193
|
+
txs (list[QuerySubaccountInfoTx], optional): You can optionally provide a list of txs, to get an estimated view
|
|
194
|
+
of what the subaccount state would look like if the transactions were applied.
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
SubaccountInfoData: Information about the specified subaccount.
|
|
198
|
+
"""
|
|
199
|
+
return ensure_data_type(
|
|
200
|
+
self.query(QuerySubaccountInfoParams(subaccount=subaccount, txs=txs)).data,
|
|
201
|
+
SubaccountInfoData,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
def get_subaccount_open_orders(
|
|
205
|
+
self, product_id: int, sender: str
|
|
206
|
+
) -> SubaccountOpenOrdersData:
|
|
207
|
+
"""
|
|
208
|
+
Retrieves the open orders for a subaccount on a specific product.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
product_id (int): The identifier of the product for which open orders are to be fetched.
|
|
212
|
+
|
|
213
|
+
sender (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
SubaccountOpenOrdersData: A data object containing the open orders for the
|
|
217
|
+
specified subaccount on the provided product.
|
|
218
|
+
"""
|
|
219
|
+
return ensure_data_type(
|
|
220
|
+
self.query(
|
|
221
|
+
QuerySubaccountOpenOrdersParams(product_id=product_id, sender=sender)
|
|
222
|
+
).data,
|
|
223
|
+
SubaccountOpenOrdersData,
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def get_subaccount_multi_products_open_orders(
|
|
227
|
+
self, product_ids: list[int], sender: str
|
|
228
|
+
) -> SubaccountMultiProductsOpenOrdersData:
|
|
229
|
+
"""
|
|
230
|
+
Retrieves the open orders for a subaccount on a specific product.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
product_ids (list[int]): List of product ids to fetch open orders for.
|
|
234
|
+
|
|
235
|
+
sender (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
SubaccountMultiProductsOpenOrdersData: A data object containing the open orders for the
|
|
239
|
+
specified subaccount on the provided product.
|
|
240
|
+
"""
|
|
241
|
+
return ensure_data_type(
|
|
242
|
+
self.query(
|
|
243
|
+
QuerySubaccountMultiProductOpenOrdersParams(
|
|
244
|
+
product_ids=product_ids, sender=sender
|
|
245
|
+
)
|
|
246
|
+
).data,
|
|
247
|
+
SubaccountMultiProductsOpenOrdersData,
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
def get_market_liquidity(self, product_id: int, depth: int) -> MarketLiquidityData:
|
|
251
|
+
"""
|
|
252
|
+
Query the engine for market liquidity data for a specific product.
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
product_id (int): The id of the product.
|
|
256
|
+
|
|
257
|
+
depth (int): The depth of the market.
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
MarketLiquidityData: Market liquidity data for the specified product.
|
|
261
|
+
"""
|
|
262
|
+
return ensure_data_type(
|
|
263
|
+
self.query(
|
|
264
|
+
QueryMarketLiquidityParams(product_id=product_id, depth=depth)
|
|
265
|
+
).data,
|
|
266
|
+
MarketLiquidityData,
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
def get_symbols(
|
|
270
|
+
self,
|
|
271
|
+
product_type: Optional[str] = None,
|
|
272
|
+
product_ids: Optional[list[int]] = None,
|
|
273
|
+
) -> SymbolsData:
|
|
274
|
+
"""
|
|
275
|
+
Query engine for symbols and product info
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
product_type (Optional[str): "spot" or "perp" products
|
|
279
|
+
|
|
280
|
+
product_ids (Optional[list[int]]): product_ids to return info for
|
|
281
|
+
|
|
282
|
+
"""
|
|
283
|
+
return ensure_data_type(
|
|
284
|
+
self.query(
|
|
285
|
+
QuerySymbolsParams(product_type=product_type, product_ids=product_ids)
|
|
286
|
+
).data,
|
|
287
|
+
SymbolsData,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
def get_all_products(self) -> AllProductsData:
|
|
291
|
+
"""
|
|
292
|
+
Retrieves info about all available products,
|
|
293
|
+
including: product id, oracle price, configuration, state, etc.
|
|
294
|
+
|
|
295
|
+
Returns:
|
|
296
|
+
AllProductsData: Data about all products.
|
|
297
|
+
"""
|
|
298
|
+
return ensure_data_type(
|
|
299
|
+
self.query(QueryAllProductsParams()).data, AllProductsData
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
def get_market_price(self, product_id: int) -> MarketPriceData:
|
|
303
|
+
"""
|
|
304
|
+
Retrieves the highest bid and lowest ask price levels
|
|
305
|
+
from the orderbook for a given product.
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
product_id (int): The id of the product.
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
MarketPriceData: Market price data for the specified product.
|
|
312
|
+
"""
|
|
313
|
+
return ensure_data_type(
|
|
314
|
+
self.query(QueryMarketPriceParams(product_id=product_id)).data,
|
|
315
|
+
MarketPriceData,
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
def get_max_order_size(self, params: QueryMaxOrderSizeParams) -> MaxOrderSizeData:
|
|
319
|
+
"""
|
|
320
|
+
Retrieves the maximum order size of a given product for a specified subaccount.
|
|
321
|
+
|
|
322
|
+
Args:
|
|
323
|
+
params (QueryMaxOrderSizeParams): The parameters object that contains
|
|
324
|
+
the details of the subaccount and product for which the max order size is to be fetched.
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
MaxOrderSizeData: A data object containing the maximum order size possible
|
|
328
|
+
for the given subaccount and product.
|
|
329
|
+
"""
|
|
330
|
+
return ensure_data_type(
|
|
331
|
+
self.query(QueryMaxOrderSizeParams.parse_obj(params)).data, MaxOrderSizeData
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
def get_max_withdrawable(
|
|
335
|
+
self, product_id: int, sender: str, spot_leverage: Optional[bool] = None
|
|
336
|
+
) -> MaxWithdrawableData:
|
|
337
|
+
"""
|
|
338
|
+
Retrieves the maximum withdrawable amount for a given spot product for a subaccount.
|
|
339
|
+
|
|
340
|
+
Args:
|
|
341
|
+
product_id (int): ID of the spot product.
|
|
342
|
+
|
|
343
|
+
sender (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
344
|
+
|
|
345
|
+
spot_leverage (bool, optional): If False, calculates without borrowing. Defaults to True.
|
|
346
|
+
|
|
347
|
+
Returns:
|
|
348
|
+
MaxWithdrawableData: Contains the maximum withdrawable amount.
|
|
349
|
+
"""
|
|
350
|
+
return ensure_data_type(
|
|
351
|
+
self.query(
|
|
352
|
+
QueryMaxWithdrawableParams(
|
|
353
|
+
product_id=product_id, sender=sender, spot_leverage=spot_leverage
|
|
354
|
+
)
|
|
355
|
+
).data,
|
|
356
|
+
MaxWithdrawableData,
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
def get_max_lp_mintable(
|
|
360
|
+
self, product_id: int, sender: str, spot_leverage: Optional[bool] = None
|
|
361
|
+
) -> MaxLpMintableData:
|
|
362
|
+
"""
|
|
363
|
+
Retrieves the maximum LP token amount mintable for a given product for a subaccount.
|
|
364
|
+
|
|
365
|
+
Args:
|
|
366
|
+
product_id (int): ID of the product.
|
|
367
|
+
|
|
368
|
+
sender (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
369
|
+
|
|
370
|
+
spot_leverage (bool, optional): If False, calculates without considering borrowing. Defaults to True.
|
|
371
|
+
|
|
372
|
+
Returns:
|
|
373
|
+
MaxLpMintableData: Contains the maximum LP token mintable amount.
|
|
374
|
+
"""
|
|
375
|
+
return ensure_data_type(
|
|
376
|
+
self.query(
|
|
377
|
+
QueryMaxLpMintableParams(
|
|
378
|
+
product_id=product_id, sender=sender, spot_leverage=spot_leverage
|
|
379
|
+
)
|
|
380
|
+
).data,
|
|
381
|
+
MaxLpMintableData,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
def get_fee_rates(self, sender: str) -> FeeRatesData:
|
|
385
|
+
"""
|
|
386
|
+
Retrieves the fee rates associated with a specific subaccount.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
sender (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
FeeRatesData: Contains fee rates information associated with the subaccount.
|
|
393
|
+
"""
|
|
394
|
+
return ensure_data_type(
|
|
395
|
+
self.query(QueryFeeRatesParams(sender=sender)).data, FeeRatesData
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
def get_health_groups(self) -> HealthGroupsData:
|
|
399
|
+
"""
|
|
400
|
+
Retrieves all available health groups. A health group represents a set of perp
|
|
401
|
+
and spot products whose health is calculated together, such as BTC
|
|
402
|
+
and BTC-PERP.
|
|
403
|
+
|
|
404
|
+
Returns:
|
|
405
|
+
HealthGroupsData: Contains health group information, each including both a spot
|
|
406
|
+
and a perp product.
|
|
407
|
+
"""
|
|
408
|
+
return ensure_data_type(
|
|
409
|
+
self.query(QueryHealthGroupsParams()).data, HealthGroupsData
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
def get_linked_signer(self, subaccount: str) -> LinkedSignerData:
|
|
413
|
+
"""
|
|
414
|
+
Retrieves the current linked signer for the specified subaccount.
|
|
415
|
+
|
|
416
|
+
Args:
|
|
417
|
+
subaccount (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
418
|
+
|
|
419
|
+
Returns:
|
|
420
|
+
LinkedSignerData: Information about the currently linked signer for the subaccount.
|
|
421
|
+
"""
|
|
422
|
+
return ensure_data_type(
|
|
423
|
+
self.query(QueryLinkedSignerParams(subaccount=subaccount)).data,
|
|
424
|
+
LinkedSignerData,
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
def get_isolated_positions(self, subaccount: str) -> IsolatedPositionsData:
|
|
428
|
+
"""
|
|
429
|
+
Retrieves the isolated positions for a specific subaccount.
|
|
430
|
+
|
|
431
|
+
Args:
|
|
432
|
+
subaccount (str): Identifier of the subaccount (owner's address + subaccount name) sent as a hex string.
|
|
433
|
+
|
|
434
|
+
Returns:
|
|
435
|
+
IsolatedPositionsData: A data object containing the isolated positions for the specified subaccount.
|
|
436
|
+
"""
|
|
437
|
+
return ensure_data_type(
|
|
438
|
+
self.query(QueryIsolatedPositionsParams(subaccount=subaccount)).data,
|
|
439
|
+
IsolatedPositionsData,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
def _get_subaccount_product_position(
|
|
443
|
+
self, subaccount: str, product_id: int
|
|
444
|
+
) -> SubaccountPosition:
|
|
445
|
+
summary = self.get_subaccount_info(subaccount)
|
|
446
|
+
try:
|
|
447
|
+
balance = [
|
|
448
|
+
balance
|
|
449
|
+
for balance in summary.spot_balances + summary.perp_balances
|
|
450
|
+
if balance.product_id == product_id
|
|
451
|
+
][0]
|
|
452
|
+
product = [
|
|
453
|
+
product
|
|
454
|
+
for product in summary.spot_products + summary.perp_products
|
|
455
|
+
if product.product_id == product_id
|
|
456
|
+
][0]
|
|
457
|
+
except Exception as e:
|
|
458
|
+
raise Exception(f"Invalid product id provided {product_id}. Error: {e}")
|
|
459
|
+
return SubaccountPosition(balance=balance, product=product)
|
|
460
|
+
|
|
461
|
+
def get_assets(self) -> AssetsData:
|
|
462
|
+
return ensure_data_type(self._query_v2(f"{self.url_v2}/assets"), list)
|
|
463
|
+
|
|
464
|
+
def get_pairs(self, market_type: Optional[MarketType] = None) -> MarketPairsData:
|
|
465
|
+
url = f"{self.url_v2}/pairs"
|
|
466
|
+
if market_type is not None:
|
|
467
|
+
url += f"?market={str(market_type)}"
|
|
468
|
+
return ensure_data_type(self._query_v2(url), list)
|
|
469
|
+
|
|
470
|
+
def get_spots_apr(self) -> SpotsAprData:
|
|
471
|
+
return ensure_data_type(self._query_v2(f"{self.url_v2}/apr"), list)
|
|
472
|
+
|
|
473
|
+
def get_orderbook(self, ticker_id: str, depth: int) -> Orderbook:
|
|
474
|
+
return ensure_data_type(
|
|
475
|
+
Orderbook.parse_obj(
|
|
476
|
+
self._query_v2(
|
|
477
|
+
f"{self.url_v2}/orderbook?ticker_id={ticker_id}&depth={depth}"
|
|
478
|
+
)
|
|
479
|
+
),
|
|
480
|
+
Orderbook,
|
|
481
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from nado_protocol.engine_client.types.execute import *
|
|
2
|
+
from nado_protocol.engine_client.types.models import *
|
|
3
|
+
from nado_protocol.engine_client.types.query import *
|
|
4
|
+
from nado_protocol.engine_client.types.stream import *
|
|
5
|
+
from nado_protocol.utils.backend import NadoClientOpts
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class EngineClientOpts(NadoClientOpts):
|
|
9
|
+
"""
|
|
10
|
+
Model defining the configuration options for the Engine Client.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"BaseParams",
|
|
16
|
+
"SignatureParams",
|
|
17
|
+
"BaseParamsSigned",
|
|
18
|
+
"OrderParams",
|
|
19
|
+
"PlaceOrderParams",
|
|
20
|
+
"CancelOrdersParams",
|
|
21
|
+
"CancelProductOrdersParams",
|
|
22
|
+
"CancelAndPlaceParams",
|
|
23
|
+
"WithdrawCollateralParams",
|
|
24
|
+
"LiquidateSubaccountParams",
|
|
25
|
+
"MintLpParams",
|
|
26
|
+
"BurnLpParams",
|
|
27
|
+
"LinkSignerParams",
|
|
28
|
+
"ExecuteParams",
|
|
29
|
+
"TxRequest",
|
|
30
|
+
"PlaceOrderRequest",
|
|
31
|
+
"CancelOrdersRequest",
|
|
32
|
+
"CancelProductOrdersRequest",
|
|
33
|
+
"CancelAndPlaceRequest",
|
|
34
|
+
"WithdrawCollateralRequest",
|
|
35
|
+
"LiquidateSubaccountRequest",
|
|
36
|
+
"MintLpRequest",
|
|
37
|
+
"BurnLpRequest",
|
|
38
|
+
"LinkSignerRequest",
|
|
39
|
+
"ExecuteRequest",
|
|
40
|
+
"ExecuteResponse",
|
|
41
|
+
"EngineQueryType",
|
|
42
|
+
"QueryStatusParams",
|
|
43
|
+
"QueryContractsParams",
|
|
44
|
+
"QueryNoncesParams",
|
|
45
|
+
"QueryOrderParams",
|
|
46
|
+
"QuerySubaccountInfoTx",
|
|
47
|
+
"QuerySubaccountInfoParams",
|
|
48
|
+
"QuerySubaccountOpenOrdersParams",
|
|
49
|
+
"QueryMarketLiquidityParams",
|
|
50
|
+
"QueryAllProductsParams",
|
|
51
|
+
"QueryMarketPriceParams",
|
|
52
|
+
"QueryMaxOrderSizeParams",
|
|
53
|
+
"QueryMaxWithdrawableParams",
|
|
54
|
+
"QueryMaxLpMintableParams",
|
|
55
|
+
"QueryFeeRatesParams",
|
|
56
|
+
"QueryHealthGroupsParams",
|
|
57
|
+
"QueryLinkedSignerParams",
|
|
58
|
+
"QueryRequest",
|
|
59
|
+
"StatusData",
|
|
60
|
+
"ContractsData",
|
|
61
|
+
"NoncesData",
|
|
62
|
+
"OrderData",
|
|
63
|
+
"SubaccountInfoData",
|
|
64
|
+
"SubaccountOpenOrdersData",
|
|
65
|
+
"MarketLiquidityData",
|
|
66
|
+
"AllProductsData",
|
|
67
|
+
"MarketPriceData",
|
|
68
|
+
"MaxOrderSizeData",
|
|
69
|
+
"MaxWithdrawableData",
|
|
70
|
+
"MaxLpMintableData",
|
|
71
|
+
"FeeRatesData",
|
|
72
|
+
"HealthGroupsData",
|
|
73
|
+
"LinkedSignerData",
|
|
74
|
+
"QueryResponseData",
|
|
75
|
+
"QueryResponse",
|
|
76
|
+
"ResponseStatus",
|
|
77
|
+
"EngineStatus",
|
|
78
|
+
"MintLp",
|
|
79
|
+
"BurnLp",
|
|
80
|
+
"ApplyDelta",
|
|
81
|
+
"MintLpTx",
|
|
82
|
+
"BurnLpTx",
|
|
83
|
+
"ApplyDeltaTx",
|
|
84
|
+
"SubaccountHealth",
|
|
85
|
+
"SpotLpBalance",
|
|
86
|
+
"SpotBalance",
|
|
87
|
+
"SpotProductBalance",
|
|
88
|
+
"PerpLpBalance",
|
|
89
|
+
"PerpBalance",
|
|
90
|
+
"PerpProductBalance",
|
|
91
|
+
"ProductRisk",
|
|
92
|
+
"ProductBookInfo",
|
|
93
|
+
"BaseProduct",
|
|
94
|
+
"BaseProductLpState",
|
|
95
|
+
"SpotProductConfig",
|
|
96
|
+
"SpotProductState",
|
|
97
|
+
"SpotProductLpAmount",
|
|
98
|
+
"SpotProductLpState",
|
|
99
|
+
"SpotProduct",
|
|
100
|
+
"PerpProductState",
|
|
101
|
+
"PerpProductLpState",
|
|
102
|
+
"PerpProduct",
|
|
103
|
+
"MaxOrderSizeDirection",
|
|
104
|
+
"MarketLiquidity",
|
|
105
|
+
"StreamAuthenticationParams",
|
|
106
|
+
"Asset",
|
|
107
|
+
"MarketPair",
|
|
108
|
+
"SpotApr",
|
|
109
|
+
"Orderbook",
|
|
110
|
+
"AssetsData",
|
|
111
|
+
"MarketPairsData",
|
|
112
|
+
"SpotsAprData",
|
|
113
|
+
]
|