增加vnpy.data用于存放数据相关的功能模块
Before Width: | Height: | Size: 618 KiB After Width: | Height: | Size: 618 KiB |
Before Width: | Height: | Size: 234 KiB After Width: | Height: | Size: 234 KiB |
Before Width: | Height: | Size: 465 KiB After Width: | Height: | Size: 465 KiB |
Before Width: | Height: | Size: 465 KiB After Width: | Height: | Size: 465 KiB |
Before Width: | Height: | Size: 320 KiB After Width: | Height: | Size: 320 KiB |
Before Width: | Height: | Size: 319 KiB After Width: | Height: | Size: 319 KiB |
5
vnpy/data/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# vn.data - 数据相关工具
|
||||
|
||||
### 历史数据
|
||||
* datayes:通联数据接口
|
||||
* shcifco:上海中期接口
|
1
vnpy/data/datayes/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from vndatayes import DatayesApi
|
52
vnpy/data/datayes/vndatayes.py
Normal 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
|
||||
|
||||
|
||||
|
||||
|
0
vnpy/data/shcifco/__init__.py
Normal 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')
|
@ -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):
|
||||
|
@ -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
|
||||
|