Skip to content

Commit 953ff9d

Browse files
authored
Merge pull request #2 from deltadefi-protocol/doc
add doc
2 parents 3aaf437 + bdba9d0 commit 953ff9d

File tree

6 files changed

+321
-1
lines changed

6 files changed

+321
-1
lines changed

README.md

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,108 @@
1-
# python-sdk
1+
# DeltaDeFi Python SDK
2+
3+
The DeltaDeFi Python SDK provides a convenient way to interact with the DeltaDeFi API. This SDK allows developers to easily integrate DeltaDeFi's features into their Python applications.
4+
5+
## Installation
6+
7+
To install the SDK, use `pip`:
8+
9+
```sh
10+
pip install deltadefi-python-sdk
11+
```
12+
13+
## Requirements
14+
15+
- Python 3.11 or higher
16+
17+
## Usage
18+
19+
### Initialization
20+
21+
To use the SDK, you need to initialize the ApiClient with your API configuration and wallet.
22+
23+
```python
24+
from deltadefi.api_resources.api_config import ApiConfig
25+
from deltadefi.clients.clients import ApiClient
26+
from sidan_gin import HDWallet
27+
28+
# Initialize API configuration
29+
config = ApiConfig(
30+
network="mainnet",
31+
jwt="your_jwt_token",
32+
apiKey="your_api_key",
33+
signingKey="your_signing_key"
34+
)
35+
36+
# Initialize HDWallet
37+
wallet = HDWallet("your_wallet_mnemonic")
38+
39+
# Initialize ApiClient
40+
api_client = ApiClient(config=config, wallet=wallet)
41+
```
42+
43+
### Accounts
44+
45+
The Accounts client allows you to interact with account-related endpoints.
46+
47+
```python
48+
from deltadefi.clients.accounts import Accounts
49+
50+
accounts_client = api_client.accounts
51+
52+
# Sign in
53+
sign_in_request = SignInRequest(auth_key="your_auth_key", wallet_address="your_wallet_address")
54+
sign_in_response = accounts_client.sign_in(sign_in_request)
55+
print(sign_in_response)
56+
57+
# Get account balance
58+
account_balance = accounts_client.get_account_balance()
59+
print(account_balance)
60+
```
61+
62+
### Markets
63+
64+
The Markets client allows you to interact with market-related endpoints.
65+
66+
```python
67+
from deltadefi.clients.markets import Markets
68+
69+
markets_client = api_client.markets
70+
71+
# Get market depth
72+
market_depth_request = GetMarketDepthRequest(pair="BTC/USD")
73+
market_depth_response = markets_client.getDepth(market_depth_request)
74+
print(market_depth_response)
75+
76+
# Get market price
77+
market_price_request = GetMarketPriceRequest(pair="BTC/USD")
78+
market_price_response = markets_client.getMarketPrice(market_price_request)
79+
print(market_price_response)
80+
```
81+
82+
### Orders
83+
84+
The Orders client allows you to interact with order-related endpoints.
85+
86+
```python
87+
from deltadefi.clients.orders import Orders
88+
89+
orders_client = api_client.orders
90+
91+
# Build place order transaction
92+
place_order_request = BuildPlaceOrderTransactionRequest(pair="BTC/USD", amount=1, price=50000)
93+
place_order_response = orders_client.build_place_order_transaction(place_order_request)
94+
print(place_order_response)
95+
96+
# Submit place order transaction
97+
submit_order_request = SubmitPlaceOrderTransactionRequest(order_id="order_id")
98+
submit_order_response = orders_client.submit_place_order_transaction(submit_order_request)
99+
print(submit_order_response)
100+
```
101+
102+
## License
103+
104+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
105+
106+
```
107+
http://www.apache.org/licenses/LICENSE-2.0
108+
```

src/deltadefi/clients/accounts.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,29 @@
2323

2424

2525
class Accounts:
26+
"""
27+
Accounts client for interacting with the DeltaDeFi API.
28+
"""
29+
2630
def __init__(self, api_client):
31+
"""
32+
Initialize the Accounts client.
33+
34+
Args:
35+
api_client: An instance of the ApiClient.
36+
"""
2737
self.api_client = api_client
2838

