From b3cdb0e2c0060a71a43fa5fe68535559093b359f Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 27 Jun 2017 16:55:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0vnpy.data=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=AD=98=E6=94=BE=E6=95=B0=E6=8D=AE=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {vnpy/api => archive}/datayes/README.md | 0 {vnpy/api => archive}/datayes/__init__.py | 0 {vnpy/api => archive}/datayes/api.py | 0 .../datayes/config/db_EQU_D1.csv | 0 {vnpy/api => archive}/datayes/download.sh | 0 {vnpy/api => archive}/datayes/errors.py | 0 {vnpy/api => archive}/datayes/fun/fetch.R | 0 .../datayes/names/equTicker.json | 0 .../datayes/names/fudTicker.json | 0 .../datayes/names/futTicker.json | 0 .../datayes/names/idxTicker.json | 0 .../datayes/names/optTicker.json | 0 .../api => archive}/datayes/names/secID.json | 0 {vnpy/api => archive}/datayes/prepare.sh | 0 .../datayes/static/figs/fig1.png | Bin .../datayes/static/figs/fig2.png | Bin .../datayes/static/figs/fig3.png | Bin .../datayes/static/figs/fig4.png | Bin .../datayes/static/figs/fig5.png | Bin .../datayes/static/figs/fig6.png | Bin .../datayes/static/tutorial.ipynb | 0 .../datayes/static/tutorial.md | 0 {vnpy/api => archive}/datayes/storage.py | 0 {vnpy/api => archive}/datayes/tests.py | 0 {vnpy/api => archive}/datayes/update.sh | 0 vnpy/data/README.md | 5 ++ vnpy/{api/shcifco => data}/__init__.py | 0 vnpy/data/datayes/__init__.py | 1 + vnpy/data/datayes/vndatayes.py | 52 ++++++++++++++++++ vnpy/data/shcifco/__init__.py | 0 vnpy/{api => data}/shcifco/vnshcifco.py | 4 +- vnpy/trader/app/ctaStrategy/ctaHistoryData.py | 6 +- vnpy/trader/app/spreadTrading/stEngine.py | 4 +- 33 files changed, 66 insertions(+), 6 deletions(-) rename {vnpy/api => archive}/datayes/README.md (100%) rename {vnpy/api => archive}/datayes/__init__.py (100%) rename {vnpy/api => archive}/datayes/api.py (100%) rename {vnpy/api => archive}/datayes/config/db_EQU_D1.csv (100%) rename {vnpy/api => archive}/datayes/download.sh (100%) rename {vnpy/api => archive}/datayes/errors.py (100%) rename {vnpy/api => archive}/datayes/fun/fetch.R (100%) rename {vnpy/api => archive}/datayes/names/equTicker.json (100%) rename {vnpy/api => archive}/datayes/names/fudTicker.json (100%) rename {vnpy/api => archive}/datayes/names/futTicker.json (100%) rename {vnpy/api => archive}/datayes/names/idxTicker.json (100%) rename {vnpy/api => archive}/datayes/names/optTicker.json (100%) rename {vnpy/api => archive}/datayes/names/secID.json (100%) rename {vnpy/api => archive}/datayes/prepare.sh (100%) rename {vnpy/api => archive}/datayes/static/figs/fig1.png (100%) rename {vnpy/api => archive}/datayes/static/figs/fig2.png (100%) rename {vnpy/api => archive}/datayes/static/figs/fig3.png (100%) rename {vnpy/api => archive}/datayes/static/figs/fig4.png (100%) rename {vnpy/api => archive}/datayes/static/figs/fig5.png (100%) rename {vnpy/api => archive}/datayes/static/figs/fig6.png (100%) rename {vnpy/api => archive}/datayes/static/tutorial.ipynb (100%) rename {vnpy/api => archive}/datayes/static/tutorial.md (100%) rename {vnpy/api => archive}/datayes/storage.py (100%) rename {vnpy/api => archive}/datayes/tests.py (100%) rename {vnpy/api => archive}/datayes/update.sh (100%) create mode 100644 vnpy/data/README.md rename vnpy/{api/shcifco => data}/__init__.py (100%) create mode 100644 vnpy/data/datayes/__init__.py create mode 100644 vnpy/data/datayes/vndatayes.py create mode 100644 vnpy/data/shcifco/__init__.py rename vnpy/{api => data}/shcifco/vnshcifco.py (98%) diff --git a/vnpy/api/datayes/README.md b/archive/datayes/README.md similarity index 100% rename from vnpy/api/datayes/README.md rename to archive/datayes/README.md diff --git a/vnpy/api/datayes/__init__.py b/archive/datayes/__init__.py similarity index 100% rename from vnpy/api/datayes/__init__.py rename to archive/datayes/__init__.py diff --git a/vnpy/api/datayes/api.py b/archive/datayes/api.py similarity index 100% rename from vnpy/api/datayes/api.py rename to archive/datayes/api.py diff --git a/vnpy/api/datayes/config/db_EQU_D1.csv b/archive/datayes/config/db_EQU_D1.csv similarity index 100% rename from vnpy/api/datayes/config/db_EQU_D1.csv rename to archive/datayes/config/db_EQU_D1.csv diff --git a/vnpy/api/datayes/download.sh b/archive/datayes/download.sh similarity index 100% rename from vnpy/api/datayes/download.sh rename to archive/datayes/download.sh diff --git a/vnpy/api/datayes/errors.py b/archive/datayes/errors.py similarity index 100% rename from vnpy/api/datayes/errors.py rename to archive/datayes/errors.py diff --git a/vnpy/api/datayes/fun/fetch.R b/archive/datayes/fun/fetch.R similarity index 100% rename from vnpy/api/datayes/fun/fetch.R rename to archive/datayes/fun/fetch.R diff --git a/vnpy/api/datayes/names/equTicker.json b/archive/datayes/names/equTicker.json similarity index 100% rename from vnpy/api/datayes/names/equTicker.json rename to archive/datayes/names/equTicker.json diff --git a/vnpy/api/datayes/names/fudTicker.json b/archive/datayes/names/fudTicker.json similarity index 100% rename from vnpy/api/datayes/names/fudTicker.json rename to archive/datayes/names/fudTicker.json diff --git a/vnpy/api/datayes/names/futTicker.json b/archive/datayes/names/futTicker.json similarity index 100% rename from vnpy/api/datayes/names/futTicker.json rename to archive/datayes/names/futTicker.json diff --git a/vnpy/api/datayes/names/idxTicker.json b/archive/datayes/names/idxTicker.json similarity index 100% rename from vnpy/api/datayes/names/idxTicker.json rename to archive/datayes/names/idxTicker.json diff --git a/vnpy/api/datayes/names/optTicker.json b/archive/datayes/names/optTicker.json similarity index 100% rename from vnpy/api/datayes/names/optTicker.json rename to archive/datayes/names/optTicker.json diff --git a/vnpy/api/datayes/names/secID.json b/archive/datayes/names/secID.json similarity index 100% rename from vnpy/api/datayes/names/secID.json rename to archive/datayes/names/secID.json diff --git a/vnpy/api/datayes/prepare.sh b/archive/datayes/prepare.sh similarity index 100% rename from vnpy/api/datayes/prepare.sh rename to archive/datayes/prepare.sh diff --git a/vnpy/api/datayes/static/figs/fig1.png b/archive/datayes/static/figs/fig1.png similarity index 100% rename from vnpy/api/datayes/static/figs/fig1.png rename to archive/datayes/static/figs/fig1.png diff --git a/vnpy/api/datayes/static/figs/fig2.png b/archive/datayes/static/figs/fig2.png similarity index 100% rename from vnpy/api/datayes/static/figs/fig2.png rename to archive/datayes/static/figs/fig2.png diff --git a/vnpy/api/datayes/static/figs/fig3.png b/archive/datayes/static/figs/fig3.png similarity index 100% rename from vnpy/api/datayes/static/figs/fig3.png rename to archive/datayes/static/figs/fig3.png diff --git a/vnpy/api/datayes/static/figs/fig4.png b/archive/datayes/static/figs/fig4.png similarity index 100% rename from vnpy/api/datayes/static/figs/fig4.png rename to archive/datayes/static/figs/fig4.png diff --git a/vnpy/api/datayes/static/figs/fig5.png b/archive/datayes/static/figs/fig5.png similarity index 100% rename from vnpy/api/datayes/static/figs/fig5.png rename to archive/datayes/static/figs/fig5.png diff --git a/vnpy/api/datayes/static/figs/fig6.png b/archive/datayes/static/figs/fig6.png similarity index 100% rename from vnpy/api/datayes/static/figs/fig6.png rename to archive/datayes/static/figs/fig6.png diff --git a/vnpy/api/datayes/static/tutorial.ipynb b/archive/datayes/static/tutorial.ipynb similarity index 100% rename from vnpy/api/datayes/static/tutorial.ipynb rename to archive/datayes/static/tutorial.ipynb diff --git a/vnpy/api/datayes/static/tutorial.md b/archive/datayes/static/tutorial.md similarity index 100% rename from vnpy/api/datayes/static/tutorial.md rename to archive/datayes/static/tutorial.md diff --git a/vnpy/api/datayes/storage.py b/archive/datayes/storage.py similarity index 100% rename from vnpy/api/datayes/storage.py rename to archive/datayes/storage.py diff --git a/vnpy/api/datayes/tests.py b/archive/datayes/tests.py similarity index 100% rename from vnpy/api/datayes/tests.py rename to archive/datayes/tests.py diff --git a/vnpy/api/datayes/update.sh b/archive/datayes/update.sh similarity index 100% rename from vnpy/api/datayes/update.sh rename to archive/datayes/update.sh diff --git a/vnpy/data/README.md b/vnpy/data/README.md new file mode 100644 index 00000000..b00cb83f --- /dev/null +++ b/vnpy/data/README.md @@ -0,0 +1,5 @@ +# vn.data - 数据相关工具 + +### 历史数据 +* datayes:通联数据接口 +* shcifco:上海中期接口 \ No newline at end of file diff --git a/vnpy/api/shcifco/__init__.py b/vnpy/data/__init__.py similarity index 100% rename from vnpy/api/shcifco/__init__.py rename to vnpy/data/__init__.py diff --git a/vnpy/data/datayes/__init__.py b/vnpy/data/datayes/__init__.py new file mode 100644 index 00000000..e06b8545 --- /dev/null +++ b/vnpy/data/datayes/__init__.py @@ -0,0 +1 @@ +from vndatayes import DatayesApi \ No newline at end of file diff --git a/vnpy/data/datayes/vndatayes.py b/vnpy/data/datayes/vndatayes.py new file mode 100644 index 00000000..f64aaf68 --- /dev/null +++ b/vnpy/data/datayes/vndatayes.py @@ -0,0 +1,52 @@ +# encoding: UTF-8 + +'''一个简单的通联数据客户端,主要使用requests开发,比通联官网的python例子更为简洁。''' + +import os +import requests +import json + + +HTTP_OK = 200 + + +######################################################################## +class DatayesApi(object): + """通联数据API""" + + #---------------------------------------------------------------------- + def __init__(self, token, + domain="http://api.wmcloud.com/data", + version="v1"): + """Constructor""" + self.domain = domain # 主域名 + self.version = version # API版本 + self.token = token # 授权码 + + self.header = {} # http请求头部 + self.header['Connection'] = 'keep_alive' + self.header['Authorization'] = 'Bearer ' + self.token + + #---------------------------------------------------------------------- + def downloadData(self, path, params): + """下载数据""" + url = '/'.join([self.domain, self.version, path]) + r = requests.get(url=url, headers=self.header, params=params) + + if r.status_code != HTTP_OK: + print u'http请求失败,状态代码%s' %r.status_code + return None + else: + result = r.json() + if 'retMsg' in result and result['retMsg'] == 'Success': + return result['data'] + else: + if 'retMsg' in result: + print u'查询失败,返回信息%s' %result['retMsg'] + elif 'message' in result: + print u'查询失败,返回信息%s' %result['message'] + return None + + + + \ No newline at end of file diff --git a/vnpy/data/shcifco/__init__.py b/vnpy/data/shcifco/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vnpy/api/shcifco/vnshcifco.py b/vnpy/data/shcifco/vnshcifco.py similarity index 98% rename from vnpy/api/shcifco/vnshcifco.py rename to vnpy/data/shcifco/vnshcifco.py index 06626e97..94927d9c 100644 --- a/vnpy/api/shcifco/vnshcifco.py +++ b/vnpy/data/shcifco/vnshcifco.py @@ -7,7 +7,7 @@ HTTP_OK = 200 ######################################################################## -class DataApi(object): +class ShcifcoApi(object): """数据接口""" #---------------------------------------------------------------------- @@ -124,7 +124,7 @@ if __name__ == "__main__": port = '10102' token = 'testd2cda34b2d317779e812eb84ee4224a6_123456' - api = DataApi(ip, port, token) + api = ShcifcoApi(ip, port, token) api.getData(path, params) print api.getLastTick('cu1709') diff --git a/vnpy/trader/app/ctaStrategy/ctaHistoryData.py b/vnpy/trader/app/ctaStrategy/ctaHistoryData.py index 5366468d..d9c97375 100644 --- a/vnpy/trader/app/ctaStrategy/ctaHistoryData.py +++ b/vnpy/trader/app/ctaStrategy/ctaHistoryData.py @@ -13,10 +13,10 @@ from multiprocessing.pool import ThreadPool import pymongo +from vnpy.data.datayes import DatayesApi from vnpy.trader.vtGlobal import globalSetting from vnpy.trader.vtConstant import * from vnpy.trader.vtObject import VtBarData -from vnpy.trader.app.ctaStrategy.datayesClient import DatayesClient # 以下为vn.trader和通联数据规定的交易所代码映射 @@ -33,10 +33,10 @@ class HistoryDataEngine(object): """CTA模块用的历史数据引擎""" #---------------------------------------------------------------------- - def __init__(self): + def __init__(self, token): """Constructor""" self.dbClient = pymongo.MongoClient(globalSetting['mongoHost'], globalSetting['mongoPort']) - self.datayesClient = DatayesClient() + self.datayesClient = DatayesApi(token) #---------------------------------------------------------------------- def lastTradeDate(self): diff --git a/vnpy/trader/app/spreadTrading/stEngine.py b/vnpy/trader/app/spreadTrading/stEngine.py index 71e89c31..6789da12 100644 --- a/vnpy/trader/app/spreadTrading/stEngine.py +++ b/vnpy/trader/app/spreadTrading/stEngine.py @@ -11,7 +11,8 @@ from vnpy.trader.vtEvent import (EVENT_TICK, EVENT_TRADE, EVENT_POSITION, from vnpy.trader.vtObject import (VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData) from vnpy.trader.vtConstant import (DIRECTION_LONG, DIRECTION_SHORT, - OFFSET_OPEN, OFFSET_CLOSE) + OFFSET_OPEN, OFFSET_CLOSE, + PRICETYPE_LIMITPRICE) from .stBase import (StLeg, StSpread, EVENT_SPREADTRADING_TICK, EVENT_SPREADTRADING_POS, EVENT_SPREADTRADING_LOG, @@ -358,6 +359,7 @@ class StAlgoEngine(object): req.direction = direction req.offset = offset req.volume = volume + req.priceType = PRICETYPE_LIMITPRICE if direction == DIRECTION_LONG: req.price = price + payup * contract.priceTick