deltadefi 0.0.8__tar.gz → 0.0.10__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 (26) hide show
  1. {deltadefi-0.0.8 → deltadefi-0.0.10}/PKG-INFO +4 -4
  2. {deltadefi-0.0.8 → deltadefi-0.0.10}/README.md +3 -3
  3. {deltadefi-0.0.8 → deltadefi-0.0.10}/pyproject.toml +1 -1
  4. deltadefi-0.0.10/src/deltadefi/clients/__init__.py +2 -0
  5. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/clients/accounts.py +14 -2
  6. deltadefi-0.0.10/src/deltadefi/clients/client.py +110 -0
  7. deltadefi-0.0.8/src/deltadefi/clients/order.py → deltadefi-0.0.10/src/deltadefi/clients/orders.py +1 -7
  8. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/constants/constants.py +1 -1
  9. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/models/models.py +28 -4
  10. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/responses/accounts.py +2 -0
  11. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/responses/responses.py +0 -5
  12. deltadefi-0.0.8/src/deltadefi/clients/__init__.py +0 -2
  13. deltadefi-0.0.8/src/deltadefi/clients/clients.py +0 -84
  14. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/__init__.py +0 -0
  15. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/api.py +0 -0
  16. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/api_resources/__init__.py +0 -0
  17. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/api_resources/auth.py +0 -0
  18. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/api_resources/validation.py +0 -0
  19. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/clients/app.py +0 -0
  20. /deltadefi-0.0.8/src/deltadefi/clients/market.py → /deltadefi-0.0.10/src/deltadefi/clients/markets.py +0 -0
  21. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/constants/__init__.py +0 -0
  22. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/error.py +0 -0
  23. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/lib/__init__.py +0 -0
  24. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/lib/utils.py +0 -0
  25. {deltadefi-0.0.8 → deltadefi-0.0.10}/src/deltadefi/models/__init__.py +0 -0
  26. {deltadefi-0.0.8 → deltadefi-0.0.10}/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.8
3
+ Version: 0.0.10
4
4
  Summary: Python SDK for DeltaDeFi protocol.
5
5
  License: Apache-2.0
6
6
  Keywords: cardano
@@ -79,11 +79,11 @@ The Market client allows you to interact with market-related endpoints.
79
79
 
80
80
  ```python
81
81
  # Get market depth
82
- market_depth = api.market.get_depth("ADAUSDX")
82
+ market_depth = api.market.get_depth("ADAUSDM")
83
83
  print(market_depth_response)
84
84
 
85
85
  # Get market price
86
- market_price_response = api.market.get_market_price("ADAUSDX")
86
+ market_price_response = api.market.get_market_price("ADAUSDM")
87
87
  print(market_price_response)
88
88
  ```
89
89
 
@@ -94,7 +94,7 @@ The Order client allows you to interact with order-related endpoints.
94
94
  ```python
95
95
  # Build place order transaction
96
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")
97
+ place_order_response = api.order.build_place_order_transaction(symbol="ADAUSDM", amount=50, price=0.75, type="limit")
98
98
  print(place_order_response)
99
99
 
100
100
  # Submit place order transaction
@@ -51,11 +51,11 @@ The Market client allows you to interact with market-related endpoints.
51
51
 
52
52
  ```python
53
53
  # Get market depth
54
- market_depth = api.market.get_depth("ADAUSDX")
54
+ market_depth = api.market.get_depth("ADAUSDM")
55
55
  print(market_depth_response)
56
56
 
57
57
  # Get market price
58
- market_price_response = api.market.get_market_price("ADAUSDX")
58
+ market_price_response = api.market.get_market_price("ADAUSDM")
59
59
  print(market_price_response)
60
60
  ```
61
61
 
@@ -66,7 +66,7 @@ The Order client allows you to interact with order-related endpoints.
66
66
  ```python
67
67
  # Build place order transaction
68
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")
69
+ place_order_response = api.order.build_place_order_transaction(symbol="ADAUSDM", amount=50, price=0.75, type="limit")
70
70
  print(place_order_response)
71
71
 
72
72
  # Submit place order transaction
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "deltadefi"
3
- version = "0.0.8"
3
+ version = "0.0.10"
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,
@@ -71,15 +72,26 @@ class Accounts(API):
71
72
  url_path = "/withdrawal-records"
72
73
  return self.send_request("GET", self.group_url_path + url_path, kwargs)
73
74
 
74
- def get_order_records(self, **kwargs) -> GetOrderRecordResponse:
75
+ def get_order_records(
76
+ self, status: OrderStatusType, **kwargs
77
+ ) -> GetOrderRecordResponse:
75
78
  """
76
79
  Get order records.
77
80
 
81
+ Args:
82
+ status: The status of the order records to retrieve. It can be "openOrder",
83
+ "orderHistory", or "tradingHistory".
84
+ limit: Optional; The maximum number of records to return. Defaults to 10, max 250.
85
+ page: Optional; The page number for pagination. Defaults to 1.
86
+
78
87
  Returns:
79
88
  A GetOrderRecordResponse object containing the order records.
80
89
  """
90
+ check_required_parameter(status, "status")
91
+ payload = {"status": status, **kwargs}
92
+
81
93
  url_path = "/order-records"
82
- return self.send_request("GET", self.group_url_path + url_path, kwargs)
94
+ return self.send_request("GET", self.group_url_path + url_path, payload)
83
95
 
84
96
  def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
