Skip to content

Commit 5212220

Browse files
committed
chore: fix types
1 parent 9fbbfb9 commit 5212220

File tree

7 files changed

+151
-47
lines changed

7 files changed

+151
-47
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "deltadefi"
3-
version = "0.1.3"
3+
version = "1.0.0"
44
description = "Python SDK for DeltaDeFi protocol."
55
readme = "README.md"
66
requires-python = ">3.11,<4.0.0"
@@ -44,6 +44,7 @@ dev = [
4444
"twine>=5.0.0",
4545
"build>=1.3.0",
4646
"pre-commit>=4.3.0",
47+
"types-requests>=2.32.4.20250913",
4748
]
4849

4950
docs = [

src/deltadefi/clients/accounts.py

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#
2+
from typing import cast
23

34
from sidan_gin import Asset, UTxO
45

@@ -43,7 +44,10 @@ def get_operation_key(self, **kwargs) -> GetOperationKeyResponse:
4344
"""
4445

4546
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+
)
4751

4852
def create_new_api_key(self, **kwargs) -> CreateNewAPIKeyResponse:
4953
"""
@@ -54,7 +58,10 @@ def create_new_api_key(self, **kwargs) -> CreateNewAPIKeyResponse:
5458
"""
5559

5660
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+
)
5865

5966
def get_deposit_records(self, **kwargs) -> GetDepositRecordsResponse:
6067
"""
@@ -64,7 +71,10 @@ def get_deposit_records(self, **kwargs) -> GetDepositRecordsResponse:
6471
A GetDepositRecordsResponse object containing the deposit records.
6572
"""
6673
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+
)
6878

6979
def get_withdrawal_records(self, **kwargs) -> GetWithdrawalRecordsResponse:
7080
"""
@@ -74,7 +84,10 @@ def get_withdrawal_records(self, **kwargs) -> GetWithdrawalRecordsResponse:
7484
A GetWithdrawalRecordsResponse object containing the withdrawal records.
7585
"""
7686
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+
)
7891

7992
def get_order_records(
8093
self, status: OrderStatusType, **kwargs
@@ -95,7 +108,10 @@ def get_order_records(
95108
payload = {"status": status, **kwargs}
96109

97110
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+
)
99115

100116
def get_order_record(self, order_id: str, **kwargs) -> GetOrderRecordResponse:
101117
"""
@@ -110,7 +126,10 @@ def get_order_record(self, order_id: str, **kwargs) -> GetOrderRecordResponse:
110126
check_required_parameter(order_id, "order_id")
111127

112128
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+
)
114133

115134
def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
116135
"""
@@ -120,7 +139,10 @@ def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
120139
A GetAccountBalanceResponse object containing the account balance.
121140
"""
122141
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+
)
124146

125147
def build_deposit_transaction(
126148
self, deposit_amount: list[Asset], input_utxos: list[UTxO], **kwargs
@@ -145,7 +167,10 @@ def build_deposit_transaction(
145167
}
146168

147169
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+
)
149174

