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