11# flake8: noqa: E501
2- from sidan_gin import HDWallet
2+ from sidan_gin import Wallet
33
44from deltadefi .clients .accounts import Accounts
55from deltadefi .clients .app import App
66from deltadefi .clients .market import Market
77from deltadefi .clients .order import Order
8+ from deltadefi .models .models import OrderSide , OrderType
89from deltadefi .responses import PostOrderResponse
910
1011
@@ -17,15 +18,15 @@ def __init__(
1718 self ,
1819 network : str = "preprod" ,
1920 api_key : str = None ,
20- wallet : HDWallet = None ,
21+ wallet : Wallet = None ,
2122 base_url : str = None ,
2223 ):
2324 """
2425 Initialize the ApiClient.
2526
2627 Args:
2728 config: An instance of ApiConfig containing the API configuration.
28- wallet: An instance of HDWallet for signing transactions.
29+ wallet: An instance of Wallet for signing transactions.
2930 base_url: Optional; The base URL for the API. Defaults to "https://api-dev.deltadefi.io".
3031 """
3132 if network == "mainnet" :
@@ -46,23 +47,38 @@ def __init__(
4647 self .order = Order (base_url = base_url , api_key = api_key )
4748 self .market = Market (base_url = base_url , api_key = api_key )
4849
49- async def post_order (self , ** kwargs ) -> PostOrderResponse :
50+ def post_order (
51+ self , symbol : str , side : OrderSide , type : OrderType , quantity : int , ** kwargs
52+ ) -> PostOrderResponse :
5053 """
51- Post an order to the DeltaDeFi API.
54+ Post an order to the DeltaDeFi API. It includes building the transaction, signing it with the wallet, and submitting it.
5255
5356 Args:
54- data: A PostOrderRequest object containing the order details.
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.
5562
5663 Returns:
5764 A PostOrderResponse object containing the response from the API.
5865
5966 Raises:
6067 ValueError: If the wallet is not initialized.
6168 """
69+ print (
70+ f"post_order: symbol={ symbol } , side={ side } , type={ type } , quantity={ quantity } , kwargs={ kwargs } "
71+ )
6272 if not hasattr (self , "wallet" ) or self .wallet is None :
6373 raise ValueError ("Wallet is not initialized" )
6474
65- build_res = "" # TODO: import wallet build order
75+ build_res = self .order .build_place_order_transaction (
76+ symbol , side , type , quantity , ** kwargs
77+ )
78+ print (f"build_res: { build_res } " )
6679 signed_tx = self .wallet .sign_tx (build_res ["tx_hex" ])
67- submit_res = signed_tx + "" # TODO: import wallet submit tx
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 } " )
6884 return submit_res
0 commit comments