deltadefi 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
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.
- deltadefi/api.py +77 -0
- deltadefi/clients/__init__.py +0 -4
- deltadefi/clients/accounts.py +62 -125
- deltadefi/clients/app.py +8 -17
- deltadefi/clients/clients.py +10 -20
- deltadefi/clients/markets.py +43 -35
- deltadefi/clients/order.py +122 -0
- deltadefi/error.py +57 -58
- deltadefi/lib/__init__.py +0 -0
- deltadefi/lib/utils.py +46 -0
- deltadefi/models/models.py +1 -3
- deltadefi/responses/accounts.py +0 -6
- {deltadefi-0.0.1.dist-info → deltadefi-0.0.2.dist-info}/METADATA +13 -38
- deltadefi-0.0.2.dist-info/RECORD +24 -0
- deltadefi/clients/orders.py +0 -107
- deltadefi/requests/__init__.py +0 -3
- deltadefi/requests/accounts.py +0 -31
- deltadefi/requests/requests.py +0 -67
- deltadefi-0.0.1.dist-info/RECORD +0 -24
- {deltadefi-0.0.1.dist-info → deltadefi-0.0.2.dist-info}/WHEEL +0 -0
deltadefi/api.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from deltadefi.error import ClientError, ServerError
|
|
6
|
+
from deltadefi.lib.utils import clean_none_value, encoded_string
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class API(object):
|
|
10
|
+
def __init__(self, base_url=None, api_key=None, timeout=None, **kwargs):
|
|
11
|
+
self.base_url = base_url
|
|
12
|
+
self.api_key = api_key
|
|
13
|
+
self.timeout = timeout
|
|
14
|
+
self.session = requests.Session()
|
|
15
|
+
self.session.headers.update(
|
|
16
|
+
{
|
|
17
|
+
"Content-Type": "application/json;charset=utf-8",
|
|
18
|
+
"X-API-KEY": api_key if api_key is not None else "",
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def send_request(self, http_method, url_path, payload=None):
|
|
23
|
+
if payload is None:
|
|
24
|
+
payload = {}
|
|
25
|
+
url = self.base_url + url_path
|
|
26
|
+
params = clean_none_value(
|
|
27
|
+
{
|
|
28
|
+
"url": url,
|
|
29
|
+
"params": self._prepare_params(payload),
|
|
30
|
+
"timeout": self.timeout,
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
response = self._dispatch_request(http_method)(**params)
|
|
34
|
+
self._handle_exception(response)
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
data = response.json()
|
|
38
|
+
except ValueError:
|
|
39
|
+
data = response.text
|
|
40
|
+
result = {}
|
|
41
|
+
|
|
42
|
+
if len(result) != 0:
|
|
43
|
+
result["data"] = data
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
return data
|
|
47
|
+
|
|
48
|
+
def _dispatch_request(self, http_method):
|
|
49
|
+
return {
|
|
50
|
+
"GET": self.session.get,
|
|
51
|
+
"DELETE": self.session.delete,
|
|
52
|
+
"PUT": self.session.put,
|
|
53
|
+
"POST": self.session.post,
|
|
54
|
+
}.get(http_method, "GET")
|
|
55
|
+
|
|
56
|
+
def _prepare_params(self, params):
|
|
57
|
+
return encoded_string(clean_none_value(params))
|
|
58
|
+
|
|
59
|
+
def _handle_exception(self, response):
|
|
60
|
+
status_code = response.status_code
|
|
61
|
+
if status_code < 400:
|
|
62
|
+
return
|
|
63
|
+
if 400 <= status_code < 500:
|
|
64
|
+
try:
|
|
65
|
+
err = json.loads(response.text)
|
|
66
|
+
except json.JSONDecodeError:
|
|
67
|
+
raise ClientError(
|
|
68
|
+
status_code, None, response.text, response.headers, None
|
|
69
|
+
)
|
|
70
|
+
error_data = None
|
|
71
|
+
if "data" in err:
|
|
72
|
+
error_data = err["data"]
|
|
73
|
+
print("Error?", err)
|
|
74
|
+
raise ClientError(
|
|
75
|
+
status_code, err["code"], err["msg"], response.headers, error_data
|
|
76
|
+
)
|
|
77
|
+
raise ServerError(status_code, response.text)
|
deltadefi/clients/__init__.py
CHANGED
deltadefi/clients/accounts.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
SubmitWithdrawalTransactionRequest,
|
|
9
|
-
)
|
|
1
|
+
#
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from sidan_gin import Asset, UTxO
|
|
5
|
+
|
|
6
|
+
from deltadefi.api import API
|
|
7
|
+
from deltadefi.lib.utils import check_required_parameter, check_required_parameters
|
|
10
8
|
from deltadefi.responses import (
|
|
11
9
|
BuildDepositTransactionResponse,
|
|
12
10
|
BuildWithdrawalTransactionResponse,
|
|
@@ -14,124 +12,75 @@ from deltadefi.responses import (
|
|
|
14
12
|
GetAccountBalanceResponse,
|
|
15
13
|
GetDepositRecordsResponse,
|
|
16
14
|
GetOrderRecordResponse,
|
|
17
|
-
GetTermsAndConditionResponse,
|
|
18
15
|
GetWithdrawalRecordsResponse,
|
|
19
|
-
SignInResponse,
|
|
20
16
|
SubmitDepositTransactionResponse,
|
|
21
17
|
SubmitWithdrawalTransactionResponse,
|
|
22
18
|
)
|
|
23
19
|
|
|
24
20
|
|
|
25
|
-
class Accounts:
|
|
21
|
+
class Accounts(API):
|
|
26
22
|
"""
|
|
27
23
|
Accounts client for interacting with the DeltaDeFi API.
|
|
28
24
|
"""
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
"""
|
|
32
|
-
Initialize the Accounts client.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
api_client: An instance of the ApiClient.
|
|
36
|
-
"""
|
|
37
|
-
self.api_client = api_client
|
|
38
|
-
|
|
39
|
-
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.
|
|
26
|
+
group_url_path = "/accounts"
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"""
|
|
49
|
-
auth_key = data["auth_key"]
|
|
50
|
-
wallet_address = data["wallet_address"]
|
|
51
|
-
headers = {
|
|
52
|
-
"X-API-KEY": auth_key,
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
}
|
|
55
|
-
response = requests.post(
|
|
56
|
-
f"{self.api_client.base_url}/accounts/signin",
|
|
57
|
-
json={"wallet_address": wallet_address},
|
|
58
|
-
headers=headers,
|
|
59
|
-
)
|
|
60
|
-
response.raise_for_status()
|
|
61
|
-
return response.json()
|
|
28
|
+
def __init__(self, api_key=None, base_url=None, **kwargs):
|
|
29
|
+
super().__init__(api_key=api_key, base_url=base_url, **kwargs)
|
|
62
30
|
|
|
63
|
-
def
|
|
31
|
+
def create_new_api_key(self, **kwargs) -> CreateNewAPIKeyResponse:
|
|
64
32
|
"""
|
|
65
33
|
Create a new API key.
|
|
66
34
|
|
|
67
35
|
Returns:
|
|
68
36
|
A CreateNewAPIKeyResponse object containing the new API key.
|
|
69
37
|
"""
|
|
70
|
-
response = requests.get(
|
|
71
|
-
f"{self.api_client.base_url}/accounts/new-api-key",
|
|
72
|
-
headers=self.api_client.headers,
|
|
73
|
-
)
|
|
74
|
-
response.raise_for_status()
|
|
75
|
-
return response.json()
|
|
76
38
|
|
|
77
|
-
|
|
39
|
+
url_path = "/new-api-key"
|
|
40
|
+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
|
|
41
|
+
|
|
42
|
+
def get_deposit_records(self, **kwargs) -> GetDepositRecordsResponse:
|
|
78
43
|
"""
|
|
79
44
|
Get deposit records.
|
|
80
45
|
|
|
81
46
|
Returns:
|
|
82
47
|
A GetDepositRecordsResponse object containing the deposit records.
|
|
83
48
|
"""
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
headers=self.api_client.headers,
|
|
87
|
-
)
|
|
88
|
-
response.raise_for_status()
|
|
89
|
-
return response.json()
|
|
49
|
+
url_path = "/deposit-records"
|
|
50
|
+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
|
|
90
51
|
|
|
91
|
-
def
|
|
52
|
+
def get_withdrawal_records(self, **kwargs) -> GetWithdrawalRecordsResponse:
|
|
92
53
|
"""
|
|
93
54
|
Get withdrawal records.
|
|
94
55
|
|
|
95
56
|
Returns:
|
|
96
57
|
A GetWithdrawalRecordsResponse object containing the withdrawal records.
|
|
97
58
|
"""
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
headers=self.api_client.headers,
|
|
101
|
-
)
|
|
102
|
-
response.raise_for_status()
|
|
103
|
-
return response.json()
|
|
59
|
+
url_path = "/withdrawal-records"
|
|
60
|
+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
|
|
104
61
|
|
|
105
|
-
def
|
|
62
|
+
def get_order_records(self, **kwargs) -> GetOrderRecordResponse:
|
|
106
63
|
"""
|
|
107
64
|
Get order records.
|
|
108
65
|
|
|
109
66
|
Returns:
|
|
110
67
|
A GetOrderRecordResponse object containing the order records.
|
|
111
68
|
"""
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
headers=self.api_client.headers,
|
|
115
|
-
)
|
|
116
|
-
response.raise_for_status()
|
|
117
|
-
return response.json()
|
|
69
|
+
url_path = "/order-records"
|
|
70
|
+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
|
|
118
71
|
|
|
119
|
-
def
|
|
72
|
+
def get_account_balance(self, **kwargs) -> GetAccountBalanceResponse:
|
|
120
73
|
"""
|
|
121
74
|
Get account balance.
|
|
122
75
|
|
|
123
76
|
Returns:
|
|
124
77
|
A GetAccountBalanceResponse object containing the account balance.
|
|
125
78
|
"""
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
headers=self.api_client.headers,
|
|
129
|
-
)
|
|
130
|
-
response.raise_for_status()
|
|
131
|
-
return response.json()
|
|
79
|
+
url_path = "/balance"
|
|
80
|
+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
|
|
132
81
|
|
|
133
|
-
def
|
|
134
|
-
self,
|
|
82
|
+
def build_deposit_transaction(
|
|
83
|
+
self, deposit_amount: List[Asset], input_utxos: List[UTxO], **kwargs
|
|
135
84
|
) -> BuildDepositTransactionResponse:
|
|
136
85
|
"""
|
|
137
86
|
Build a deposit transaction.
|
|
@@ -142,16 +91,21 @@ class Accounts:
|
|
|
142
91
|
Returns:
|
|
143
92
|
A BuildDepositTransactionResponse object containing the built deposit transaction.
|
|
144
93
|
"""
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
headers=self.api_client.headers,
|
|
94
|
+
|
|
95
|
+
check_required_parameters(
|
|
96
|
+
[[deposit_amount, "deposit_amount"], [input_utxos, "input_utxos"]]
|
|
149
97
|
)
|
|
150
|
-
|
|
151
|
-
|
|
98
|
+
payload = {
|
|
99
|
+
"deposit_amount": deposit_amount,
|
|
100
|
+
"input_utxos": input_utxos,
|
|
101
|
+
**kwargs,
|
|
102
|
+
}
|
|
152
103
|
|
|
153
|
-
|
|
154
|
-
self,
|
|
104
|
+
url_path = "/deposit/build"
|
|
105
|
+
return self.send_request("POST", self.group_url_path + url_path, payload)
|
|
106
|
+
|
|
107
|
+
def build_withdrawal_transaction(
|
|
108
|
+
self, withdrawal_amount: List[Asset], **kwargs
|
|
155
109
|
) -> BuildWithdrawalTransactionResponse:
|
|
156
110
|
"""
|
|
157
111
|
Build a withdrawal transaction.
|
|
@@ -162,16 +116,15 @@ class Accounts:
|
|
|
162
116
|
Returns:
|
|
163
117
|
A BuildWithdrawalTransactionResponse object containing the built withdrawal transaction.
|
|
164
118
|
"""
|
|
165
|
-
response = requests.post(
|
|
166
|
-
f"{self.api_client.base_url}/accounts/withdrawal/build",
|
|
167
|
-
json=data,
|
|
168
|
-
headers=self.api_client.headers,
|
|
169
|
-
)
|
|
170
|
-
response.raise_for_status()
|
|
171
|
-
return response.json()
|
|
172
119
|
|
|
173
|
-
|
|
174
|
-
|
|
120
|
+
check_required_parameter(withdrawal_amount, "withdrawal_amount")
|
|
121
|
+
payload = {"withdrawal_amount": withdrawal_amount, **kwargs}
|
|
122
|
+
|
|
123
|
+
url_path = "/withdrawal/build"
|
|
124
|
+
return self.send_request("POST", self.group_url_path + url_path, payload)
|
|
125
|
+
|
|
126
|
+
def submit_deposit_transaction(
|
|
127
|
+
self, signed_tx: str, **kwargs
|
|
175
128
|
) -> SubmitDepositTransactionResponse:
|
|
176
129
|
"""
|
|
177
130
|
Submit a deposit transaction.
|
|
@@ -182,16 +135,15 @@ class Accounts:
|
|
|
182
135
|
Returns:
|
|
183
136
|
A SubmitDepositTransactionResponse object containing the submitted deposit transaction.
|
|
184
137
|
"""
|
|
185
|
-
response = requests.post(
|
|
186
|
-
f"{self.api_client.base_url}/accounts/deposit/submit",
|
|
187
|
-
json=data,
|
|
188
|
-
headers=self.api_client.headers,
|
|
189
|
-
)
|
|
190
|
-
response.raise_for_status()
|
|
191
|
-
return response.json()
|
|
192
138
|
|
|
193
|
-
|
|
194
|
-
|
|
139
|
+
check_required_parameter(signed_tx, "signed_tx")
|
|
140
|
+
payload = {"signed_tx": signed_tx, **kwargs}
|
|
141
|
+
|
|
142
|
+
url_path = "/deposit/submit"
|
|
143
|
+
return self.send_request("POST", self.group_url_path + url_path, payload)
|
|
144
|
+
|
|
145
|
+
def submit_withdrawal_transaction(
|
|
146
|
+
self, signed_tx: str, **kwargs
|
|
195
147
|
) -> SubmitWithdrawalTransactionResponse:
|
|
196
148
|
"""
|
|
197
149
|
Submit a withdrawal transaction.
|
|
@@ -202,24 +154,9 @@ class Accounts:
|
|
|
202
154
|
Returns:
|
|
203
155
|
A SubmitWithdrawalTransactionResponse object containing the submitted withdrawal transaction.
|
|
204
156
|
"""
|
|
205
|
-
response = requests.post(
|
|
206
|
-
f"{self.api_client.base_url}/accounts/withdrawal/submit",
|
|
207
|
-
json=data,
|
|
208
|
-
headers=self.api_client.headers,
|
|
209
|
-
)
|
|
210
|
-
response.raise_for_status()
|
|
211
|
-
return response.json()
|
|
212
157
|
|
|
213
|
-
|
|
214
|
-
""
|
|
215
|
-
Get terms and conditions.
|
|
158
|
+
check_required_parameter(signed_tx, "signed_tx")
|
|
159
|
+
payload = {"signed_tx": signed_tx, **kwargs}
|
|
216
160
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
"""
|
|
220
|
-
response = requests.get(
|
|
221
|
-
f"{self.api_client.base_url}/accounts/terms-and-condition",
|
|
222
|
-
headers=self.api_client.headers,
|
|
223
|
-
)
|
|
224
|
-
response.raise_for_status()
|
|
225
|
-
return response.json()
|
|
161
|
+
url_path = "/withdrawal/submit"
|
|
162
|
+
return self.send_request("POST", self.group_url_path + url_path, payload)
|
deltadefi/clients/app.py
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
from deltadefi.api import API
|
|
3
2
|
from deltadefi.responses import GetTermsAndConditionResponse
|
|
4
3
|
|
|
5
4
|
|
|
6
|
-
class App:
|
|
5
|
+
class App(API):
|
|
7
6
|
"""
|
|
8
7
|
App client for interacting with the DeltaDeFi API.
|
|
9
8
|
"""
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
"""
|
|
13
|
-
Initialize the App client.
|
|
10
|
+
group_url_path = "/app"
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"""
|
|
18
|
-
self.api_client = api_client
|
|
12
|
+
def __init__(self, api_key=None, base_url=None, **kwargs):
|
|
13
|
+
super().__init__(api_key=api_key, base_url=base_url, **kwargs)
|
|
19
14
|
|
|
20
|
-
def
|
|
15
|
+
def get_terms_and_condition(self, **kwargs) -> GetTermsAndConditionResponse:
|
|
21
16
|
"""
|
|
22
17
|
Get terms and conditions.
|
|
23
18
|
|
|
24
19
|
Returns:
|
|
25
20
|
A GetTermsAndConditionResponse object containing the terms and conditions.
|
|
26
21
|
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
headers=self.api_client.headers,
|
|
30
|
-
)
|
|
31
|
-
response.raise_for_status()
|
|
32
|
-
return response.json()
|
|
22
|
+
url_path = "/terms-and-conditions"
|
|
23
|
+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
|
deltadefi/clients/clients.py
CHANGED
|
@@ -3,9 +3,9 @@ from sidan_gin import HDWallet
|
|
|
3
3
|
|
|
4
4
|
from deltadefi.api_resources.auth import ApiHeaders
|
|
5
5
|
from deltadefi.clients.accounts import Accounts
|
|
6
|
+
from deltadefi.clients.app import App
|
|
6
7
|
from deltadefi.clients.markets import Markets
|
|
7
|
-
from deltadefi.clients.
|
|
8
|
-
from deltadefi.requests import PostOrderRequest
|
|
8
|
+
from deltadefi.clients.order import Order
|
|
9
9
|
from deltadefi.responses import PostOrderResponse
|
|
10
10
|
|
|
11
11
|
|
|
@@ -17,7 +17,6 @@ class ApiClient:
|
|
|
17
17
|
def __init__(
|
|
18
18
|
self,
|
|
19
19
|
network: str = "preprod",
|
|
20
|
-
jwt: str = None,
|
|
21
20
|
api_key: str = None,
|
|
22
21
|
wallet: HDWallet = None,
|
|
23
22
|
base_url: str = None,
|
|
@@ -30,11 +29,6 @@ class ApiClient:
|
|
|
30
29
|
wallet: An instance of HDWallet for signing transactions.
|
|
31
30
|
base_url: Optional; The base URL for the API. Defaults to "https://api-dev.deltadefi.io".
|
|
32
31
|
"""
|
|
33
|
-
self.base_url = base_url or "https://api-dev.deltadefi.io"
|
|
34
|
-
headers: ApiHeaders = {
|
|
35
|
-
"Content-Type": "application/json",
|
|
36
|
-
}
|
|
37
|
-
|
|
38
32
|
if network == "mainnet":
|
|
39
33
|
self.network_id = 1
|
|
40
34
|
base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
|
|
@@ -42,20 +36,16 @@ class ApiClient:
|
|
|
42
36
|
self.network_id = 0
|
|
43
37
|
base_url = "https://api-dev.deltadefi.io"
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if api_key is not None:
|
|
49
|
-
headers["X-API-KEY"] = api_key
|
|
50
|
-
|
|
51
|
-
if wallet is not None:
|
|
52
|
-
self.wallet = wallet.signing_key
|
|
39
|
+
self.api_key = api_key
|
|
40
|
+
self.wallet = wallet
|
|
41
|
+
self.base_url = base_url
|
|
53
42
|
|
|
54
|
-
self.accounts = Accounts(
|
|
55
|
-
self.
|
|
56
|
-
self.
|
|
43
|
+
self.accounts = Accounts(base_url=base_url, api_key=api_key)
|
|
44
|
+
self.app = App(base_url=base_url, api_key=api_key)
|
|
45
|
+
self.order = Order(base_url=base_url, api_key=api_key)
|
|
46
|
+
self.markets = Markets(base_url=base_url, api_key=api_key)
|
|
57
47
|
|
|
58
|
-
async def post_order(self,
|
|
48
|
+
async def post_order(self, **kwargs) -> PostOrderResponse:
|
|
59
49
|
"""
|
|
60
50
|
Post an order to the DeltaDeFi API.
|
|
61
51
|
|
deltadefi/clients/markets.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
# flake8: noqa: E501
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
from typing import Literal
|
|
4
4
|
|
|
5
|
-
from deltadefi.
|
|
6
|
-
|
|
7
|
-
GetMarketDepthRequest,
|
|
8
|
-
GetMarketPriceRequest,
|
|
9
|
-
)
|
|
5
|
+
from deltadefi.api import API
|
|
6
|
+
from deltadefi.lib.utils import check_required_parameter, check_required_parameters
|
|
10
7
|
from deltadefi.responses import (
|
|
11
8
|
GetAggregatedPriceResponse,
|
|
12
9
|
GetMarketDepthResponse,
|
|
@@ -14,21 +11,17 @@ from deltadefi.responses import (
|
|
|
14
11
|
)
|
|
15
12
|
|
|
16
13
|
|
|
17
|
-
class Markets:
|
|
14
|
+
class Markets(API):
|
|
18
15
|
"""
|
|
19
16
|
Markets client for interacting with the DeltaDeFi API.
|
|
20
17
|
"""
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
"""
|
|
24
|
-
Initialize the Markets client.
|
|
19
|
+
group_url_path = "/market"
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"""
|
|
29
|
-
self.api_client = api_client
|
|
21
|
+
def __init__(self, api_key=None, base_url=None, **kwargs):
|
|
22
|
+
super().__init__(api_key=api_key, base_url=base_url, **kwargs)
|
|
30
23
|
|
|
31
|
-
def
|
|
24
|
+
def get_depth(self, symbol: str, **kwargs) -> GetMarketDepthResponse:
|
|
32
25
|
"""
|
|
33
26
|
Get market depth.
|
|
34
27
|
|
|
@@ -38,14 +31,14 @@ class Markets:
|
|
|
38
31
|
Returns:
|
|
39
32
|
A GetMarketDepthResponse object containing the market depth.
|
|
40
33
|
"""
|
|
41
|
-
response = requests.get(
|
|
42
|
-
f"{self.api_client.base_url}/market/depth?pair={data['pair']}",
|
|
43
|
-
headers=self.api_client.headers,
|
|
44
|
-
)
|
|
45
|
-
response.raise_for_status()
|
|
46
|
-
return response.json()
|
|
47
34
|
|
|
48
|
-
|
|
35
|
+
check_required_parameter(symbol, "symbol")
|
|
36
|
+
payload = {"symbol": symbol, **kwargs}
|
|
37
|
+
url_path = "/depth"
|
|
38
|
+
|
|
39
|
+
return self.send_request("GET", self.group_url_path + url_path, payload)
|
|
40
|
+
|
|
41
|
+
def get_market_price(self, symbol: str, **kwargs) -> GetMarketPriceResponse:
|
|
49
42
|
"""
|
|
50
43
|
Get market price.
|
|
51
44
|
|
|
@@ -55,15 +48,17 @@ class Markets:
|
|
|
55
48
|
Returns:
|
|
56
49
|
A GetMarketPriceResponse object containing the market price.
|
|
57
50
|
"""
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
response.raise_for_status()
|
|
63
|
-
return response.json()
|
|
51
|
+
check_required_parameter(symbol, "symbol")
|
|
52
|
+
payload = {"symbol": symbol, **kwargs}
|
|
53
|
+
url_path = "/market-price"
|
|
54
|
+
return self.send_request("GET", self.group_url_path + url_path, payload)
|
|
64
55
|
|
|
65
|
-
def
|
|
66
|
-
self,
|
|
56
|
+
def get_aggregated_price(
|
|
57
|
+
self,
|
|
58
|
+
symbol: str,
|
|
59
|
+
interval: Literal["15m", "30m", "1h", "1d", "1w", "1M"],
|
|
60
|
+
start: int,
|
|
61
|
+
end: int,
|
|
67
62
|
) -> GetAggregatedPriceResponse:
|
|
68
63
|
"""
|
|
69
64
|
Get aggregated price.
|
|
@@ -74,9 +69,22 @@ class Markets:
|
|
|
74
69
|
Returns:
|
|
75
70
|
A GetAggregatedPriceResponse object containing the aggregated price.
|
|
76
71
|
"""
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
|
|
73
|
+
check_required_parameters(
|
|
74
|
+
[
|
|
75
|
+
[symbol, "symbol"],
|
|
76
|
+
[interval, "interval"],
|
|
77
|
+
[start, "start"],
|
|
78
|
+
[end, "end"],
|
|
79
|
+
]
|
|
80
|
+
)
|
|
81
|
+
url_path = f"/aggregated-trade/{symbol}"
|
|
82
|
+
return self.send_request(
|
|
83
|
+
"GET",
|
|
84
|
+
self.group_url_path + url_path,
|
|
85
|
+
{
|
|
86
|
+
"interval": interval,
|
|
87
|
+
"start": start,
|
|
88
|
+
"end": end,
|
|
89
|
+
},
|
|
80
90
|
)
|
|
81
|
-
response.raise_for_status()
|
|
82
|
-
return response.json()
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
from deltadefi.api import API
|
|
2
|
+
from deltadefi.lib.utils import check_required_parameter, check_required_parameters
|
|
3
|
+
from deltadefi.models.models import OrderSide, OrderType
|
|
4
|
+
from deltadefi.responses import (
|
|
5
|
+
BuildCancelOrderTransactionResponse,
|
|
6
|
+
BuildPlaceOrderTransactionResponse,
|
|
7
|
+
SubmitCancelOrderTransactionResponse,
|
|
8
|
+
SubmitPlaceOrderTransactionResponse,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Order(API):
|
|
13
|
+
"""
|
|
14
|
+
Orders client for interacting with the DeltaDeFi API.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
group_url_path = "/order"
|
|
18
|
+
|
|
19
|
+
def __init__(self, api_key=None, base_url=None, **kwargs):
|
|
20
|
+
super().__init__(api_key=api_key, base_url=base_url, **kwargs)
|
|
21
|
+
|
|
22
|
+
def build_place_order_transaction(
|
|
23
|
+
self,
|
|
24
|
+
symbol: str,
|
|
25
|
+
side: OrderSide,
|
|
26
|
+
type: OrderType,
|
|
27
|
+
quantity: int,
|
|
28
|
+
price: int,
|
|
29
|
+
max_slippage_basis_point: int,
|
|
30
|
+
limit_slippage: bool,
|
|
31
|
+
**kwargs,
|
|
32
|
+
) -> BuildPlaceOrderTransactionResponse:
|
|
33
|
+
"""
|
|
34
|
+
Build a place order transaction.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
data: A BuildPlaceOrderTransactionRequest object containing the order details.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
A BuildPlaceOrderTransactionResponse object containing the built order transaction.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
check_required_parameters(
|
|
44
|
+
[symbol, "symbol"],
|
|
45
|
+
[side, "side"],
|
|
46
|
+
[type, "type"],
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if type == "limit":
|
|
50
|
+
check_required_parameter(price, "price")
|
|
51
|
+
|
|
52
|
+
if type == "market" and limit_slippage:
|
|
53
|
+
check_required_parameter(
|
|
54
|
+
max_slippage_basis_point, "max_slippage_basis_point"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
payload = {
|
|
58
|
+
"symbol": symbol,
|
|
59
|
+
"side": side,
|
|
60
|
+
"type": type,
|
|
61
|
+
"quantity": quantity,
|
|
62
|
+
"max_slippage_basis_point": max_slippage_basis_point,
|
|
63
|
+
"limit_slippage": limit_slippage,
|
|
64
|
+
**kwargs,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
url_path = "/build"
|
|
68
|
+
return self.send_request("POST", self.group_url_path + url_path, payload)
|
|
69
|
+
|
|
70
|
+
def build_cancel_order_transaction(
|
|
71
|
+
self, order_id: str, **kwargs
|
|
72
|
+
) -> BuildCancelOrderTransactionResponse:
|
|
73
|
+
"""
|
|
74
|
+
Build a cancel order transaction.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
order_id: The ID of the order to be canceled.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
A BuildCancelOrderTransactionResponse object containing the built cancel order transaction.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
check_required_parameter(order_id, "order_id")
|
|
84
|
+
|
|
85
|
+
url_path = f"/{order_id}/build"
|
|
86
|
+
return self.send_request("DELETE", self.group_url_path + url_path, **kwargs)
|
|
87
|
+
|
|
88
|
+
def submit_place_order_transaction(
|
|
89
|
+
self, order_id: str, signed_tx: str, **kwargs
|
|
90
|
+
) -> SubmitPlaceOrderTransactionResponse:
|
|
91
|
+
"""
|
|
92
|
+
Submit a place order transaction.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
data: A SubmitPlaceOrderTransactionRequest object containing the order details.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
A SubmitPlaceOrderTransactionResponse object containing the submitted order transaction.
|
|
99
|
+
"""
|
|
100
|
+
check_required_parameters([order_id, "order_id"], [signed_tx, "signed_tx"])
|
|
101
|
+
payload = {"order_id": order_id, "signed_tx": signed_tx, **kwargs}
|
|
102
|
+
|
|
103
|
+
url_path = "/submit"
|
|
104
|
+
return self.send_request("POST", self.group_url_path + url_path, payload)
|
|
105
|
+
|
|
106
|
+
def submit_cancel_order_transaction(
|
|
107
|
+
self, signed_tx: str, **kwargs
|
|
108
|
+
) -> SubmitCancelOrderTransactionResponse:
|
|
109
|
+
"""
|
|
110
|
+
Submit a cancel order transaction.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
data: A SubmitCancelOrderTransactionRequest object containing the cancel order details.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
A SubmitCancelOrderTransactionResponse object containing the submitted cancel order transaction.
|
|
117
|
+
"""
|
|
118
|
+
check_required_parameter(signed_tx, "signed_tx")
|
|
119
|
+
payload = {"signed_tx": signed_tx, **kwargs}
|
|
120
|
+
|
|
121
|
+
path_url = "/submit"
|
|
122
|
+
return self.send_request("DELETE", self.group_url_path + path_url, payload)
|
deltadefi/error.py
CHANGED
|
@@ -1,63 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class deltadefi_sdkError(Exception):
|
|
5
|
-
def __init__(
|
|
6
|
-
self,
|
|
7
|
-
message=None,
|
|
8
|
-
http_body=None,
|
|
9
|
-
http_status=None,
|
|
10
|
-
json_body=None,
|
|
11
|
-
headers=None,
|
|
12
|
-
code=None,
|
|
13
|
-
):
|
|
14
|
-
super(deltadefi_sdkError, self).__init__(message)
|
|
15
|
-
|
|
16
|
-
self._message = message
|
|
17
|
-
self.http_body = http_body
|
|
18
|
-
self.http_status = http_status
|
|
19
|
-
self.json_body = json_body
|
|
20
|
-
self.headers = headers or {}
|
|
21
|
-
self.code = code
|
|
22
|
-
self.request_id = self.headers.get("request-id", None)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class APIError(deltadefi_sdkError):
|
|
1
|
+
class Error(Exception):
|
|
26
2
|
pass
|
|
27
3
|
|
|
28
4
|
|
|
29
|
-
class
|
|
30
|
-
def
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class InvalidRequestError(deltadefi_sdkErrorWithParamCode):
|
|
42
|
-
def __init__(
|
|
43
|
-
self,
|
|
44
|
-
message,
|
|
45
|
-
param,
|
|
46
|
-
code=None,
|
|
47
|
-
http_body=None,
|
|
48
|
-
http_status=None,
|
|
49
|
-
json_body=None,
|
|
50
|
-
headers=None,
|
|
51
|
-
):
|
|
52
|
-
super(InvalidRequestError, self).__init__(
|
|
53
|
-
message, http_body, http_status, json_body, headers, code
|
|
54
|
-
)
|
|
55
|
-
self.param = param
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class AuthenticationError(deltadefi_sdkError):
|
|
59
|
-
pass
|
|
5
|
+
class ClientError(Error):
|
|
6
|
+
def __init__(self, status_code, error_code, error_message, header, error_data=None):
|
|
7
|
+
# https status code
|
|
8
|
+
self.status_code = status_code
|
|
9
|
+
# error code returned from server
|
|
10
|
+
self.error_code = error_code
|
|
11
|
+
# error message returned from server
|
|
12
|
+
self.error_message = error_message
|
|
13
|
+
# the whole response header returned from server
|
|
14
|
+
self.header = header
|
|
15
|
+
# return data if it's returned from server
|
|
16
|
+
self.error_data = error_data
|
|
60
17
|
|
|
61
18
|
|
|
62
|
-
class
|
|
63
|
-
|
|
19
|
+
class ServerError(Error):
|
|
20
|
+
def __init__(self, status_code, message):
|
|
21
|
+
self.status_code = status_code
|
|
22
|
+
self.message = message
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ParameterRequiredError(Error):
|
|
26
|
+
def __init__(self, params):
|
|
27
|
+
self.params = params
|
|
28
|
+
|
|
29
|
+
def __str__(self):
|
|
30
|
+
return "%s is mandatory, but received empty." % (", ".join(self.params))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ParameterValueError(Error):
|
|
34
|
+
def __init__(self, params):
|
|
35
|
+
self.params = params
|
|
36
|
+
|
|
37
|
+
def __str__(self):
|
|
38
|
+
return "the enum value %s is invalid." % (", ".join(self.params))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ParameterTypeError(Error):
|
|
42
|
+
def __init__(self, params):
|
|
43
|
+
self.params = params
|
|
44
|
+
|
|
45
|
+
def __str__(self):
|
|
46
|
+
return f"{self.params[0]} data type has to be {self.params[1]}"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ParameterArgumentError(Error):
|
|
50
|
+
def __init__(self, error_message):
|
|
51
|
+
self.error_message = error_message
|
|
52
|
+
|
|
53
|
+
def __str__(self):
|
|
54
|
+
return self.error_message
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class WebsocketClientError(Error):
|
|
58
|
+
def __init__(self, error_message):
|
|
59
|
+
self.error_message = error_message
|
|
60
|
+
|
|
61
|
+
def __str__(self):
|
|
62
|
+
return self.error_message
|
|
File without changes
|
deltadefi/lib/utils.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from urllib.parse import urlencode
|
|
2
|
+
|
|
3
|
+
from deltadefi.error import (
|
|
4
|
+
ParameterRequiredError,
|
|
5
|
+
ParameterTypeError,
|
|
6
|
+
ParameterValueError,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def clean_none_value(d) -> dict:
|
|
11
|
+
out = {}
|
|
12
|
+
for k in d.keys():
|
|
13
|
+
if d[k] is not None:
|
|
14
|
+
out[k] = d[k]
|
|
15
|
+
return out
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def check_required_parameter(value, name):
|
|
19
|
+
if not value and value != 0:
|
|
20
|
+
raise ParameterRequiredError([name])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def check_required_parameters(params):
|
|
24
|
+
"""Validate multiple parameters
|
|
25
|
+
params = [
|
|
26
|
+
['btcusdt', 'symbol'],
|
|
27
|
+
[10, 'price']
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
for p in params:
|
|
32
|
+
check_required_parameter(p[0], p[1])
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def check_enum_parameter(value, enum_class):
|
|
36
|
+
if value not in set(item.value for item in enum_class):
|
|
37
|
+
raise ParameterValueError([value])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def check_type_parameter(value, name, data_type):
|
|
41
|
+
if value is not None and not isinstance(value, data_type):
|
|
42
|
+
raise ParameterTypeError([name, data_type])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def encoded_string(query):
|
|
46
|
+
return urlencode(query, True).replace("%40", "@")
|
deltadefi/models/models.py
CHANGED
|
@@ -3,8 +3,6 @@ from typing import List, Literal
|
|
|
3
3
|
|
|
4
4
|
from sidan_gin import Asset
|
|
5
5
|
|
|
6
|
-
TradingSymbol = Literal["ADAUSDX"]
|
|
7
|
-
|
|
8
6
|
OrderStatus = Literal["building", "open", "closed", "failed"]
|
|
9
7
|
|
|
10
8
|
OrderSide = Literal["buy", "sell"]
|
|
@@ -35,7 +33,7 @@ class TransactionStatus:
|
|
|
35
33
|
class OrderJSON:
|
|
36
34
|
order_id: str
|
|
37
35
|
status: OrderStatus
|
|
38
|
-
symbol:
|
|
36
|
+
symbol: str
|
|
39
37
|
orig_qty: str
|
|
40
38
|
executed_qty: str
|
|
41
39
|
side: OrderSide
|
deltadefi/responses/accounts.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: deltadefi
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Python SDK for DeltaDeFi protocol.
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Keywords: cardano
|
|
@@ -34,7 +34,7 @@ The DeltaDeFi Python SDK provides a convenient way to interact with the DeltaDeF
|
|
|
34
34
|
To install the SDK, use `pip`:
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
|
-
pip install deltadefi
|
|
37
|
+
pip install deltadefi
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Requirements
|
|
@@ -48,19 +48,18 @@ pip install deltadefi-python-sdk
|
|
|
48
48
|
To use the SDK, you need to initialize the ApiClient with your API configuration and wallet.
|
|
49
49
|
|
|
50
50
|
```python
|
|
51
|
-
from deltadefi.
|
|
52
|
-
from deltadefi.clients.clients import ApiClient
|
|
51
|
+
from deltadefi.clients import ApiClient
|
|
53
52
|
from sidan_gin import HDWallet
|
|
54
53
|
|
|
55
54
|
# Initialize API configuration
|
|
56
|
-
network="
|
|
55
|
+
network="preprod",
|
|
57
56
|
api_key="your_api_key",
|
|
58
57
|
|
|
59
58
|
# Initialize HDWallet
|
|
60
59
|
wallet = HDWallet("your_wallet_mnemonic")
|
|
61
60
|
|
|
62
61
|
# Initialize ApiClient
|
|
63
|
-
|
|
62
|
+
api = ApiClient(network=network, api_key=api_key, wallet=wallet)
|
|
64
63
|
```
|
|
65
64
|
|
|
66
65
|
### Accounts
|
|
@@ -68,17 +67,8 @@ api_client = ApiClient(network=network, api_key=api_key, wallet=wallet)
|
|
|
68
67
|
The Accounts client allows you to interact with account-related endpoints.
|
|
69
68
|
|
|
70
69
|
```python
|
|
71
|
-
from deltadefi.clients.accounts import Accounts
|
|
72
|
-
|
|
73
|
-
accounts_client = api_client.accounts
|
|
74
|
-
|
|
75
|
-
# Sign in
|
|
76
|
-
sign_in_request = SignInRequest(auth_key="your_auth_key", wallet_address="your_wallet_address")
|
|
77
|
-
sign_in_response = accounts_client.sign_in(sign_in_request)
|
|
78
|
-
print(sign_in_response)
|
|
79
|
-
|
|
80
70
|
# Get account balance
|
|
81
|
-
account_balance =
|
|
71
|
+
account_balance = api.accounts.get_account_balance()
|
|
82
72
|
print(account_balance)
|
|
83
73
|
```
|
|
84
74
|
|
|
@@ -87,46 +77,31 @@ print(account_balance)
|
|
|
87
77
|
The Markets client allows you to interact with market-related endpoints.
|
|
88
78
|
|
|
89
79
|
```python
|
|
90
|
-
from deltadefi.clients.markets import Markets
|
|
91
|
-
|
|
92
|
-
markets_client = api_client.markets
|
|
93
|
-
|
|
94
80
|
# Get market depth
|
|
95
|
-
|
|
96
|
-
market_depth_response = markets_client.getDepth(market_depth_request)
|
|
81
|
+
market_depth = api.markets.get_depth("ADAUSDX")
|
|
97
82
|
print(market_depth_response)
|
|
98
83
|
|
|
99
84
|
# Get market price
|
|
100
|
-
|
|
101
|
-
market_price_response = markets_client.getMarketPrice(market_price_request)
|
|
85
|
+
market_price_response = api.markets.get_market_price("ADAUSDX")
|
|
102
86
|
print(market_price_response)
|
|
103
87
|
```
|
|
104
88
|
|
|
105
|
-
###
|
|
89
|
+
### Order
|
|
106
90
|
|
|
107
|
-
The
|
|
91
|
+
The Order client allows you to interact with order-related endpoints.
|
|
108
92
|
|
|
109
93
|
```python
|
|
110
|
-
from deltadefi.clients.orders import Orders
|
|
111
|
-
|
|
112
|
-
orders_client = api_client.orders
|
|
113
|
-
|
|
114
94
|
# Build place order transaction
|
|
115
95
|
place_order_request = BuildPlaceOrderTransactionRequest(pair="BTC/USD", amount=1, price=50000)
|
|
116
|
-
place_order_response =
|
|
96
|
+
place_order_response = api.order.build_place_order_transaction(symbol="ADAUSDX", amount=50, price=0.75, type="limit")
|
|
117
97
|
print(place_order_response)
|
|
118
98
|
|
|
119
99
|
# Submit place order transaction
|
|
120
|
-
|
|
121
|
-
submit_order_response = orders_client.submit_place_order_transaction(submit_order_request)
|
|
100
|
+
submit_order_response = api.order.submit_place_order_transaction(signed_tx="<signed_tx>", order_id="<order_id>")
|
|
122
101
|
print(submit_order_response)
|
|
123
102
|
```
|
|
124
103
|
|
|
125
104
|
## License
|
|
126
105
|
|
|
127
|
-
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
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
131
|
-
```
|
|
106
|
+
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 <http://www.apache.org/licenses/LICENSE-2.0>
|
|
132
107
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
deltadefi/__init__.py,sha256=_dbB-toNXZvwZxj5DnEY0nW5noDnDpF4QsJNEwGO_IA,46
|
|
2
|
+
deltadefi/api.py,sha256=TKlP9yWwZhz2HrmqWYvhB7YUvSfzxKkN219dJsduLVs,2371
|
|
3
|
+
deltadefi/api_resources/__init__.py,sha256=_SGHTpaQTIBvh9Rm868IT5pXpvvGBPqz3bxkY6YapZ4,61
|
|
4
|
+
deltadefi/api_resources/auth.py,sha256=Mpl4Dbh_d_gGhwLo2CtBSKxZ21DC74x-qjVhlczZCDE,278
|
|
5
|
+
deltadefi/api_resources/validation.py,sha256=vz-hovpLy9SMOIFGcBHC8vWZH8CJRlQP8rcbbTSM-PM,1375
|
|
6
|
+
deltadefi/clients/__init__.py,sha256=AoK_kj_UKpxtCa3_if3yeHFAzHli9Mg-tsrUKOX7eH8,38
|
|
7
|
+
deltadefi/clients/accounts.py,sha256=I3Yh82iHVK932u2Luvewbxk_KJ-WVLYqH048XBFgrsQ,5347
|
|
8
|
+
deltadefi/clients/app.py,sha256=TOgRlP83p91r7oS4ez8Gfm8soQzFHrJAmOHZJoGZ4SM,712
|
|
9
|
+
deltadefi/clients/clients.py,sha256=KtKWTr3-dgMgmJc8jVqzZ9qJ8I41T8G8KkNNTe9SEz0,2253
|
|
10
|
+
deltadefi/clients/markets.py,sha256=EK1VRtLRtmUtIISdJtDthmWsjx_sDWkgJgdjqeQ8lXc,2581
|
|
11
|
+
deltadefi/clients/order.py,sha256=1IfYf4uqNz9nchv4l7ulxhUDd_Yink2r8hGWmDf85Jc,3927
|
|
12
|
+
deltadefi/constants/__init__.py,sha256=7LkrzfLTJsCCUl5IgZYrl-AbY_cf1fftcLklgnBYDTs,40
|
|
13
|
+
deltadefi/constants/constants.py,sha256=9Ksb8_4t78KJpHVUnRArKlvgQk-CzcYsLRmA5qUnMwc,168
|
|
14
|
+
deltadefi/error.py,sha256=Pq55p7FQbVn1GTih7NQBI7ZcVUUrlkaFKn-SwZUxBA8,1650
|
|
15
|
+
deltadefi/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
deltadefi/lib/utils.py,sha256=zuQFAKQphbGxDdPzBURw4A2n3AkRSbzmjMLHPLm9Ed4,1035
|
|
17
|
+
deltadefi/models/__init__.py,sha256=oDJj6Y4gXN6C7Oz_t2fq8hej-D0G9OqfXjL4Jaeq8z8,37
|
|
18
|
+
deltadefi/models/models.py,sha256=vnNFFPMQcOOSKhONHNHXJIx4wddV4IKeBszykiqWCwk,1182
|
|
19
|
+
deltadefi/responses/__init__.py,sha256=JKSIUQu6qI_XhbAR2mVMCKNvR6x_vFZdyLGOuQTVrVY,64
|
|
20
|
+
deltadefi/responses/accounts.py,sha256=aVQq1CqebIQz0YuNphFlA2fGBgvmf8FpboJzToEiY2g,939
|
|
21
|
+
deltadefi/responses/responses.py,sha256=etlx83GgZC2noLKo8GKrmDo3Xhwup-g8Ob29f0WYA4I,993
|
|
22
|
+
deltadefi-0.0.2.dist-info/METADATA,sha256=_Md2KzsVrl6HX1wuEuiJIBS3F8Fwti4KFoX_gf3tI74,3085
|
|
23
|
+
deltadefi-0.0.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
24
|
+
deltadefi-0.0.2.dist-info/RECORD,,
|
deltadefi/clients/orders.py
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
|
|
3
|
-
from deltadefi.requests import (
|
|
4
|
-
BuildPlaceOrderTransactionRequest,
|
|
5
|
-
SubmitCancelOrderTransactionRequest,
|
|
6
|
-
SubmitPlaceOrderTransactionRequest,
|
|
7
|
-
)
|
|
8
|
-
from deltadefi.responses import (
|
|
9
|
-
BuildCancelOrderTransactionResponse,
|
|
10
|
-
BuildPlaceOrderTransactionResponse,
|
|
11
|
-
SubmitCancelOrderTransactionResponse,
|
|
12
|
-
SubmitPlaceOrderTransactionResponse,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Orders:
|
|
17
|
-
"""
|
|
18
|
-
Orders client for interacting with the DeltaDeFi API.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
def __init__(self, api_client):
|
|
22
|
-
"""
|
|
23
|
-
Initialize the Orders client.
|
|
24
|
-
|
|
25
|
-
Args:
|
|
26
|
-
api_client: An instance of the ApiClient.
|
|
27
|
-
"""
|
|
28
|
-
self.api_client = api_client
|
|
29
|
-
|
|
30
|
-
def build_place_order_transaction(
|
|
31
|
-
self, data: BuildPlaceOrderTransactionRequest
|
|
32
|
-
) -> BuildPlaceOrderTransactionResponse:
|
|
33
|
-
"""
|
|
34
|
-
Build a place order transaction.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
data: A BuildPlaceOrderTransactionRequest object containing the order details.
|
|
38
|
-
|
|
39
|
-
Returns:
|
|
40
|
-
A BuildPlaceOrderTransactionResponse object containing the built order transaction.
|
|
41
|
-
"""
|
|
42
|
-
response = requests.post(
|
|
43
|
-
f"{self.api_client.base_url}/order/build",
|
|
44
|
-
json=data,
|
|
45
|
-
headers=self.api_client.headers,
|
|
46
|
-
)
|
|
47
|
-
response.raise_for_status()
|
|
48
|
-
return response.json()
|
|
49
|
-
|
|
50
|
-
def build_cancel_order_transaction(
|
|
51
|
-
self, order_id: str
|
|
52
|
-
) -> BuildCancelOrderTransactionResponse:
|
|
53
|
-
"""
|
|
54
|
-
Build a cancel order transaction.
|
|
55
|
-
|
|
56
|
-
Args:
|
|
57
|
-
order_id: The ID of the order to be canceled.
|
|
58
|
-
|
|
59
|
-
Returns:
|
|
60
|
-
A BuildCancelOrderTransactionResponse object containing the built cancel order transaction.
|
|
61
|
-
"""
|
|
62
|
-
response = requests.delete(
|
|
63
|
-
f"{self.api_client.base_url}/order/{order_id}/build",
|
|
64
|
-
headers=self.api_client.headers,
|
|
65
|
-
)
|
|
66
|
-
response.raise_for_status()
|
|
67
|
-
return response.json()
|
|
68
|
-
|
|
69
|
-
def submit_place_order_transaction(
|
|
70
|
-
self, data: SubmitPlaceOrderTransactionRequest
|
|
71
|
-
) -> SubmitPlaceOrderTransactionResponse:
|
|
72
|
-
"""
|
|
73
|
-
Submit a place order transaction.
|
|
74
|
-
|
|
75
|
-
Args:
|
|
76
|
-
data: A SubmitPlaceOrderTransactionRequest object containing the order details.
|
|
77
|
-
|
|
78
|
-
Returns:
|
|
79
|
-
A SubmitPlaceOrderTransactionResponse object containing the submitted order transaction.
|
|
80
|
-
"""
|
|
81
|
-
response = requests.post(
|
|
82
|
-
f"{self.api_client.base_url}/order/submit",
|
|
83
|
-
json=data,
|
|
84
|
-
headers=self.api_client.headers,
|
|
85
|
-
)
|
|
86
|
-
response.raise_for_status()
|
|
87
|
-
return response.json()
|
|
88
|
-
|
|
89
|
-
def submit_cancel_order_transaction(
|
|
90
|
-
self, data: SubmitCancelOrderTransactionRequest
|
|
91
|
-
) -> SubmitCancelOrderTransactionResponse:
|
|
92
|
-
"""
|
|
93
|
-
Submit a cancel order transaction.
|
|
94
|
-
|
|
95
|
-
Args:
|
|
96
|
-
data: A SubmitCancelOrderTransactionRequest object containing the cancel order details.
|
|
97
|
-
|
|
98
|
-
Returns:
|
|
99
|
-
A SubmitCancelOrderTransactionResponse object containing the submitted cancel order transaction.
|
|
100
|
-
"""
|
|
101
|
-
response = requests.delete(
|
|
102
|
-
f"{self.api_client.base_url}/order/submit",
|
|
103
|
-
json=data,
|
|
104
|
-
headers=self.api_client.headers,
|
|
105
|
-
)
|
|
106
|
-
response.raise_for_status()
|
|
107
|
-
return response.json()
|
deltadefi/requests/__init__.py
DELETED
deltadefi/requests/accounts.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import List
|
|
3
|
-
|
|
4
|
-
from sidan_gin import Asset, UTxO
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@dataclass
|
|
8
|
-
class SignInRequest:
|
|
9
|
-
wallet_address: str
|
|
10
|
-
auth_key: str
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@dataclass
|
|
14
|
-
class BuildDepositTransactionRequest:
|
|
15
|
-
deposit_amount: List[Asset]
|
|
16
|
-
input_utxos: List[UTxO]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@dataclass
|
|
20
|
-
class BuildWithdrawalTransactionRequest:
|
|
21
|
-
withdrawal_amount: List[Asset]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@dataclass
|
|
25
|
-
class SubmitDepositTransactionRequest:
|
|
26
|
-
signed_tx: str
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@dataclass
|
|
30
|
-
class SubmitWithdrawalTransactionRequest:
|
|
31
|
-
signed_txs: List[str]
|
deltadefi/requests/requests.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import Literal, Optional
|
|
3
|
-
|
|
4
|
-
from deltadefi.models import OrderSide, OrderType, TradingSymbol
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@dataclass
|
|
8
|
-
class GetMarketDepthRequest:
|
|
9
|
-
pair: str
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@dataclass
|
|
13
|
-
class GetMarketPriceRequest:
|
|
14
|
-
pair: str
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Interval = Literal["15m", "30m", "1h", "1d", "1w", "1M"]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@dataclass
|
|
21
|
-
class GetAggregatedPriceRequest:
|
|
22
|
-
pair: str
|
|
23
|
-
interval: Interval
|
|
24
|
-
start: Optional[int]
|
|
25
|
-
end: Optional[int]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
# class TradingSymbol(str):
|
|
29
|
-
# pass
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# class OrderSide(str):
|
|
33
|
-
# pass
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# class OrderType(str):
|
|
37
|
-
# pass
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@dataclass
|
|
41
|
-
class BuildPlaceOrderTransactionRequest:
|
|
42
|
-
pair: TradingSymbol
|
|
43
|
-
side: OrderSide
|
|
44
|
-
type: OrderType
|
|
45
|
-
quantity: float
|
|
46
|
-
price: Optional[float]
|
|
47
|
-
basis_point: Optional[float]
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class PostOrderRequest(BuildPlaceOrderTransactionRequest):
|
|
51
|
-
pass
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@dataclass
|
|
55
|
-
class SubmitPlaceOrderTransactionRequest:
|
|
56
|
-
order_id: str
|
|
57
|
-
signed_tx: str
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@dataclass
|
|
61
|
-
class BuildCancelOrderTransactionRequest:
|
|
62
|
-
order_id: str
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@dataclass
|
|
66
|
-
class SubmitCancelOrderTransactionRequest:
|
|
67
|
-
signed_tx: str
|
deltadefi-0.0.1.dist-info/RECORD
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
deltadefi/__init__.py,sha256=_dbB-toNXZvwZxj5DnEY0nW5noDnDpF4QsJNEwGO_IA,46
|
|
2
|
-
deltadefi/api_resources/__init__.py,sha256=_SGHTpaQTIBvh9Rm868IT5pXpvvGBPqz3bxkY6YapZ4,61
|
|
3
|
-
deltadefi/api_resources/auth.py,sha256=Mpl4Dbh_d_gGhwLo2CtBSKxZ21DC74x-qjVhlczZCDE,278
|
|
4
|
-
deltadefi/api_resources/validation.py,sha256=vz-hovpLy9SMOIFGcBHC8vWZH8CJRlQP8rcbbTSM-PM,1375
|
|
5
|
-
deltadefi/clients/__init__.py,sha256=EsZ3uPvBHMmxzx29tAddhDd4Nk1tDZ6eFewLG1Hh6fs,126
|
|
6
|
-
deltadefi/clients/accounts.py,sha256=vWIVsftRA2TYgtmRxTqD2Ex1BYO2EFOkvbnSZyCGdpA,7044
|
|
7
|
-
deltadefi/clients/app.py,sha256=nt1jULimogIk70qR9De5r6NnL1O1ursmfnfIm6pmtJs,815
|
|
8
|
-
deltadefi/clients/clients.py,sha256=kFmGa2pgNgFrfKnYCt_aZb9brLCWi5GtQKVGydaHb3M,2446
|
|
9
|
-
deltadefi/clients/markets.py,sha256=byWzMenDJehTV3Ro5v9okXAGi3erdJ1c8iVuvBKNJDw,2388
|
|
10
|
-
deltadefi/clients/orders.py,sha256=c53D67Iu6-xb_ucsu3TK6HR5fKmHttz-JT6NhvlCYJA,3285
|
|
11
|
-
deltadefi/constants/__init__.py,sha256=7LkrzfLTJsCCUl5IgZYrl-AbY_cf1fftcLklgnBYDTs,40
|
|
12
|
-
deltadefi/constants/constants.py,sha256=9Ksb8_4t78KJpHVUnRArKlvgQk-CzcYsLRmA5qUnMwc,168
|
|
13
|
-
deltadefi/error.py,sha256=KIOHxGgv5Qa2IYUBByCE0uEM8fjBfyasVb2Acz3B77Y,1524
|
|
14
|
-
deltadefi/models/__init__.py,sha256=oDJj6Y4gXN6C7Oz_t2fq8hej-D0G9OqfXjL4Jaeq8z8,37
|
|
15
|
-
deltadefi/models/models.py,sha256=4vU2vVJpMDSPKYQH41JKC1raKf2kelEcAik45qUyopc,1228
|
|
16
|
-
deltadefi/requests/__init__.py,sha256=LmC-3pphj__BcvaPzFpJ1fvJDrCHtvstQ9y6zSW67JE,63
|
|
17
|
-
deltadefi/requests/accounts.py,sha256=zCzmNCLNW75Xcmy_JbVWtAJOqqLavDqZLmh-Ll-TQqU,521
|
|
18
|
-
deltadefi/requests/requests.py,sha256=3-LM2p-JHp8F8gGujtZcTAxb7um8C2WG9rgFap4hnSU,1062
|
|
19
|
-
deltadefi/responses/__init__.py,sha256=JKSIUQu6qI_XhbAR2mVMCKNvR6x_vFZdyLGOuQTVrVY,64
|
|
20
|
-
deltadefi/responses/accounts.py,sha256=6MvyAvrJ5Mc1hJ6BhQovtRiOsZZJzY_PsPpO5CNfe_c,1013
|
|
21
|
-
deltadefi/responses/responses.py,sha256=etlx83GgZC2noLKo8GKrmDo3Xhwup-g8Ob29f0WYA4I,993
|
|
22
|
-
deltadefi-0.0.1.dist-info/METADATA,sha256=A0iBWAGnqgwosUTeRsP529CDKpQOP6cW-3WqcyGk4Q8,3806
|
|
23
|
-
deltadefi-0.0.1.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
24
|
-
deltadefi-0.0.1.dist-info/RECORD,,
|
|
File without changes
|