150175
def build_withdrawal_transaction(
151176
self, withdrawal_amount: list[Asset], **kwargs
@@ -164,7 +189,10 @@ def build_withdrawal_transaction(
164189
payload = {"withdrawal_amount": withdrawal_amount, **kwargs}
165190

166191
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+
)
168196

169197
def build_transferal_transaction(
170198
self, transferal_amount: list[Asset], to_address: str, **kwargs
@@ -179,8 +207,8 @@ def build_transferal_transaction(
179207
A BuildTransferalTransactionResponse object containing the built transferal transaction.
180208
"""
181209

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"]]
184212
)
185213
payload = {
186214
"transferal_amount": transferal_amount,
@@ -189,7 +217,10 @@ def build_transferal_transaction(
189217
}
190218

191219
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+
)
193224

194225
def submit_deposit_transaction(
195226
self, signed_tx: str, **kwargs
@@ -208,7 +239,10 @@ def submit_deposit_transaction(
208239
payload = {"signed_tx": signed_tx, **kwargs}
209240

210241
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+
)
212246

213247
def submit_withdrawal_transaction(
214248
self, signed_tx: str, **kwargs
@@ -227,7 +261,10 @@ def submit_withdrawal_transaction(
227261
payload = {"signed_tx": signed_tx, **kwargs}
228262

229263
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+
)
231268

232269
def submit_transferal_transaction(
233270
self, signed_tx: str, **kwargs
@@ -246,4 +283,7 @@ def submit_transferal_transaction(
246283
payload = {"signed_tx": signed_tx, **kwargs}
247284

248285
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+
)

src/deltadefi/clients/client.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(
1818
network: str = "preprod",
1919
api_key: str | None = None,
2020
base_url: str | None = None,
21+
ws_url: str | None = None,
2122
master_wallet: Wallet | None = None,
2223
):
2324
"""
@@ -30,30 +31,26 @@ def __init__(
3031
"""
3132
if network == "mainnet":
3233
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"
3436
else:
3537
self.network_id = 0
3638
self.base_url = "https://api-staging.deltadefi.io"
39+
self.ws_url = "wss://stream-staging.deltadefi.io"
3740

3841
if base_url:
3942
self.base_url = base_url
4043

44+
if ws_url:
45+
self.ws_url = ws_url
46+
4147
self.api_key = api_key
4248
self.master_wallet = master_wallet
4349

4450
self.accounts = Accounts(base_url=self.base_url, api_key=api_key)
4551
self.orders = Order(base_url=self.base_url, api_key=api_key)
4652
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)
5754

5855
def load_operation_key(self, password: str):
5956
"""
@@ -116,3 +113,25 @@ def cancel_order(self, order_id: str, **kwargs):
116113
signed_tx = self.operation_wallet.sign_tx(build_res["tx_hex"])
117114
self.orders.submit_cancel_order_transaction(signed_tx, **kwargs)
118115
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+
}

src/deltadefi/clients/markets.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal
1+
from typing import Literal, cast
22

33
from deltadefi.api import API
44
from deltadefi.responses import GetAggregatedPriceResponse, GetMarketPriceResponse
@@ -28,7 +28,10 @@ def get_market_price(self, symbol: str, **kwargs) -> GetMarketPriceResponse:
2828
check_required_parameter(symbol, "symbol")
2929
payload = {"symbol": symbol, **kwargs}
3030
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+
)
3235

3336
def get_aggregated_price(
3437
self,
@@ -56,12 +59,15 @@ def get_aggregated_price(
5659
]
5760
)
5861
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+
),
6773
)

src/deltadefi/clients/orders.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import cast
2+
13
from deltadefi.api import API
24
from deltadefi.models.models import OrderSide, OrderType
35
from deltadefi.responses import (
@@ -68,7 +70,10 @@ def build_place_order_transaction(
6870
}
6971

7072
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+
)
7277

7378
def build_cancel_order_transaction(
7479
self, order_id: str, **kwargs
@@ -86,7 +91,10 @@ def build_cancel_order_transaction(
8691
check_required_parameter(order_id, "order_id")
8792

8893
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+
)
9098

9199
def build_cancel_all_orders_transaction(
92100
self, **kwargs
@@ -99,7 +107,10 @@ def build_cancel_all_orders_transaction(
99107
"""
100108

101109
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+
)
103114

104115
def submit_place_order_transaction(
105116
self, order_id: str, signed_tx: str, **kwargs
@@ -118,7 +129,10 @@ def submit_place_order_transaction(
118129
payload = {"order_id": order_id, "signed_tx": signed_tx, **kwargs}
119130

120131
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+
)
122136

123137
def submit_cancel_order_transaction(self, signed_tx: str, **kwargs):
124138
"""
@@ -146,4 +160,7 @@ def submit_cancel_all_orders_transaction(
146160
payload = {"signed_txs": signed_txs, **kwargs}
147161

148162
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+
)

0 commit comments

Comments
 (0)