<NME> .gitignore
<BEF> ﻿# C++源代码
ipch/
Release/


# Jupyter
.ipynb_checkpoints

# IDE
.vscode
.idea
*.wpr
*.wpu
.vs
x64

# Temp
build
dist
*.local

# VeighNa
.vntrader

# Visual Studio intermediate files
*.exp
*.iobj
*.ipdb
*.pdb

# Documents
_build
_static
_templates

# Misc
.DS_Store
vn.trader/ctaAlgo/data/*
vn.trader/build/*
vn.trader/dist/*

<MSG> Merge pull request #288 from vnpy/dev

Dev
<DFF> @@ -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/*
\ No newline at end of file
+vn.trader/dist/*
+*.bak

{'commit': 'diff --git a/.gitignore b/.gitignore\nindex 45f47ea9..54c74033 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -1,4 +1,4 @@\n-\ufeff# C++源代码\n+# C++源代码\n ipch/\n Release/\n \n@@ -49,4 +49,5 @@ vn.lts/build/*\n \n vn.trader/ctaAlgo/data/*\n vn.trader/build/*\n-vn.trader/dist/*\n\\ No newline at end of file\n+vn.trader/dist/*\n+*.bak\ndiff --git a/vn.trader/VT_setting.json b/vn.trader/VT_setting.json\nindex 5f15b65d..776c8d36 100644\n--- a/vn.trader/VT_setting.json\n+++ b/vn.trader/VT_setting.json\n@@ -7,5 +7,5 @@\n \t"mongoLogging": true,\n \n \t"darkStyle": true,\n-\t"language": "English"\n+\t"language": "english"\n }\n\\ No newline at end of file\ndiff --git a/vn.trader/ctaStrategy/ctaHistoryData.py b/vn.trader/ctaStrategy/ctaHistoryData.py\nindex b6fb211e..0ddc0d7a 100644\n--- a/vn.trader/ctaStrategy/ctaHistoryData.py\n+++ b/vn.trader/ctaStrategy/ctaHistoryData.py\n@@ -436,6 +436,52 @@ def loadTdxCsv(fileName, dbName, symbol):\n     \n     print u\'插入完毕，耗时：%s\' % (time()-start)\n     \n+#----------------------------------------------------------------------\n+def loadTBCsv(fileName, dbName, symbol):\n+    """将TradeBlazer导出的csv格式的历史数据插入到Mongo数据库中\n+        数据样本：\n+        //时间,开盘价,最高价,最低价,收盘价,成交量,持仓量\n+        2017/04/05 09:00,3200,3240,3173,3187,312690,2453850\n+    """\n+    import csv\n+    \n+    start = time()\n+    print u\'开始读取CSV文件%s中的数据插入到%s的%s中\' %(fileName, dbName, symbol)\n+    \n+    # 锁定集合，并创建索引\n+    host, port, logging = loadMongoSetting()\n+    \n+    client = pymongo.MongoClient(host, port)    \n+    collection = client[dbName][symbol]\n+    collection.ensure_index([(\'datetime\', pymongo.ASCENDING)], unique=True)\n+    \n+    # 读取数据和插入到数据库\n+    reader = csv.reader(file(fileName, \'r\'))\n+    for d in reader:\n+        if len(d[0]) > 10:\n+            bar = CtaBarData()\n+            bar.vtSymbol = symbol\n+            bar.symbol = symbol\n+            \n+            bar.datetime = datetime.strptime(d[0], \'%Y/%m/%d %H:%M\')\n+            bar.date = bar.datetime.date().strftime(\'%Y%m%d\')\n+            bar.time = bar.datetime.time().strftime(\'%H:%M:%S\')\n+            \n+            bar.open = float(d[1])\n+            bar.high = float(d[2])\n+            bar.low = float(d[3])\n+            bar.close = float(d[4])\n+            \n+            bar.volume = float(d[5])\n+            bar.openInterest = float(d[6])\n+\n+            flt = {\'datetime\': bar.datetime}\n+            collection.update_one(flt, {\'$set\':bar.__dict__}, upsert=True)\n+            print \'%s \\t %s\' % (bar.date, bar.time)\n+    \n+    print u\'插入完毕，耗时：%s\' % (time()-start)\n+    \n+    \n if __name__ == \'__main__\':\n     ## 简单的测试脚本可以写在这里\n     #from time import sleep\ndiff --git a/vn.trader/ctaStrategy/language/__init__.py b/vn.trader/ctaStrategy/language/__init__.py\nindex 9b79651c..e42bd064 100644\n--- a/vn.trader/ctaStrategy/language/__init__.py\n+++ b/vn.trader/ctaStrategy/language/__init__.py\n@@ -5,7 +5,7 @@ import os\n import traceback\n \n # 默认设置\n-from Chinese import text\n+from chinese import text\n \n # 获取目录上级路径\n path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\'))\n@@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n try:\n     f = file(SETTING_FILENAME)\n     setting = json.load(f)\n-    if setting[\'language\'] == \'English\':\n-        from English import text\n+    if setting[\'language\'] == \'english\':\n+        from english import text\n     f.close()\n except:\n     traceback.print_exc()\ndiff --git a/vn.trader/dataRecorder/language/__init__.py b/vn.trader/dataRecorder/language/__init__.py\nindex 9b79651c..e42bd064 100644\n--- a/vn.trader/dataRecorder/language/__init__.py\n+++ b/vn.trader/dataRecorder/language/__init__.py\n@@ -5,7 +5,7 @@ import os\n import traceback\n \n # 默认设置\n-from Chinese import text\n+from chinese import text\n \n # 获取目录上级路径\n path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\'))\n@@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n try:\n     f = file(SETTING_FILENAME)\n     setting = json.load(f)\n-    if setting[\'language\'] == \'English\':\n-        from English import text\n+    if setting[\'language\'] == \'english\':\n+        from english import text\n     f.close()\n except:\n     traceback.print_exc()\ndiff --git a/vn.trader/gateway/ctpGateway/CTP_connect.json b/vn.trader/gateway/ctpGateway/CTP_connect.json\nindex fe1ffded..0f3215d3 100644\n--- a/vn.trader/gateway/ctpGateway/CTP_connect.json\n+++ b/vn.trader/gateway/ctpGateway/CTP_connect.json\n@@ -1,7 +1,7 @@\n {\n     "brokerID": "9999", \n     "tdAddress": "tcp://180.168.146.187:10000", \n-    "password": "simnow申请", \n-    "mdAddress": "tcp://180.168.212.228:41213", \n-    "userID": "simnow申请"\n+    "password": "19890624", \n+    "mdAddress": "tcp://180.168.146.187:10010", \n+    "userID": "000300"\n }\n\\ No newline at end of file\ndiff --git a/vn.trader/gateway/ctpGateway/ctpGateway.py b/vn.trader/gateway/ctpGateway/ctpGateway.py\nindex 0d38e711..24d620b6 100644\n--- a/vn.trader/gateway/ctpGateway/ctpGateway.py\n+++ b/vn.trader/gateway/ctpGateway/ctpGateway.py\n@@ -710,7 +710,8 @@ class CtpTdApi(TdApi):\n         pos.positionProfit += data[\'PositionProfit\']\n         \n         # 计算持仓均价\n-        pos.price = (cost + data[\'PositionCost\']) / pos.position\n+        if pos.position:\n+            pos.price = (cost + data[\'PositionCost\']) / pos.position\n         \n         # 读取冻结\n         if pos.direction is DIRECTION_LONG: \ndiff --git a/vn.trader/gateway/ctpGateway/language/__init__.py b/vn.trader/gateway/ctpGateway/language/__init__.py\nindex 9b79651c..8325ae0c 100644\n--- a/vn.trader/gateway/ctpGateway/language/__init__.py\n+++ b/vn.trader/gateway/ctpGateway/language/__init__.py\n@@ -5,10 +5,10 @@ import os\n import traceback\n \n # 默认设置\n-from Chinese import text\n+from chinese import text\n \n # 获取目录上级路径\n-path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\'))\n+path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\', \'..\'))\n SETTING_FILENAME = \'VT_setting.json\'\n SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n \n@@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n try:\n     f = file(SETTING_FILENAME)\n     setting = json.load(f)\n-    if setting[\'language\'] == \'English\':\n-        from English import text\n+    if setting[\'language\'] == \'english\':\n+        from english import text\n     f.close()\n except:\n     traceback.print_exc()\ndiff --git a/vn.trader/gateway/ibGateway/language/__init__.py b/vn.trader/gateway/ibGateway/language/__init__.py\nindex 9b79651c..8325ae0c 100644\n--- a/vn.trader/gateway/ibGateway/language/__init__.py\n+++ b/vn.trader/gateway/ibGateway/language/__init__.py\n@@ -5,10 +5,10 @@ import os\n import traceback\n \n # 默认设置\n-from Chinese import text\n+from chinese import text\n \n # 获取目录上级路径\n-path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\'))\n+path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\', \'..\'))\n SETTING_FILENAME = \'VT_setting.json\'\n SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n \n@@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n try:\n     f = file(SETTING_FILENAME)\n     setting = json.load(f)\n-    if setting[\'language\'] == \'English\':\n-        from English import text\n+    if setting[\'language\'] == \'english\':\n+        from english import text\n     f.close()\n except:\n     traceback.print_exc()\ndiff --git a/vn.trader/language/__init__.py b/vn.trader/language/__init__.py\nindex 7c23b182..696e9d4e 100644\n--- a/vn.trader/language/__init__.py\n+++ b/vn.trader/language/__init__.py\n@@ -4,7 +4,7 @@ import json\n import os\n \n # 默认设置\n-from Chinese import text, constant\n+from chinese import text, constant\n \n # 获取目录上级路径\n path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\'))\n@@ -15,8 +15,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n try:\n     f = file(SETTING_FILENAME)\n     setting = json.load(f)\n-    if setting[\'language\'] == \'English\':\n-        from English import text, constant\n+    if setting[\'language\'] == \'english\':\n+        from english import text, constant\n     f.close()\n except:\n     pass\ndiff --git a/vn.trader/language/chinese/text.py b/vn.trader/language/chinese/text.py\nindex 995b3c72..dfad30fb 100644\n--- a/vn.trader/language/chinese/text.py\n+++ b/vn.trader/language/chinese/text.py\n@@ -123,4 +123,11 @@ TEST = u\'测试\'\n CONNECT = u\'连接\'\n \n CPU_MEMORY_INFO = u\'CPU使用率：{cpu}%   内存使用率：{memory}%\'\n-CONFIRM_EXIT = u\'确认退出？\'\n\\ No newline at end of file\n+CONFIRM_EXIT = u\'确认退出？\'\n+\n+GATEWAY_NOT_EXIST = u\'接口不存在：{gateway}\'\n+DATABASE_CONNECTING_COMPLETED = u\'MongoDB连接成功\'\n+DATABASE_CONNECTING_FAILED = u\'MongoDB连接失败\'\n+DATA_INSERT_FAILED = u\'数据插入失败，MongoDB没有连接\'\n+DATA_QUERY_FAILED = u\'数据查询失败，MongoDB没有连接\'\n+DATA_UPDATE_FAILED = u\'数据更新失败，MongoDB没有连接\'\ndiff --git a/vn.trader/language/english/text.py b/vn.trader/language/english/text.py\nindex d68cc67d..3864191d 100644\n--- a/vn.trader/language/english/text.py\n+++ b/vn.trader/language/english/text.py\n@@ -87,11 +87,11 @@ ASK_PRICE_3 = u\'Ask Price 3\'\n ASK_PRICE_4 = u\'Ask Price 4\'\n ASK_PRICE_5 = u\'Ask Price 5\'\n \n-BID_VOLUME_1 = u\'Bid Price 1\'\n-BID_VOLUME_2 = u\'Bid Price 2\'\n-BID_VOLUME_3 = u\'Bid Price 3\'\n-BID_VOLUME_4 = u\'Bid Price 4\'\n-BID_VOLUME_5 = u\'Bid Price 5\'\n+BID_VOLUME_1 = u\'Bid Volume 1\'\n+BID_VOLUME_2 = u\'Bid Volume 2\'\n+BID_VOLUME_3 = u\'Bid Volume 3\'\n+BID_VOLUME_4 = u\'Bid Volume 4\'\n+BID_VOLUME_5 = u\'Bid Volume 5\'\n ASK_VOLUME_1 = u\'Ask Volume 1\'\n ASK_VOLUME_2 = u\'Ask Volume 2\'\n ASK_VOLUME_3 = u\'Ask Volume 3\'\n@@ -123,4 +123,11 @@ TEST = u\'Test\'\n CONNECT = u\'Connect \'\n \n CPU_MEMORY_INFO = u\'CPU Usage：{cpu}%   Memory Usage：{memory}%\'\n-CONFIRM_EXIT = u\'Confirm Exit？\'\n\\ No newline at end of file\n+CONFIRM_EXIT = u\'Confirm Exit？\'\n+\n+GATEWAY_NOT_EXIST = u"Can\'t find the gateway：{gateway}"\n+DATABASE_CONNECTING_COMPLETED = u\'MongoDB is connected.\'\n+DATABASE_CONNECTING_FAILED = u\'Failed to connect to MongoDB.\'\n+DATA_INSERT_FAILED = u\'Data insert failed，please connect MongoDB first.\'\n+DATA_QUERY_FAILED = u\'Data query failed, please connect MongoDB first.\'\n+DATA_UPDATE_FAILED = u\'Data update failed, please connect MongoDB first.\'\n\\ No newline at end of file\ndiff --git a/vn.trader/riskManager/language/__init__.py b/vn.trader/riskManager/language/__init__.py\nindex 9b79651c..e42bd064 100644\n--- a/vn.trader/riskManager/language/__init__.py\n+++ b/vn.trader/riskManager/language/__init__.py\n@@ -5,7 +5,7 @@ import os\n import traceback\n \n # 默认设置\n-from Chinese import text\n+from chinese import text\n \n # 获取目录上级路径\n path = os.path.abspath(os.path.join(os.path.dirname(__file__), \'..\', \'..\'))\n@@ -16,8 +16,8 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)\n try:\n     f = file(SETTING_FILENAME)\n     setting = json.load(f)\n-    if setting[\'language\'] == \'English\':\n-        from English import text\n+    if setting[\'language\'] == \'english\':\n+        from english import text\n     f.close()\n except:\n     traceback.print_exc()\ndiff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py\nindex c4c6864a..ec9c796a 100644\n--- a/vn.trader/vtEngine.py\n+++ b/vn.trader/vtEngine.py\n@@ -10,6 +10,7 @@ from pymongo.errors import ConnectionFailure\n from eventEngine import *\n from vtGateway import *\n from vtFunction import loadMongoSetting\n+from language import text\n \n from gateway import GATEWAY_DICT\n from ctaStrategy.ctaEngine import CtaEngine\n@@ -75,7 +76,7 @@ class MainEngine(object):\n             # 接口连接后自动执行数据库连接的任务\n             self.dbConnect()\n         else:\n-            self.writeLog(u\'接口不存在：%s\' %gatewayName)\n+            self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))\n         \n     #----------------------------------------------------------------------\n     def subscribe(self, subscribeReq, gatewayName):\n@@ -84,7 +85,7 @@ class MainEngine(object):\n             gateway = self.gatewayDict[gatewayName]\n             gateway.subscribe(subscribeReq)\n         else:\n-            self.writeLog(u\'接口不存在：%s\' %gatewayName)        \n+            self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))        \n         \n     #----------------------------------------------------------------------\n     def sendOrder(self, orderReq, gatewayName):\n@@ -97,7 +98,7 @@ class MainEngine(object):\n             gateway = self.gatewayDict[gatewayName]\n             return gateway.sendOrder(orderReq)\n         else:\n-            self.writeLog(u\'接口不存在：%s\' %gatewayName)        \n+            self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))        \n     \n     #----------------------------------------------------------------------\n     def cancelOrder(self, cancelOrderReq, gatewayName):\n@@ -106,7 +107,8 @@ class MainEngine(object):\n             gateway = self.gatewayDict[gatewayName]\n             gateway.cancelOrder(cancelOrderReq)\n         else:\n-            self.writeLog(u\'接口不存在：%s\' %gatewayName)        \n+            self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))\n+            \n         \n     #----------------------------------------------------------------------\n     def qryAccount(self, gatewayName):\n@@ -115,7 +117,7 @@ class MainEngine(object):\n             gateway = self.gatewayDict[gatewayName]\n             gateway.qryAccount()\n         else:\n-            self.writeLog(u\'接口不存在：%s\' %gatewayName)        \n+            self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))        \n         \n     #----------------------------------------------------------------------\n     def qryPosition(self, gatewayName):\n@@ -124,7 +126,7 @@ class MainEngine(object):\n             gateway = self.gatewayDict[gatewayName]\n             gateway.qryPosition()\n         else:\n-            self.writeLog(u\'接口不存在：%s\' %gatewayName)        \n+            self.writeLog(text.GATEWAY_NOT_EXIST.format(gateway=gatewayName))        \n         \n     #----------------------------------------------------------------------\n     def exit(self):\n@@ -165,14 +167,14 @@ class MainEngine(object):\n                 # 调用server_info查询服务器状态，防止服务器异常并未连接成功\n                 self.dbClient.server_info()\n \n-                self.writeLog(u\'MongoDB连接成功\')\n+                self.writeLog(text.DATABASE_CONNECTING_COMPLETED)\n                 \n                 # 如果启动日志记录，则注册日志事件监听函数\n                 if logging:\n                     self.eventEngine.register(EVENT_LOG, self.dbLogging)\n                     \n             except ConnectionFailure:\n-                self.writeLog(u\'MongoDB连接失败\')\n+                self.writeLog(text.DATABASE_CONNECTING_FAILED)\n     \n     #----------------------------------------------------------------------\n     def dbInsert(self, dbName, collectionName, d):\n@@ -182,7 +184,7 @@ class MainEngine(object):\n             collection = db[collectionName]\n             collection.insert_one(d)\n         else:\n-            self.writeLog(u\'数据插入失败，MongoDB没有连接\')\n+            self.writeLog(text.DATA_INSERT_FAILED)\n     \n     #----------------------------------------------------------------------\n     def dbQuery(self, dbName, collectionName, d):\n@@ -196,7 +198,7 @@ class MainEngine(object):\n             else:\n                 return []\n         else:\n-            self.writeLog(u\'数据查询失败，MongoDB没有连接\')   \n+            self.writeLog(text.DATA_QUERY_FAILED)   \n             return []\n         \n     #----------------------------------------------------------------------\n@@ -207,7 +209,7 @@ class MainEngine(object):\n             collection = db[collectionName]\n             collection.replace_one(flt, d, upsert)\n         else:\n-            self.writeLog(u\'数据更新失败，MongoDB没有连接\')        \n+            self.writeLog(text.DATA_UPDATE_FAILED)        \n             \n     #----------------------------------------------------------------------\n     def dbLogging(self, event):\n', 'commit_subject': 'Merge pull request #288 from vnpy/dev', 'repo_name': 'vnpy/vnpy', 'committer': {'name': 'GitHub', 'email': '1505422b2465e9a84f6fdfaa161078890c593f06@github.com', 'time_sec': '1492007993', 'tz_offset': '480', 'date': {'seconds': '1492007993'}}, 'commit_tree': 'cc63197fb4d956ca1b5c1b46191a795f679b72d3', 'commit_message': 'Merge pull request #288 from vnpy/dev\n\nDev', 'language_name': 'Shell', 'license': 'mit', 'hunks': '@@ -1,4 +1,4 @@\n-\ufeff# C++源代码\n+# C++源代码\n ipch/\n Release/\n \n@@ -49,4 +49,5 @@ vn.lts/build/*\n \n vn.trader/ctaAlgo/data/*\n vn.trader/build/*\n-vn.trader/dist/*\n\\ No newline at end of file\n+vn.trader/dist/*\n+*.bak\n', 'addition_count': 3, 'deletion_count': 2, 'src_file': 'a/.gitignore', 'tgt_file': 'b/.gitignore', 'file_extension': '', 'before_file': '\ufeff# C++源代码\nipch/\nRelease/\n\n\n# Jupyter\n.ipynb_checkpoints\n\n# IDE\n.vscode\n.idea\n*.wpr\n*.wpu\n.vs\nx64\n\n# Temp\nbuild\ndist\n*.local\n\n# VeighNa\n.vntrader\n\n# Visual Studio intermediate files\n*.exp\n*.iobj\n*.ipdb\n*.pdb\n\n# Documents\n_build\n_static\n_templates\n\n# Misc\n.DS_Store\nvn.trader/ctaAlgo/data/*\nvn.trader/build/*\nvn.trader/dist/*\n', 'message': 'Merge pull request #288 from vnpy/dev\n\nDev', 'author_name': 'GitHub', 'lang': 'gitignore'}