deltadefi 0.1.3__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,3 +1,5 @@
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 (
@@ -68,7 +70,10 @@ class Order(API):
68
70
  }
69
71
 
70
72
  url_path = "/build"
71
- 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
+ )
72
77
 
73
78
  def build_cancel_order_transaction(
74
79
  self, order_id: str, **kwargs
@@ -86,7 +91,10 @@ class Order(API):
86
91
  check_required_parameter(order_id, "order_id")
87
92
 
88
93
  url_path = f"/{order_id}/build"
89
- 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
+ )
90
98
 
91
99
  def build_cancel_all_orders_transaction(
92
100
  self, **kwargs
@@ -99,7 +107,10 @@ class Order(API):
99
107
  """
100
108
 
101
109
  url_path = "/cancel-all/build"
102
- return self.send_request("DELETE", self.group_url_path + url_path, **kwargs)
110
+ return cast(
111
+ "BuildCancelAllOrdersTransactionResponse",
112
+ self.send_request("DELETE", self.group_url_path + url_path, **kwargs),
113
+ )
103
114
 
104
115
  def submit_place_order_transaction(
105
116
  self, order_id: str, signed_tx: str, **kwargs
@@ -118,7 +129,10 @@ class Order(API):
118
129
  payload = {"order_id": order_id, "signed_tx": signed_tx, **kwargs}
119
130
 
120
131
  url_path = "/submit"
121
- 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
+ )
122
136
 
123
137
  def submit_cancel_order_transaction(self, signed_tx: str, **kwargs):
124
138
  """
@@ -146,4 +160,7 @@ class Order(API):
146
160
  payload = {"signed_txs": signed_txs, **kwargs}
147
161
 
148
162
  path_url = "/cancel-all/submit"
149
- return self.send_request("DELETE", self.group_url_path + path_url, payload)
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deltadefi
3
- Version: 0.1.3
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,11 +5,11 @@ 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=-VZppN4dJitzRkkNCWy9PWLdwGUpnYBNhugaUZIr1PU,5010
12
- deltadefi/clients/websocket.py,sha256=o6BEd_KVPmSLpMhAC7j98ACqJuMYPxjcLt57EXzoeqw,12370
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
@@ -19,6 +19,6 @@ deltadefi/responses/accounts.py,sha256=o-It4vyNsiDeCmHa-XQl77KuCVtJi7qlPdn059fgw
19
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.3.dist-info/METADATA,sha256=Z9x_HjX5QSutdHYw5AIvIlTW3LoNMpciyPbAzEHxXY4,3075
23
- deltadefi-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
24
- deltadefi-0.1.3.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,,