2939
def sign_in(self, data: SignInRequest) -> SignInResponse:
40+
"""
41+
Sign in to the DeltaDeFi API.
42+
43+
Args:
44+
data: A SignInRequest object containing the authentication key and wallet address.
45+
46+
Returns:
47+
A SignInResponse object containing the sign-in response.
48+
"""
3049
auth_key = data["auth_key"]
3150
wallet_address = data["wallet_address"]
3251
headers = {
@@ -42,6 +61,12 @@ def sign_in(self, data: SignInRequest) -> SignInResponse:
4261
return response.json()
4362

4463
def createNewApiKey(self) -> CreateNewAPIKeyResponse:
64+
"""
65+
Create a new API key.
66+
67+
Returns:
68+
A CreateNewAPIKeyResponse object containing the new API key.
69+
"""
4570
response = requests.get(
4671
f"{self.api_client.base_url}/accounts/new-api-key",
4772
headers=self.api_client.headers,
@@ -50,6 +75,12 @@ def createNewApiKey(self) -> CreateNewAPIKeyResponse:
5075
return response.json()
5176

5277
def getDepositRecords(self) -> GetDepositRecordsResponse:
78+
"""
79+
Get deposit records.
80+
81+
Returns:
82+
A GetDepositRecordsResponse object containing the deposit records.
83+
"""
5384
response = requests.get(
5485
f"{self.api_client.base_url}/accounts/deposit-records",
5586
headers=self.api_client.headers,
@@ -58,6 +89,12 @@ def getDepositRecords(self) -> GetDepositRecordsResponse:
5889
return response.json()
5990

6091
def getWithdrawalRecords(self) -> GetWithdrawalRecordsResponse:
92+
"""
93+
Get withdrawal records.
94+
95+
Returns:
96+
A GetWithdrawalRecordsResponse object containing the withdrawal records.
97+
"""
6198
response = requests.get(
6299
f"{self.api_client.base_url}/accounts/withdrawal-records",
63100
headers=self.api_client.headers,
@@ -66,6 +103,12 @@ def getWithdrawalRecords(self) -> GetWithdrawalRecordsResponse:
66103
return response.json()
67104

68105
def getOrderRecords(self) -> GetOrderRecordResponse:
106+
"""
107+
Get order records.
108+
109+
Returns:
110+
A GetOrderRecordResponse object containing the order records.
111+
"""
69112
response = requests.get(
70113
f"{self.api_client.base_url}/accounts/order-records",
71114
headers=self.api_client.headers,
@@ -74,6 +117,12 @@ def getOrderRecords(self) -> GetOrderRecordResponse:
74117
return response.json()
75118

76119
def getAccountBalance(self) -> GetAccountBalanceResponse:
120+
"""
121+
Get account balance.
122+
123+
Returns:
124+
A GetAccountBalanceResponse object containing the account balance.
125+
"""
77126
response = requests.get(
78127
f"{self.api_client.base_url}/accounts/balance",
79128
headers=self.api_client.headers,
@@ -84,6 +133,15 @@ def getAccountBalance(self) -> GetAccountBalanceResponse:
84133
def buildDepositTransaction(
85134
self, data: BuildDepositTransactionRequest
86135
) -> BuildDepositTransactionResponse:
136+
"""
137+
Build a deposit transaction.
138+
139+
Args:
140+
data: A BuildDepositTransactionRequest object containing the deposit transaction details.
141+
142+
Returns:
143+
A BuildDepositTransactionResponse object containing the built deposit transaction.
144+
"""
87145
response = requests.post(
88146
f"{self.api_client.base_url}/accounts/deposit/build",
89147
json=data,
@@ -95,6 +153,15 @@ def buildDepositTransaction(
95153
def buildWithdrawalTransaction(
96154
self, data: BuildWithdrawalTransactionRequest
97155
) -> BuildWithdrawalTransactionResponse:
156+
"""
157+
Build a withdrawal transaction.
158+
159+
Args:
160+
data: A BuildWithdrawalTransactionRequest object containing the withdrawal transaction details.
161+
162+
Returns:
163+
A BuildWithdrawalTransactionResponse object containing the built withdrawal transaction.
164+
"""
98165
response = requests.post(
99166
f"{self.api_client.base_url}/accounts/withdrawal/build",
100167
json=data,
@@ -106,6 +173,15 @@ def buildWithdrawalTransaction(
106173
def submitDepositTransaction(
107174
self, data: SubmitDepositTransactionRequest
108175
) -> SubmitDepositTransactionResponse:
176+
"""
177+
Submit a deposit transaction.
178+
179+
Args:
180+
data: A SubmitDepositTransactionRequest object containing the deposit transaction details.
181+
182+
Returns:
183+
A SubmitDepositTransactionResponse object containing the submitted deposit transaction.
184+
"""
109185
response = requests.post(
110186
f"{self.api_client.base_url}/accounts/deposit/submit",
111187
json=data,
@@ -117,6 +193,15 @@ def submitDepositTransaction(
117193
def submitWithdrawalTransaction(
118194
self, data: SubmitWithdrawalTransactionRequest
119195
) -> SubmitWithdrawalTransactionResponse:
196+
"""
197+
Submit a withdrawal transaction.
198+
199+
Args:
200+
data: A SubmitWithdrawalTransactionRequest object containing the withdrawal transaction details.
201+
202+
Returns:
203+
A SubmitWithdrawalTransactionResponse object containing the submitted withdrawal transaction.
204+
"""
120205
response = requests.post(
121206
f"{self.api_client.base_url}/accounts/withdrawal/submit",
122207
json=data,
@@ -126,6 +211,12 @@ def submitWithdrawalTransaction(
126211
return response.json()
127212

128213
def getTermsAndCondition(self) -> GetTermsAndConditionResponse:
214+
"""
215+
Get terms and conditions.
216+
217+
Returns:
218+
A GetTermsAndConditionResponse object containing the terms and conditions.
219+
"""
129220
response = requests.get(
130221
f"{self.api_client.base_url}/accounts/terms-and-condition",
131222
headers=self.api_client.headers,

src/deltadefi/clients/app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44

55

66
class App:
7+
"""
8+
App client for interacting with the DeltaDeFi API.
9+
"""
10+
711
def __init__(self, api_client):
12+
"""
13+
Initialize the App client.
14+
15+
Args:
16+
api_client: An instance of the ApiClient.
17+
"""
818
self.api_client = api_client
919

1020
def getTermsAndCondition(self) -> GetTermsAndConditionResponse:
21+
"""
22+
Get terms and conditions.
23+
24+
Returns:
25+
A GetTermsAndConditionResponse object containing the terms and conditions.
26+
"""
1127
response = requests.get(
1228
f"{self.api_client.base_url}/terms-and-conditions",
1329
headers=self.api_client.headers,

src/deltadefi/clients/clients.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@
1313

1414

1515
class ApiClient:
16+
"""
17+
ApiClient for interacting with the DeltaDeFi API.
18+
"""
1619

1720
def __init__(
1821
self,
1922
config: ApiConfig,
2023
wallet: HDWallet,
2124
base_url: Optional[str] = None,
2225
):
26+
"""
27+
Initialize the ApiClient.
28+
29+
Args:
30+
config: An instance of ApiConfig containing the API configuration.
31+
wallet: An instance of HDWallet for signing transactions.
32+
base_url: Optional; The base URL for the API. Defaults to "https://api-dev.deltadefi.io".
33+
"""
2334
self.base_url = base_url or "https://api-dev.deltadefi.io"
2435
headers: ApiHeaders = {
2536
"Content-Type": "application/json",
@@ -44,6 +55,18 @@ def __init__(
4455
self.markets = Markets(self)
4556

4657
async def post_order(self, data: PostOrderRequest) -> PostOrderResponse:
58+
"""
59+
Post an order to the DeltaDeFi API.
60+
61+
Args:
62+
data: A PostOrderRequest object containing the order details.
63+
64+
Returns:
65+
A PostOrderResponse object containing the response from the API.
66+
67+
Raises:
68+
ValueError: If the wallet is not initialized.
69+
"""
4770
if not hasattr(self, "wallet") or self.wallet is None:
4871
raise ValueError("Wallet is not initialized")
4972

0 commit comments

Comments
 (0)