deltadefi 0.0.9__tar.gz → 0.0.11__tar.gz

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.

Files changed (25) hide show
  1. {deltadefi-0.0.9 → deltadefi-0.0.11}/PKG-INFO +21 -17
  2. {deltadefi-0.0.9 → deltadefi-0.0.11}/README.md +20 -16
  3. {deltadefi-0.0.9 → deltadefi-0.0.11}/pyproject.toml +1 -1
  4. deltadefi-0.0.11/src/deltadefi/clients/__init__.py +2 -0
  5. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/clients/accounts.py +63 -3
  6. deltadefi-0.0.9/src/deltadefi/clients/clients.py → deltadefi-0.0.11/src/deltadefi/clients/client.py +44 -18
  7. deltadefi-0.0.9/src/deltadefi/clients/order.py → deltadefi-0.0.11/src/deltadefi/clients/orders.py +1 -7
  8. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/constants/constants.py +1 -1
  9. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/models/models.py +28 -4
  10. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/responses/accounts.py +12 -0
  11. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/responses/responses.py +0 -5
  12. deltadefi-0.0.9/src/deltadefi/clients/__init__.py +0 -2
  13. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/__init__.py +0 -0
  14. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/api.py +0 -0
  15. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/api_resources/__init__.py +0 -0
  16. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/api_resources/auth.py +0 -0
  17. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/api_resources/validation.py +0 -0
  18. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/clients/app.py +0 -0
  19. /deltadefi-0.0.9/src/deltadefi/clients/market.py → /deltadefi-0.0.11/src/deltadefi/clients/markets.py +0 -0
  20. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/constants/__init__.py +0 -0
  21. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/error.py +0 -0
  22. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/lib/__init__.py +0 -0
  23. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/lib/utils.py +0 -0
  24. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/models/__init__.py +0 -0
  25. {deltadefi-0.0.9 → deltadefi-0.0.11}/src/deltadefi/responses/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: deltadefi
3
- Version: 0.0.9
3
+ Version: 0.0.11
4
4
  Summary: Python SDK for DeltaDeFi protocol.
5
5
  License: Apache-2.0
6
6
  Keywords: cardano
@@ -56,11 +56,8 @@ from sidan_gin import HDWallet
56
56
  network="preprod",
57
57
  api_key="your_api_key",
58
58
 
59
- # Initialize HDWallet
60
- wallet = HDWallet("your_wallet_mnemonic")
61
-
62
59
  # Initialize ApiClient
63
- api = ApiClient(network=network, api_key=api_key, wallet=wallet)
60
+ api = ApiClient(network=network, api_key=api_key)
64
61
  ```
65
62
 
66
63
  ### Accounts
@@ -73,33 +70,40 @@ account_balance = api.accounts.get_account_balance()
73
70
  print(account_balance)
74
71
  ```
75
72
 
76
- ### Market
73
+ ### Markets
77
74
 
78
75
  The Market client allows you to interact with market-related endpoints.
79
76
 
80
77
  ```python
81
78
  # Get market depth
82
- market_depth = api.market.get_depth("ADAUSDX")
79
+ market_depth = api.markets.get_depth("ADAUSDM")
83
80
  print(market_depth_response)
84
81
 
85
82
  # Get market price
86
- market_price_response = api.market.get_market_price("ADAUSDX")
83
+ market_price_response = api.markets.get_market_price("ADAUSDM")
87
84
  print(market_price_response)
88
85
  ```
89
86
 
90
- ### Order
87
+ ### Orders
91
88
 
92
89
  The Order client allows you to interact with order-related endpoints.
93
90
 
94
91
  ```python
95
- # Build place order transaction
96
- place_order_request = BuildPlaceOrderTransactionRequest(pair="BTC/USD", amount=1, price=50000)
97
- place_order_response = api.order.build_place_order_transaction(symbol="ADAUSDX", amount=50, price=0.75, type="limit")
98
- print(place_order_response)
99
-
100
- # Submit place order transaction
101
- submit_order_response = api.order.submit_place_order_transaction(signed_tx="<signed_tx>", order_id="<order_id>")
102
- print(submit_order_response)
92
+ api_key = os.environ.get("DELTADEFI_API_KEY")
93
+ password = os.environ.get("TRADING_PASSWORD")
94
+
95
+ api = ApiClient(api_key=api_key)
96
+ api.load_operation_key(password)
97
+
98
+ res = api.post_order(
99
+ symbol="ADAUSDM",
100
+ side="sell",
101
+ type="limit",
102
+ quantity=51,
103
+ price=15,
104
+ )
105
+
106
+ print("Order submitted successfully.", res)
103
107
  ```
