Merge branch 'dev' of https://github.com/vnpy/vnpy into dev
This commit is contained in:
commit
ba1733a46a
22
.travis.yml
Normal file
22
.travis.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
group: travis_latest
|
||||||
|
language: python
|
||||||
|
cache: pip
|
||||||
|
python:
|
||||||
|
- 2.7
|
||||||
|
- 3.6
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- python: 3.6
|
||||||
|
install:
|
||||||
|
- pip install -r requirements.txt
|
||||||
|
- pip install flake8 # pytest # add another testing frameworks later
|
||||||
|
before_script:
|
||||||
|
# stop the build if there are Python syntax errors or undefined names
|
||||||
|
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
|
||||||
|
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||||
|
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||||
|
script:
|
||||||
|
- true # pytest --capture=sys # add other tests here
|
||||||
|
notifications:
|
||||||
|
on_success: change
|
||||||
|
on_failure: change # `always` will be the setting once code changes slow down
|
@ -1,6 +1,10 @@
|
|||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
|
|
||||||
# 重载sys模块,设置默认字符串编码方式为utf8
|
# 重载sys模块,设置默认字符串编码方式为utf8
|
||||||
|
try:
|
||||||
|
reload # Python 2
|
||||||
|
except NameError: # Python 3
|
||||||
|
from importlib import reload
|
||||||
import sys
|
import sys
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
@ -19,7 +23,9 @@ from vnpy.trader.uiMainWindow import MainWindow
|
|||||||
from vnpy.trader.gateway import (ctpGateway, oandaGateway,
|
from vnpy.trader.gateway import (ctpGateway, oandaGateway,
|
||||||
ibGateway)
|
ibGateway)
|
||||||
|
|
||||||
if system == 'Windows':
|
if system == 'Linux':
|
||||||
|
from vnpy.trader.gateway import xtpGateway
|
||||||
|
elif system == 'Windows':
|
||||||
from vnpy.trader.gateway import (femasGateway, xspeedGateway,
|
from vnpy.trader.gateway import (femasGateway, xspeedGateway,
|
||||||
futuGateway, secGateway)
|
futuGateway, secGateway)
|
||||||
|
|
||||||
|
@ -177,11 +177,22 @@ def loadTbPlusCsv(fileName, dbName, symbol):
|
|||||||
print u'插入完毕,耗时:%s' % (time()-start)
|
print u'插入完毕,耗时:%s' % (time()-start)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
"""
|
||||||
|
使用中银国际证券通达信导出的1分钟K线数据为模版
|
||||||
|
格式:csv
|
||||||
|
样例:
|
||||||
|
|
||||||
|
时间 开盘价 最高价 最低价 收盘价 成交量
|
||||||
|
2017/09/28-10:52 3457 3459 3456 3458 466
|
||||||
|
|
||||||
|
注意事项:导出csv后手工删除表头和表尾
|
||||||
|
"""
|
||||||
def loadTdxCsv(fileName, dbName, symbol):
|
def loadTdxCsv(fileName, dbName, symbol):
|
||||||
"""将通达信导出的csv格式的历史分钟数据插入到Mongo数据库中"""
|
"""将通达信导出的csv格式的历史分钟数据插入到Mongo数据库中"""
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
start = time()
|
start = time()
|
||||||
|
date_correct = ""
|
||||||
print u'开始读取CSV文件%s中的数据插入到%s的%s中' %(fileName, dbName, symbol)
|
print u'开始读取CSV文件%s中的数据插入到%s的%s中' %(fileName, dbName, symbol)
|
||||||
|
|
||||||
# 锁定集合,并创建索引
|
# 锁定集合,并创建索引
|
||||||
@ -195,19 +206,75 @@ def loadTdxCsv(fileName, dbName, symbol):
|
|||||||
bar = VtBarData()
|
bar = VtBarData()
|
||||||
bar.vtSymbol = symbol
|
bar.vtSymbol = symbol
|
||||||
bar.symbol = symbol
|
bar.symbol = symbol
|
||||||
bar.open = float(d[2])
|
bar.open = float(d[1])
|
||||||
bar.high = float(d[3])
|
bar.high = float(d[2])
|
||||||
bar.low = float(d[4])
|
bar.low = float(d[3])
|
||||||
bar.close = float(d[5])
|
bar.close = float(d[4])
|
||||||
bar.date = datetime.strptime(d[0], '%Y/%m/%d').strftime('%Y%m%d')
|
#通达信的夜盘时间按照新的一天计算,此处将其按照当天日期统计,方便后续查阅
|
||||||
bar.time = d[1][:2]+':'+d[1][2:4]+':00'
|
date_temp,time_temp = d[0].strip(' ').replace('\xef\xbb\xbf','').split('-',1)
|
||||||
|
if time_temp == '15:00':
|
||||||
|
date_correct = date_temp
|
||||||
|
if time_temp[:2] == "21" or time_temp[:2] == "22" or time_temp[:2] == "23":
|
||||||
|
date_temp = date_correct
|
||||||
|
|
||||||
|
bar.date = datetime.strptime(date_temp, '%Y/%m/%d').strftime('%Y%m%d')
|
||||||
|
bar.time = time_temp[:2]+':'+time_temp[3:5]+':00'
|
||||||
bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S')
|
bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S')
|
||||||
bar.volume = d[6]
|
bar.volume = d[5]
|
||||||
bar.openInterest = d[7]
|
|
||||||
|
flt = {'datetime': bar.datetime}
|
||||||
|
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
|
||||||
|
|
||||||
|
print u'插入完毕,耗时:%s' % (time()-start)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
"""
|
||||||
|
使用中银国际证券通达信导出的1分钟K线数据为模版
|
||||||
|
格式:lc1
|
||||||
|
|
||||||
|
注意事项:
|
||||||
|
"""
|
||||||
|
def loadTdxLc1(fileName, dbName, symbol):
|
||||||
|
"""将通达信导出的lc1格式的历史分钟数据插入到Mongo数据库中"""
|
||||||
|
from struct import *
|
||||||
|
|
||||||
|
start = time()
|
||||||
|
|
||||||
|
print u'开始读取通达信Lc1文件%s中的数据插入到%s的%s中' %(fileName, dbName, symbol)
|
||||||
|
|
||||||
|
# 锁定集合,并创建索引
|
||||||
|
client = pymongo.MongoClient(globalSetting['mongoHost'], globalSetting['mongoPort'])
|
||||||
|
collection = client[dbName][symbol]
|
||||||
|
collection.ensure_index([('datetime', pymongo.ASCENDING)], unique=True)
|
||||||
|
|
||||||
|
#读取二进制文件
|
||||||
|
ofile=open(fileName,'rb')
|
||||||
|
buf=ofile.read()
|
||||||
|
ofile.close()
|
||||||
|
|
||||||
|
num=len(buf)
|
||||||
|
no=num/32
|
||||||
|
b=0
|
||||||
|
e=32
|
||||||
|
dl = []
|
||||||
|
for i in xrange(no):
|
||||||
|
a=unpack('hhfffffii',buf[b:e])
|
||||||
|
b=b+32
|
||||||
|
e=e+32
|
||||||
|
bar = VtBarData()
|
||||||
|
bar.vtSymbol = symbol
|
||||||
|
bar.symbol = symbol
|
||||||
|
bar.open = a[2]
|
||||||
|
bar.high = a[3]
|
||||||
|
bar.low = a[4]
|
||||||
|
bar.close = a[5]
|
||||||
|
bar.date = str(int(a[0]/2048)+2004)+str(int(a[0]%2048/100)).zfill(2)+str(a[0]%2048%100).zfill(2)
|
||||||
|
bar.time = str(int(a[1]/60)).zfill(2)+':'+str(a[1]%60).zfill(2)+':00'
|
||||||
|
bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S')
|
||||||
|
bar.volume = a[7]
|
||||||
|
|
||||||
flt = {'datetime': bar.datetime}
|
flt = {'datetime': bar.datetime}
|
||||||
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
|
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
|
||||||
print bar.date, bar.time
|
|
||||||
|
|
||||||
print u'插入完毕,耗时:%s' % (time()-start)
|
print u'插入完毕,耗时:%s' % (time()-start)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user