Skip to content

Commit

Permalink
fix balance in place order
Browse files Browse the repository at this point in the history
  • Loading branch information
r0fls committed Jun 18, 2024
1 parent 32344d0 commit 3ef719e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion brokers/base_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def place_order(self, symbol, quantity, order_type, strategy, price=None):

# Fetch the latest cash balance for the strategy
latest_balance = session.query(Balance).filter_by(
strategy=strategy, type='cash').order_by(Balance.timestamp.desc()).first()
broker=self.broker_name, strategy=strategy, type='cash').order_by(Balance.timestamp.desc()).first()
if latest_balance:
# Calculate the order cost
order_cost = trade.executed_price * quantity
Expand All @@ -175,6 +175,8 @@ async def place_order(self, symbol, quantity, order_type, strategy, price=None):
)
session.add(new_balance)
session.commit()
else:
logger.info('No balance records found for {strategy} in {self.broker_name}')

return response
except Exception as e:
Expand Down

0 comments on commit 3ef719e

Please sign in to comment.