Merge pull request #1814 from vnpy/issue-fix

Issue fix
This commit is contained in:
vn.py 2019-06-10 14:56:42 +08:00 committed by GitHub
commit 3d1c794d5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 25 deletions

View File

@ -72,7 +72,7 @@ def main():
## 接口分类 ## 接口分类
| 接口 | 类型 | | 接口 | 类型 |
| ------ | :------: | | -------- | :----------------------------------------: |
| CTP | 期货 | | CTP | 期货 |
| FEMAS | 期货 | | FEMAS | 期货 |
| OES | 国内股票 | | OES | 国内股票 |
@ -270,8 +270,11 @@ main_engine.add_gateway(IbGateway)
   
#### 其他特点 #### 其他特点
可交易品种几乎覆盖全球的股票、期权、期权;手续费相对较低。 可交易品种几乎覆盖全球的股票、期权、期权;手续费相对较低。
注意IB接口的合约代码较为特殊请前往官网的产品查询板块查询VN Trader中使用的是盈透证券对于每个合约在某一交易所的唯一标识符ConId来作为合约代码而非Symbol或者LocalName。
   

View File

@ -17,8 +17,8 @@ from vnpy.trader.ui import MainWindow, create_qapp
# from vnpy.gateway.onetoken import OnetokenGateway # from vnpy.gateway.onetoken import OnetokenGateway
# from vnpy.gateway.okexf import OkexfGateway # from vnpy.gateway.okexf import OkexfGateway
# from vnpy.gateway.xtp import XtpGateway # from vnpy.gateway.xtp import XtpGateway
# from vnpy.gateway.hbdm import HbdmGateway from vnpy.gateway.hbdm import HbdmGateway
from vnpy.gateway.tap import TapGateway # from vnpy.gateway.tap import TapGateway
# from vnpy.app.cta_strategy import CtaStrategyApp # from vnpy.app.cta_strategy import CtaStrategyApp
# from vnpy.app.csv_loader import CsvLoaderApp # from vnpy.app.csv_loader import CsvLoaderApp
@ -49,8 +49,8 @@ def main():
# main_engine.add_gateway(BitfinexGateway) # main_engine.add_gateway(BitfinexGateway)
# main_engine.add_gateway(OnetokenGateway) # main_engine.add_gateway(OnetokenGateway)
# main_engine.add_gateway(OkexfGateway) # main_engine.add_gateway(OkexfGateway)
# main_engine.add_gateway(HbdmGateway) main_engine.add_gateway(HbdmGateway)
main_engine.add_gateway(TapGateway) # main_engine.add_gateway(TapGateway)
# main_engine.add_app(CtaStrategyApp) # main_engine.add_app(CtaStrategyApp)
# main_engine.add_app(CtaBacktesterApp) # main_engine.add_app(CtaBacktesterApp)

View File

@ -214,6 +214,8 @@ class BacktestingEngine:
if not self.end: if not self.end:
self.end = datetime.now() self.end = datetime.now()
self.history_data.clear() # Clear previously loaded history data
# Load 30 days of data each time and allow for progress update # Load 30 days of data each time and allow for progress update
progress_delta = timedelta(days=30) progress_delta = timedelta(days=30)
total_delta = self.end - self.start total_delta = self.end - self.start

View File

@ -36,7 +36,7 @@ from vnpy.trader.constant import (
Offset, Offset,
Status Status
) )
from vnpy.trader.utility import load_json, save_json, extract_vt_symbol from vnpy.trader.utility import load_json, save_json, extract_vt_symbol, round_to
from vnpy.trader.database import database_manager from vnpy.trader.database import database_manager
from vnpy.trader.rqdata import rqdata_client from vnpy.trader.rqdata import rqdata_client
@ -465,6 +465,10 @@ class CtaEngine(BaseEngine):
self.write_log(f"委托失败,找不到合约:{strategy.vt_symbol}", strategy) self.write_log(f"委托失败,找不到合约:{strategy.vt_symbol}", strategy)
return "" return ""
# Round order price and volume to nearest incremental value
price = round_to(price, contract.pricetick)
volume = round_to(volume, contract.min_volume)
if stop: if stop:
if contract.stop_supported: if contract.stop_supported:
return self.send_server_stop_order(strategy, contract, direction, offset, price, volume, lock) return self.send_server_stop_order(strategy, contract, direction, offset, price, volume, lock)

View File

@ -958,6 +958,9 @@ class HbdmDataWebsocketApi(HbdmWebsocketApiBase):
"""""" """"""
self.gateway.write_log("行情Websocket API连接成功") self.gateway.write_log("行情Websocket API连接成功")
for ws_symbol in self.ticks.keys():
self.subscribe_data(ws_symbol)
def subscribe(self, req: SubscribeRequest): def subscribe(self, req: SubscribeRequest):
"""""" """"""
contract_type = symbol_type_map.get(req.symbol, "") contract_type = symbol_type_map.get(req.symbol, "")
@ -980,6 +983,10 @@ class HbdmDataWebsocketApi(HbdmWebsocketApiBase):
) )
self.ticks[ws_symbol] = tick self.ticks[ws_symbol] = tick
self.subscribe_data(ws_symbol)
def subscribe_data(self, ws_symbol: str):
""""""
# Subscribe to market depth update # Subscribe to market depth update
self.req_id += 1 self.req_id += 1
req = { req = {

View File

@ -416,6 +416,9 @@ class IbApi(EWrapper):
accountName, accountName,
) )
if not contract.exchange:
return
ib_size = contract.multiplier ib_size = contract.multiplier
if not ib_size: if not ib_size:
ib_size = 1 ib_size = 1

View File

@ -299,7 +299,7 @@ class LogEngine(BaseEngine):
file_path = log_path.joinpath(filename) file_path = log_path.joinpath(filename)
file_handler = logging.FileHandler( file_handler = logging.FileHandler(
file_path, mode="w", encoding="utf8" file_path, mode="a", encoding="utf8"
) )
file_handler.setLevel(self.level) file_handler.setLevel(self.level)
file_handler.setFormatter(self.formatter) file_handler.setFormatter(self.formatter)