dipcoin-client 1.3.0__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.
- dipcoin_client/__init__.py +9 -0
- dipcoin_client/api_service.py +147 -0
- dipcoin_client/client.py +1001 -0
- dipcoin_client/constants.py +60 -0
- dipcoin_client/contracts.py +145 -0
- dipcoin_client/enumerations.py +98 -0
- dipcoin_client/interfaces.py +130 -0
- dipcoin_client/onboarding_signer.py +34 -0
- dipcoin_client/order_signer.py +123 -0
- dipcoin_client/socket_manager.py +110 -0
- dipcoin_client/sui_graphql_client.py +326 -0
- dipcoin_client/util.py +344 -0
- dipcoin_client/wallets.py +309 -0
- dipcoin_client/websocket_client.py +181 -0
- dipcoin_client-1.3.0.dist-info/METADATA +397 -0
- dipcoin_client-1.3.0.dist-info/RECORD +28 -0
- dipcoin_client-1.3.0.dist-info/WHEEL +5 -0
- dipcoin_client-1.3.0.dist-info/licenses/LICENSE +21 -0
- dipcoin_client-1.3.0.dist-info/top_level.txt +2 -0
- sui_utils/__init__.py +8 -0
- sui_utils/account.py +67 -0
- sui_utils/bcs.py +135 -0
- sui_utils/coin_utils.py +164 -0
- sui_utils/enumerations.py +6 -0
- sui_utils/rpc.py +344 -0
- sui_utils/signer.py +250 -0
- sui_utils/sui_interfaces.py +92 -0
- sui_utils/utilities.py +356 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from .api_service import *
|
|
2
|
+
from .client import *
|
|
3
|
+
from .constants import *
|
|
4
|
+
from .enumerations import *
|
|
5
|
+
from .interfaces import *
|
|
6
|
+
from .sui_graphql_client import SuiGraphQLClient
|
|
7
|
+
from .util import calculate_max_removable_margin, normalize_price, normalize_qty
|
|
8
|
+
from .wallets import *
|
|
9
|
+
from sui_utils import *
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
from .interfaces import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class APIService:
|
|
8
|
+
def __init__(self, url):
|
|
9
|
+
self.server_url = url
|
|
10
|
+
self.auth_token = None
|
|
11
|
+
self.api_token = None
|
|
12
|
+
# config proxy for example:
|
|
13
|
+
# export HTTP_PROXY="http://127.0.0.1:1087"
|
|
14
|
+
# export HTTPS_PROXY="http://127.0.0.1:1087"
|
|
15
|
+
self.proxy = os.getenv("HTTP_PROXY") or os.getenv("HTTPS_PROXY") or None
|
|
16
|
+
|
|
17
|
+
# trust_env=True aiohttp will auto proxy
|
|
18
|
+
self.client = aiohttp.ClientSession(
|
|
19
|
+
connector=aiohttp.TCPConnector(ssl=False),
|
|
20
|
+
trust_env=True,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
async def close_session(self):
|
|
24
|
+
if self.client is not None:
|
|
25
|
+
return await self.client.close()
|
|
26
|
+
|
|
27
|
+
async def get(self, service_url, query={}, auth_required=False, wallet=""):
|
|
28
|
+
"""
|
|
29
|
+
Makes a GET request and returns the results
|
|
30
|
+
Inputs:
|
|
31
|
+
- service_url(str): the url to make the request to.
|
|
32
|
+
- query(dict): the get query.
|
|
33
|
+
- auth_required(bool): indicates whether authorization is required for the call or not.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
url = self._create_url(service_url)
|
|
37
|
+
# print("url", url)
|
|
38
|
+
|
|
39
|
+
response = None
|
|
40
|
+
if auth_required:
|
|
41
|
+
headers = {
|
|
42
|
+
'Authorization': 'Bearer {}'.format(self.auth_token),
|
|
43
|
+
'x-wallet-address': wallet,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
response = await self.client.get(
|
|
47
|
+
url,
|
|
48
|
+
params=query,
|
|
49
|
+
headers=headers,
|
|
50
|
+
proxy=self.proxy,
|
|
51
|
+
)
|
|
52
|
+
else:
|
|
53
|
+
response = await self.client.get(url, params=query, proxy=self.proxy)
|
|
54
|
+
|
|
55
|
+
# print("response",response)
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
if response.status != 503: # checking for service unavailitbility
|
|
59
|
+
return await response.json()
|
|
60
|
+
else:
|
|
61
|
+
return response
|
|
62
|
+
except:
|
|
63
|
+
raise Exception("Error while getting {}: {}".format(url, response))
|
|
64
|
+
|
|
65
|
+
async def post(self, service_url, data, auth_required=False, contentType="", wallet=""):
|
|
66
|
+
"""
|
|
67
|
+
Makes a POST request and returns the results
|
|
68
|
+
Inputs:
|
|
69
|
+
- service_url(str): the url to make the request to.
|
|
70
|
+
- data(dict): the data to post with POST request.
|
|
71
|
+
- auth_required(bool): indicates whether authorization is required for the call or not.
|
|
72
|
+
"""
|
|
73
|
+
url = self._create_url(service_url)
|
|
74
|
+
# print("url", url, data)
|
|
75
|
+
response = None
|
|
76
|
+
|
|
77
|
+
headers = {
|
|
78
|
+
'Content-Type': 'application/json'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if auth_required:
|
|
82
|
+
headers['Authorization'] = 'Bearer {}'.format(self.auth_token)
|
|
83
|
+
headers["x-wallet-address"] = wallet
|
|
84
|
+
|
|
85
|
+
if contentType != "":
|
|
86
|
+
headers['Content-Type'] = contentType
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
import json
|
|
90
|
+
json_data = json.dumps(data)
|
|
91
|
+
|
|
92
|
+
response = await self.client.post(
|
|
93
|
+
url=url,
|
|
94
|
+
data=json_data,
|
|
95
|
+
headers=headers,
|
|
96
|
+
proxy=self.proxy,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
if response.status != 503: # checking for service unavailitbility
|
|
101
|
+
return await response.json()
|
|
102
|
+
else:
|
|
103
|
+
return response
|
|
104
|
+
except:
|
|
105
|
+
raise Exception(
|
|
106
|
+
"Error while posting to {}: {}".format(url, response))
|
|
107
|
+
|
|
108
|
+
async def delete(self, service_url, data, auth_required=False):
|
|
109
|
+
"""
|
|
110
|
+
Makes a DELETE request and returns the results
|
|
111
|
+
Inputs:
|
|
112
|
+
- service_url(str): the url to make the request to.
|
|
113
|
+
- data(dict): the data to post with POST request.
|
|
114
|
+
- auth_required(bool): indicates whether authorization is required for the call or not.
|
|
115
|
+
"""
|
|
116
|
+
url = self._create_url(service_url)
|
|
117
|
+
|
|
118
|
+
response = None
|
|
119
|
+
if auth_required:
|
|
120
|
+
headers = {
|
|
121
|
+
'Authorization': 'Bearer {}'.format(self.auth_token)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
response = await self.client.delete(
|
|
125
|
+
url=url,
|
|
126
|
+
data=data,
|
|
127
|
+
headers=headers,
|
|
128
|
+
proxy=self.proxy,
|
|
129
|
+
)
|
|
130
|
+
else:
|
|
131
|
+
response = await self.client.delete(url=url, data=data, proxy=self.proxy)
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
return await response.json()
|
|
135
|
+
except:
|
|
136
|
+
raise Exception(
|
|
137
|
+
"Error while posting to {}: {}".format(url, response))
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
Private methods
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
def _create_url(self, path):
|
|
144
|
+
"""
|
|
145
|
+
Appends namespace to server url
|
|
146
|
+
"""
|
|
147
|
+
return "{}/{}".format(self.server_url.rstrip("/"), path.lstrip("/"))
|