104
108
 
105
109
  ## Development
@@ -28,11 +28,8 @@ from sidan_gin import HDWallet
28
28
  network="preprod",
29
29
  api_key="your_api_key",
30
30
 
31
- # Initialize HDWallet
32
- wallet = HDWallet("your_wallet_mnemonic")
33
-
34
31
  # Initialize ApiClient
35
- api = ApiClient(network=network, api_key=api_key, wallet=wallet)
32
+ api = ApiClient(network=network, api_key=api_key)
36
33
  ```
37
34
 
38
35
  ### Accounts
@@ -45,33 +42,40 @@ account_balance = api.accounts.get_account_balance()
45
42
  print(account_balance)
46
43
  ```
47
44
 
48
- ### Market
45
+ ### Markets
49
46
 
50
47
  The Market client allows you to interact with market-related endpoints.
51
48
 
52
49
  ```python
53
50
  # Get market depth
54
- market_depth = api.market.get_depth("ADAUSDX")
51
+ market_depth = api.markets.get_depth("ADAUSDM")
55
52
  print(market_depth_response)
56
53
 
57
54
  # Get market price
58
- market_price_response = api.market.get_market_price("ADAUSDX")
55
+ market_price_response = api.markets.get_market_price("ADAUSDM")
59
56
  print(market_price_response)
60
57
  ```
61
58
 
62
- ### Order
59
+ ### Orders
63
60
 
64
61
  The Order client allows you to interact with order-related endpoints.
65
62
 
66
63
  ```python
67
- # Build place order transaction
68
- place_order_request = BuildPlaceOrderTransactionRequest(pair="BTC/USD", amount=1, price=50000)
69
- place_order_response = api.order.build_place_order_transaction(symbol="ADAUSDX", amount=50, price=0.75, type="limit")
70
- print(place_order_response)
71
-
72
- # Submit place order transaction
73
- submit_order_response = api.order.submit_place_order_transaction(signed_tx="<signed_tx>", order_id="<order_id>")
74
- print(submit_order_response)
64
+ api_key = os.environ.get("DELTADEFI_API_KEY")
65
+ password = os.environ.get("TRADING_PASSWORD")
66
+
67
+ api = ApiClient(api_key=api_key)
68
+ api.load_operation_key(password)
69
+
70
+ res = api.post_order(
71
+ symbol="ADAUSDM",
72
+ side="sell",
73
+ type="limit",
74
+ quantity=51,
75
+ price=15,
76
+ )
77
+
78
+ print("Order submitted successfully.", res)
75
79
  ```
76
80
 
