From 27fab6bfba38b8cf47cb4fb3a21538ceca0a9ab8 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 20 Sep 2018 02:42:54 -0400 Subject: [PATCH 1/7] =?UTF-8?q?[Fix]=20=E4=BF=AE=E6=AD=A3=E5=B8=82?= =?UTF-8?q?=E4=BB=B7=E5=8D=95=E6=97=A0=E6=B3=95=E4=B8=8B=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/gateway/bitmexGateway/bitmexGateway.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vnpy/trader/gateway/bitmexGateway/bitmexGateway.py b/vnpy/trader/gateway/bitmexGateway/bitmexGateway.py index 599ead71..b55c3309 100644 --- a/vnpy/trader/gateway/bitmexGateway/bitmexGateway.py +++ b/vnpy/trader/gateway/bitmexGateway/bitmexGateway.py @@ -196,6 +196,11 @@ class RestApi(BitmexRestApi): 'orderQty': orderReq.volume, 'clOrdID': str(orderId) } + + # 市价单不能有price字段 + if orderReq.priceType == PRICETYPE_MARKETPRICE: + req.pop('price') + self.addReq('POST', '/order', self.onSendOrder, postdict=req) return vtOrderID From e690c65ea8b836e7ff01c9412328b31f48cfb087 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 7 Oct 2018 09:24:12 +0800 Subject: [PATCH 2/7] =?UTF-8?q?[Del]=E7=A7=BB=E9=99=A4=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5MongoDB=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/vtEngine.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index e86d2c8f..489a6dfd 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -113,9 +113,6 @@ class MainEngine(object): if gateway: gateway.connect() - - # 接口连接后自动执行数据库连接的任务 - self.dbConnect() #---------------------------------------------------------------------- def subscribe(self, subscribeReq, gatewayName): From c530a0a1b16c2f1d76758f2d756c05bb8908e2ad Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 10 Oct 2018 16:40:00 +0800 Subject: [PATCH 3/7] [Fix]Close #1153 --- vnpy/api/okex/vnokex.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vnpy/api/okex/vnokex.py b/vnpy/api/okex/vnokex.py index 555df99f..7d769b31 100644 --- a/vnpy/api/okex/vnokex.py +++ b/vnpy/api/okex/vnokex.py @@ -111,7 +111,8 @@ class OkexApi(object): if not self.reconnecting: self.reconnecting = True - self.closeWebsocket() # 首先关闭之前的连接 + self.closeWebsocket() # 首先关闭之前的连接 + self.heartbeatReceived = True # 将心跳状态设为正常 self.initWebsocket() self.reconnecting = False From 72fef7f1ff96caeba2ba60b16048f86f805e0064 Mon Sep 17 00:00:00 2001 From: huguanghui Date: Thu, 11 Oct 2018 20:30:59 +0800 Subject: [PATCH 4/7] fix symbol error --- vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py b/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py index 220358d2..f1128d45 100644 --- a/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py +++ b/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py @@ -7,13 +7,14 @@ from vnpy.trader.vtConstant import (DIRECTION_LONG, DIRECTION_SHORT, OFFSET_OPEN, OFFSET_CLOSE, STATUS_ALLTRADED, STATUS_CANCELLED, STATUS_REJECTED) + from vnpy.trader.uiQt import QtGui from vnpy.trader.app.algoTrading.algoTemplate import AlgoTemplate from vnpy.trader.app.algoTrading.uiAlgoWidget import AlgoWidget, QtWidgets -STATUS_FINISHED = set([STATUS_ALLTRADED, STATUS_CANCELLED, STATUS_REJECTED]) +STATUS_FINISHED = {STATUS_ALLTRADED, STATUS_CANCELLED, STATUS_REJECTED} ######################################################################## @@ -157,7 +158,7 @@ class ArbitrageAlgo(AlgoTemplate): tick.bidPrice5, volume) elif self.netPos < 0: - self.passiveOrderID = self.buy(self.activeVtSymbol, + self.passiveOrderID = self.buy(self.passiveVtSymbol, tick.askPrice5, volume) From 100700257bc937000488fbcfaf500d886f106984 Mon Sep 17 00:00:00 2001 From: huguanghui Date: Thu, 11 Oct 2018 20:34:27 +0800 Subject: [PATCH 5/7] fix symbol error --- vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py b/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py index f1128d45..6af2a99b 100644 --- a/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py +++ b/vnpy/trader/app/algoTrading/algo/arbitrageAlgo.py @@ -14,7 +14,7 @@ from vnpy.trader.app.algoTrading.algoTemplate import AlgoTemplate from vnpy.trader.app.algoTrading.uiAlgoWidget import AlgoWidget, QtWidgets -STATUS_FINISHED = {STATUS_ALLTRADED, STATUS_CANCELLED, STATUS_REJECTED} +STATUS_FINISHED = set([STATUS_ALLTRADED, STATUS_CANCELLED, STATUS_REJECTED]) ######################################################################## From bd6447a7082ce4def2354bfc9640bbbe997121c3 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 12 Oct 2018 14:45:18 +0800 Subject: [PATCH 6/7] =?UTF-8?q?[Mod]=E8=B0=83=E6=95=B4DataService=E7=9B=B8?= =?UTF-8?q?=E5=85=B3Demo=E7=9A=84=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => DataService}/CoinapiDataService/config.json | 0 .../CoinapiDataService/dataService.py | 7 ++++--- .../CoinapiDataService/downloadData.py | 0 .../CoinapiDataService/runService.py | 0 examples/{ => DataService}/FutuDataService/README.md | 0 .../{ => DataService}/FutuDataService/config.json | 0 .../{ => DataService}/FutuDataService/dataService.py | 0 .../{ => DataService}/FutuDataService/downloadData.py | 0 .../{ => DataService}/FutuDataService/runService.py | 0 examples/DataService/README.md | 11 +++++++++++ .../{ => DataService}/ShcifcoDataService/config.json | 0 .../ShcifcoDataService/dataService.py | 0 .../ShcifcoDataService/downloadData.py | 0 .../ShcifcoDataService/runService.py | 0 examples/{ => DataService}/TqDataService/README.md | 0 examples/{ => DataService}/TqDataService/config.json | 0 .../{ => DataService}/TqDataService/dataService.py | 0 .../{ => DataService}/TqDataService/downloadData.py | 0 .../{ => DataService}/TqDataService/runService.py | 0 .../{ => DataService}/TushareDataService/config.json | 0 .../TushareDataService/dataService.py | 0 .../TushareDataService/downloadData.py | 0 .../TushareDataService/runService.py | 0 examples/README.md | 10 +--------- 24 files changed, 16 insertions(+), 12 deletions(-) rename examples/{ => DataService}/CoinapiDataService/config.json (100%) rename examples/{ => DataService}/CoinapiDataService/dataService.py (95%) rename examples/{ => DataService}/CoinapiDataService/downloadData.py (100%) rename examples/{ => DataService}/CoinapiDataService/runService.py (100%) rename examples/{ => DataService}/FutuDataService/README.md (100%) rename examples/{ => DataService}/FutuDataService/config.json (100%) rename examples/{ => DataService}/FutuDataService/dataService.py (100%) rename examples/{ => DataService}/FutuDataService/downloadData.py (100%) rename examples/{ => DataService}/FutuDataService/runService.py (100%) create mode 100644 examples/DataService/README.md rename examples/{ => DataService}/ShcifcoDataService/config.json (100%) rename examples/{ => DataService}/ShcifcoDataService/dataService.py (100%) rename examples/{ => DataService}/ShcifcoDataService/downloadData.py (100%) rename examples/{ => DataService}/ShcifcoDataService/runService.py (100%) rename examples/{ => DataService}/TqDataService/README.md (100%) rename examples/{ => DataService}/TqDataService/config.json (100%) rename examples/{ => DataService}/TqDataService/dataService.py (100%) rename examples/{ => DataService}/TqDataService/downloadData.py (100%) rename examples/{ => DataService}/TqDataService/runService.py (100%) rename examples/{ => DataService}/TushareDataService/config.json (100%) rename examples/{ => DataService}/TushareDataService/dataService.py (100%) rename examples/{ => DataService}/TushareDataService/downloadData.py (100%) rename examples/{ => DataService}/TushareDataService/runService.py (100%) diff --git a/examples/CoinapiDataService/config.json b/examples/DataService/CoinapiDataService/config.json similarity index 100% rename from examples/CoinapiDataService/config.json rename to examples/DataService/CoinapiDataService/config.json diff --git a/examples/CoinapiDataService/dataService.py b/examples/DataService/CoinapiDataService/dataService.py similarity index 95% rename from examples/CoinapiDataService/dataService.py rename to examples/DataService/CoinapiDataService/dataService.py index 21e52138..5b65ea56 100644 --- a/examples/CoinapiDataService/dataService.py +++ b/examples/DataService/CoinapiDataService/dataService.py @@ -31,10 +31,11 @@ headers = {'X-CoinAPI-Key': APIKEY} #---------------------------------------------------------------------- def generateVtBar(symbol, d): """生成K线""" + l = symbol.split('_') bar = VtBarData() - - bar.symbol = symbol - bar.vtSymbol = symbol + bar.symbol = l[-2] + l[-1] + bar.exchange = l[0] + bar.vtSymbol = '/'.join([bar.symbol, bar.exchange]) bar.datetime = datetime.datetime.strptime(d['time_open'], '%Y-%m-%dT%H:%M:%S.%f0Z') bar.date = bar.datetime.strftime('%Y%m%d') bar.time = bar.datetime.strftime('%H:%M:%S') diff --git a/examples/CoinapiDataService/downloadData.py b/examples/DataService/CoinapiDataService/downloadData.py similarity index 100% rename from examples/CoinapiDataService/downloadData.py rename to examples/DataService/CoinapiDataService/downloadData.py diff --git a/examples/CoinapiDataService/runService.py b/examples/DataService/CoinapiDataService/runService.py similarity index 100% rename from examples/CoinapiDataService/runService.py rename to examples/DataService/CoinapiDataService/runService.py diff --git a/examples/FutuDataService/README.md b/examples/DataService/FutuDataService/README.md similarity index 100% rename from examples/FutuDataService/README.md rename to examples/DataService/FutuDataService/README.md diff --git a/examples/FutuDataService/config.json b/examples/DataService/FutuDataService/config.json similarity index 100% rename from examples/FutuDataService/config.json rename to examples/DataService/FutuDataService/config.json diff --git a/examples/FutuDataService/dataService.py b/examples/DataService/FutuDataService/dataService.py similarity index 100% rename from examples/FutuDataService/dataService.py rename to examples/DataService/FutuDataService/dataService.py diff --git a/examples/FutuDataService/downloadData.py b/examples/DataService/FutuDataService/downloadData.py similarity index 100% rename from examples/FutuDataService/downloadData.py rename to examples/DataService/FutuDataService/downloadData.py diff --git a/examples/FutuDataService/runService.py b/examples/DataService/FutuDataService/runService.py similarity index 100% rename from examples/FutuDataService/runService.py rename to examples/DataService/FutuDataService/runService.py diff --git a/examples/DataService/README.md b/examples/DataService/README.md new file mode 100644 index 00000000..ee4f0a7c --- /dev/null +++ b/examples/DataService/README.md @@ -0,0 +1,11 @@ +# DataService说明 + +* ShcifcoDataService:上海中期历史行情服务(期货) + +* TqDataService:天勤历史行情服务(期货) + +* TushareDataService:TuShare历史行情服务(A股) + +* FutuDataService:富途证券历史行情服务(美股、港股) + +* CoinapiDataService:CoinAPI.io历史行情服务(数字货币) \ No newline at end of file diff --git a/examples/ShcifcoDataService/config.json b/examples/DataService/ShcifcoDataService/config.json similarity index 100% rename from examples/ShcifcoDataService/config.json rename to examples/DataService/ShcifcoDataService/config.json diff --git a/examples/ShcifcoDataService/dataService.py b/examples/DataService/ShcifcoDataService/dataService.py similarity index 100% rename from examples/ShcifcoDataService/dataService.py rename to examples/DataService/ShcifcoDataService/dataService.py diff --git a/examples/ShcifcoDataService/downloadData.py b/examples/DataService/ShcifcoDataService/downloadData.py similarity index 100% rename from examples/ShcifcoDataService/downloadData.py rename to examples/DataService/ShcifcoDataService/downloadData.py diff --git a/examples/ShcifcoDataService/runService.py b/examples/DataService/ShcifcoDataService/runService.py similarity index 100% rename from examples/ShcifcoDataService/runService.py rename to examples/DataService/ShcifcoDataService/runService.py diff --git a/examples/TqDataService/README.md b/examples/DataService/TqDataService/README.md similarity index 100% rename from examples/TqDataService/README.md rename to examples/DataService/TqDataService/README.md diff --git a/examples/TqDataService/config.json b/examples/DataService/TqDataService/config.json similarity index 100% rename from examples/TqDataService/config.json rename to examples/DataService/TqDataService/config.json diff --git a/examples/TqDataService/dataService.py b/examples/DataService/TqDataService/dataService.py similarity index 100% rename from examples/TqDataService/dataService.py rename to examples/DataService/TqDataService/dataService.py diff --git a/examples/TqDataService/downloadData.py b/examples/DataService/TqDataService/downloadData.py similarity index 100% rename from examples/TqDataService/downloadData.py rename to examples/DataService/TqDataService/downloadData.py diff --git a/examples/TqDataService/runService.py b/examples/DataService/TqDataService/runService.py similarity index 100% rename from examples/TqDataService/runService.py rename to examples/DataService/TqDataService/runService.py diff --git a/examples/TushareDataService/config.json b/examples/DataService/TushareDataService/config.json similarity index 100% rename from examples/TushareDataService/config.json rename to examples/DataService/TushareDataService/config.json diff --git a/examples/TushareDataService/dataService.py b/examples/DataService/TushareDataService/dataService.py similarity index 100% rename from examples/TushareDataService/dataService.py rename to examples/DataService/TushareDataService/dataService.py diff --git a/examples/TushareDataService/downloadData.py b/examples/DataService/TushareDataService/downloadData.py similarity index 100% rename from examples/TushareDataService/downloadData.py rename to examples/DataService/TushareDataService/downloadData.py diff --git a/examples/TushareDataService/runService.py b/examples/DataService/TushareDataService/runService.py similarity index 100% rename from examples/TushareDataService/runService.py rename to examples/DataService/TushareDataService/runService.py diff --git a/examples/README.md b/examples/README.md index f42ddc5a..cd55637b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -20,12 +20,4 @@ * ServerClient:服务端(业务逻辑)和客户端(GUI界面)分离的VnTrader -* ShcifcoDataService:上海中期历史行情服务(期货) - -* TqDataService:天勤历史行情服务(期货) - -* TushareDataService:TuShare历史行情服务(A股) - -* FutuDataService:富途证券历史行情服务(美股、港股) - -* CoinapiDataService:CoinAPI.io历史行情服务(数字货币) \ No newline at end of file +* DataService:用于下载历史行情数据以及每日数据自动更新的数据服务 \ No newline at end of file From a9f1a7c64965ee83467eb4fc009e150e795829c2 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 12 Oct 2018 15:43:15 +0800 Subject: [PATCH 7/7] =?UTF-8?q?[Add]=E6=96=B0=E5=A2=9ECryptoCompare?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E5=AD=97=E8=B4=A7=E5=B8=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataService/CccDataService/config.json | 10 ++ .../DataService/CccDataService/dataService.py | 106 ++++++++++++++++++ .../CccDataService/downloadData.py | 14 +++ .../DataService/CccDataService/runService.py | 33 ++++++ 4 files changed, 163 insertions(+) create mode 100644 examples/DataService/CccDataService/config.json create mode 100644 examples/DataService/CccDataService/dataService.py create mode 100644 examples/DataService/CccDataService/downloadData.py create mode 100644 examples/DataService/CccDataService/runService.py diff --git a/examples/DataService/CccDataService/config.json b/examples/DataService/CccDataService/config.json new file mode 100644 index 00000000..787d3e41 --- /dev/null +++ b/examples/DataService/CccDataService/config.json @@ -0,0 +1,10 @@ +{ + "MONGO_HOST": "localhost", + "MONGO_PORT": 27017, + + "SYMBOLS": [ + "BTC/USDT.OKEX", + "BTC/USDT.HUOBIPRO", + "BTC/USDT.BINANCE" + ] +} \ No newline at end of file diff --git a/examples/DataService/CccDataService/dataService.py b/examples/DataService/CccDataService/dataService.py new file mode 100644 index 00000000..e7ffc88a --- /dev/null +++ b/examples/DataService/CccDataService/dataService.py @@ -0,0 +1,106 @@ +# encoding: UTF-8 + +from __future__ import print_function + +import json +import time +import datetime + +import requests +from pymongo import MongoClient, ASCENDING + +from vnpy.trader.vtObject import VtBarData +from vnpy.trader.app.ctaStrategy.ctaBase import MINUTE_DB_NAME + + +# 加载配置 +config = open('config.json') +setting = json.load(config) + +MONGO_HOST = setting['MONGO_HOST'] +MONGO_PORT = setting['MONGO_PORT'] +SYMBOLS = setting['SYMBOLS'] + +mc = MongoClient(MONGO_HOST, MONGO_PORT) # Mongo连接 +db = mc[MINUTE_DB_NAME] # 数据库 + + +#---------------------------------------------------------------------- +def generateVtBar(vtSymbol, d): + """生成K线""" + bar = VtBarData() + bar.vtSymbol = vtSymbol + bar.symbol, bar.exchange = bar.vtSymbol.split('.') + + bar.datetime = datetime.datetime.fromtimestamp(d['time']) + bar.date = bar.datetime.strftime('%Y%m%d') + bar.time = bar.datetime.strftime('%H:%M:%S') + + bar.open = d['open'] + bar.high = d['high'] + bar.low = d['low'] + bar.close = d['close'] + bar.volume = d['volumeto'] + + return bar + +#---------------------------------------------------------------------- +def downloadMinuteBarBySymbol(vtSymbol, end): + """下载某一合约的分钟线数据""" + end = datetime.datetime.strptime(end, '%Y%m%d') + startTime = time.time() + + cl = db[vtSymbol] + cl.ensure_index([('datetime', ASCENDING)], unique=True) + + symbol, exchange = vtSymbol.split('.') + fsym, tsym = symbol.split('/') + + url = 'https://min-api.cryptocompare.com/data/histominute' + params = { + 'fsym': fsym, + 'tsym': tsym, + 'e': exchange, + 'toTs': int(time.mktime(end.timetuple())) + } + resp = requests.get(url, headers={}, params=params) + + if resp.status_code != 200: + print(u'%s数据下载失败' %vtSymbol) + return + + j = resp.json() + l = j['Data'] + + for d in l: + bar = generateVtBar(vtSymbol, d) + d = bar.__dict__ + flt = {'datetime': bar.datetime} + cl.replace_one(flt, d, True) + + endTime = time.time() + cost = (endTime - startTime) * 1000 + + + print(u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(vtSymbol, + datetime.datetime.fromtimestamp(l[0]['time']), + datetime.datetime.fromtimestamp(l[-1]['time']), + cost)) + +#---------------------------------------------------------------------- +def downloadAllMinuteBar(end): + """下载所有配置中的合约的分钟线数据""" + print('-' * 50) + print(u'开始下载合约分钟线数据') + print('-' * 50) + + for symbol in SYMBOLS: + downloadMinuteBarBySymbol(symbol, end) + time.sleep(1) + + print('-' * 50) + print(u'合约分钟线数据下载完成') + print('-' * 50) + + + \ No newline at end of file diff --git a/examples/DataService/CccDataService/downloadData.py b/examples/DataService/CccDataService/downloadData.py new file mode 100644 index 00000000..1da0bc31 --- /dev/null +++ b/examples/DataService/CccDataService/downloadData.py @@ -0,0 +1,14 @@ +# encoding: UTF-8 + +""" +立即下载数据到数据库中,用于手动执行更新操作。 +""" + +from dataService import * + + +if __name__ == '__main__': + #downMinuteBarBySymbol('BTC/USDT.OKEX', '20181012') + #downMinuteBarBySymbol('BTC/USDT.HUOBIPRO', '20181012') + #downMinuteBarBySymbol('BTC/USDT.BINANCE', '20181012') + downloadAllMinuteBar('20181012') \ No newline at end of file diff --git a/examples/DataService/CccDataService/runService.py b/examples/DataService/CccDataService/runService.py new file mode 100644 index 00000000..4826e810 --- /dev/null +++ b/examples/DataService/CccDataService/runService.py @@ -0,0 +1,33 @@ +# encoding: UTF-8 + +""" +定时服务,可无人值守运行,实现每日自动下载更新历史行情数据到数据库中。 +""" +from __future__ import print_function + +from dataService import * + + +if __name__ == '__main__': + taskCompletedDate = None + + taskTime = datetime.time(hour=22, minute=0) + + # 进入主循环 + while True: + t = datetime.datetime.now() + + # 每天到达任务下载时间后,执行数据下载的操作 + if t.time() > taskTime and (taskCompletedDate is None or t.date() != taskCompletedDate): + end = t.strftime('%Y%m%d') + start = (t - datetime.timedelta(1)).strftime('%Y%m%d') + + # 下载过去24小时的K线数据 + downloadAllMinuteBar(start, end) + + # 更新任务完成的日期 + taskCompletedDate = t.date() + else: + print(u'当前时间%s,任务定时%s' %(t, taskTime)) + + time.sleep(60) \ No newline at end of file