增加vnpy.data用于存放数据相关的功能模块

This commit is contained in:
vn.py 2017-06-27 16:55:37 +08:00
parent 1aea18504a
commit b3cdb0e2c0
33 changed files with 66 additions and 6 deletions

View File

Before

Width:  |  Height:  |  Size: 618 KiB

After

Width:  |  Height:  |  Size: 618 KiB

View File

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

View File

Before

Width:  |  Height:  |  Size: 465 KiB

After

Width:  |  Height:  |  Size: 465 KiB

View File

Before

Width:  |  Height:  |  Size: 465 KiB

After

Width:  |  Height:  |  Size: 465 KiB

View File

Before

Width:  |  Height:  |  Size: 320 KiB

After

Width:  |  Height:  |  Size: 320 KiB

View File

Before

Width:  |  Height:  |  Size: 319 KiB

After

Width:  |  Height:  |  Size: 319 KiB

5
vnpy/data/README.md Normal file
View File

@ -0,0 +1,5 @@
# vn.data - 数据相关工具
### 历史数据
* datayes通联数据接口
* shcifco上海中期接口

View File

@ -0,0 +1 @@
from vndatayes import DatayesApi

View File

@ -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

View File

View File

@ -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')

View File

@ -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):

View File

@ -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