From 063609de19a6f7e97c68f7da1e5ca422449349e9 Mon Sep 17 00:00:00 2001 From: uvok Date: Fri, 18 Apr 2025 19:27:01 +0200 Subject: Add timestamp prop and fix queue to use it --- trade.py | 10 ++++++++++ trade_queue.py | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/trade.py b/trade.py index 30a0030..7c2ecc7 100644 --- a/trade.py +++ b/trade.py @@ -105,6 +105,16 @@ class Trade: """ return self.__timestamp.split(" ")[0] + @property + def timestamp(self) -> str: + """ + Get the timestamp of the trade. + + Returns: + str: The trade timestamp as a string. + """ + return self.__timestamp + @property def price_per_coin(self) -> Decimal: """ diff --git a/trade_queue.py b/trade_queue.py index 6e8c2c5..4c48779 100644 --- a/trade_queue.py +++ b/trade_queue.py @@ -46,15 +46,15 @@ class FIFOQueue: """ return list(deepcopy(self.__queue)) - def add(self, amount: Decimal, total_cost: Decimal, date: str) -> None: + def add(self, amount: Decimal, total_cost: Decimal, timestamp: str) -> None: """ Add a trade to the queue by specifying properties. """ - trade = Trade(amount, total_cost, date) + trade = Trade(amount, total_cost, timestamp) bisect.insort( self.__queue, trade, - key=lambda t: t.date + key=lambda t: t.timestamp ) self._cache_valid = False logger.info(f"Added trade: {trade}.") @@ -66,7 +66,7 @@ class FIFOQueue: bisect.insort( self.__queue, trade, - key=lambda t: t.date + key=lambda t: t.timestamp ) self._cache_valid = False logger.info(f"Added trade: {trade}.") -- cgit v1.2.3