Skip to content

Commit

Permalink
Fix missing inherited precisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Wu committed Sep 26, 2024
1 parent ae79a71 commit 56ce904
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 55 deletions.
10 changes: 4 additions & 6 deletions api/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
class Account(BinbotApi):
def __init__(self):
self.db = setup_db()
self._price_precision: int = 0
self._qty_precision: int = 0
pass

def setup_mongocache(self):
Expand All @@ -38,17 +36,17 @@ def calculate_price_precision(self, symbol) -> int:
.as_tuple()
.exponent
)
self._price_precision = int(precision)
return self._price_precision
price_precision = int(precision)
return price_precision

def calculate_qty_precision(self, symbol) -> int:
precision = -1 * (
Decimal(str(self.lot_size_by_symbol(symbol, "stepSize")))
.as_tuple()
.exponent
)
self._qty_precision = int(precision)
return self._qty_precision
qty_precision = int(precision)
return qty_precision

def _exchange_info(self, symbol=None):
"""
Expand Down
8 changes: 5 additions & 3 deletions api/bots/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from bots.schemas import BotSchema, ErrorsRequestBody
from deals.controllers import CreateDealController
from tools.exceptions import BinanceErrors, InsufficientBalance
import asyncio


class Bot(Database, Account):
Expand Down Expand Up @@ -188,12 +189,13 @@ def delete(self, bot_ids: List[str] = Query(...)):

return resp

def activate(self, bot: dict | BotSchema):
async def activate(self, bot: dict | BotSchema):
if isinstance(bot, dict):
self.active_bot = BotSchema(**bot)
self.active_bot = BotSchema.model_validate(bot)
else:
self.active_bot = bot
CreateDealController(self.active_bot, db_collection="bots").open_deal()

await CreateDealController(self.active_bot, db_collection="bots").open_deal()
self.base_producer.update_required(self.producer, "ACTIVATE_BOT")
return bot

Expand Down
4 changes: 2 additions & 2 deletions api/bots/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def delete(id: List[str] = Query(...)):


@bot_blueprint.get("/bot/activate/{id}", tags=["bots"])
def activate_by_id(id: str):
async def activate_by_id(id: str):
"""
Activate bot
Expand All @@ -81,7 +81,7 @@ def activate_by_id(id: str):
bot = bot_instance.get_one(id)
if bot:
try:
bot_instance.activate(bot)
await bot_instance.activate(bot)
return json_response_message("Successfully activated bot!")
except BinbotErrors as error:
bot_instance.post_errors_by_id(id, error.message)
Expand Down
17 changes: 3 additions & 14 deletions api/deals/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, bot, db_collection_name):
self.active_bot = bot
self.db_collection = self._db[db_collection_name]
self.market_domination_reversal = None
self.price_precision = self.calculate_price_precision(bot.pair)
self.qty_precision = self.calculate_qty_precision(bot.pair)

if self.active_bot.strategy == Strategy.margin_short:
self.isolated_balance: float = self.get_isolated_balance(
self.active_bot.pair
Expand All @@ -43,20 +46,6 @@ def __repr__(self) -> str:
"""
return f"BaseDeal({self.__dict__})"

@property
def price_precision(self):
if self._price_precision == 0:
self._price_precision = self.calculate_price_precision(self.active_bot.pair)

return self._price_precision

@property
def qty_precision(self):
if self._qty_precision == 0:
self._qty_precision = self.calculate_qty_precision(self.active_bot.pair)

return self._qty_precision

def generate_id(self):
return uuid.uuid4()

Expand Down
16 changes: 0 additions & 16 deletions api/deals/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,8 @@ class CreateDealController(BaseDeal):
def __init__(self, bot: BotSchema, db_collection="paper_trading"):
# Inherit from parent class
super().__init__(bot, db_collection)
self._price_precision = 0
self._qty_precision = 0
self.active_bot = bot

@property
def price_precision(self):
if self._price_precision == 0:
self._price_precision = self.calculate_price_precision(self.active_bot.pair)

return self._price_precision

@property
def qty_precision(self):
if self._qty_precision == 0:
self._qty_precision = self.calculate_qty_precision(self.active_bot.pair)

return self._qty_precision

def get_one_balance(self, symbol="BTC"):
# Response after request
data = self.bb_request(url=self.bb_balance_url)
Expand Down
14 changes: 0 additions & 14 deletions api/orders/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ def __init__(self) -> None:
self.save_bot_streaming = self.save_bot_streaming
pass

@property
def price_precision(self, symbol):
if self._price_precision == 0:
self._price_precision = self.calculate_price_precision(symbol)

return self._price_precision

@property
def qty_precision(self, symbol):
if self._qty_precision == 0:
self._qty_precision = self.calculate_qty_precision(symbol)

return self._qty_precision

def zero_remainder(self, x):
number = x

Expand Down

0 comments on commit 56ce904

Please sign in to comment.