85
97
  """
@@ -0,0 +1,110 @@
1
+ # flake8: noqa: E501
2
+ from sidan_gin import Wallet, decrypt_with_cipher
3
+
4
+ from deltadefi.clients.accounts import Accounts
5
+ from deltadefi.clients.app import App
6
+ from deltadefi.clients.markets import Market
7
+ from deltadefi.clients.orders import Order
8
+ from deltadefi.models.models import OrderSide, OrderType
9
+ from deltadefi.responses import PostOrderResponse
10
+
11
+
12
+ class ApiClient:
13
+ """
14
+ ApiClient for interacting with the DeltaDeFi API.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ network: str = "preprod",
20
+ api_key: str = None,
21
+ base_url: str = None,
22
+ master_wallet: Wallet = None,
23
+ ):
24
+ """
25
+ Initialize the ApiClient.
26
+
27
+ Args:
28
+ config: An instance of ApiConfig containing the API configuration.
29
+ wallet: An instance of Wallet for signing transactions.
30
+ base_url: Optional; The base URL for the API. Defaults to "https://api-dev.deltadefi.io".
31
+ """
32
+ if network == "mainnet":
33
+ self.network_id = 1
34
+ self.base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
35
+ else:
36
+ self.network_id = 0
37
+ self.base_url = "https://api-staging.deltadefi.io"
38
+
39
+ if base_url:
40
+ self.base_url = base_url
41
+
42
+ self.api_key = api_key
43
+ self.master_wallet = master_wallet
44
+
45
+ self.accounts = Accounts(base_url=self.base_url, api_key=api_key)
46
+ self.app = App(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)
63
+
64
+ def post_order(
65
+ self, symbol: str, side: OrderSide, type: OrderType, quantity: int, **kwargs
66
+ ) -> PostOrderResponse:
67
+ """
68
+ Post an order to the DeltaDeFi API. It includes building the transaction, signing it with the wallet, and submitting it.
69
+
70
+ Args:
71
+ symbol: The trading pair symbol (e.g., "BTC-USD").
72
+ side: The side of the order (e.g., "buy" or "sell").
73
+ type: The type of the order (e.g., "limit" or "market").
74
+ quantity: The quantity of the asset to be traded.
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.
78
+
79
+ Returns:
80
+ A PostOrderResponse object containing the response from the API.
81
+
82
+ Raises:
83
+ ValueError: If the wallet is not initialized.
84
+ """
85
+ if not hasattr(self, "operation_wallet") or self.operation_wallet is None:
86
+ raise ValueError("Operation wallet is not initialized")
87
+
88
+ build_res = self.orders.build_place_order_transaction(
89
+ symbol, side, type, quantity, **kwargs
90
+ )
91
+ signed_tx = self.operation_wallet.sign_tx(build_res["tx_hex"])
92
+ submit_res = self.orders.submit_place_order_transaction(
93
+ build_res["order_id"], signed_tx, **kwargs
94
+ )
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
@@ -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 *
@@ -1,84 +0,0 @@
1
- # flake8: noqa: E501
2
- from sidan_gin import Wallet
3
-
4
- from deltadefi.clients.accounts import Accounts
5
- from deltadefi.clients.app import App
6
- from deltadefi.clients.market import Market
7
- from deltadefi.clients.order import Order
8
- from deltadefi.models.models import OrderSide, OrderType
9
- from deltadefi.responses import PostOrderResponse
10
-
11
-
12
- class ApiClient:
13
- """
14
- ApiClient for interacting with the DeltaDeFi API.
15
- """
16
-
17
- def __init__(
18
- self,
19
- network: str = "preprod",
20
- api_key: str = None,
21
- wallet: Wallet = None,
22
- base_url: str = None,
23
- ):
24
- """
25
- Initialize the ApiClient.
26
-
27
- Args:
28
- config: An instance of ApiConfig containing the API configuration.
29
- wallet: An instance of Wallet for signing transactions.
30
- base_url: Optional; The base URL for the API. Defaults to "https://api-dev.deltadefi.io".
31
- """
32
- if network == "mainnet":
33
- self.network_id = 1
34
- self.base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
35
- else:
36
- self.network_id = 0
37
- self.base_url = "https://api-staging.deltadefi.io"
38
-
39
- if base_url:
40
- self.base_url = base_url
41
-
42
- self.api_key = api_key
43
- self.wallet = wallet
44
-
45
- self.accounts = Accounts(base_url=base_url, api_key=api_key)
46
- self.app = App(base_url=base_url, api_key=api_key)
47
- self.order = Order(base_url=base_url, api_key=api_key)
48
- self.market = Market(base_url=base_url, api_key=api_key)
49
-
50
- def post_order(
51
- self, symbol: str, side: OrderSide, type: OrderType, quantity: int, **kwargs
52
- ) -> PostOrderResponse:
53
- """
54
- Post an order to the DeltaDeFi API. It includes building the transaction, signing it with the wallet, and submitting it.
55
-
56
- Args:
57
- symbol: The trading pair symbol (e.g., "BTC-USD").
58
- side: The side of the order (e.g., "buy" or "sell").
59
- type: The type of the order (e.g., "limit" or "market").
60
- quantity: The quantity of the asset to be traded.
61
- **kwargs: Additional parameters for the order, such as price, limit_slippage, etc.
62
-
63
- Returns:
64
- A PostOrderResponse object containing the response from the API.
65
-
66
- Raises:
67
- ValueError: If the wallet is not initialized.
68
- """
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")
74
-
75
- build_res = self.order.build_place_order_transaction(
76
- symbol, side, type, quantity, **kwargs
77
- )
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(
81
- build_res["order_id"], signed_tx, **kwargs
82
- )
83
- print(f"submit_res: {submit_res}")
84
- return submit_res