fix get_positions in simulation trader
This commit is contained in:
parent
89b8ffe767
commit
e525c9e5f7
@ -9,6 +9,8 @@ from trade_constants import (
|
||||
from position_manager import PositionManager
|
||||
from base_trader import BaseTrader
|
||||
import random
|
||||
from typing import Dict
|
||||
from local_position import LocalPosition
|
||||
|
||||
|
||||
class SimulationTrader(BaseTrader):
|
||||
@ -130,11 +132,11 @@ class SimulationTrader(BaseTrader):
|
||||
self.logger.info(message)
|
||||
|
||||
position_managers = self.get_all_position_managers()
|
||||
positions = {}
|
||||
positions: Dict[str, LocalPosition] = {}
|
||||
for position_manager in position_managers.values():
|
||||
positions.update(position_manager.get_positions())
|
||||
# convert to json list
|
||||
return [position.to_dict() for position in positions.values()]
|
||||
return [{"account_id": "simulation", "code": position.code, "total_amount": position.total_amount, "closeable_amount": position.closeable_amount} for position in positions.values()]
|
||||
|
||||
def get_today_trades(self):
|
||||
message = "模拟交易:查询今日成交"
|
||||
@ -157,15 +159,16 @@ class SimulationTrader(BaseTrader):
|
||||
Returns:
|
||||
dict: 持仓详情,如果未持有则返回None
|
||||
"""
|
||||
positions = self.position_manager.get_positions(strategy_name)
|
||||
position_manager = self.get_position_manager(strategy_name)
|
||||
positions = position_manager.get_positions()
|
||||
if stock_code in positions:
|
||||
position_info = positions[stock_code]
|
||||
return {
|
||||
"account_id": "simulation",
|
||||
"stock_code": stock_code,
|
||||
"code": stock_code,
|
||||
"strategy_name": strategy_name,
|
||||
"volume": position_info.total_amount,
|
||||
"can_use_volume": position_info.closeable_amount,
|
||||
"total_amount": position_info.total_amount,
|
||||
"closeable_amount": position_info.closeable_amount,
|
||||
}
|
||||
return None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user