Skip to content

Commit

Permalink
account query interval
Browse files Browse the repository at this point in the history
  • Loading branch information
lin committed Dec 19, 2020
1 parent 9331830 commit 4d8a2f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
28 changes: 20 additions & 8 deletions howtrader/trader/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from .setting import SETTINGS
from .utility import get_folder_path, TRADER_DIR


class MainEngine:
"""
Acts as the core of VN Trader.
Expand All @@ -62,8 +63,8 @@ def __init__(self, event_engine: EventEngine = None):
self.apps: Dict[str, BaseApp] = {}
self.exchanges: List[Exchange] = []

os.chdir(TRADER_DIR) # Change working directory
self.init_engines() # Initialize function engines
os.chdir(TRADER_DIR) # Change working directory
self.init_engines() # Initialize function engines

def add_engine(self, engine_class: Any) -> "BaseEngine":
"""
Expand Down Expand Up @@ -228,10 +229,16 @@ def query_history(self, req: HistoryRequest, gateway_name: str) -> Optional[List

def query_position(self):
"""
query the account and position
query the position
"""
for gateway in self.gateways.values():
gateway.query_position()

def query_account(self):
"""
query the account
"""
for gateway in self.gateways.values():
gateway.query_account()

def close(self) -> None:
Expand All @@ -255,10 +262,10 @@ class BaseEngine(ABC):
"""

def __init__(
self,
main_engine: MainEngine,
event_engine: EventEngine,
engine_name: str,
self,
main_engine: MainEngine,
event_engine: EventEngine,
engine_name: str,
):
""""""
self.main_engine = main_engine
Expand Down Expand Up @@ -368,6 +375,7 @@ def __init__(self, main_engine: MainEngine, event_engine: EventEngine):

self.order_update_interval = 0 # for counting the timer.
self.position_update_interval = 0
self.account_update_interval = 0

def add_function(self) -> None:
"""Add query function to main engine."""
Expand Down Expand Up @@ -452,6 +460,10 @@ def process_timer(self, event: Event) -> None:
self.main_engine.query_position()
self.position_update_interval = 0

if self.account_update_interval >= SETTINGS.get('account_update_interval', 120):
self.account_update_interval = 0
self.main_engine.query_account()

def get_tick(self, vt_symbol: str) -> Optional[TickData]:
"""
Get latest market tick data by vt_symbol.
Expand Down Expand Up @@ -581,7 +593,7 @@ def run(self) -> None:
msg = self.queue.get(block=True, timeout=1)

with smtplib.SMTP_SSL(
SETTINGS["email.server"], SETTINGS["email.port"]
SETTINGS["email.server"], SETTINGS["email.port"]
) as smtp:
smtp.login(
SETTINGS["email.username"], SETTINGS["email.password"]
Expand Down
1 change: 1 addition & 0 deletions howtrader/trader/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"font.size": 12,
"order_update_interval": 120,
"position_update_interval": 120,
"account_update_interval": 120,
"log.active": True,
"log.level": CRITICAL,
"log.console": True,
Expand Down

0 comments on commit 4d8a2f3

Please sign in to comment.