ddx-python 1.0.4__cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.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.
Files changed (106) hide show
  1. ddx/.gitignore +1 -0
  2. ddx/__init__.py +58 -0
  3. ddx/_rust/__init__.pyi +2685 -0
  4. ddx/_rust/common/__init__.pyi +17 -0
  5. ddx/_rust/common/accounting.pyi +6 -0
  6. ddx/_rust/common/enums.pyi +3 -0
  7. ddx/_rust/common/requests/__init__.pyi +23 -0
  8. ddx/_rust/common/requests/intents.pyi +19 -0
  9. ddx/_rust/common/specs.pyi +17 -0
  10. ddx/_rust/common/state/__init__.pyi +41 -0
  11. ddx/_rust/common/state/keys.pyi +29 -0
  12. ddx/_rust/common/transactions.pyi +7 -0
  13. ddx/_rust/decimal.pyi +3 -0
  14. ddx/_rust/h256.pyi +3 -0
  15. ddx/_rust.abi3.so +0 -0
  16. ddx/app_config/ethereum/addresses.json +526 -0
  17. ddx/auditor/README.md +32 -0
  18. ddx/auditor/__init__.py +0 -0
  19. ddx/auditor/auditor_driver.py +1043 -0
  20. ddx/auditor/websocket_message.py +54 -0
  21. ddx/common/__init__.py +0 -0
  22. ddx/common/epoch_params.py +28 -0
  23. ddx/common/fill_context.py +141 -0
  24. ddx/common/logging.py +184 -0
  25. ddx/common/market_aware_account.py +259 -0
  26. ddx/common/market_specs.py +64 -0
  27. ddx/common/trade_mining_params.py +19 -0
  28. ddx/common/transaction_utils.py +85 -0
  29. ddx/common/transactions/__init__.py +0 -0
  30. ddx/common/transactions/advance_epoch.py +91 -0
  31. ddx/common/transactions/advance_settlement_epoch.py +63 -0
  32. ddx/common/transactions/all_price_checkpoints.py +84 -0
  33. ddx/common/transactions/cancel.py +76 -0
  34. ddx/common/transactions/cancel_all.py +88 -0
  35. ddx/common/transactions/complete_fill.py +103 -0
  36. ddx/common/transactions/disaster_recovery.py +96 -0
  37. ddx/common/transactions/event.py +48 -0
  38. ddx/common/transactions/fee_distribution.py +119 -0
  39. ddx/common/transactions/funding.py +292 -0
  40. ddx/common/transactions/futures_expiry.py +123 -0
  41. ddx/common/transactions/genesis.py +108 -0
  42. ddx/common/transactions/inner/__init__.py +0 -0
  43. ddx/common/transactions/inner/adl_outcome.py +25 -0
  44. ddx/common/transactions/inner/fill.py +232 -0
  45. ddx/common/transactions/inner/liquidated_position.py +41 -0
  46. ddx/common/transactions/inner/liquidation_entry.py +41 -0
  47. ddx/common/transactions/inner/liquidation_fill.py +118 -0
  48. ddx/common/transactions/inner/outcome.py +32 -0
  49. ddx/common/transactions/inner/trade_fill.py +292 -0
  50. ddx/common/transactions/insurance_fund_update.py +138 -0
  51. ddx/common/transactions/insurance_fund_withdraw.py +100 -0
  52. ddx/common/transactions/liquidation.py +353 -0
  53. ddx/common/transactions/partial_fill.py +125 -0
  54. ddx/common/transactions/pnl_realization.py +120 -0
  55. ddx/common/transactions/post.py +72 -0
  56. ddx/common/transactions/post_order.py +95 -0
  57. ddx/common/transactions/price_checkpoint.py +97 -0
  58. ddx/common/transactions/signer_registered.py +62 -0
  59. ddx/common/transactions/specs_update.py +61 -0
  60. ddx/common/transactions/strategy_update.py +158 -0
  61. ddx/common/transactions/tradable_product_update.py +98 -0
  62. ddx/common/transactions/trade_mining.py +147 -0
  63. ddx/common/transactions/trader_update.py +131 -0
  64. ddx/common/transactions/withdraw.py +90 -0
  65. ddx/common/transactions/withdraw_ddx.py +74 -0
  66. ddx/common/utils.py +176 -0
  67. ddx/config.py +17 -0
  68. ddx/derivadex_client.py +270 -0
  69. ddx/models/__init__.py +0 -0
  70. ddx/models/base.py +132 -0
  71. ddx/py.typed +0 -0
  72. ddx/realtime_client/__init__.py +2 -0
  73. ddx/realtime_client/config.py +2 -0
  74. ddx/realtime_client/models/__init__.py +611 -0
  75. ddx/realtime_client/realtime_client.py +646 -0
  76. ddx/rest_client/__init__.py +0 -0
  77. ddx/rest_client/clients/__init__.py +0 -0
  78. ddx/rest_client/clients/base_client.py +60 -0
  79. ddx/rest_client/clients/market_client.py +1243 -0
  80. ddx/rest_client/clients/on_chain_client.py +439 -0
  81. ddx/rest_client/clients/signed_client.py +292 -0
  82. ddx/rest_client/clients/system_client.py +843 -0
  83. ddx/rest_client/clients/trade_client.py +357 -0
  84. ddx/rest_client/constants/__init__.py +0 -0
  85. ddx/rest_client/constants/endpoints.py +66 -0
  86. ddx/rest_client/contracts/__init__.py +0 -0
  87. ddx/rest_client/contracts/checkpoint/__init__.py +560 -0
  88. ddx/rest_client/contracts/ddx/__init__.py +1949 -0
  89. ddx/rest_client/contracts/dummy_token/__init__.py +1014 -0
  90. ddx/rest_client/contracts/i_collateral/__init__.py +1414 -0
  91. ddx/rest_client/contracts/i_stake/__init__.py +696 -0
  92. ddx/rest_client/exceptions/__init__.py +0 -0
  93. ddx/rest_client/exceptions/exceptions.py +32 -0
  94. ddx/rest_client/http/__init__.py +0 -0
  95. ddx/rest_client/http/http_client.py +336 -0
  96. ddx/rest_client/models/__init__.py +0 -0
  97. ddx/rest_client/models/market.py +693 -0
  98. ddx/rest_client/models/signed.py +61 -0
  99. ddx/rest_client/models/system.py +311 -0
  100. ddx/rest_client/models/trade.py +185 -0
  101. ddx/rest_client/utils/__init__.py +0 -0
  102. ddx/rest_client/utils/encryption_utils.py +26 -0
  103. ddx/utils/__init__.py +0 -0
  104. ddx_python-1.0.4.dist-info/METADATA +63 -0
  105. ddx_python-1.0.4.dist-info/RECORD +106 -0
  106. ddx_python-1.0.4.dist-info/WHEEL +5 -0
