diff --git a/api/bots/controllers.py b/api/bots/controllers.py index c515c00f6..cac9d62c6 100644 --- a/api/bots/controllers.py +++ b/api/bots/controllers.py @@ -26,6 +26,9 @@ def __init__(self, collection_name="paper_trading"): self.db_collection = self.db[collection_name] def _update_required(self): + """ + Streaming controller requires reload + """ self.db.research_controller.update_one({"_id": "settings"}, {"$set": {"update_required": time()}}) return diff --git a/api/bots/schemas.py b/api/bots/schemas.py index fbbd28467..4d892cf46 100644 --- a/api/bots/schemas.py +++ b/api/bots/schemas.py @@ -2,7 +2,7 @@ from typing import List, Literal from bson.objectid import ObjectId -from tools.enum_definitions import Status +from tools.enum_definitions import CloseCondition, Status from deals.schema import DealSchema, OrderSchema from pydantic import BaseModel, Field, validator from tools.enum_definitions import BinbotEnums diff --git a/api/charts/models.py b/api/charts/models.py index 97ae39ce6..1935045a7 100644 --- a/api/charts/models.py +++ b/api/charts/models.py @@ -136,7 +136,6 @@ def check_gaps(self, df, params: CandlestickParams): @params - df [Pandas dataframe] """ - logging.warning(f"Checking gaps in the kline data for {params.symbol}") kline_df = df.copy(deep=True) df["gaps_check"] = df[0].diff()[1:] df = df.dropna() @@ -146,17 +145,14 @@ def check_gaps(self, df, params: CandlestickParams): gaps_check = df["gaps_check"].to_numpy() # Check difference between now and last kline - try: - check_latest = ((time() * 1000) - df[0].to_numpy()[-1]) > gaps_check[-1] - except Exception as e: - print(e) + check_latest = ((time() * 1000) - df[0].to_numpy()[-1]) > gaps_check[-1] # If true, no gaps try: no_gaps = gaps_check.all() if not bool(no_gaps) or check_latest: kline_df = self.delete_and_create_klines(params) except IndexError as e: - print("Check gaps Index Error", e) + logging.error("Check gaps Index Error", e) kline_df = self.delete_and_create_klines(params) return kline_df diff --git a/api/db.py b/api/db.py index 3836cb74a..1727ff149 100644 --- a/api/db.py +++ b/api/db.py @@ -11,4 +11,5 @@ def setup_db(): password=os.getenv("MONGO_AUTH_PASSWORD"), ) db = mongo[os.getenv("MONGO_APP_DATABASE")] + db.bots.create_index("id", unique=True) return db diff --git a/api/tools/enum_definitions.py b/api/tools/enum_definitions.py index afe578cba..2740df07d 100644 --- a/api/tools/enum_definitions.py +++ b/api/tools/enum_definitions.py @@ -86,3 +86,10 @@ class OrderSide(str, Enum): def __str__(self): return str(self.str) + +class CloseCondition(str, Enum): + dynamic = "dynamic" # Dynamic trailling, stop_loss, take_profit or trailling_profit + timestamp = "timestamp" # Market domination timestamp in milliseconds + + def __str__(self): + return str(self.str) \ No newline at end of file