diff --git a/pyproject.toml b/pyproject.toml index 2a2de62..c5ec2cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [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" diff --git a/src/bluefin_v2_client/api_service.py b/src/bluefin_v2_client/api_service.py index 35b5a10..e89d40c 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: + 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: + 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: + 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": "" }, }