@@ -0,0 +1,357 @@
1
+ from typing import Optional, AsyncIterator
2
+
3
+ from ddx.rest_client.clients.base_client import BaseClient
4
+ from ddx.rest_client.constants.endpoints import Trade
5
+ from ddx.rest_client.models.trade import (
6
+ FeesHistoryResponse,
7
+ Fee,
8
+ PositionsResponse,
9
+ Position,
10
+ StrategyResponse,
11
+ StrategyMetricsResponse,
12
+ TraderResponse,
13
+ StrategiesResponse,
14
+ )
15
+
16
+
17
+ class TradeClient(BaseClient):
18
+ """
19
+ Trade-related operations and data access.
20
+
21
+ Provides access to strategy fees, positions, metrics, and trader information
22
+ through the API endpoints.
23
+ """
24
+
25
+ async def get_strategy_fees_history_page(
26
+ self,
27
+ trader: str,
28
+ strategy_id: str,
29
+ limit: Optional[int] = None,
30
+ epoch: Optional[int] = None,
31
+ tx_ordinal: Optional[int] = None,
32
+ ordinal: Optional[int] = None,
33
+ symbol: Optional[str] = None,
34
+ order: Optional[str] = None,
35
+ ) -> FeesHistoryResponse:
36
+ """
37
+ Get a single page of maker/taker fee aggregates for a strategy.
38
+
39
+ Parameters
40
+ ----------
41
+ trader : str
42
+ The trader address
43
+ strategy_id : str
44
+ The strategy ID
45
+ limit : Optional[int]
46
+ The number of rows to return
47
+ epoch : Optional[int]
48
+ The epoch boundary used when fetching the next timeseries page
49
+ tx_ordinal : Optional[int]
50
+ The txOrdinal boundary used when fetching the next timeseries page.
51
+ Must be passed along with epoch
52
+ ordinal : Optional[int]
53
+ The ordinal boundary used when fetching the next timeseries page.
54
+ Must be passed along with epoch and txOrdinal
55
+ symbol : Optional[str]
56
+ The symbol
57
+ order : Optional[str]
58
+ The ordering of the results. Values: "asc", "desc"
59
+
60
+ Returns
61
+ -------
62
+ FeesHistoryResponse
63
+ Single page of strategy fees history data
64
+ """
65
+
66
+ params = {
67
+ "trader": trader,
68
+ "strategyId": strategy_id,
69
+ "limit": limit,
70
+ "epoch": epoch,
71
+ "txOrdinal": tx_ordinal,
72
+ "ordinal": ordinal,
73
+ "symbol": symbol,
74
+ "order": order,
75
+ }
76
+ params = {k: v for k, v in params.items() if v is not None}
77
+
78
+ response = await self._http.get(
79
+ self._build_url(Trade.GET_STRATEGY_FEES_HISTORY), params=params
80
+ )
81
+
82
+ return FeesHistoryResponse.model_validate(response)
83
+
84
+ async def get_strategy_fees_history(
85
+ self,
86
+ trader: str,
87
+ strategy_id: str,
88
+ symbol: Optional[str] = None,
89
+ order: Optional[str] = None,
90
+ limit: Optional[int] = 100,
91
+ ) -> AsyncIterator[Fee]:
92
+ """
93
+ Get all maker/taker fee aggregates for a strategy.
94
+
95
+ Automatically handles pagination using epoch, tx_ordinal, and ordinal.
96
+
97
+ Parameters
98
+ ----------
99
+ trader : str
100
+ The trader address
101
+ strategy_id : str
102
+ The strategy ID
103
+ symbol : Optional[str]
104
+ The symbol
105
+ order : Optional[str]
106
+ The ordering of the results. Values: "asc", "desc"
107
+ limit : Optional[int]
108
+ The number of rows to return per page
109
+
110
+ Yields
111
+ ------
112
+ Fee
113
+ Strategy fee entries
114
+ """
115
+
116
+ epoch = None
117
+ tx_ordinal = None
118
+ ordinal = None
119
+
120
+ while True:
121
+ response = await self.get_strategy_fees_history_page(
122
+ trader=trader,
123
+ strategy_id=strategy_id,
124
+ limit=limit,
125
+ epoch=epoch,
126
+ tx_ordinal=tx_ordinal,
127
+ ordinal=ordinal,
128
+ symbol=symbol,
129
+ order=order,
130
+ )
131
+
132
+ if not response.value:
133
+ break
134
+
135
+ for item in response.value:
136
+ yield item
137
+
138
+ if response.next_epoch is None:
139
+ break
140
+
141
+ epoch = response.next_epoch
142
+ tx_ordinal = response.next_tx_ordinal
143
+ ordinal = response.next_ordinal
144
+
145
+ async def get_strategy_positions_page(
146
+ self,
147
+ trader: str,
148
+ strategy_id: str,
149
+ limit: Optional[int] = None,
150
+ offset: Optional[int] = None,
151
+ symbol: Optional[str] = None,
152
+ ) -> PositionsResponse:
153
+ """
154
+ Get a single page of current positions for a strategy.
155
+
156
+ Parameters
157
+ ----------
158
+ trader : str
159
+ The trader address
160
+ strategy_id : str
161
+ The strategy ID
162
+ limit : Optional[int]
163
+ The number of rows to return
164
+ offset : Optional[int]
165
+ The offset of returned rows
166
+ symbol : Optional[str]
167
+ The symbol
168
+
169
+ Returns
170
+ -------
171
+ PositionsResponse
172
+ Single page of strategy positions data
173
+ """
174
+
175
+ params = {
176
+ "trader": trader,
177
+ "strategyId": strategy_id,
178
+ "limit": limit,
179
+ "offset": offset,
180
+ "symbol": symbol,
181
+ }
182
+ params = {k: v for k, v in params.items() if v is not None}
183
+
184
+ response = await self._http.get(
185
+ self._build_url(Trade.GET_STRATEGY_POSITIONS), params=params
186
+ )
187
+
188
+ return PositionsResponse.model_validate(response)
189
+
190
+ async def get_strategy_positions(
191
+ self,
192
+ trader: str,
193
+ strategy_id: str,
194
+ symbol: Optional[str] = None,
195
+ limit: Optional[int] = 100,
196
+ ) -> AsyncIterator[Position]:
197
+ """
198
+ Get all current positions for a strategy.
199
+
200
+ Automatically handles pagination using offset.
201
+
202
+ Parameters
203
+ ----------
204
+ trader : str
205
+ The trader address
206
+ strategy_id : str
207
+ The strategy ID
208
+ symbol : Optional[str]
209
+ The symbol
210
+ limit : Optional[int]
211
+ The number of rows to return per page
212
+
213
+ Yields
214
+ ------
215
+ Position
216
+ Strategy position entries
217
+ """
218
+
219
+ offset = 0
220
+
221
+ while True:
222
+ response = await self.get_strategy_positions_page(
223
+ trader=trader,
224
+ strategy_id=strategy_id,
225
+ limit=limit,
226
+ offset=offset,
227
+ symbol=symbol,
228
+ )
229
+
230
+ if not response.value:
231
+ break
232
+
233
+ for item in response.value:
234
+ yield item
235
+
236
+ if len(response.value) < limit:
237
+ break
238
+
239
+ offset += len(response.value)
240
+
241
+ async def get_strategy(
242
+ self,
243
+ trader: str,
244
+ strategy_id: str,
245
+ ) -> StrategyResponse:
246
+ """
247
+ Get current state of trader's strategy.
248
+
249
+ Parameters
250
+ ----------
251
+ trader : str
252
+ The trader address
253
+ strategy_id : str
254
+ The strategy ID
255
+
256
+ Returns
257
+ -------
258
+ StrategyResponse
259
+ Strategy information including trader address, strategy ID hash,
260
+ max leverage, available collateral, locked collateral, and frozen status
261
+ """
262
+
263
+ params = {
264
+ "trader": trader,
265
+ "strategyId": strategy_id,
266
+ }
267
+
268
+ response = await self._http.get(self._build_url(Trade.GET_STRATEGY), params=params)
269
+
270
+ return StrategyResponse.model_validate(response)
271
+
272
+ async def get_strategies(
273
+ self,
274
+ trader: str,
275
+ ) -> StrategiesResponse:
276
+ """
277
+ Get current state of trader's strategies.
278
+
279
+ Parameters
280
+ ----------
281
+ trader : str
282
+ The trader address
283
+
284
+ Returns
285
+ -------
286
+ StrategiesResponse
287
+ Strategies information including trader address, strategy ID hash,
288
+ max leverage, available collateral, locked collateral, and frozen status
289
+ """
290
+
291
+ params = {
292
+ "trader": trader,
293
+ }
294
+
295
+ response = await self._http.get(self._build_url(Trade.GET_STRATEGIES), params=params)
296
+
297
+ return StrategiesResponse.model_validate(response)
298
+
299
+ async def get_strategy_metrics(
300
+ self,
301
+ trader: str,
302
+ strategy_id: str,
303
+ ) -> StrategyMetricsResponse:
304
+ """
305
+ Get KPIs and risk metrics for a strategy.
306
+
307
+ Includes margin fraction, maintenance margin ratio, leverage,
308
+ strategy available collateral and strategy value.
309
+
310
+ Parameters
311
+ ----------
312
+ trader : str
313
+ The trader address
314
+ strategy_id : str
315
+ The strategy ID
316
+
317
+ Returns
318
+ -------
319
+ StrategyMetricsResponse
320
+ Strategy metrics including margin fraction, MMR, leverage,
321
+ strategy margin, and strategy value
322
+ """
323
+
324
+ params = {
325
+ "trader": trader,
326
+ "strategyId": strategy_id,
327
+ }
328
+
329
+ response = await self._http.get(self._build_url(Trade.GET_STRATEGY_METRICS), params=params)
330
+
331
+ return StrategyMetricsResponse.model_validate(response)
332
+
333
+ async def get_trader(
334
+ self,
335
+ trader: str,
336
+ ) -> TraderResponse:
337
+ """
338
+ Get current trader DDX balance and profile.
339
+
340
+ Parameters
341
+ ----------
342
+ trader : str
343
+ The trader address
344
+
345
+ Returns
346
+ -------
347
+ TraderResponse
348
+ Trader information including DDX balances and fee payment preferences
349
+ """
350
+
351
+ params = {
352
+ "trader": trader,
353
+ }
354
+
355
+ response = await self._http.get(self._build_url(Trade.GET_TRADER), params=params)
356
+
357
+ return TraderResponse.model_validate(response)
File without changes
@@ -0,0 +1,66 @@
1
+ from enum import Enum
2
+
3
+
4
+ class System(str, Enum):
5
+ """Enum containing all system-related endpoint paths."""
6
+
7
+ GET_EXCHANGE_INFO = "/exchange/api/v1/exchange_info"
8
+ GET_CONNECTION_INFO = "/exchange/api/v1/ping"
9
+ GET_SYMBOLS = "/exchange/api/v1/symbols"
10
+ GET_SERVER_TIME = "/exchange/api/v1/time"
11
+ GET_COLLATERAL_AGGREGATION = "/stats/api/v1/aggregations/collateral"
12
+ GET_DDX_AGGREGATION = "/stats/api/v1/aggregations/ddx"
13
+ GET_INSURANCE_FUND_AGGREGATION = "/stats/api/v1/aggregations/insurance_fund"
14
+ GET_EPOCH_HISTORY = "/stats/api/v1/epochs"
15
+ GET_INSURANCE_FUND_HISTORY = "/stats/api/v1/insurance_fund"
16
+ GET_SPECS = "/stats/api/v1/specs"
17
+ GET_EXCHANGE_STATUS = "/stats/api/v1/status"
18
+ GET_DDX_SUPPLY = "/stats/api/v1/supply"
19
+ GET_TRADABLE_PRODUCTS = "/stats/api/v1/tradable_products"
20
+
21
+ GET_DEPLOYMENT_INFO = "/contract-server/addresses"
22
+
23
+
24
+ class Trade(str, Enum):
25
+ """Enum containing all trade-related endpoint paths."""
26
+
27
+ GET_STRATEGY_FEES_HISTORY = "/stats/api/v1/fees"
28
+ GET_STRATEGY_POSITIONS = "/stats/api/v1/positions"
29
+ GET_STRATEGY = "/stats/api/v1/strategy"
30
+ GET_STRATEGIES = "/stats/api/v1/strategies"
31
+ GET_STRATEGY_METRICS = "/stats/api/v1/strategy_metrics"
32
+ GET_TRADER = "/stats/api/v1/trader"
33
+
34
+
35
+ class Market(str, Enum):
36
+ """Enum containing all market-related endpoint paths."""
37
+
38
+ GET_MARK_PRICE_HISTORY = "/exchange/api/v1/mark_prices"
39
+ GET_ORDER_BOOK_L3 = "/exchange/api/v1/order_book"
40
+ GET_ORDER_UPDATE_HISTORY = "/exchange/api/v1/order_updates"
41
+ GET_STRATEGY_UPDATE_HISTORY = "/exchange/api/v1/strategy_updates"
42
+ GET_TICKERS = "/exchange/api/v1/tickers"
43
+ GET_TRADER_UPDATE_HISTORY = "/exchange/api/v1/trader_updates"
44
+ GET_BALANCE_AGGREGATION = "/stats/api/v1/aggregations/balance"
45
+ GET_FEES_AGGREGATION = "/stats/api/v1/aggregations/fees"
46
+ GET_FUNDING_RATE_COMPARISON_AGGREGATION = "/stats/api/v1/aggregations/funding_rate_comparison"
47
+ GET_TOP_TRADERS_AGGREGATION = "/stats/api/v1/aggregations/traders"
48
+ GET_VOLUME_AGGREGATION = "/stats/api/v1/aggregations/volume"
49
+ GET_FUNDING_RATE_HISTORY = "/stats/api/v1/funding_rate_history"
50
+ GET_OPEN_INTEREST_HISTORY = "/stats/api/v1/open_interest_history"
51
+ GET_ORDER_BOOK_L2 = "/stats/api/v1/order_book_l2"
52
+ GET_PRICE_CHECKPOINT_HISTORY = "/stats/api/v1/price_checkpoints"
53
+
54
+
55
+ class Signed(str, Enum):
56
+ """Enum containing all signed endpoint paths."""
57
+
58
+ ENCRYPTION_KEY = "/v2/encryption-key"
59
+ SUBMIT_REQUEST = "/v2/request"
60
+
61
+
62
+ class OnChain(str, Enum):
63
+ """Enum containing all on-chain-related endpoint paths."""
64
+
65
+ KYC_AUTH = "/kyc/v1/kyc-auth"
66
+ PROOF = "/v2/proof"
File without changes