From b92eea8978d3b604be2848eaab5fdb87dc81b3b4 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 9 Jun 2018 22:03:10 +0800 Subject: [PATCH] =?UTF-8?q?[Add]MainEngine=E5=A2=9E=E5=8A=A0dbDelete?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/language/chinese/text.py | 1 + vnpy/trader/language/english/text.py | 3 ++- vnpy/trader/vtEngine.py | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/vnpy/trader/language/chinese/text.py b/vnpy/trader/language/chinese/text.py index 61850491..f9729083 100644 --- a/vnpy/trader/language/chinese/text.py +++ b/vnpy/trader/language/chinese/text.py @@ -137,3 +137,4 @@ DATABASE_CONNECTING_FAILED = u'MongoDB连接失败' DATA_INSERT_FAILED = u'数据插入失败,MongoDB没有连接' DATA_QUERY_FAILED = u'数据查询失败,MongoDB没有连接' DATA_UPDATE_FAILED = u'数据更新失败,MongoDB没有连接' +DATA_DELETE_FAILED = u'数据删除失败,MongoDB没有连接' \ No newline at end of file diff --git a/vnpy/trader/language/english/text.py b/vnpy/trader/language/english/text.py index 6268d9c8..68ed2985 100644 --- a/vnpy/trader/language/english/text.py +++ b/vnpy/trader/language/english/text.py @@ -137,4 +137,5 @@ 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.' \ No newline at end of file +DATA_UPDATE_FAILED = u'Data update failed, please connect MongoDB first.' +DATA_DELETE_FAILED = u'Data delete failed, please connect MongoDB first.' \ No newline at end of file diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 75584a1f..e86d2c8f 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -251,7 +251,17 @@ class MainEngine(object): collection = db[collectionName] collection.replace_one(flt, d, upsert) else: - self.writeLog(text.DATA_UPDATE_FAILED) + self.writeLog(text.DATA_UPDATE_FAILED) + + #---------------------------------------------------------------------- + def dbDelete(self, dbName, collectionName, flt): + """从数据库中删除数据,flt是过滤条件""" + if self.dbClient: + db = self.dbClient[dbName] + collection = db[collectionName] + collection.delete_one(flt) + else: + self.writeLog(text.DATA_DELETE_FAILED) #---------------------------------------------------------------------- def dbLogging(self, event): @@ -735,7 +745,7 @@ class LogEngine(object): function = self.levelFunctionDict[log.logLevel] # 获取日志级别对应的处理函数 msg = '\t'.join([log.gatewayName, log.logContent]) function(msg) - + ######################################################################## class PositionDetail(object):