From a9a0918f5149bbb954d69cc4832cd066e694bfe9 Mon Sep 17 00:00:00 2001 From: Akhilleshgoswami Date: Fri, 11 Nov 2022 13:43:04 +0530 Subject: [PATCH] documenting code --- components/cruize_data_manager.py | 17 ++++ components/dydx_order_manager.py | 78 ++++++++++++++++--- components/firebase_data_manager.py | 42 ++++++++++ components/price_floor_manager.py | 22 +++++- components/transaction_manager.py | 32 ++++++++ cruize_operations/views.py | 18 ++--- deployment_scripts/clean.sh | 2 +- deployment_scripts/deploy.sh | 1 + deployment_scripts/install_requirements.sh | 1 + deployment_scripts/stop.sh | 2 +- dydx_user/serializers/__init__.py | 1 + .../serializers/dydx_user_serializers.py | 9 +++ dydx_user/views.py | 27 ++++++- order/serializers/__init__.py | 1 + order/serializers/order_serializer.py | 4 + order/views.py | 14 +++- services/celery/celery.py | 13 +++- settings_config/common.py | 1 + settings_config/production_settings.py | 4 +- 19 files changed, 254 insertions(+), 35 deletions(-) create mode 100644 dydx_user/serializers/__init__.py create mode 100644 dydx_user/serializers/dydx_user_serializers.py diff --git a/components/cruize_data_manager.py b/components/cruize_data_manager.py index 59eeb21..9e9262a 100644 --- a/components/cruize_data_manager.py +++ b/components/cruize_data_manager.py @@ -3,8 +3,19 @@ from components import FirebaseDataManager from utilities import cruize_constants +""" +class :: CruizeDataManager - is used to manage the db data operation for backend. such as storing data on db, getting data form db etc. +""" + class CruizeDataManager(object): + + """ + method :: save_asset_tvl - is used to store total TLV of an asset. + params :: asset_data - contain the details of asset TLV. + return :: None + """ + def save_asset_tvl(self, asset_data): firebase_db_manager_obj = FirebaseDataManager() asset_tvl_data = firebase_db_manager_obj.fetch_data( @@ -32,6 +43,12 @@ def save_asset_tvl(self, asset_data): data=tvl_data, ) + """ + method :: fetch_user_transactions - is used to fetch the user's transaction from DB . + params :: user_data - contain the details of user's such as user's wallet address. + return :: user's transaction. + """ + def fetch_user_transactions(self, user_data): firebase_db_obj = FirebaseDataManager() firebase_data = firebase_db_obj.fetch_sub_collections( diff --git a/components/dydx_order_manager.py b/components/dydx_order_manager.py index d9dc2fd..8f6ed28 100644 --- a/components/dydx_order_manager.py +++ b/components/dydx_order_manager.py @@ -1,6 +1,5 @@ import time from datetime import datetime, timedelta - import pandas from dateutil.relativedelta import relativedelta from dydx3 import constants @@ -15,7 +14,10 @@ from utilities.enums import AssetCodes -# class: DydxOrderManager - is responsible for managing order on dydx. +"""class::DydxOrderManager is responsible for managing operation on Dydx + such us opening and closing order on dydx, calculating open and close price for position, + computing market volatility for an asset etc, to perform all of these task there are function written is the class + """ class DydxOrderManager: @@ -27,16 +29,27 @@ def __init__(self, dydx_client=None): self.firebase_data_manager_obj = FirebaseDataManager() self.dydx_client = dydx_client + """ + method :: create_order - is used to open and close orders on dydx. + params :: order_params - contains all the necessary parameter to open an order on dydx. + params :: dydx_client - is a dydx client. with the help of this + client we perform operation on dydx it's different for the different asset. + """ + def create_order(self, order_params, dydx_client): dydx_order = DydxOrder() - # we have to keep separate volume of btc and eth to open different position on dydx. - # total_btc_volume * 5 --> would be the open size for the btc - # total_eth_volume * 5 --> would be the open size for eth order_information = dydx_order.create_order(order_params, dydx_client) dydx_order_details = vars(order_information) dydx_order_details = dydx_order_details["data"]["order"] return dydx_order_details + """ + method :: calculate_open_close_price - is used to calculate the open and close price for orders on dydx. + params :: asset_pair - is the pair of asset such as ETH-USD,BTC-USD. + params :: eth_order_size - it is the size of the order for which we have to calculate the open and close price. + params :: symbol - symbol is the sign for the asset ETH-USD,LINK-USD. + """ + def calculate_open_close_price(self, asset_pair, eth_order_size, symbol): bids_consumed = 0 dydx_order_obj = DydxOrder() @@ -116,10 +129,10 @@ def create_order_params(self, side, market, size, market_price, dydx_client): return order_params """ - :method - calculate_asst_volume. - :params - market_price:current market price of asset. - :params - total_volume:total volume of asset. - :return - asset total value in usd. + method :: get_asset_price_and_size - is used to get the total equity of an asset multiply by leverage and the market price of an asset. + params :: asset_address - is the chainlink Oracal address . + params :: dydx_client - is a dydx client. with the help of this client we perform operation on dydx it's different for the different asset. + return :: asset total equity in dydx multiply by leverage and the market price of the asset. """ def get_asset_price_and_size(self, asset_address, dydx_client): @@ -136,6 +149,12 @@ def get_asset_price_and_size(self, asset_address, dydx_client): return asset_details + """ + method :: compute_market_volatility - is used compute the market volatility for an asset. + params :: prices_data - an array of 6 months price data. + return :: sigma ema and mu ema for an given asset price data. + """ + def compute_market_volatility(self, prices_data): volatility_data = {"sigma_ema": None, "mu_ema": None} percentage_EMA = [] @@ -149,6 +168,11 @@ def compute_market_volatility(self, prices_data): volatility_data["mu_ema"] = float(mu_ema) return volatility_data + """ + method :: market_volatility - is used compute the market volatility for an asset. + params :: symbol - symbol of an asset such as ETH-USD, BTC-USD. + """ + def market_volatility(self, symbol): volatility_data = {} months_price_data = [] @@ -223,6 +247,13 @@ def market_volatility(self, symbol): data={"ema": volatility_data}, document=symbol, collection_name="ema_data" ) + """ + method :: position_status - is used to get open position status on dydx for an asset. + params :: collection_name - collection for the asset ex ETHBUSD,BTCBUSD. + params :: symbol - symbol of an asset such as ETH-USD, BTC-USD. + return :: True if the short position is open on dydx else False. + """ + def position_status(self, collection_name, symbol): # fetch data from db @@ -238,6 +269,14 @@ def position_status(self, collection_name, symbol): return False return position_status[symbol] + """ + method :: set_position_status - is used to set open position status on dydx for an asset. + params :: collection_name - collection for the asset ex ETHBUSD,BTCBUSD. + params :: symbol - symbol of an asset such as ETH-USD, BTC-USD. + params :: status - status of an position ex. True or false. + return :: None. + """ + def set_position_status(self, collection_name, symbol, status): # store data to db self.firebase_data_manager_obj.store_data( @@ -248,6 +287,13 @@ def deposit_test_fund(self, dydx_client): dydx_p_client = dydx_client["dydx_instance"] return dydx_p_client.private.request_testnet_tokens() + """ + method :: deposit_to_dydx - is used to deposit USDC to dydx. + params :: amount - USDC value in number. + params ::dydx_client - is a dydx client. with the help of this client we perform operation on dydx it's different for the different asset. + return :: transaction hash for deposit transaction. + """ + def deposit_to_dydx(self, amount, dydx_client): try: dydx_p_client = dydx_client["dydx_instance"] @@ -264,6 +310,13 @@ def deposit_to_dydx(self, amount, dydx_client): except Exception as e: raise Exception(e) + """ + method :: withdraw_from_dydx - is used to withdraw USDC from dydx. + params :: recipient_address - the account in which we want to withdraw fund. + params ::dydx_client - is a dydx client. with the help of this client we perform operation on dydx it's different for the different asset. + return :: transaction hash for deposit transaction. + """ + def withdraw_from_dydx(self, recipient_address, dydx_client): try: dydx_p_client = dydx_client["dydx_instance"] @@ -278,8 +331,11 @@ def withdraw_from_dydx(self, recipient_address, dydx_client): except Exception as e: raise Exception(e) - # open order on dydx celery task algo - # asset type -- ETH-USD,BTC-USD etc + """ + method :: open_order_on_dydx - is used to open orders on dydx. it has algorithm to open order's on dydx + params :: order_details - contains all the necessary parameter to open an order on dydx. + """ + def open_order_on_dydx(self, order_details): dydx_asset_instance = asset_dydx_instance[order_details["asset_pair"]] dydx_order_manager = DydxOrderManager(dydx_asset_instance) diff --git a/components/firebase_data_manager.py b/components/firebase_data_manager.py index 0353007..30b9b71 100644 --- a/components/firebase_data_manager.py +++ b/components/firebase_data_manager.py @@ -4,24 +4,46 @@ from services.firebase_cloud_client import FirebaseClient from settings_config import firebase_client +"""class :: FirebaseDataManager is used to manage the firebase db oprations such as storing,fetching and updating the +data. """ + class FirebaseDataManager(object): def __init__(self): self.firebase_client = firebase_client + """method :: get_firebase_client - is used to get the firebase client. + return :: firebase client. + """ + def get_firebase_client(self): if self.firebase_client is None: self.firebase_client = FirebaseClient().get_firebase_client return self.firebase_client + """ + method :: update_data - is used to update the data on firebase db + return :: None. + """ + def update_data(self, order_id, collection, data): self.firebase_client = self.get_firebase_client() self.firebase_client.collection(collection).document(order_id).update(data) + """ + method :: store_data - is used to store the data on firebase db + return :: None. + """ + def store_data(self, data, document, collection_name): self.firebase_client = self.get_firebase_client() self.firebase_client.collection(collection_name).document(document).set(data) + """ + method :: bulk_store - is used to store the data on firebase db in bulk . + return :: None. + """ + def bulk_store(self, data, collection_name, field): self.firebase_client = self.get_firebase_client() batch = self.firebase_client.batch() @@ -30,6 +52,11 @@ def bulk_store(self, data, collection_name, field): batch.set(write, {field: str(value)}) batch.commit() + """ + method :: store_sub_collections - is used to store sub_collections the data on firebase db . + return :: None. + """ + def store_sub_collections( self, data, collection, document_name, sub_collection, sub_document ): @@ -39,6 +66,11 @@ def store_sub_collections( sub_collection ).document(sub_document).set(data) + """ + method :: fetch_sub_collections - is used to fetch sub_collections from the firebase db . + return :: data of sub collection. + """ + def fetch_sub_collections(self, collection, document_name, sub_collection): self.firebase_client = self.get_firebase_client() firebase_data = ( @@ -49,6 +81,11 @@ def fetch_sub_collections(self, collection, document_name, sub_collection): ) return firebase_data + """ + method :: fetch_data - is used to fetch data from the firebase db . + return :: collection data. + """ + def fetch_data(self, collection_name, document_name): self.firebase_client = self.get_firebase_client() firebase_data = ( @@ -60,6 +97,11 @@ def fetch_data(self, collection_name, document_name): firebase_data = vars(firebase_data) return firebase_data.get("_data", None) + """ + method :: fetch_collections - is used to fetch collections from the firebase db . + return :: collection . + """ + def fetch_collections(self, collection_name): self.firebase_client = self.get_firebase_client() collection_obj = self.firebase_client.collection(collection_name) diff --git a/components/price_floor_manager.py b/components/price_floor_manager.py index 81cf6bb..1901850 100644 --- a/components/price_floor_manager.py +++ b/components/price_floor_manager.py @@ -2,9 +2,18 @@ from services.market_data.coingecko import CoinGecko firebase_data_manager_obj = FirebaseDataManager() +"""class :: PriceFloorManager is used to manage the price floor data such a setting up price floor , retrieving price floor. +etc. +""" class PriceFloorManager: + """ + method :: set_price_floor - is used to set the price floor of an given asset. + params :: asset_name - name of the asset such as bitcoin etc. + params :: number_of_days - for how much time you want to calculate the price floor. + """ + def set_price_floor(self, asset_name, number_of_days=30): coin_gecko = CoinGecko() @@ -18,7 +27,7 @@ def set_price_floor(self, asset_name, number_of_days=30): prices.sort(reverse=True) asset_peak_price = prices[0] current_price_floor = asset_peak_price * 0.60 - # TODO: if perivous_price_floor < current_price_floor : update the price floor, else don't update + # TODO: if pervious_price_floor < current_price_floor : update the price floor, else don't update # get price floor firebase_data_manager_obj.store_data( data={ @@ -32,6 +41,12 @@ def set_price_floor(self, asset_name, number_of_days=30): except Exception as e: raise Exception(e) + """ + method :: get_asset_price_floor - is used to get the price floor of an given asset. + params :: asset_name - name of the asset such as bitcoin etc. + return :: price floor of given asset. + """ + def get_asset_price_floor(self, asset_name): asset_price_floor_details = firebase_data_manager_obj.fetch_data( document_name=asset_name, collection_name="price_floor_data" @@ -39,6 +54,11 @@ def get_asset_price_floor(self, asset_name): asset_price_floor_details = asset_price_floor_details.get("price_floor") return asset_price_floor_details + """ + method :: get_assets_price_floors - is used to get the price floors of an given all asset that are supported by cruize. + return :: price floors of assets. + """ + def get_assets_price_floors(self): asset_price_floor_details = firebase_data_manager_obj.fetch_collections( "price_floor_data" diff --git a/components/transaction_manager.py b/components/transaction_manager.py index 361c118..b905bc5 100644 --- a/components/transaction_manager.py +++ b/components/transaction_manager.py @@ -4,12 +4,21 @@ from services.contracts import LoadContracts from utilities import cruize_constants +"""class :: TransactionManager - is used to manage the on chain transactions for our dydx wallets.""" + class TransactionManager: def __init__(self): self.load_contract = LoadContracts() self.w3 = self.load_contract.web3_provider() + """ + method :: sign_transactions - is used to sing transactions for wallets. + params :: transaction - is the transaction details. + params :: private_key - private key of cruize wallet. + returns :: sing transaction. + """ + def sign_transactions(self, transaction, private_key): signed_transaction = self.w3.eth.account.sign_transaction( transaction, private_key @@ -19,6 +28,18 @@ def sign_transactions(self, transaction, private_key): ) return str(self.w3.toHex(transaction_hash)) + """ + method :: create_transaction - is used to create transactions for wallets. + params :: nonce - nonce of cruize wallets. + params :: private_key - private key of cruize wallet. + params :: max_fee_per_gas - max fee per gas for transactions. + params :: from_account - wallet address. + params :: chain_id - id for chain. + params :: eth_value - value of eth in the transactions. + return :: transaction. + + """ + def create_transaction( self, nonce, @@ -40,6 +61,11 @@ def create_transaction( transaction["value"] = self.w3.toWei(eth_value, "ether") return transaction + """ + method :: transaction_gas_price - is used to predict the transactions gas fee. + returns ::transaction gas price. + """ + def transaction_gas_price(self, max_wait_seconds, sample_size, probability): price_strategy = self.get_gas_price_strategy( max_wait_seconds, sample_size, probability @@ -60,6 +86,12 @@ def get_gas_price_strategy( ) return price_strategy + """ + method :: build_transaction - is used to build the transactions . + params :: wallet_address - wallet address of cruize wallet. + returns :: build transaction + """ + def build_transaction(self, wallet_address, eth_value=None): gas_price = self.transaction_gas_price( cruize_constants.MAX_WAIT_SECONDS, diff --git a/cruize_operations/views.py b/cruize_operations/views.py index cb6a837..5ec40fe 100644 --- a/cruize_operations/views.py +++ b/cruize_operations/views.py @@ -13,7 +13,7 @@ from cruize_operations.serilaizer import TvlSerializer from services.avve_asset_apy import AaveApy from services.contracts.cruize.cruize_contract import Cruize -from utilities import cruize_constants + price_floor_manager = PriceFloorManager() @@ -95,10 +95,10 @@ def fetch_user_transactions(self, request): return Response(result, status.HTTP_500_INTERNAL_SERVER_ERROR) def price_floor(self, request): - result = {"result": None, "error": None} + result = {"message": None, "error": None} try: - result["result"] = price_floor_manager.get_assets_price_floors() + result["message"] = price_floor_manager.get_assets_price_floors() return Response(result, status.HTTP_200_OK) except Exception as e: result["error"] = e @@ -109,10 +109,10 @@ def set_price_floor(self, request): serializer = serializer_class(data=request.data) serializer.is_valid(raise_exception=True) asset_data = serializer.data - result = {"result": None, "error": None} + result = {"message": None, "error": None} try: - result["result"] = price_floor_manager.set_price_floor( + result["message"] = price_floor_manager.set_price_floor( asset_data["asset_name"], asset_data["days"] ) return Response(result, status.HTTP_200_OK) @@ -121,10 +121,10 @@ def set_price_floor(self, request): return Response(result, status.HTTP_500_INTERNAL_SERVER_ERROR) def fetch_asset_apy(self, request): - result = {"result": None, "error": None} + result = {"message": None, "error": None} try: aave_apy_obj = AaveApy() - result["result"] = aave_apy_obj.fetch_asset_apys() + result["message"] = aave_apy_obj.fetch_asset_apys() return Response(result, status.HTTP_200_OK) except Exception as e: result["error"] = e @@ -135,11 +135,11 @@ def save_asset_tvl(self, request): serializer = serializer_class(data=request.data) serializer.is_valid(raise_exception=True) asset_data = serializer.validated_data - result = {"result": None, "error": None} + result = {"message": None, "error": None} try: cruize_data_manager_obj = CruizeDataManager() cruize_data_manager_obj.save_asset_tvl(asset_data) - result["result"] = "success" + result["message"] = "success" return Response(result, status.HTTP_200_OK) except Exception as e: result["error"] = e diff --git a/deployment_scripts/clean.sh b/deployment_scripts/clean.sh index e1a9ead..6844ade 100644 --- a/deployment_scripts/clean.sh +++ b/deployment_scripts/clean.sh @@ -1,5 +1,5 @@ #!/bin/bash - +# this file is used to clean the project from the server so that we can redeploy it. sudo rm -rf /home/ubuntu/trident if [ -d /home/ubuntu/trident/ ]; then rm -rf /home/ubuntu/trident/ diff --git a/deployment_scripts/deploy.sh b/deployment_scripts/deploy.sh index e46aace..df15c32 100644 --- a/deployment_scripts/deploy.sh +++ b/deployment_scripts/deploy.sh @@ -1,3 +1,4 @@ #!/bin/bash +# this file is used on the server to deploy the app . sudo systemctl restart gunicorn diff --git a/deployment_scripts/install_requirements.sh b/deployment_scripts/install_requirements.sh index 109eb23..5b4a862 100644 --- a/deployment_scripts/install_requirements.sh +++ b/deployment_scripts/install_requirements.sh @@ -1,5 +1,6 @@ #!/bin/bash +# this file used while deploying the app on sever to install required dependency to run the app . sudo apt-get install python3-pip python3-dev nginx sudo apt-get install -y python-psycopg2 libncurses5-dev libffi libffi-devel libxml2-devel libxslt-devel libxslt1-dev sudo apt-get install -y python-lxml python-devel gcc patch python-setuptools diff --git a/deployment_scripts/stop.sh b/deployment_scripts/stop.sh index 3450b4f..5240c52 100644 --- a/deployment_scripts/stop.sh +++ b/deployment_scripts/stop.sh @@ -1,3 +1,3 @@ #!/bin/bash - +# this file is used on the server to stop the running application . sudo systemctl stop gunicorn \ No newline at end of file diff --git a/dydx_user/serializers/__init__.py b/dydx_user/serializers/__init__.py new file mode 100644 index 0000000..f55f034 --- /dev/null +++ b/dydx_user/serializers/__init__.py @@ -0,0 +1 @@ +from .dydx_user_serializers import PositionidSerializers, RegisterUserSerializers diff --git a/dydx_user/serializers/dydx_user_serializers.py b/dydx_user/serializers/dydx_user_serializers.py new file mode 100644 index 0000000..ed8c265 --- /dev/null +++ b/dydx_user/serializers/dydx_user_serializers.py @@ -0,0 +1,9 @@ +from rest_framework import serializers + + +class PositionidSerializers(serializers.Serializer): + asset_pair = serializers.CharField(required=True) + + +class RegisterUserSerializers(serializers.Serializer): + asset_pair = serializers.CharField(required=True) diff --git a/dydx_user/views.py b/dydx_user/views.py index 830d4ae..d27e0d5 100644 --- a/dydx_user/views.py +++ b/dydx_user/views.py @@ -2,21 +2,32 @@ from rest_framework import status from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet + +from dydx_user.serializers import PositionidSerializers, RegisterUserSerializers from services import DydxAdmin +from settings_config import asset_dydx_instance from utilities.error_handler import ErrorHandler -# will fix it letter . + class User(GenericViewSet): def initialize(self): self.dydx_admin_obj = DydxAdmin() self.error_handler = ErrorHandler() + # return : position id of account's def position_id(self, request): + # query params will contain the asset pair name ex ETH-USD BTC-USD . + request_body = request.query_params + serializer_class = PositionidSerializers + serializer = serializer_class(data=request_body) + serializer.is_valid(raise_exception=True) + data = serializer.validated_data self.initialize() - result = {"message": None, "error": None} try: - position_id = self.dydx_admin_obj.get_position_id() + position_id = self.dydx_admin_obj.get_position_id( + asset_dydx_instance[data["asset_pair"]] + ) result["message"] = {"position_id": position_id} return Response(result, status.HTTP_200_OK) except DydxApiError or ValueError as e: @@ -27,10 +38,18 @@ def position_id(self, request): return Response(result, status.HTTP_500_INTERNAL_SERVER_ERROR) def register_user(self, request): + # query params will contain the asset pair name ex ETH-USD BTC-USD . self.initialize() + request_body = request.query_params + serializer_class = RegisterUserSerializers + serializer = serializer_class(data=request_body) + serializer.is_valid(raise_exception=True) + data = serializer.validated_data result = {"message": None, "error": None} try: - user = self.dydx_admin_obj.register_user() + user = self.dydx_admin_obj.register_user( + asset_dydx_instance[data["asset_pair"]] + ) if user is None: raise Exception("Fail to register") result["message"] = user["data"]["signature"] diff --git a/order/serializers/__init__.py b/order/serializers/__init__.py index 61a9ad6..442cc0b 100644 --- a/order/serializers/__init__.py +++ b/order/serializers/__init__.py @@ -2,4 +2,5 @@ OrderRequestSerializer, CancelOrderRequestSerializer, FirestoreOrdersRequestSerializer, + DydxAllOrdersRequestSerializer, ) diff --git a/order/serializers/order_serializer.py b/order/serializers/order_serializer.py index 0ae6f66..9599644 100644 --- a/order/serializers/order_serializer.py +++ b/order/serializers/order_serializer.py @@ -21,3 +21,7 @@ class CancelOrderRequestSerializer(serializers.Serializer): class FirestoreOrdersRequestSerializer(serializers.Serializer): order_id = serializers.CharField(required=False) + + +class DydxAllOrdersRequestSerializer(serializers.Serializer): + type = serializers.CharField(required=True) diff --git a/order/views.py b/order/views.py index e7377e3..e6c4298 100644 --- a/order/views.py +++ b/order/views.py @@ -7,8 +7,10 @@ OrderRequestSerializer, CancelOrderRequestSerializer, FirestoreOrdersRequestSerializer, + DydxAllOrdersRequestSerializer, ) from services import DydxOrder, DydxAdmin +from settings_config import dydx_p_client_obj, asset_dydx_instance from utilities.error_handler import ErrorHandler @@ -38,9 +40,12 @@ def create(self, request): order_data["market"], order_data["size"], order_data["price"], + dydx_p_client_obj["side"], ) - dydx_order_details = self.dydx_order_obj.create_order(order_data) + dydx_order_details = self.dydx_order_obj.create_order( + order_data, asset_dydx_instance["side"] + ) dydx_order_details = vars(dydx_order_details) result["message"] = dydx_order_details["data"]["order"] @@ -84,12 +89,15 @@ def cancel(self, request): """ def dydx_order(self, request): - result = {"message": None, "error": None} + self.serializer_class = DydxAllOrdersRequestSerializer + serializer = self.serializer_class(data=request.data) + serializer.is_valid(raise_exception=True) + validate_data = serializer.data dydx_admin_obj = DydxAdmin() error_handler = ErrorHandler() try: - orders = dydx_admin_obj.get_account() + orders = dydx_admin_obj.get_account(validate_data["type"]) orders = vars(orders) orders_data = orders["data"]["account"]["openPositions"] if not orders_data: diff --git a/services/celery/celery.py b/services/celery/celery.py index 6b577b9..c107b45 100644 --- a/services/celery/celery.py +++ b/services/celery/celery.py @@ -30,7 +30,7 @@ def check_withdrawal(): # need to send an notification for the order conformation -## For ETH +# Task :: open_eth_order_on_dydx - is used to open eth order on dydx @app.task(name="open_eth_order_on_dydx", track_started=True) def open_eth_order_on_dydx(eth_trigger_price=None): print("Start::open eth order on dydx") @@ -47,7 +47,7 @@ def open_eth_order_on_dydx(eth_trigger_price=None): dydx_order_manager_obj.open_order_on_dydx(asset_details) -# For ETH +# Task :: close_eth_order_on_dydx - is used to close eth order on dydx @app.task(name="close_eth_order_on_dydx", default_retry_delay=4 * 60) def close_eth_order_on_dydx( eth_trigger_price=None, @@ -66,7 +66,7 @@ def close_eth_order_on_dydx( dydx_order_manager_obj.close_order_on_dydx(asset_details) -# BTC --> positions +# Task :: open_btc_order_on_dydx - is used to open btc order on dydx @app.task(name="open_btc_order_on_dydx", track_started=True) def open_btc_order_on_dydx(btc_trigger_price=None): print("Start::open btc order on dydx") @@ -83,6 +83,7 @@ def open_btc_order_on_dydx(btc_trigger_price=None): dydx_order_manager_obj.open_order_on_dydx(asset_details) +# Task :: close_btc_order_on_dydx - is used to close btc order on dydx @app.task(name="close_btc_order_on_dydx", default_retry_delay=4 * 60) def close_btc_order_on_dydx(btc_trigger_price=None): print("Start::close btc order on dydx") @@ -99,6 +100,7 @@ def close_btc_order_on_dydx(btc_trigger_price=None): dydx_order_manager_obj.close_order_on_dydx(asset_details) +# Task :: compute_eth_usdc_volatility - is used to compute eth usdc volatility. @app.task( name="compute_eth_usdc_volatility", ) @@ -114,6 +116,9 @@ def compute_eth_usdc_volatility(): print("time all", end_time - current_time) +# Task :: compute_btc_usdc_volatility - is used to compute btc usdc volatility. + + @app.task( name="compute_btc_usdc_volatility", ) @@ -124,6 +129,7 @@ def compute_btc_usdc_volatility(): print("End::compute_btc_usdc_volatility") +# Task :: set_price_floor - is used to set the price. # TODO: set price floor for other asset's too. @app.task( name="set_price_floor", @@ -135,6 +141,7 @@ def set_price_floor(): price_floor_manager_obj.set_price_floor("bitcoin") +# Task :: store_asset_apys - is used to store assets apys. @app.task(name="store_asset_apy") def store_asset_apys(): print("store_asset_apys :: Setting apy") diff --git a/settings_config/common.py b/settings_config/common.py index 6ae6b9e..6808300 100644 --- a/settings_config/common.py +++ b/settings_config/common.py @@ -1,4 +1,5 @@ # Application definition + INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", diff --git a/settings_config/production_settings.py b/settings_config/production_settings.py index 87f628d..833e55f 100644 --- a/settings_config/production_settings.py +++ b/settings_config/production_settings.py @@ -1,17 +1,17 @@ import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration - -from .common import * from django.core.wsgi import get_wsgi_application SECRET_KEY = "j7qelfcc!qe*%((o3p0ju20obkx^j9+9#%%d-t15gqnz^*$om#" DEBUG = False + CORS_ALLOWED_ORIGINS = [ "http://localhost:3000", "https://test.app.cruize.finance", "https://www.test.app.cruize.finance", "https://www.beta.app.cruize.finance", ] +# here we add the all the host that are free to use over services. ALLOWED_HOSTS = [ "52.20.55.165", "test2.trident.cruize.finance",