77
81
  ## Development
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "deltadefi"
3
- version = "0.0.9"
3
+ version = "0.0.11"
4
4
  classifiers = [
5
5
  "Intended Audience :: Developers",
6
6
  "License :: OSI Approved :: Apache Software License",
@@ -0,0 +1,2 @@
1
+ # flake8: noqa
2
+ from .client import *
@@ -5,6 +5,7 @@ from sidan_gin import Asset, UTxO
5
5
 
6
6
  from deltadefi.api import API
7
7
  from deltadefi.lib.utils import check_required_parameter, check_required_parameters
8
+ from deltadefi.models.models import OrderStatusType
8
9
  from deltadefi.responses import (
9
10
  BuildDepositTransactionResponse,
10
11
  BuildWithdrawalTransactionResponse,
@@ -16,7 +17,11 @@ from deltadefi.responses import (
16
17
  SubmitDepositTransactionResponse,
17
18
  SubmitWithdrawalTransactionResponse,
18
19
  )
19
- from deltadefi.responses.accounts import GetOperationKeyResponse
20
+ from deltadefi.responses.accounts import (
21
+ BuildTransferalTransactionResponse,
22
+ GetOperationKeyResponse,
23
+ SubmitTransferalTransactionResponse,
24
+ )
20
25
 
21
26
 
22
27
  class Accounts(API):
@@ -71,15 +76,26 @@ class Accounts(API):
71
76
  url_path = "/withdrawal-records"
72
77
  return self.send_request("GET", self.group_url_path + url_path, kwargs)
73
78
 
74
- def get_order_records(self, **kwargs) -> GetOrderRecordResponse:
79
+ def get_order_records(
80
+ self, status: OrderStatusType, **kwargs
81
+ ) -> GetOrderRecordResponse:
75
82
  """
76
83
  Get order records.
77
84
 
85
+ Args:
86
+ status: The status of the order records to retrieve. It can be "openOrder",
87
+ "orderHistory", or "tradingHistory".
88
+ limit: Optional; The maximum number of records to return. Defaults to 10, max 250.
89
+ page: Optional; The page number for pagination. Defaults to 1.
90
+
78
91
  Returns:
79
92
  A GetOrderRecordResponse object containing the order records.
80
93
  """
94
+ check_required_parameter(status, "status")
95
+ payload = {"status": status, **kwargs}
96
+
81
97
  url_path = "/order-records"
82
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
98
+ return self.send_request("GET", self.group_url_path + url_path, payload)
83
99
 
84
100
  def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
85
101
  """
@@ -135,6 +151,31 @@ class Accounts(API):
135
151
  url_path = "/withdrawal/build"
136
152
  return self.send_request("POST", self.group_url_path + url_path, payload)
137
153
 
154
+ def build_transferal_transaction(
155
+ self, transferal_amount: List[Asset], to_address: str, **kwargs
156
+ ) -> BuildTransferalTransactionResponse:
157
+ """
158
+ Build a transferal transaction.
159
+
160
+ Args:
161
+ data: A BuildTransferalTransactionRequest object containing the transferal transaction details.
162
+
163
+ Returns:
164
+ A BuildTransferalTransactionResponse object containing the built transferal transaction.
165
+ """
166
+
167
+ check_required_parameter(
168
+ transferal_amount, "transferal_amount", to_address, "to_address"
169
+ )
170
+ payload = {
171
+ "transferal_amount": transferal_amount,
172
+ "to_address": to_address,
173
+ **kwargs,
174
+ }
175
+
176
+ url_path = "/transferal/build"
177
+ return self.send_request("POST", self.group_url_path + url_path, payload)
178
+
138
179
  def submit_deposit_transaction(
139
180
  self, signed_tx: str, **kwargs
140
181
  ) -> SubmitDepositTransactionResponse:
@@ -172,3 +213,22 @@ class Accounts(API):
172
213
 
173
214
  url_path = "/withdrawal/submit"
174
215
  return self.send_request("POST", self.group_url_path + url_path, payload)
216
+
217
+ def submit_transferal_transaction(
218
+ self, signed_tx: str, **kwargs
219
+ ) -> SubmitTransferalTransactionResponse:
220
+ """
221
+ Submit a transferal transaction.
222
+
223
+ Args:
224
+ data: A SubmitTransferalTransactionRequest object containing the transferal transaction details.
225
+
226
+ Returns:
227
+ A SubmitTransferalTransactionResponse object containing the submitted transferal transaction.
228
+ """
229
+
230
+ check_required_parameter(signed_tx, "signed_tx")
231
+ payload = {"signed_tx": signed_tx, **kwargs}
232
+
233
+ url_path = "/transferal/submit"
234
+ return self.send_request("POST", self.group_url_path + url_path, payload)
@@ -1,10 +1,10 @@
1
1
  # flake8: noqa: E501
2
- from sidan_gin import Wallet
2
+ from sidan_gin import Wallet, decrypt_with_cipher
3
3
 
4
4
  from deltadefi.clients.accounts import Accounts
5
5
  from deltadefi.clients.app import App
6
- from deltadefi.clients.market import Market
7
- from deltadefi.clients.order import Order
6
+ from deltadefi.clients.markets import Market
7
+ from deltadefi.clients.orders import Order
8
8
  from deltadefi.models.models import OrderSide, OrderType
9
9
  from deltadefi.responses import PostOrderResponse
10
10
 
@@ -18,8 +18,8 @@ class ApiClient:
18
18
  self,
19
19
  network: str = "preprod",
20
20
  api_key: str = None,
21
- wallet: Wallet = None,
22
21
  base_url: str = None,
22
+ master_wallet: Wallet = None,
23
23
  ):
24
24
  """
25
25
  Initialize the ApiClient.
@@ -40,12 +40,26 @@ class ApiClient:
40
40
  self.base_url = base_url
41
41
 
42
42
  self.api_key = api_key
43
- self.wallet = wallet
43
+ self.master_wallet = master_wallet
44
44
 
45
45
  self.accounts = Accounts(base_url=self.base_url, api_key=api_key)
46
46
  self.app = App(base_url=self.base_url, api_key=api_key)
47
- self.order = Order(base_url=self.base_url, api_key=api_key)
48
- self.market = Market(base_url=self.base_url, api_key=api_key)
47
+ self.orders = Order(base_url=self.base_url, api_key=api_key)
48
+ self.markets = Market(base_url=self.base_url, api_key=api_key)
49
+
50
+ def load_operation_key(self, password: str):
51
+ """
52
+ Load the operation key from the wallet using the provided password.
53
+
54
+ Args:
55
+ password: The password to decrypt the operation key.
56
+
57
+ Returns:
58
+ The decrypted operation key.
59
+ """
60
+ res = self.accounts.get_operation_key()
61
+ operation_key = decrypt_with_cipher(res["encrypted_operation_key"], password)
62
+ self.operation_wallet = Wallet.new_root_key(operation_key)
49
63
 
50
64
  def post_order(
51
65
  self, symbol: str, side: OrderSide, type: OrderType, quantity: int, **kwargs
@@ -58,7 +72,9 @@ class ApiClient:
58
72
  side: The side of the order (e.g., "buy" or "sell").
59
73
  type: The type of the order (e.g., "limit" or "market").
60
74
  quantity: The quantity of the asset to be traded.
61
- **kwargs: Additional parameters for the order, such as price, limit_slippage, etc.
75
+ price: Required for limit order; The price for limit orders.
76
+ limit_slippage: Optional; Whether to apply slippage for market orders. Defaults to False.
77
+ max_slippage_basis_point: Optional; The maximum slippage in basis points for market orders. Defaults to null.
62
78
 
63
79
  Returns:
64
80
  A PostOrderResponse object containing the response from the API.
@@ -66,19 +82,29 @@ class ApiClient:
66
82
  Raises:
67
83
  ValueError: If the wallet is not initialized.
68
84
  """
69
- print(
70
- f"post_order: symbol={symbol}, side={side}, type={type}, quantity={quantity}, kwargs={kwargs}"
71
- )
72
- if not hasattr(self, "wallet") or self.wallet is None:
73
- raise ValueError("Wallet is not initialized")
85
+ if not hasattr(self, "operation_wallet") or self.operation_wallet is None:
86
+ raise ValueError("Operation wallet is not initialized")
74
87
 
75
- build_res = self.order.build_place_order_transaction(
88
+ build_res = self.orders.build_place_order_transaction(
76
89
  symbol, side, type, quantity, **kwargs
77
90
  )
78
- print(f"build_res: {build_res}")
79
- signed_tx = self.wallet.sign_tx(build_res["tx_hex"])
80
- submit_res = self.order.submit_place_order_transaction(
91
+ signed_tx = self.operation_wallet.sign_tx(build_res["tx_hex"])
92
+ submit_res = self.orders.submit_place_order_transaction(
81
93
  build_res["order_id"], signed_tx, **kwargs
82
94
  )
83
- print(f"submit_res: {submit_res}")
84
95
  return submit_res
96
+
97
+ def cancel_order(self, order_id: str, **kwargs):
98
+ """
99
+ Cancel an order by its ID.
100
+
101
+ Args:
102
+ order_id: The ID of the order to be canceled.
103
+ """
104
+ if not hasattr(self, "operation_wallet") or self.operation_wallet is None:
105
+ raise ValueError("Operation wallet is not initialized")
106
+
107
+ build_res = self.orders.build_cancel_order_transaction(order_id)
108
+ signed_tx = self.operation_wallet.sign_tx(build_res["tx_hex"])
109
+ self.orders.submit_cancel_order_transaction(signed_tx, **kwargs)
110
+ return {"message": "Order cancelled successfully", "order_id": order_id}
@@ -4,7 +4,6 @@ from deltadefi.models.models import OrderSide, OrderType
4
4
  from deltadefi.responses import (
5
5
  BuildCancelOrderTransactionResponse,
6
6
  BuildPlaceOrderTransactionResponse,
7
- SubmitCancelOrderTransactionResponse,
8
7
  SubmitPlaceOrderTransactionResponse,
9
8
  )
10
9
 
@@ -105,17 +104,12 @@ class Order(API):
105
104
  url_path = "/submit"
106
105
  return self.send_request("POST", self.group_url_path + url_path, payload)
107
106
 
108
- def submit_cancel_order_transaction(
109
- self, signed_tx: str, **kwargs
110
- ) -> SubmitCancelOrderTransactionResponse:
107
+ def submit_cancel_order_transaction(self, signed_tx: str, **kwargs):
111
108
  """
112
109
  Submit a cancel order transaction.
113
110
 
114
111
  Args:
115
112
  data: A SubmitCancelOrderTransactionRequest object containing the cancel order details.
116
-
117
- Returns:
118
- A SubmitCancelOrderTransactionResponse object containing the submitted cancel order transaction.
119
113
  """
120
114
  check_required_parameter(signed_tx, "signed_tx")
121
115
  payload = {"signed_tx": signed_tx, **kwargs}
@@ -1,6 +1,6 @@
1
1
  from typing import Literal
2
2
 
3
- TradingPair = Literal["ADAUSDX"]
3
+ TradingPair = Literal["ADAUSDM"]
4
4
  TradingSide = Literal["buy", "sell"]
5
5
  TradingType = Literal["limit", "market"]
6
6
  TimeInForce = Literal["GTC"]
@@ -1,9 +1,11 @@
1
1
  from dataclasses import dataclass
2
2
  from typing import List, Literal
3
3
 
4
- from sidan_gin import Asset
4
+ OrderStatusType = Literal["openOrder", "orderHistory", "tradingHistory"]
5
5
 
6
- OrderStatus = Literal["building", "open", "closed", "failed"]
6
+ OrderStatus = Literal[
7
+ "open", "fully_filled", "partially_filled", "cancelled", "partially_cancelled"
8
+ ]
7
9
 
8
10
  OrderSide = Literal["buy", "sell"]
9
11
 
@@ -20,6 +22,13 @@ OrderTypes = {
20
22
  }
21
23
 
22
24
 
25
+ @dataclass
26
+ class AssetRecord:
27
+ asset: str
28
+ asset_unit: str
29
+ qty: float
30
+
31
+
23
32
  @dataclass
24
33
  class TransactionStatus:
25
34
  building = "building"
@@ -50,7 +59,7 @@ class OrderJSON:
50
59
  class DepositRecord:
51
60
  created_at: str
52
61
  status: TransactionStatus
53
- assets: List[Asset]
62
+ assets: List[AssetRecord]
54
63
  tx_hash: str
55
64
 
56
65
 
@@ -58,7 +67,7 @@ class DepositRecord:
58
67
  class WithdrawalRecord:
59
68
  created_at: str
60
69
  status: TransactionStatus
61
- assets: List[Asset]
70
+ assets: List[AssetRecord]
62
71
 
63
72
 
64
73
  @dataclass
@@ -66,3 +75,18 @@ class AssetBalance:
66
75
  asset: str
67
76
  free: int
68
77
  locked: int
78
+
79
+
80
+ @dataclass
81
+ class OrderFillingRecordJSON:
82
+ execution_id: str
83
+ order_id: str
84
+ status: OrderStatus
85
+ symbol: str
86
+ executed_qty: str
87
+ side: OrderSide
88
+ type: OrderType
89
+ fee_charged: str
90
+ fee_unit: str
91
+ executed_price: float
92
+ created_time: int
@@ -4,6 +4,7 @@ from typing import List, TypedDict
4
4
  from deltadefi.models.models import (
5
5
  AssetBalance,
6
6
  DepositRecord,
7
+ OrderFillingRecordJSON,
7
8
  OrderJSON,
8
9
  WithdrawalRecord,
9
10
  )
@@ -43,6 +44,7 @@ class GetWithdrawalRecordsResponse(List[WithdrawalRecord]):
43
44
  @dataclass
44
45
  class GetOrderRecordResponse(TypedDict):
45
46
  orders: List[OrderJSON]
47
+ order_filling_records: List[OrderFillingRecordJSON]
46
48
 
47
49
 
48
50
  @dataclass
@@ -50,11 +52,21 @@ class BuildWithdrawalTransactionResponse(TypedDict):
50
52
  tx_hex: str
51
53
 
52
54
 
55
+ @dataclass
56
+ class BuildTransferalTransactionResponse(TypedDict):
57
+ tx_hex: str
58
+
59
+
53
60
  @dataclass
54
61
  class SubmitWithdrawalTransactionResponse(TypedDict):
55
62
  tx_hash: str
56
63
 
57
64
 
65
+ @dataclass
66
+ class SubmitTransferalTransactionResponse(TypedDict):
67
+ tx_hash: str
68
+
69
+
58
70
  @dataclass
59
71
  class GetAccountInfoResponse(TypedDict):
60
72
  api_key: str
@@ -61,8 +61,3 @@ class PostOrderResponse(SubmitPlaceOrderTransactionResponse):
61
61
  @dataclass
62
62
  class BuildCancelOrderTransactionResponse(TypedDict):
63
63
  tx_hex: str
64
-
65
-
66
- @dataclass
67
- class SubmitCancelOrderTransactionResponse(TypedDict):
68
- tx_hash: str
@@ -1,2 +0,0 @@
1
- # flake8: noqa
2
- from .clients import *