diff --git a/.travis.yml b/.travis.yml index 2c4cb042..e5b57753 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,6 @@ 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 diff --git a/vnpy/api/binance/test.py b/vnpy/api/binance/test.py index 83dd365c..d755fd21 100644 --- a/vnpy/api/binance/test.py +++ b/vnpy/api/binance/test.py @@ -1,6 +1,9 @@ +from __future__ import absolute_import from time import sleep -from vnbinance import BinanceApi +from six.moves import input + +from .vnbinance import BinanceApi if __name__ == '__main__': @@ -40,4 +43,4 @@ if __name__ == '__main__': #api.initDataStream(['btcusdt@ticker', 'btcusdt@depth5']) #api.initUserStream('NXvaiFwZz2LuKqINVerKOnWaQQG1JhdQNejiZKY9Kmgk4lZgTvm3nRAnXJK7') - raw_input() \ No newline at end of file + input() diff --git a/vnpy/api/binance/vnbinance.py b/vnpy/api/binance/vnbinance.py index da67de8e..618e428a 100644 --- a/vnpy/api/binance/vnbinance.py +++ b/vnpy/api/binance/vnbinance.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import json import requests import hmac @@ -389,107 +390,107 @@ class BinanceApi(object): #---------------------------------------------------------------------- def onError(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryPing(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryTime(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryExchangeInfo(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryDepth(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryTrades(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryAggTrades(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryKlines(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryTicker24HR(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryTickerPrice(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryBookTicker(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onNewOrder(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryOrder(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onCancelOrder(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryOpenOrders(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryAllOrders(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryAccount(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onQueryMyTrades(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onStartStream(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onKeepaliveStream(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) #---------------------------------------------------------------------- def onCloseStream(self, data, reqid): """""" - print(data, reqid) + print((data, reqid)) ################################################### ## Websocket Function @@ -547,12 +548,12 @@ class BinanceApi(object): #---------------------------------------------------------------------- def onDataStreamError(self, msg): """""" - print msg + print(msg) #---------------------------------------------------------------------- def onMarketData(self, data): """""" - print data + print(data) #---------------------------------------------------------------------- def initUserStream(self, key): @@ -608,12 +609,12 @@ class BinanceApi(object): #---------------------------------------------------------------------- def onUserStreamError(self, msg): """""" - print msg + print(msg) #---------------------------------------------------------------------- def onUserData(self, data): """""" - print data + print(data) #---------------------------------------------------------------------- def runKeepalive(self): diff --git a/vnpy/api/bitfinex/vnbitfinex.py b/vnpy/api/bitfinex/vnbitfinex.py index ee308d68..0132c000 100644 --- a/vnpy/api/bitfinex/vnbitfinex.py +++ b/vnpy/api/bitfinex/vnbitfinex.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import json import requests import traceback @@ -9,6 +10,8 @@ from queue import Queue, Empty import websocket +from six.moves import input + WEBSOCKET_V2_URL = 'wss://api.bitfinex.com/ws/2' RESTFUL_V1_URL = 'https://api.bitfinex.com/v1' @@ -78,17 +81,17 @@ class BitfinexApi(object): #---------------------------------------------------------------------- def onConnect(self): """""" - print 'connected' + print('connected') #---------------------------------------------------------------------- def onData(self, data): """""" - print data + print(data) #---------------------------------------------------------------------- def onError(self, msg): """""" - print msg + print(msg) #---------------------------------------------------------------------- def sendReq(self, req): @@ -130,5 +133,4 @@ if __name__ == '__main__': } api.sendReq(d) - raw_input() - \ No newline at end of file + input() diff --git a/vnpy/api/huobi/vnhuobi.py b/vnpy/api/huobi/vnhuobi.py index 8877a371..514db58a 100644 --- a/vnpy/api/huobi/vnhuobi.py +++ b/vnpy/api/huobi/vnhuobi.py @@ -1,23 +1,25 @@ # encoding: utf-8 from __future__ import print_function -import urllib -import hmac + import base64 import hashlib -import requests +import hmac +import json +import ssl import traceback +import urllib +import zlib from copy import copy from datetime import datetime -from threading import Thread -from queue import Queue, Empty from multiprocessing.dummy import Pool +from queue import Empty, Queue +from threading import Thread from time import sleep -import json -import zlib -from websocket import create_connection, _exceptions +import requests +from websocket import _exceptions, create_connection # 常量定义 TIMEOUT = 10 @@ -660,4 +662,4 @@ class DataApi(object): #---------------------------------------------------------------------- def onMarketDetail(self, data): """市场细节推送""" - print(data) \ No newline at end of file + print(data) diff --git a/vnpy/api/sgit/__init__.py b/vnpy/api/sgit/__init__.py index 7bdd52cd..906277fd 100644 --- a/vnpy/api/sgit/__init__.py +++ b/vnpy/api/sgit/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnsgitmd import MdApi -from vnsgittd import TdApi -from sgit_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnsgitmd import MdApi +from .vnsgittd import TdApi +from .sgit_data_type import defineDict \ No newline at end of file diff --git a/vnpy/event/eventEngine.py b/vnpy/event/eventEngine.py index 5d259ee0..dff82489 100644 --- a/vnpy/event/eventEngine.py +++ b/vnpy/event/eventEngine.py @@ -1,6 +1,7 @@ # encoding: UTF-8 # 系统模块 +from __future__ import print_function from queue import Queue, Empty from threading import Thread from time import sleep diff --git a/vnpy/event/eventType.py b/vnpy/event/eventType.py index 0515bcb1..acda0150 100644 --- a/vnpy/event/eventType.py +++ b/vnpy/event/eventType.py @@ -10,6 +10,7 @@ 建议将所有的常量定义放在该文件中,便于检查是否存在重复的现象。 ''' +from __future__ import print_function EVENT_TIMER = 'eTimer' # 计时器事件,每隔1秒发送一次 diff --git a/vnpy/rpc/testClient.py b/vnpy/rpc/testClient.py index d4d03fd3..f1bcf5b9 100644 --- a/vnpy/rpc/testClient.py +++ b/vnpy/rpc/testClient.py @@ -1,9 +1,10 @@ # encoding: UTF-8 from __future__ import print_function +from __future__ import absolute_import from time import sleep -from vnrpc import RpcClient +from .vnrpc import RpcClient ######################################################################## diff --git a/vnpy/rpc/testServer.py b/vnpy/rpc/testServer.py index cb5760b1..0a8a39c2 100644 --- a/vnpy/rpc/testServer.py +++ b/vnpy/rpc/testServer.py @@ -1,9 +1,10 @@ # encoding: UTF-8 from __future__ import print_function +from __future__ import absolute_import from time import sleep, time -from vnrpc import RpcServer +from .vnrpc import RpcServer ######################################################################## diff --git a/vnpy/trader/app/algoTrading/twapAlgo.py b/vnpy/trader/app/algoTrading/twapAlgo.py index a2c309c5..c31aceb6 100644 --- a/vnpy/trader/app/algoTrading/twapAlgo.py +++ b/vnpy/trader/app/algoTrading/twapAlgo.py @@ -3,6 +3,8 @@ from __future__ import division from collections import OrderedDict +from six import text_type + from vnpy.trader.vtConstant import (DIRECTION_LONG, DIRECTION_SHORT) from vnpy.trader.uiQt import QtWidgets @@ -23,7 +25,7 @@ class TwapAlgo(AlgoTemplate): # 参数,强制类型转换,保证从CSV加载的配置正确 self.vtSymbol = str(setting['vtSymbol']) # 合约代码 - self.direction = unicode(setting['direction']) # 买卖 + self.direction = text_type(setting['direction']) # 买卖 self.targetPrice = float(setting['targetPrice']) # 目标价格 self.totalVolume = float(setting['totalVolume']) # 总数量 self.time = int(setting['time']) # 执行时间 @@ -261,4 +263,4 @@ class TwapWidget(AlgoWidget): return setting - \ No newline at end of file + diff --git a/vnpy/trader/app/algoTrading/uiAlgoManager.py b/vnpy/trader/app/algoTrading/uiAlgoManager.py index 895e3fa0..59aec40c 100644 --- a/vnpy/trader/app/algoTrading/uiAlgoManager.py +++ b/vnpy/trader/app/algoTrading/uiAlgoManager.py @@ -4,6 +4,8 @@ import csv import traceback from collections import OrderedDict +from six import text_type + from vnpy.event import Event from vnpy.trader.uiQt import QtCore, QtWidgets @@ -465,7 +467,7 @@ class AlgoManager(QtWidgets.QWidget): def loadCsv(self, path): """读取CSV配置文件""" try: - with open(unicode(path)) as f: + with open(text_type(path)) as f: buf = [line.encode('UTF-8') for line in f] reader = csv.DictReader(buf) @@ -498,4 +500,4 @@ class AlgoManager(QtWidgets.QWidget): path, fileType = QtWidgets.QFileDialog.getOpenFileName(self, u'启动篮子算法', '', 'CSV(*.csv) ') l = self.loadCsv(path) for setting in l: - self.algoEngine.addAlgo(setting) \ No newline at end of file + self.algoEngine.addAlgo(setting) diff --git a/vnpy/trader/app/algoTrading/uiAlgoWidget.py b/vnpy/trader/app/algoTrading/uiAlgoWidget.py index addb3090..1f4a1baa 100644 --- a/vnpy/trader/app/algoTrading/uiAlgoWidget.py +++ b/vnpy/trader/app/algoTrading/uiAlgoWidget.py @@ -1,5 +1,7 @@ # encoding: UTF-8 +from six import text_type + from vnpy.trader.uiQt import QtWidgets @@ -54,7 +56,7 @@ class AlgoWidget(QtWidgets.QWidget): """保存算法配置""" setting = self.getAlgoSetting() setting['templateName'] = self.templateName - setting['settingName'] = unicode(self.lineSettingName.text()) + setting['settingName'] = text_type(self.lineSettingName.text()) self.algoEngine.saveAlgoSetting(setting) self.lineSettingName.setText('') diff --git a/vnpy/trader/gateway/binanceGateway/binanceGateway.py b/vnpy/trader/gateway/binanceGateway/binanceGateway.py index 229c2494..64fd6a5d 100644 --- a/vnpy/trader/gateway/binanceGateway/binanceGateway.py +++ b/vnpy/trader/gateway/binanceGateway/binanceGateway.py @@ -3,6 +3,7 @@ ''' vnpy.api.binance的gateway接入 ''' +from __future__ import print_function import os import json @@ -40,11 +41,11 @@ priceTypeMap[PRICETYPE_MARKETPRICE] = 'MARKET' #---------------------------------------------------------------------- def print_dict(d): """""" - print '-' * 30 + print('-' * 30) l = d.keys() l.sort() for k in l: - print '%s:%s' %(k, d[k]) + print('%s:%s' %(k, d[k])) ######################################################################## diff --git a/vnpy/trader/gateway/futuGateway/Futu_connect.json b/vnpy/trader/gateway/futuGateway/Futu_connect.json index d26a492d..723cefb8 100644 --- a/vnpy/trader/gateway/futuGateway/Futu_connect.json +++ b/vnpy/trader/gateway/futuGateway/Futu_connect.json @@ -3,5 +3,5 @@ "port": 11111, "market": "HK", "password": "123123", - "env": 1 + "env": "REAL" } \ No newline at end of file diff --git a/vnpy/trader/gateway/futuGateway/futuGateway.py b/vnpy/trader/gateway/futuGateway/futuGateway.py index d557abcb..f4a5431a 100644 --- a/vnpy/trader/gateway/futuGateway/futuGateway.py +++ b/vnpy/trader/gateway/futuGateway/futuGateway.py @@ -12,14 +12,9 @@ from datetime import datetime from copy import copy import futuquant as ft -from futuquant import (RET_ERROR, RET_OK, PriceRegularMode, +from futuquant import (RET_ERROR, RET_OK, TrdEnv, StockQuoteHandlerBase, OrderBookHandlerBase, TradeOrderHandlerBase, TradeDealHandlerBase) - -#from futuquant.open_context import (RET_ERROR, RET_OK, PriceRegularMode, - #StockQuoteHandlerBase, OrderBookHandlerBase, - #USTradeOrderHandlerBase, USTradeDealHandlerBase, - #HKTradeOrderHandlerBase, HKTradeDealHandlerBase) from vnpy.trader.vtGateway import * from vnpy.trader.vtConstant import GATEWAYTYPE_INTERNATIONAL @@ -182,15 +177,11 @@ class FutuGateway(VtGateway): # 连接交易接口 if self.market == 'US': self.tradeCtx = ft.OpenUSTradeContext(self.host, self.port) - OrderHandlerBase = USTradeOrderHandlerBase - DealHandlerBase = USTradeDealHandlerBase else: self.tradeCtx = ft.OpenHKTradeContext(self.host, self.port) - OrderHandlerBase = HKTradeOrderHandlerBase - DealHandlerBase = HKTradeDealHandlerBase - + # 继承实现处理器类 - class OrderHandler(OrderHandlerBase): + class OrderHandler(TradeOrderHandlerBase): """委托处理器""" gateway = self # 缓存Gateway对象 @@ -201,7 +192,7 @@ class FutuGateway(VtGateway): self.gateway.processOrder(content) return RET_OK, content - class DealHandler(DealHandlerBase): + class DealHandler(TradeDealHandlerBase): """订单簿处理器""" gateway = self @@ -223,11 +214,6 @@ class FutuGateway(VtGateway): # 启动交易接口 self.tradeCtx.start() - # 订阅委托推送 - self.tradeCtx.subscribe_order_deal_push([], - order_deal_push=True, - envtype=self.env) - self.writeLog(u'交易接口连接成功') #---------------------------------------------------------------------- @@ -306,7 +292,7 @@ class FutuGateway(VtGateway): #---------------------------------------------------------------------- def qryAccount(self): """查询账户资金""" - code, data = self.tradeCtx.accinfo_query(self.env) + code, data = self.tradeCtx.accinfo_query(trd_env=self.env, acc_id=0) if code: self.writeError(code, u'查询账户资金失败:%s' %data) @@ -327,7 +313,7 @@ class FutuGateway(VtGateway): #---------------------------------------------------------------------- def qryPosition(self): """查询持仓""" - code, data = self.tradeCtx.position_list_query(envtype=self.env) + code, data = self.tradeCtx.position_list_query(trd_env=self.env, acc_id=0) if code: self.writeError(code, u'查询持仓失败:%s' %data) @@ -356,7 +342,7 @@ class FutuGateway(VtGateway): #---------------------------------------------------------------------- def qryOrder(self): """查询委托""" - code, data = self.tradeCtx.order_list_query("", envtype=self.env) + code, data = self.tradeCtx.order_list_query("", trd_env=self.env) if code: self.writeError(code, u'查询委托失败:%s' %data) diff --git a/vnpy/trader/uiBasicWidget.py b/vnpy/trader/uiBasicWidget.py index 4cde79f1..138e9ccf 100644 --- a/vnpy/trader/uiBasicWidget.py +++ b/vnpy/trader/uiBasicWidget.py @@ -1144,7 +1144,7 @@ class ContractMonitor(BasicMonitor): """显示所有合约数据""" l = self.mainEngine.getAllContracts() d = {'.'.join([contract.exchange, contract.symbol]):contract for contract in l} - l2 = d.keys() + l2 = list(d.keys()) l2.sort(reverse=True) self.setRowCount(len(l2)) diff --git a/vnpy/trader/vtFunction.py b/vnpy/trader/vtFunction.py index 1fc55c9a..7673177a 100644 --- a/vnpy/trader/vtFunction.py +++ b/vnpy/trader/vtFunction.py @@ -11,6 +11,8 @@ import traceback from datetime import datetime from math import isnan +from six import text_type + #---------------------------------------------------------------------- def safeUnicode(value): @@ -26,7 +28,7 @@ def safeUnicode(value): if abs(d.as_tuple().exponent) > MAX_DECIMAL: value = round(value, ndigits=MAX_DECIMAL) - return unicode(value) + return text_type(value) #----------------------------------------------------------------------