deltadefi 0.1.1__py3-none-any.whl → 1.0.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.

Potentially problematic release.


This version of deltadefi might be problematic. Click here for more details.

@@ -1,4 +1,5 @@
1
1
  #
2
+ from typing import cast
2
3
 
3
4
  from sidan_gin import Asset, UTxO
4
5
 
@@ -43,7 +44,10 @@ class Accounts(API):
43
44
  """
44
45
 
45
46
  url_path = "/operation-key"
46
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
47
+ return cast(
48
+ "GetOperationKeyResponse",
49
+ self.send_request("GET", self.group_url_path + url_path, kwargs),
50
+ )
47
51
 
48
52
  def create_new_api_key(self, **kwargs) -> CreateNewAPIKeyResponse:
49
53
  """
@@ -54,7 +58,10 @@ class Accounts(API):
54
58
  """
55
59
 
56
60
  url_path = "/new-api-key"
57
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
61
+ return cast(
62
+ "CreateNewAPIKeyResponse",
63
+ self.send_request("GET", self.group_url_path + url_path, kwargs),
64
+ )
58
65
 
59
66
  def get_deposit_records(self, **kwargs) -> GetDepositRecordsResponse:
60
67
  """
@@ -64,7 +71,10 @@ class Accounts(API):
64
71
  A GetDepositRecordsResponse object containing the deposit records.
65
72
  """
66
73
  url_path = "/deposit-records"
67
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
74
+ return cast(
75
+ "GetDepositRecordsResponse",
76
+ self.send_request("GET", self.group_url_path + url_path, kwargs),
77
+ )
68
78
 
69
79
  def get_withdrawal_records(self, **kwargs) -> GetWithdrawalRecordsResponse:
70
80
  """
@@ -74,7 +84,10 @@ class Accounts(API):
74
84
  A GetWithdrawalRecordsResponse object containing the withdrawal records.
75
85
  """
76
86
  url_path = "/withdrawal-records"
77
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
87
+ return cast(
88
+ "GetWithdrawalRecordsResponse",
89
+ self.send_request("GET", self.group_url_path + url_path, kwargs),
90
+ )
78
91
 
79
92
  def get_order_records(
80
93
  self, status: OrderStatusType, **kwargs
@@ -95,7 +108,10 @@ class Accounts(API):
95
108
  payload = {"status": status, **kwargs}
96
109
 
97
110
  url_path = "/order-records"
98
- return self.send_request("GET", self.group_url_path + url_path, payload)
111
+ return cast(
112
+ "GetOrderRecordsResponse",
113
+ self.send_request("GET", self.group_url_path + url_path, payload),
114
+ )
99
115
 
100
116
  def get_order_record(self, order_id: str, **kwargs) -> GetOrderRecordResponse:
101
117
  """
@@ -110,7 +126,10 @@ class Accounts(API):
110
126
  check_required_parameter(order_id, "order_id")
111
127
 
112
128
  url_path = f"/order/{order_id}"
113
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
129
+ return cast(
130
+ "GetOrderRecordResponse",
131
+ self.send_request("GET", self.group_url_path + url_path, kwargs),
132
+ )
114
133
 
115
134
  def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
116
135
  """
@@ -120,7 +139,10 @@ class Accounts(API):
120
139
  A GetAccountBalanceResponse object containing the account balance.
121
140
  """
122
141
  url_path = "/balance"
123
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
142
+ return cast(
143
+ "GetAccountBalanceResponse",
144
+ self.send_request("GET", self.group_url_path + url_path, kwargs),
145
+ )
124
146
 
125
147
  def build_deposit_transaction(
126
148
  self, deposit_amount: list[Asset], input_utxos: list[UTxO], **kwargs
@@ -145,7 +167,10 @@ class Accounts(API):
145
167
  }
146
168
 
147
169
  url_path = "/deposit/build"
148
- return self.send_request("POST", self.group_url_path + url_path, payload)
170
+ return cast(
171
+ "BuildDepositTransactionResponse",
172
+ self.send_request("POST", self.group_url_path + url_path, payload),
173
+ )
149
174
 
