From 40bad7acf125a536442b81bbb479d93b6739135b Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Fri, 15 Sep 2023 21:25:50 +0500 Subject: [PATCH 1/3] added uuid implementation --- pyproject.toml | 37 +------------- src/bluefin_v2_client/api_service.py | 74 ++++++++++++++++------------ src/bluefin_v2_client/client.py | 6 +++ src/bluefin_v2_client/constants.py | 11 +++++ 4 files changed, 61 insertions(+), 67 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2a2de62..a330ba9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,45 +1,12 @@ [project] name = "bluefin_v2_client" -version = "2.5.0" +version = "2.5.1" description = "Library to interact with Bluefin exchange protocol including its off-chain api-gateway and on-chain contracts" readme = "README.md" requires-python = ">=3.8" keywords = ["bluefin", "exchange", "decentralized", "perpetuals", "blockchain"] dependencies = [ - 'requests ~= 2.31.0', - 'aiohttp ~= 3.8.5', - 'aiosignal ~= 1.3.1', - 'asn1crypto ~= 1.5.1', - 'async-timeout ~= 4.0.3', - 'attrs ~= 23.1.0', - 'bidict ~= 0.22.1', - 'bip-utils ~= 2.7.1', - 'cbor2 ~= 5.4.6', - 'cffi ~= 1.15.1', - 'charset-normalizer ~= 3.2.0', - 'coincurve ~= 17.0.0', - 'crcmod ~= 1.7', - 'ecdsa ~= 0.18.0', - 'ed25519-blake2b ~= 1.4', - 'frozenlist ~= 1.4.0', - 'gevent ~= 23.7.0', - 'greenlet ~= 2.0.2', - 'idna ~= 3.4', - 'multidict ~= 6.0.4', - 'netifaces ~= 0.10.6', - 'py-sr25519-bindings ~= 0.2.0', - 'pycparser ~= 2.21', - 'pycryptodome ~= 3.18.0', - 'PyNaCl ~= 1.5.0', - 'python-engineio ~= 4.6.0', - 'python-socketio ~= 5.8.0', - 'six ~= 1.16.0', - 'socketio ~= 0.2.1', - 'websocket ~= 0.2.1', - 'websocket-client ~= 1.6.2', - 'yarl ~= 1.9.2', - 'zope.event ~= 5.0', - 'zope.interface ~= 6.0' + 'requests ~= 2.31.0' ] [project.urls] diff --git a/src/bluefin_v2_client/api_service.py b/src/bluefin_v2_client/api_service.py index 35b5a10..66d1b6b 100644 --- a/src/bluefin_v2_client/api_service.py +++ b/src/bluefin_v2_client/api_service.py @@ -17,26 +17,28 @@ async def close_session(self): async def get(self, service_url, query={}, auth_required=False): """ - Makes a GET request and returns the results - Inputs: - - service_url(str): the url to make the request to. - - query(dict): the get query. - - auth_required(bool): indicates whether authorization is required for the call or not. + Makes a GET request and returns the results + Inputs: + - service_url(str): the url to make the request to. + - query(dict): the get query. + - auth_required(bool): indicates whether authorization is required for the call or not. """ + url = self._create_url(service_url) response = None if auth_required: + headers = { + 'Authorization': 'Bearer {}'.format(self.auth_token), + 'x-api-token': self.api_token or '' + } + if self.uuid and self.uuid is not "": + headers['x-mm-id'] = self.uuid + response = await self.client.get( url, params=query, - headers={ - "Authorization": "Bearer {}".format(self.auth_token) - if self.auth_token - else "", - "x-api-token": self.api_token or "", - "x-mm-id": self.uuid or "", - }, + headers=headers ) else: response = await self.client.get(url, params=query) @@ -51,22 +53,23 @@ async def get(self, service_url, query={}, auth_required=False): async def post(self, service_url, data, auth_required=False, contentType=""): """ - Makes a POST request and returns the results - Inputs: - - service_url(str): the url to make the request to. - - data(dict): the data to post with POST request. - - auth_required(bool): indicates whether authorization is required for the call or not. + Makes a POST request and returns the results + Inputs: + - service_url(str): the url to make the request to. + - data(dict): the data to post with POST request. + - auth_required(bool): indicates whether authorization is required for the call or not. """ url = self._create_url(service_url) response = None if auth_required: headers = { - "Authorization": "Bearer {}".format(self.auth_token), - "x-mm-id": self.uuid or "", + 'Authorization': 'Bearer {}'.format(self.auth_token) } + if self.uuid and self.uuid is not "": + headers['x-mm-id'] = self.uuid if contentType is not "": - headers["Content-type"] = contentType + headers['Content-type'] = contentType response = await self.client.post(url=url, data=data, headers=headers) else: @@ -78,35 +81,39 @@ async def post(self, service_url, data, auth_required=False, contentType=""): else: return response except: - raise Exception("Error while posting to {}: {}".format(url, response)) + raise Exception( + "Error while posting to {}: {}".format(url, response)) async def delete(self, service_url, data, auth_required=False): """ - Makes a DELETE request and returns the results - Inputs: - - service_url(str): the url to make the request to. - - data(dict): the data to post with POST request. - - auth_required(bool): indicates whether authorization is required for the call or not. + Makes a DELETE request and returns the results + Inputs: + - service_url(str): the url to make the request to. + - data(dict): the data to post with POST request. + - auth_required(bool): indicates whether authorization is required for the call or not. """ url = self._create_url(service_url) response = None if auth_required: + headers = { + 'Authorization': 'Bearer {}'.format(self.auth_token) + } + if self.uuid and self.uuid is not "": + headers['x-mm-id'] = self.uuid + response = await self.client.delete( url=url, data=data, - headers={ - "Authorization": "Bearer {}".format(self.auth_token), - "x-mm-id": self.uuid or "", - }, - ) + headers=headers) else: response = await self.client.delete(url=url, data=data) try: return await response.json() except: - raise Exception("Error while posting to {}: {}".format(url, response)) + raise Exception( + "Error while posting to {}: {}".format(url, response)) """ Private methods @@ -117,3 +124,6 @@ def _create_url(self, path): Appends namespace to server url """ return "{}{}".format(self.server_url, path) + + def set_uuid(self, uuid): + self.uuid = uuid diff --git a/src/bluefin_v2_client/client.py b/src/bluefin_v2_client/client.py index 9c9272f..7fbe4b4 100644 --- a/src/bluefin_v2_client/client.py +++ b/src/bluefin_v2_client/client.py @@ -93,6 +93,12 @@ async def onboard_user(self, token: str = None): return user_auth_token + + def set_uuid(self, uuid): + self.apis.set_uuid(uuid) + self.dms_api.set_uuid(uuid) + + async def authorize_signed_hash(self, signed_hash: str): """ Registers user as an authorized user on server and returns authorization token. diff --git a/src/bluefin_v2_client/constants.py b/src/bluefin_v2_client/constants.py index 83346c0..eb0e4bf 100644 --- a/src/bluefin_v2_client/constants.py +++ b/src/bluefin_v2_client/constants.py @@ -6,6 +6,7 @@ "dmsURL": "https://api.sui-staging.bluefin.io/dead-man-switch", "webSocketURL": "wss://notifications.api.sui-staging.bluefin.io", "onboardingUrl": "https://testnet.bluefin.io", + "UUID": "" }, "SUI_PROD": { "url": "https://fullnode.testnet.sui.io:443", @@ -14,6 +15,16 @@ "dmsURL": "https://api.sui-prod.bluefin.io/dead-man-switch", "webSocketURL": "wss://notifications.api.sui-prod.bluefin.io", "onboardingUrl": "https://trade-sui.bluefin.exchange", + "UUID": "" + }, + "SUI_PROD_INTERNAL": { + "url": "https://fullnode.testnet.sui.io:443", + "apiGateway": "https://dapi.api.sui-prod.int.bluefin.io", + "socketURL": "wss://dapi.api.sui-prod.int.bluefin.io", + "dmsURL": "https://api.sui-prod.int.bluefin.io/dead-man-switch", + "webSocketURL": "wss://notifications.api.sui-prod.int.bluefin.io", + "onboardingUrl": "https://trade-sui.bluefin.exchange", + "UUID": "" }, } From 292c583c88388ad2950f120883553b534a314c14 Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Fri, 15 Sep 2023 21:37:20 +0500 Subject: [PATCH 2/3] fixed pytoml --- pyproject.toml | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a330ba9..c5ec2cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,40 @@ readme = "README.md" requires-python = ">=3.8" keywords = ["bluefin", "exchange", "decentralized", "perpetuals", "blockchain"] dependencies = [ - 'requests ~= 2.31.0' + 'requests ~= 2.31.0', + 'aiohttp ~= 3.8.5', + 'aiosignal ~= 1.3.1', + 'asn1crypto ~= 1.5.1', + 'async-timeout ~= 4.0.3', + 'attrs ~= 23.1.0', + 'bidict ~= 0.22.1', + 'bip-utils ~= 2.7.1', + 'cbor2 ~= 5.4.6', + 'cffi ~= 1.15.1', + 'charset-normalizer ~= 3.2.0', + 'coincurve ~= 17.0.0', + 'crcmod ~= 1.7', + 'ecdsa ~= 0.18.0', + 'ed25519-blake2b ~= 1.4', + 'frozenlist ~= 1.4.0', + 'gevent ~= 23.7.0', + 'greenlet ~= 2.0.2', + 'idna ~= 3.4', + 'multidict ~= 6.0.4', + 'netifaces ~= 0.10.6', + 'py-sr25519-bindings ~= 0.2.0', + 'pycparser ~= 2.21', + 'pycryptodome ~= 3.18.0', + 'PyNaCl ~= 1.5.0', + 'python-engineio ~= 4.6.0', + 'python-socketio ~= 5.8.0', + 'six ~= 1.16.0', + 'socketio ~= 0.2.1', + 'websocket ~= 0.2.1', + 'websocket-client ~= 1.6.2', + 'yarl ~= 1.9.2', + 'zope.event ~= 5.0', + 'zope.interface ~= 6.0' ] [project.urls] From 7f1a24c908d41b54e2de34bff9c498311d572938 Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Sat, 16 Sep 2023 01:48:19 +0500 Subject: [PATCH 3/3] fixed extra condition --- src/bluefin_v2_client/api_service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bluefin_v2_client/api_service.py b/src/bluefin_v2_client/api_service.py index 66d1b6b..e89d40c 100644 --- a/src/bluefin_v2_client/api_service.py +++ b/src/bluefin_v2_client/api_service.py @@ -32,7 +32,7 @@ async def get(self, service_url, query={}, auth_required=False): 'Authorization': 'Bearer {}'.format(self.auth_token), 'x-api-token': self.api_token or '' } - if self.uuid and self.uuid is not "": + if self.uuid: headers['x-mm-id'] = self.uuid response = await self.client.get( @@ -65,7 +65,7 @@ async def post(self, service_url, data, auth_required=False, contentType=""): headers = { 'Authorization': 'Bearer {}'.format(self.auth_token) } - if self.uuid and self.uuid is not "": + if self.uuid: headers['x-mm-id'] = self.uuid if contentType is not "": @@ -99,7 +99,7 @@ async def delete(self, service_url, data, auth_required=False): headers = { 'Authorization': 'Bearer {}'.format(self.auth_token) } - if self.uuid and self.uuid is not "": + if self.uuid: headers['x-mm-id'] = self.uuid response = await self.client.delete(