[Add] send_email function to ScriptEngine

This commit is contained in:
vn.py 2019-07-03 13:19:17 +08:00
parent afa7f1a227
commit 5eded16f48
2 changed files with 33 additions and 9 deletions

View File

@ -3,7 +3,20 @@ from vnpy.app.script_trader import ScriptEngine
def run(engine: ScriptEngine):
""""""
"""
脚本策略的主函数说明
1. 唯一入参是脚本引擎ScriptEngine对象通用它来完成查询和请求操作
2. 该函数会通过一个独立的线程来启动运行区别于其他策略模块的事件驱动
3. while循环的维护请通过engine.strategy_active状态来判断实现可控退出
脚本策略的应用举例
1. 自定义篮子委托执行执行算法
2. 股指期货和一篮子股票之间的对冲策略
3. 国内外商品数字货币跨交易所的套利
4. 自定义组合指数行情监控以及消息通知
5. 股票市场扫描选股类交易策略龙一龙二
6. 等等~~~
"""
vt_symbols = ["IF1912.CFFEX", "rb2001.SHFE"]
# 订阅行情

View File

@ -3,7 +3,7 @@
import sys
import importlib
import traceback
from typing import Sequence, Callable, Any
from typing import Sequence, Any
from pathlib import Path
from datetime import datetime
from threading import Thread
@ -54,7 +54,9 @@ class ScriptEngine(BaseEngine):
self.write_log("RQData数据接口初始化成功")
def start_strategy(self, script_path: str):
""""""
"""
Start running strategy function in strategy_thread.
"""
if self.strategy_active:
return
self.strategy_active = True
@ -66,7 +68,9 @@ class ScriptEngine(BaseEngine):
self.write_log("策略交易脚本启动")
def run_strategy(self, script_path: str):
""""""
"""
Load strategy script and call the run function.
"""
path = Path(script_path)
sys.path.append(str(path.parent))
@ -81,12 +85,10 @@ class ScriptEngine(BaseEngine):
msg = f"触发异常已停止\n{traceback.format_exc()}"
self.write_log(msg)
def connect_gateway(self, setting: dict, gateway_name: str):
""""""
self.main_engine.connect(setting, gateway_name)
def stop_strategy(self):
""""""
"""
Stop the running strategy.
"""
if not self.strategy_active:
return
self.strategy_active = False
@ -97,6 +99,10 @@ class ScriptEngine(BaseEngine):
self.write_log("策略交易脚本停止")
def connect_gateway(self, setting: dict, gateway_name: str):
""""""
self.main_engine.connect(setting, gateway_name)
def send_order(
self,
vt_symbol: str,
@ -259,6 +265,11 @@ class ScriptEngine(BaseEngine):
event = Event(EVENT_SCRIPT_LOG, log)
self.event_engine.put(event)
def send_email(self, msg: str) -> None:
""""""
subject = "脚本策略引擎通知"
self.main_engine.send_email(subject, msg)
def to_df(data_list: Sequence):
""""""