150
175
  def build_withdrawal_transaction(
151
176
  self, withdrawal_amount: list[Asset], **kwargs
@@ -164,7 +189,10 @@ class Accounts(API):
164
189
  payload = {"withdrawal_amount": withdrawal_amount, **kwargs}
165
190
 
166
191
  url_path = "/withdrawal/build"
167
- return self.send_request("POST", self.group_url_path + url_path, payload)
192
+ return cast(
193
+ "BuildWithdrawalTransactionResponse",
194
+ self.send_request("POST", self.group_url_path + url_path, payload),
195
+ )
168
196
 
169
197
  def build_transferal_transaction(
170
198
  self, transferal_amount: list[Asset], to_address: str, **kwargs
@@ -179,8 +207,8 @@ class Accounts(API):
179
207
  A BuildTransferalTransactionResponse object containing the built transferal transaction.
180
208
  """
181
209
 
182
- check_required_parameter(
183
- transferal_amount, "transferal_amount", to_address, "to_address"
210
+ check_required_parameters(
211
+ [[transferal_amount, "transferal_amount"], [to_address, "to_address"]]
184
212
  )
185
213
  payload = {
186
214
  "transferal_amount": transferal_amount,
@@ -189,7 +217,10 @@ class Accounts(API):
189
217
  }
190
218
 
191
219
  url_path = "/transferal/build"
192
- return self.send_request("POST", self.group_url_path + url_path, payload)
220
+ return cast(
221
+ "BuildTransferalTransactionResponse",
222
+ self.send_request("POST", self.group_url_path + url_path, payload),
223
+ )
193
224
 
194
225
  def submit_deposit_transaction(
195
226
  self, signed_tx: str, **kwargs
@@ -208,7 +239,10 @@ class Accounts(API):
208
239
  payload = {"signed_tx": signed_tx, **kwargs}
209
240
 
210
241
  url_path = "/deposit/submit"
211
- return self.send_request("POST", self.group_url_path + url_path, payload)
242
+ return cast(
243
+ "SubmitDepositTransactionResponse",
244
+ self.send_request("POST", self.group_url_path + url_path, payload),
245
+ )
212
246
 
213
247
  def submit_withdrawal_transaction(
214
248
  self, signed_tx: str, **kwargs
@@ -227,7 +261,10 @@ class Accounts(API):
227
261
  payload = {"signed_tx": signed_tx, **kwargs}
228
262
 
229
263
  url_path = "/withdrawal/submit"
230
- return self.send_request("POST", self.group_url_path + url_path, payload)
264
+ return cast(
265
+ "SubmitWithdrawalTransactionResponse",
266
+ self.send_request("POST", self.group_url_path + url_path, payload),
267
+ )
231
268
 
232
269
  def submit_transferal_transaction(
233
270
  self, signed_tx: str, **kwargs
@@ -246,4 +283,7 @@ class Accounts(API):
246
283
  payload = {"signed_tx": signed_tx, **kwargs}
247
284
 
248
285
  url_path = "/transferal/submit"
249
- return self.send_request("POST", self.group_url_path + url_path, payload)
286
+ return cast(
287
+ "SubmitTransferalTransactionResponse",
288
+ self.send_request("POST", self.group_url_path + url_path, payload),
289
+ )
@@ -18,6 +18,7 @@ class ApiClient:
18
18
  network: str = "preprod",
19
19
  api_key: str | None = None,
20
20
  base_url: str | None = None,
21
+ ws_url: str | None = None,
21
22
  master_wallet: Wallet | None = None,
22
23
  ):
23
24
  """
@@ -30,30 +31,26 @@ class ApiClient:
30
31
  """
31
32
  if network == "mainnet":
32
33
  self.network_id = 1
33
- self.base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
34
+ self.base_url = "https://api.deltadefi.io"
35
+ self.ws_url = "wss://stream.deltadefi.io"
34
36
  else:
35
37
  self.network_id = 0
36
38
  self.base_url = "https://api-staging.deltadefi.io"
39
+ self.ws_url = "wss://stream-staging.deltadefi.io"
37
40
 
38
41
  if base_url:
39
42
  self.base_url = base_url
40
43
 
44
+ if ws_url:
45
+ self.ws_url = ws_url
46
+
41
47
  self.api_key = api_key
42
48
  self.master_wallet = master_wallet
43
49
 
44
50
  self.accounts = Accounts(base_url=self.base_url, api_key=api_key)
45
51
  self.orders = Order(base_url=self.base_url, api_key=api_key)
46
52
  self.markets = Market(base_url=self.base_url, api_key=api_key)
47
-
48
- # Initialize WebSocket client with correct stream URL
49
- if network == "mainnet":
50
- ws_base_url = (
51
- "wss://stream.deltadefi.io" # TODO: Update when mainnet is available
52
- )
53
- else:
54
- ws_base_url = "wss://stream-staging.deltadefi.io"
55
-
56
- self.websocket = WebSocketClient(base_url=ws_base_url, api_key=api_key)
53
+ self.websocket = WebSocketClient(base_url=self.ws_url, api_key=api_key)
57
54
 
58
55
  def load_operation_key(self, password: str):
59
56
  """
@@ -116,3 +113,25 @@ class ApiClient:
116
113
  signed_tx = self.operation_wallet.sign_tx(build_res["tx_hex"])
117
114
  self.orders.submit_cancel_order_transaction(signed_tx, **kwargs)
118
115
  return {"message": "Order cancelled successfully", "order_id": order_id}
116
+
117
+ def cancel_all_orders(self, **kwargs):
118
+ """
119
+ Cancel all open orders for the account.
120
+ """
121
+ if not hasattr(self, "operation_wallet") or self.operation_wallet is None:
122
+ raise ValueError("Operation wallet is not initialized")
123
+
124
+ build_res = self.orders.build_cancel_all_orders_transaction()
125
+
126
+ signed_txs: list[str] = []
127
+ for tx_hex in build_res["tx_hexes"]:
128
+ signed_tx = self.operation_wallet.sign_tx(tx_hex)
129
+ signed_txs.append(signed_tx)
130
+
131
+ submit_res = self.orders.submit_cancel_all_orders_transaction(
132
+ signed_txs, **kwargs
133
+ )
134
+ return {
135
+ "message": "All orders cancelled successfully",
136
+ "cancelled_order_ids": submit_res["cancelled_order_ids"],
137
+ }
@@ -1,4 +1,4 @@
1
- from typing import Literal
1
+ from typing import Literal, cast
2
2
 
3
3
  from deltadefi.api import API
4
4
  from deltadefi.responses import GetAggregatedPriceResponse, GetMarketPriceResponse
@@ -28,7 +28,10 @@ class Market(API):
28
28
  check_required_parameter(symbol, "symbol")
29
29
  payload = {"symbol": symbol, **kwargs}
30
30
  url_path = "/market-price"
31
- return self.send_request("GET", self.group_url_path + url_path, payload)
31
+ return cast(
32
+ "GetMarketPriceResponse",
33
+ self.send_request("GET", self.group_url_path + url_path, payload),
34
+ )
32
35
 
33
36
  def get_aggregated_price(
34
37
  self,
@@ -56,12 +59,15 @@ class Market(API):
56
59
  ]
57
60
  )
58
61
  url_path = f"/graph/{symbol}"
59
- return self.send_request(
60
- "GET",
61
- self.group_url_path + url_path,
62
- {
63
- "interval": interval,
64
- "start": start,
65
- "end": end,
66
- },
62
+ return cast(
63
+ "GetAggregatedPriceResponse",
64
+ self.send_request(
65
+ "GET",
66
+ self.group_url_path + url_path,
67
+ {
68
+ "interval": interval,
69
+ "start": start,
70
+ "end": end,
71
+ },
72
+ ),
67
73
  )
@@ -1,8 +1,12 @@
1
+ from typing import cast
2
+
1
3
  from deltadefi.api import API
2
4
  from deltadefi.models.models import OrderSide, OrderType
3
5
  from deltadefi.responses import (
6
+ BuildCancelAllOrdersTransactionResponse,
4
7
  BuildCancelOrderTransactionResponse,
5
8
  BuildPlaceOrderTransactionResponse,
9
+ SubmitCancelAllOrdersTransactionResponse,
6
10
  SubmitPlaceOrderTransactionResponse,
7
11
  )
8
12
  from deltadefi.utils import check_required_parameter, check_required_parameters
@@ -66,7 +70,10 @@ class Order(API):
66
70
  }
67
71
 
68
72
  url_path = "/build"
69
- return self.send_request("POST", self.group_url_path + url_path, payload)
73
+ return cast(
74
+ "BuildPlaceOrderTransactionResponse",
75
+ self.send_request("POST", self.group_url_path + url_path, payload),
76
+ )
70
77
 
71
78
  def build_cancel_order_transaction(
72
79
  self, order_id: str, **kwargs
@@ -84,7 +91,26 @@ class Order(API):
84
91
  check_required_parameter(order_id, "order_id")
85
92
 
86
93
  url_path = f"/{order_id}/build"
87
- return self.send_request("DELETE", self.group_url_path + url_path, **kwargs)
94
+ return cast(
95
+ "BuildCancelOrderTransactionResponse",
96
+ self.send_request("DELETE", self.group_url_path + url_path, **kwargs),
97
+ )
98
+
99
+ def build_cancel_all_orders_transaction(
100
+ self, **kwargs
101
+ ) -> BuildCancelAllOrdersTransactionResponse:
102
+ """
103
+ Build a cancel all orders transaction.
104
+
105
+ Returns:
106
+ A BuildCancelAllOrdersTransactionResponse object containing the built cancel all orders transaction.
107
+ """
108
+
109
+ url_path = "/cancel-all/build"
110
+ return cast(
111
+ "BuildCancelAllOrdersTransactionResponse",
112
+ self.send_request("DELETE", self.group_url_path + url_path, **kwargs),
113
+ )
88
114
 
89
115
  def submit_place_order_transaction(
90
116
  self, order_id: str, signed_tx: str, **kwargs
@@ -93,7 +119,8 @@ class Order(API):
93
119
  Submit a place order transaction.
94
120
 
95
121
  Args:
96
- data: A SubmitPlaceOrderTransactionRequest object containing the order details.
122
+ order_id: The ID of the order to be placed.
123
+ signed_tx: The signed transaction hex string for placing the order.
97
124
 
98
125
  Returns:
99
126
  A SubmitPlaceOrderTransactionResponse object containing the submitted order transaction.
@@ -102,17 +129,38 @@ class Order(API):
102
129
  payload = {"order_id": order_id, "signed_tx": signed_tx, **kwargs}
103
130
 
104
131
  url_path = "/submit"
105
- return self.send_request("POST", self.group_url_path + url_path, payload)
132
+ return cast(
133
+ "SubmitPlaceOrderTransactionResponse",
134
+ self.send_request("POST", self.group_url_path + url_path, payload),
135
+ )
106
136
 
107
137
  def submit_cancel_order_transaction(self, signed_tx: str, **kwargs):
108
138
  """
109
139
  Submit a cancel order transaction.
110
140
 
111
141
  Args:
112
- data: A SubmitCancelOrderTransactionRequest object containing the cancel order details.
142
+ signed_tx: The signed transaction hex string for canceling the order.
113
143
  """
114
144
  check_required_parameter(signed_tx, "signed_tx")
115
145
  payload = {"signed_tx": signed_tx, **kwargs}
116
146
 
117
147
  path_url = "/submit"
118
148
  return self.send_request("DELETE", self.group_url_path + path_url, payload)
149
+
150
+ def submit_cancel_all_orders_transaction(
151
+ self, signed_txs: list[str], **kwargs
152
+ ) -> SubmitCancelAllOrdersTransactionResponse:
153
+ """
154
+ Submit a cancel all orders transaction.
155
+
156
+ Args:
157
+ signed_txs: A list of signed transaction hex strings for canceling all orders.
158
+ """
159
+ check_required_parameter(signed_txs, "signed_txs")
160
+ payload = {"signed_txs": signed_txs, **kwargs}
161
+
162
+ path_url = "/cancel-all/submit"
163
+ return cast(
164
+ "SubmitCancelAllOrdersTransactionResponse",
165
+ self.send_request("DELETE", self.group_url_path + path_url, payload),
166
+ )
@@ -47,7 +47,7 @@ class WebSocketClient:
47
47
  self.ping_interval = ping_interval
48
48
  self.ping_timeout = ping_timeout
49
49
 
50
- self.websocket: websockets.WebSocketServerProtocol | None = None
50
+ self.websocket: websockets.WebSocketClientProtocol | None = None
51
51
  self.subscriptions: dict[str, dict[str, Any]] = {}
52
52
  self.message_handlers: dict[str, Callable] = {}
53
53
  self.is_connected = False
@@ -119,10 +119,14 @@ class WebSocketClient:
119
119
  except Exception as e:
120
120
  self.logger.error(f"Error in message listener: {e}")
121
121
 
122
- async def _handle_message(self, message: str) -> None:
122
+ async def _handle_message(self, message: str | bytes) -> None:
123
123
  """Handle incoming WebSocket message."""
124
124
  try:
125
- data = json.loads(message)
125
+ # Convert bytes to string if needed
126
+ message_str = (
127
+ message.decode("utf-8") if isinstance(message, bytes) else message
128
+ )
129
+ data = json.loads(message_str)
126
130
 
127
131
  # Determine message type based on structure
128
132
  if isinstance(data, list) and len(data) > 0 and "timestamp" in data[0]:
@@ -171,7 +175,10 @@ class WebSocketClient:
171
175
  self.logger.debug(f"Unknown message format: {data}")
172
176
 
173
177
  except json.JSONDecodeError:
174
- self.logger.error(f"Failed to parse message: {message}")
178
+ message_repr = (
179
+ message.decode("utf-8") if isinstance(message, bytes) else message
180
+ )
181
+ self.logger.error(f"Failed to parse message: {message_repr}")
175
182
  except Exception as e:
176
183
  self.logger.error(f"Error handling message: {e}")
177
184
 
@@ -187,10 +194,8 @@ class WebSocketClient:
187
194
  # In a more complex implementation, you'd want to handle multiple concurrent subscriptions
188
195
  if self.subscriptions:
189
196
  first_sub = next(iter(self.subscriptions.values()))
190
- if first_sub.get("type") == "trade":
191
- await self.connect(first_sub["endpoint"])
192
- else:
193
- await self.connect()
197
+ # Always use the stored endpoint for reconnection
198
+ await self.connect(first_sub["endpoint"])
194
199
  else:
195
200
  await self.connect()
196
201
 
@@ -61,3 +61,13 @@ class PostOrderResponse(SubmitPlaceOrderTransactionResponse):
61
61
  @dataclass
62
62
  class BuildCancelOrderTransactionResponse(TypedDict):
63
63
  tx_hex: str
64
+
65
+
66
+ @dataclass
67
+ class BuildCancelAllOrdersTransactionResponse(TypedDict):
68
+ tx_hexes: list[str]
69
+
70
+
71
+ @dataclass
72
+ class SubmitCancelAllOrdersTransactionResponse(TypedDict):
73
+ cancelled_order_ids: list[str]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deltadefi
3
- Version: 0.1.1
3
+ Version: 1.0.0
4
4
  Summary: Python SDK for DeltaDeFi protocol.
5
5
  Author-email: HinsonSIDAN <wongkahinhinson@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -5,20 +5,20 @@ deltadefi/api_resources/__init__.py,sha256=_SGHTpaQTIBvh9Rm868IT5pXpvvGBPqz3bxkY
5
5
  deltadefi/api_resources/auth.py,sha256=4QCEI4P4UlQPQYctqY9Oat4hn7lsI95QihHTD_0PZKg,245
6
6
  deltadefi/api_resources/validation.py,sha256=vz-hovpLy9SMOIFGcBHC8vWZH8CJRlQP8rcbbTSM-PM,1375
7
7
  deltadefi/clients/__init__.py,sha256=4hyPuk6_bcJGXUElOvkgZ7ARlQ6QwKLp-nFgCXTbFVI,76
8
- deltadefi/clients/accounts.py,sha256=sfdPh8CWsein1UAn8h-Y0JB_zMvr95FZx2QuaL6Tico,8407
9
- deltadefi/clients/client.py,sha256=2hLOsxqBc8eu_6ovuYLRoK2popdI1_t3pGcEP8Keu9A,4619
10
- deltadefi/clients/markets.py,sha256=--wMUFYkZryZjj8wO-rxxJhHEbM3UmcPpubrHU92Bdk,1985
11
- deltadefi/clients/orders.py,sha256=AX6RZfLZFUonjKDPYc1T4wbxVomQeES1mzfJHSjhI-M,3886
12
- deltadefi/clients/websocket.py,sha256=0454RunoE9eHqmQ0wrywEwxqrie1qEXq2ObxyKXopck,12424
8
+ deltadefi/clients/accounts.py,sha256=BR5o8DZ7EmN958UzQbFl7knZyIq1gQXM7PEJVg5snoc,9393
9
+ deltadefi/clients/client.py,sha256=n6NzSk8OYbZ6mTo-TWCyVyNbGR2UAqszFfr8D3AF9Kg,5266
10
+ deltadefi/clients/markets.py,sha256=3S1zmP27AnRYeGFZMu-UncRxUJnrGGibJaBsf6O1l_8,2161
11
+ deltadefi/clients/orders.py,sha256=tonrB6pj0TEFFKRvb66FcIAL4aENzlK7RGWSY0_Gpig,5443
12
+ deltadefi/clients/websocket.py,sha256=eWWoYuhNJc-GI-Tn94HZsb5E9EbOb7ndWJOyXfYr5Ho,12686
13
13
  deltadefi/constants/__init__.py,sha256=7LkrzfLTJsCCUl5IgZYrl-AbY_cf1fftcLklgnBYDTs,40
14
14
  deltadefi/constants/constants.py,sha256=4bkY4kfNcsgoCe1xU8n2We7w-vxZXyzVw5rQvAsx4j8,168
15
15
  deltadefi/models/__init__.py,sha256=oDJj6Y4gXN6C7Oz_t2fq8hej-D0G9OqfXjL4Jaeq8z8,37
16
16
  deltadefi/models/models.py,sha256=kiRpCdzUh3WmyuFOaxlZ1rjsQ2cxLWjVFBCqsHXMtBc,1633
17
17
  deltadefi/responses/__init__.py,sha256=JKSIUQu6qI_XhbAR2mVMCKNvR6x_vFZdyLGOuQTVrVY,64
18
18
  deltadefi/responses/accounts.py,sha256=o-It4vyNsiDeCmHa-XQl77KuCVtJi7qlPdn059fgwcI,1590
19
- deltadefi/responses/responses.py,sha256=Kz5PtDnx_AgKrV7NhZqrSMnS1wPlLbu13J2BKNzN0ME,1012
19
+ deltadefi/responses/responses.py,sha256=BqutIkilVCibcxH_10FwN-dY3p3g9XFDOp9NYPbuLPw,1214
20
20
  deltadefi/utils/__init__.py,sha256=krFwciyC3ArJ1j96b5IOVMqKfiFjnKtgQvYPsw3A-MU,38
21
21
  deltadefi/utils/helpers.py,sha256=S90RpdkKJS-khuwk8B0vhOdTQXuUkutZ0RZLybeF550,1025
22
- deltadefi-0.1.1.dist-info/METADATA,sha256=_Y9ZNj9oM_W99lWEj6HzoBb2uJo3Q6DDWh_sjN0jYGw,3075
23
- deltadefi-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
24
- deltadefi-0.1.1.dist-info/RECORD,,
22
+ deltadefi-1.0.0.dist-info/METADATA,sha256=qfK9tIYw4ASRuzf1e1AoU_yTb_qJu8nX7L5vqC9bjE8,3075
23
+ deltadefi-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
24
+ deltadefi-1.0.0.dist-info/RECORD,,