Skip to content

Commit

Permalink
Merge pull request #12 from vnpy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vnpy committed Feb 20, 2022
2 parents 300bf2f + 6c7140f commit 5b45fe3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,4 @@
# 1.0.8版本

1. 将加载历史数据的异步回放,从引擎移动到策略模板中
2. 将模块的图标文件信息,改为完整路径字符串
13 changes: 7 additions & 6 deletions README.md
@@ -1,13 +1,13 @@
# vn.py框架的CTA策略模块
# VeighNa框架的CTA策略模块

<p align="center">
<img src ="https://vnpy.oss-cn-shanghai.aliyuncs.com/vnpy-logo.png"/>
</p>

<p align="center">
<img src ="https://img.shields.io/badge/version-1.0.6-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/version-1.0.8-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg"/>
<img src ="https://img.shields.io/badge/python-3.7-blue.svg" />
<img src ="https://img.shields.io/badge/python-3.7|3.8|3.9|3.10-blue.svg" />
<img src ="https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange"/>
</p>

Expand All @@ -17,16 +17,17 @@

## 安装

安装需要基于2.6.0版本以上的[VN Studio](https://www.vnpy.com)
安装环境推荐基于3.0.0版本以上的[**VeighNa Studio**](https://www.vnpy.com)

直接使用pip命令:

```
pip install vnpy_ctastrategy
```

下载解压后在cmd中运行

或者下载源代码后,解压后在cmd中运行:

```
python setup.py install
pip install .
```
4 changes: 2 additions & 2 deletions setup.cfg
@@ -1,11 +1,11 @@
[metadata]
name = vnpy_ctastrategy
version = 1.0.6
version = 1.0.8
url = https://www.vnpy.com
license = MIT
author = Xiaoyou Chen
author_email = xiaoyou.chen@mail.vnpy.com
description = CTA strategy application for vn.py quant trading framework.
description = CTA strategy application for VeighNa quant trading framework.
long_description = file: README.md
long_description_content_type = text/markdown
keywords =
Expand Down
2 changes: 1 addition & 1 deletion vnpy_ctastrategy/__init__.py
Expand Up @@ -49,4 +49,4 @@ class CtaStrategyApp(BaseApp):
display_name = "CTA策略"
engine_class = CtaEngine
widget_name = "CtaManager"
icon_name = "cta.ico"
icon_name = str(app_path.joinpath("ui", "cta.ico"))
8 changes: 5 additions & 3 deletions vnpy_ctastrategy/backtesting.py
@@ -1,6 +1,6 @@
from collections import defaultdict
from datetime import date, datetime, timedelta
from typing import Callable
from typing import Callable, List
from functools import lru_cache, partial
import traceback

Expand Down Expand Up @@ -766,15 +766,17 @@ def load_bar(
interval: Interval,
callback: Callable,
use_database: bool
):
) -> List[BarData]:
""""""
self.days = days
self.callback = callback
return []

def load_tick(self, vt_symbol: str, days: int, callback: Callable):
def load_tick(self, vt_symbol: str, days: int, callback: Callable) -> List[TickData]:
""""""
self.days = days
self.callback = callback
return []

def send_order(
self,
Expand Down
12 changes: 5 additions & 7 deletions vnpy_ctastrategy/engine.py
Expand Up @@ -4,7 +4,7 @@
import traceback
from collections import defaultdict
from pathlib import Path
from typing import Any, Callable
from typing import Any, Callable, List
from datetime import datetime, timedelta
from concurrent.futures import ThreadPoolExecutor
from copy import copy
Expand Down Expand Up @@ -550,7 +550,7 @@ def load_bar(
interval: Interval,
callback: Callable[[BarData], None],
use_database: bool
):
) -> List[BarData]:
""""""
symbol, exchange = extract_vt_symbol(vt_symbol)
end = datetime.now(LOCAL_TZ)
Expand Down Expand Up @@ -585,15 +585,14 @@ def load_bar(
end=end,
)

for bar in bars:
callback(bar)
return bars

def load_tick(
self,
vt_symbol: str,
days: int,
callback: Callable[[TickData], None]
):
) -> List[TickData]:
""""""
symbol, exchange = extract_vt_symbol(vt_symbol)
end = datetime.now(LOCAL_TZ)
Expand All @@ -606,8 +605,7 @@ def load_tick(
end=end,
)

for tick in ticks:
callback(tick)
return ticks

def call_strategy_func(
self, strategy: CtaTemplate, func: Callable, params: Any = None
Expand Down
10 changes: 8 additions & 2 deletions vnpy_ctastrategy/template.py
Expand Up @@ -298,19 +298,25 @@ def load_bar(
if not callback:
callback = self.on_bar

self.cta_engine.load_bar(
bars = self.cta_engine.load_bar(
self.vt_symbol,
days,
interval,
callback,
use_database
)

for bar in bars:
callback(bar)

def load_tick(self, days: int):
"""
Load historical tick data for initializing strategy.
"""
self.cta_engine.load_tick(self.vt_symbol, days, self.on_tick)
ticks = self.cta_engine.load_tick(self.vt_symbol, days, self.on_tick)

for tick in ticks:
self.on_tick(tick)

def put_event(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion vnpy_ctastrategy/ui/rollover.py
Expand Up @@ -107,7 +107,7 @@ def roll_all(self) -> None:
if not strategy.inited:
self.write_log(f"策略{strategy.strategy_name}尚未初始化,无法执行移仓")
return

if strategy.trading:
self.write_log(f"策略{strategy.strategy_name}正在运行中,无法执行移仓")
return
Expand Down

0 comments on commit 5b45fe3

Please sign in to comment.