Skip to content

Commit

Permalink
Prevent id duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Wu Fei authored and Carlos Wu Fei committed Jan 8, 2024
1 parent bb3a36b commit 5d33bab
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions api/bots/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion api/bots/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions api/charts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions api/tools/enum_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5d33bab

Please sign in to comment.