commit
41a8d2f7df
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
# C++源代码
|
||||
# C++源代码
|
||||
ipch/
|
||||
Release/
|
||||
|
||||
@ -49,4 +49,5 @@ vn.lts/build/*
|
||||
|
||||
vn.trader/ctaAlgo/data/*
|
||||
vn.trader/build/*
|
||||
vn.trader/dist/*
|
||||
vn.trader/dist/*
|
||||
*.bak
|
||||
|
@ -7,5 +7,5 @@
|
||||
"mongoLogging": true,
|
||||
|
||||
"darkStyle": true,
|
||||
"language": "English"
|
||||
"language": "english"
|
||||
}
|
@ -436,6 +436,52 @@ def loadTdxCsv(fileName, dbName, symbol):
|
||||
|
||||
print u'插入完毕,耗时:%s' % (time()-start)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def loadTBCsv(fileName, dbName, symbol):
|
||||
"""将TradeBlazer导出的csv格式的历史数据插入到Mongo数据库中
|
||||
数据样本:
|
||||
//时间,开盘价,最高价,最低价,收盘价,成交量,持仓量
|
||||
2017/04/05 09:00,3200,3240,3173,3187,312690,2453850
|
||||
"""
|
||||
import csv
|
||||
|
||||
start = time()
|
||||
print u'开始读取CSV文件%s中的数据插入到%s的%s中' %(fileName, dbName, symbol)
|
||||
|
||||
# 锁定集合,并创建索引
|
||||
host, port, logging = loadMongoSetting()
|
||||
|
||||
client = pymongo.MongoClient(host, port)
|
||||
collection = client[dbName][symbol]
|
||||
collection.ensure_index([('datetime', pymongo.ASCENDING)], unique=True)
|
||||
|
||||
# 读取数据和插入到数据库
|
||||
reader = csv.reader(file(fileName, 'r'))
|
||||
for d in reader:
|
||||
if len(d[0]) > 10:
|
||||
bar = CtaBarData()
|
||||
bar.vtSymbol = symbol
|
||||
bar.symbol = symbol
|
||||
|
||||
bar.datetime = datetime.strptime(d[0], '%Y/%m/%d %H:%M')
|
||||
bar.date = bar.datetime.date().strftime('%Y%m%d')
|
||||
bar.time = bar.datetime.time().strftime('%H:%M:%S')
|
||||
|
||||
bar.open = float(d[1])
|
||||
bar.high = float(d[2])
|
||||
bar.low = float(d[3])
|
||||
bar.close = float(d[4])
|
||||
|
||||
bar.volume = float(d[5])
|
||||
bar.openInterest = float(d[6])
|
||||
|
||||
flt = {'datetime': bar.datetime}
|
||||
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
|
||||
print '%s \t %s' % (bar.date, bar.time)
|
||||
|
||||
print u'插入完毕,耗时:%s' % (time()-start)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
## 简单的测试脚本可以写在这里
|
||||
#from time import sleep
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from Chinese import text
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'English':
|
||||
from English import text
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from Chinese import text
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'English':
|
||||
from English import text
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"brokerID": "9999",
|
||||
"tdAddress": "tcp://180.168.146.187:10000",
|
||||
"password": "simnow申请",
|
||||
"mdAddress": "tcp://180.168.212.228:41213",
|
||||
"userID": "simnow申请"
|
||||
"password": "19890624",
|
||||
"mdAddress": "tcp://180.168.146.187:10010",
|
||||
"userID": "000300"
|
||||
}
|
@ -710,7 +710,8 @@ class CtpTdApi(TdApi):
|
||||
pos.positionProfit += data['PositionProfit']
|
||||
|
||||
# 计算持仓均价
|
||||
pos.price = (cost + data['PositionCost']) / pos.position
|
||||
if pos.position:
|
||||
pos.price = (cost + data['PositionCost']) / pos.position
|
||||
|
||||
# 读取冻结
|
||||
if pos.direction is DIRECTION_LONG:
|
||||
|
@ -5,10 +5,10 @@ import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from Chinese import text
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
SETTING_FILENAME = 'VT_setting.json'
|
||||
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
|
||||
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'English':
|
||||
from English import text
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
@ -5,10 +5,10 @@ import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from Chinese import text
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
SETTING_FILENAME = 'VT_setting.json'
|
||||
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
|
||||
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'English':
|
||||
from English import text
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
@ -4,7 +4,7 @@ import json
|
||||
import os
|
||||
|
||||
# 默认设置
|
||||
from Chinese import text, constant
|
||||
from chinese import text, constant
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
@ -15,8 +15,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'English':
|
||||
from English import text, constant
|
||||
if setting['language'] == 'english':
|
||||
from english import text, constant
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
@ -123,4 +123,11 @@ TEST = u'测试'
|
||||
CONNECT = u'连接'
|
||||
|
||||
CPU_MEMORY_INFO = u'CPU使用率:{cpu}% 内存使用率:{memory}%'
|
||||
CONFIRM_EXIT = u'确认退出?'
|
||||
CONFIRM_EXIT = u'确认退出?'
|
||||
|
||||
GATEWAY_NOT_EXIST = u'接口不存在:{gateway}'
|
||||
DATABASE_CONNECTING_COMPLETED = u'MongoDB连接成功'
|
||||
DATABASE_CONNECTING_FAILED = u'MongoDB连接失败'
|
||||
DATA_INSERT_FAILED = u'数据插入失败,MongoDB没有连接'
|
||||
DATA_QUERY_FAILED = u'数据查询失败,MongoDB没有连接'
|
||||
DATA_UPDATE_FAILED = u'数据更新失败,MongoDB没有连接'
|
||||
|
@ -87,11 +87,11 @@ ASK_PRICE_3 = u'Ask Price 3'
|
||||
ASK_PRICE_4 = u'Ask Price 4'
|
||||
ASK_PRICE_5 = u'Ask Price 5'
|
||||
|
||||
BID_VOLUME_1 = u'Bid Price 1'
|
||||
BID_VOLUME_2 = u'Bid Price 2'
|
||||
BID_VOLUME_3 = u'Bid Price 3'
|
||||
BID_VOLUME_4 = u'Bid Price 4'
|
||||
BID_VOLUME_5 = u'Bid Price 5'
|
||||
BID_VOLUME_1 = u'Bid Volume 1'
|
||||
BID_VOLUME_2 = u'Bid Volume 2'
|
||||
BID_VOLUME_3 = u'Bid Volume 3'
|
||||
BID_VOLUME_4 = u'Bid Volume 4'
|
||||
BID_VOLUME_5 = u'Bid Volume 5'
|
||||
ASK_VOLUME_1 = u'Ask Volume 1'
|
||||
ASK_VOLUME_2 = u'Ask Volume 2'
|
||||
ASK_VOLUME_3 = u'Ask Volume 3'
|
||||
@ -123,4 +123,11 @@ TEST = u'Test'
|
||||
CONNECT = u'Connect '
|
||||
|
||||
CPU_MEMORY_INFO = u'CPU Usage:{cpu}% Memory Usage:{memory}%'
|
||||
CONFIRM_EXIT = u'Confirm Exit?'
|
||||
CONFIRM_EXIT = u'Confirm Exit?'
|
||||
|
||||
GATEWAY_NOT_EXIST = u"Can't find the gateway:{gateway}"
|
||||
DATABASE_CONNECTING_COMPLETED = u'MongoDB is connected.'
|
||||
DATABASE_CONNECTING_FAILED = u'Failed to connect to MongoDB.'
|
||||
DATA_INSERT_FAILED = u'Data insert failed,please connect MongoDB first.'
|
||||
DATA_QUERY_FAILED = u'Data query failed, please connect MongoDB first.'
|
||||
DATA_UPDATE_FAILED = u'Data update failed, please connect MongoDB first.'
|
@ -5,7 +5,7 @@ import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from Chinese import text
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'English':
|
||||
from English import text
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
@ -10,6 +10,7 @@ from pymongo.errors import ConnectionFailure
|
||||
from eventEngine import *
|
||||
from vtGateway import *
|
||||
from vtFunction import loadMongoSetting
|
||||
from language import text
|
||||
|
||||
from gateway import GATEWAY_DICT
|
||||
from ctaStrategy.ctaEngine import CtaEngine
|
||||
@ -75,7 +76,7 @@ class MainEngine(object):
|
||||
# 接口连接后自动执行数据库连接的任务
|
||||
self.dbConnect()
|
||||
else:
|
||||
self.writeLog(u'接口不存在:%s' %gatewayName)
|
||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def subscribe(self, subscribeReq, gatewayName):
|
||||
@ -84,7 +85,7 @@ class MainEngine(object):
|
||||
gateway = self.gatewayDict[gatewayName]
|
||||
gateway.subscribe(subscribeReq)
|
||||
else:
|
||||
self.writeLog(u'接口不存在:%s' %gatewayName)
|
||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def sendOrder(self, orderReq, gatewayName):
|
||||
@ -97,7 +98,7 @@ class MainEngine(object):
|
||||
gateway = self.gatewayDict[gatewayName]
|
||||
return gateway.sendOrder(orderReq)
|
||||
else:
|
||||
self.writeLog(u'接口不存在:%s' %gatewayName)
|
||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def cancelOrder(self, cancelOrderReq, gatewayName):
|
||||
@ -106,7 +107,8 @@ class MainEngine(object):
|
||||
gateway = self.gatewayDict[gatewayName]
|
||||
gateway.cancelOrder(cancelOrderReq)
|
||||
else:
|
||||
self.writeLog(u'接口不存在:%s' %gatewayName)
|
||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def qryAccount(self, gatewayName):
|
||||
@ -115,7 +117,7 @@ class MainEngine(object):
|
||||
gateway = self.gatewayDict[gatewayName]
|
||||
gateway.qryAccount()
|
||||
else:
|
||||
self.writeLog(u'接口不存在:%s' %gatewayName)
|
||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def qryPosition(self, gatewayName):
|
||||
@ -124,7 +126,7 @@ class MainEngine(object):
|
||||
gateway = self.gatewayDict[gatewayName]
|
||||
gateway.qryPosition()
|
||||
else:
|
||||
self.writeLog(u'接口不存在:%s' %gatewayName)
|
||||
self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def exit(self):
|
||||
@ -165,14 +167,14 @@ class MainEngine(object):
|
||||
# 调用server_info查询服务器状态,防止服务器异常并未连接成功
|
||||
self.dbClient.server_info()
|
||||
|
||||
self.writeLog(u'MongoDB连接成功')
|
||||
self.writeLog(text.DATABASE_CONNECTING_COMPLETED)
|
||||
|
||||
# 如果启动日志记录,则注册日志事件监听函数
|
||||
if logging:
|
||||
self.eventEngine.register(EVENT_LOG, self.dbLogging)
|
||||
|
||||
except ConnectionFailure:
|
||||
self.writeLog(u'MongoDB连接失败')
|
||||
self.writeLog(text.DATABASE_CONNECTING_FAILED)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def dbInsert(self, dbName, collectionName, d):
|
||||
@ -182,7 +184,7 @@ class MainEngine(object):
|
||||
collection = db[collectionName]
|
||||
collection.insert_one(d)
|
||||
else:
|
||||
self.writeLog(u'数据插入失败,MongoDB没有连接')
|
||||
self.writeLog(text.DATA_INSERT_FAILED)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def dbQuery(self, dbName, collectionName, d):
|
||||
@ -196,7 +198,7 @@ class MainEngine(object):
|
||||
else:
|
||||
return []
|
||||
else:
|
||||
self.writeLog(u'数据查询失败,MongoDB没有连接')
|
||||
self.writeLog(text.DATA_QUERY_FAILED)
|
||||
return []
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -207,7 +209,7 @@ class MainEngine(object):
|
||||
collection = db[collectionName]
|
||||
collection.replace_one(flt, d, upsert)
|
||||
else:
|
||||
self.writeLog(u'数据更新失败,MongoDB没有连接')
|
||||
self.writeLog(text.DATA_UPDATE_FAILED)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def dbLogging(self, event):
|
||||
|
Loading…
Reference in New Issue
Block a user