11from decimal import Decimal
22from typing import Dict , List
3+ import time
34from ..portfolio .balance import Balance
45
56
@@ -37,19 +38,7 @@ def _validate_symbol(self, symbol: str) -> None:
3738 raise ValueError ("Invalid symbol format" )
3839
3940 def execute_buy (self , symbol : str , price : Decimal , volume : Decimal ) -> bool :
40- """Execute a buy order.
41-
42- Args:
43- symbol: Trading pair symbol (e.g. 'BTC/USD')
44- price: Current market price
45- volume: Amount to buy
46-
47- Returns:
48- bool: True if order executed successfully, False otherwise
49-
50- Raises:
51- ValueError: If volume or price is not positive, or symbol is invalid
52- """
41+ """Execute a buy order."""
5342 self ._validate_symbol (symbol )
5443
5544 if volume <= 0 :
@@ -67,13 +56,14 @@ def execute_buy(self, symbol: str, price: Decimal, volume: Decimal) -> bool:
6756 # Update position
6857 self .positions [symbol ] = self .positions .get (symbol , Decimal ("0" )) + volume
6958
70- # Record trade
59+ # Record trade with timestamp
7160 self .trades_history .append ({
7261 "symbol" : symbol ,
7362 "side" : "buy" ,
7463 "price" : price ,
7564 "volume" : volume ,
76- "cost" : cost
65+ "cost" : cost ,
66+ "timestamp" : int (time .time ())
7767 })
7868
7969 return True
@@ -114,13 +104,14 @@ def execute_sell(self, symbol: str, price: Decimal, volume: Decimal) -> bool:
114104 if self .positions [symbol ] == Decimal ("0" ):
115105 del self .positions [symbol ]
116106
117- # Record trade
107+ # Record trade with timestamp
118108 self .trades_history .append ({
119109 "symbol" : symbol ,
120110 "side" : "sell" ,
121111 "price" : price ,
122112 "volume" : volume ,
123- "revenue" : revenue
113+ "revenue" : revenue ,
114+ "timestamp" : int (time .time ())
124115 })
125116
126117 return True
0 commit comments