Skip to content

Commit a56bd48

Browse files
committed
feat: update api
1 parent 1c8d23a commit a56bd48

File tree

10 files changed

+57
-27
lines changed

10 files changed

+57
-27
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ The Market client allows you to interact with market-related endpoints.
5151

5252
```python
5353
# Get market depth
54-
market_depth = api.market.get_depth("ADAUSDX")
54+
market_depth = api.market.get_depth("ADAUSDM")
5555
print(market_depth_response)
5656

5757
# Get market price
58-
market_price_response = api.market.get_market_price("ADAUSDX")
58+
market_price_response = api.market.get_market_price("ADAUSDM")
5959
print(market_price_response)
6060
```
6161

@@ -66,7 +66,7 @@ The Order client allows you to interact with order-related endpoints.
6666
```python
6767
# Build place order transaction
6868
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")
7070
print(place_order_response)
7171

7272
# Submit place order transaction

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "deltadefi"
3-
version = "0.0.9"
3+
version = "0.0.10"
44
classifiers = [
55
"Intended Audience :: Developers",
66
"License :: OSI Approved :: Apache Software License",

src/deltadefi/clients/accounts.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#
2-
from typing import List
2+
from typing import List, Literal
33

44
from sidan_gin import Asset, UTxO
55

66
from deltadefi.api import API
77
from deltadefi.lib.utils import check_required_parameter, check_required_parameters
8+
from deltadefi.models.models import OrderStatusType
89
from deltadefi.responses import (
910
BuildDepositTransactionResponse,
1011
BuildWithdrawalTransactionResponse,
@@ -71,15 +72,26 @@ def get_withdrawal_records(self, **kwargs) -> GetWithdrawalRecordsResponse:
7172
url_path = "/withdrawal-records"
7273
return self.send_request("GET", self.group_url_path + url_path, kwargs)
7374

74-
def get_order_records(self, **kwargs) -> GetOrderRecordResponse:
75+
def get_order_records(
76+
self, status: OrderStatusType, **kwargs
77+
) -> GetOrderRecordResponse:
7578
"""
7679
Get order records.
7780
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+
7887
Returns:
7988
A GetOrderRecordResponse object containing the order records.
8089
"""
90+
check_required_parameter(status, "status")
91+
payload = {"status": status, **kwargs}
92+
8193
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)
8395

8496
def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
8597
"""

src/deltadefi/clients/clients.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ def post_order(
6666
Raises:
6767
ValueError: If the wallet is not initialized.
6868
"""
69-
print(
70-
f"post_order: symbol={symbol}, side={side}, type={type}, quantity={quantity}, kwargs={kwargs}"
71-
)
7269
if not hasattr(self, "wallet") or self.wallet is None:
7370
raise ValueError("Wallet is not initialized")
7471

src/deltadefi/clients/order.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from deltadefi.responses import (
55
BuildCancelOrderTransactionResponse,
66
BuildPlaceOrderTransactionResponse,
7-
SubmitCancelOrderTransactionResponse,
87
SubmitPlaceOrderTransactionResponse,
98
)
109

@@ -105,17 +104,12 @@ def submit_place_order_transaction(
105104
url_path = "/submit"
106105
return self.send_request("POST", self.group_url_path + url_path, payload)
107106

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):
111108
"""
112109
Submit a cancel order transaction.
113110
114111
Args:
115112
data: A SubmitCancelOrderTransactionRequest object containing the cancel order details.
116-
117-
Returns:
118-
A SubmitCancelOrderTransactionResponse object containing the submitted cancel order transaction.
119113
"""
120114
check_required_parameter(signed_tx, "signed_tx")
121115
payload = {"signed_tx": signed_tx, **kwargs}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Literal
22

3-
TradingPair = Literal["ADAUSDX"]
3+
TradingPair = Literal["ADAUSDM"]
44
TradingSide = Literal["buy", "sell"]
55
TradingType = Literal["limit", "market"]
66
TimeInForce = Literal["GTC"]

src/deltadefi/models/models.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from dataclasses import dataclass
22
from typing import List, Literal
33

4-
from sidan_gin import Asset
4+
OrderStatusType = Literal["openOrder", "orderHistory", "tradingHistory"]
55

6-
OrderStatus = Literal["building", "open", "closed", "failed"]
6+
OrderStatus = Literal[
7+
"open", "fully_filled", "partially_filled", "cancelled", "partially_cancelled"
8+
]
79

810
OrderSide = Literal["buy", "sell"]
911

@@ -20,6 +22,13 @@
2022
}
2123

2224

25+
@dataclass
26+
class AssetRecord:
27+
asset: str
28+
asset_unit: str
29+
qty: float
30+
31+
2332
@dataclass
2433
class TransactionStatus:
2534
building = "building"
@@ -50,19 +59,34 @@ class OrderJSON:
5059
class DepositRecord:
5160
created_at: str
5261
status: TransactionStatus
53-
assets: List[Asset]
62+
assets: List[AssetRecord]
5463
tx_hash: str
5564

5665

5766
@dataclass
5867
class WithdrawalRecord:
5968
created_at: str
6069
status: TransactionStatus
61-
assets: List[Asset]
70+
assets: List[AssetRecord]
6271

6372

6473
@dataclass
6574
class AssetBalance:
6675
asset: str
6776
free: int
6877
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

src/deltadefi/responses/accounts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from deltadefi.models.models import (
55
AssetBalance,
66
DepositRecord,
7+
OrderFillingRecordJSON,
78
OrderJSON,
89
WithdrawalRecord,
910
)
@@ -43,6 +44,7 @@ class GetWithdrawalRecordsResponse(List[WithdrawalRecord]):
4344
@dataclass
4445
class GetOrderRecordResponse(TypedDict):
4546
orders: List[OrderJSON]
47+
order_filling_records: List[OrderFillingRecordJSON]
4648

4749

4850
@dataclass

src/deltadefi/responses/responses.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,3 @@ class PostOrderResponse(SubmitPlaceOrderTransactionResponse):
6161
@dataclass
6262
class BuildCancelOrderTransactionResponse(TypedDict):
6363
tx_hex: str
64-
65-
66-
@dataclass
67-
class SubmitCancelOrderTransactionResponse(TypedDict):
68-
tx_hash: str

tests/clients/test_accounts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def test_get_account_balance(self):
2929
response: GetAccountBalanceResponse = self.api.accounts.get_account_balance()
3030
print(f"response: {response}")
3131

32+
def test_get_order_records(self):
33+
response: GetAccountBalanceResponse = self.api.accounts.get_order_records(
34+
"openOrder"
35+
)
36+
print(f"response: {response}")
37+
3238
# # Assert
3339
# print(f"response: {response}")
3440
# self.assertIn("token", response)

0 commit comments

Comments
 (0)