Merge branch 'dev' of https://github.com/vnpy/vnpy into dev
This commit is contained in:
commit
30be00063c
@ -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
|
||||
|
@ -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()
|
||||
input()
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
||||
input()
|
||||
|
@ -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)
|
||||
print(data)
|
||||
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnsgitmd import MdApi
|
||||
from vnsgittd import TdApi
|
||||
from sgit_data_type import defineDict
|
||||
from __future__ import absolute_import
|
||||
from .vnsgitmd import MdApi
|
||||
from .vnsgittd import TdApi
|
||||
from .sgit_data_type import defineDict
|
@ -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
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
建议将所有的常量定义放在该文件中,便于检查是否存在重复的现象。
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
EVENT_TIMER = 'eTimer' # 计时器事件,每隔1秒发送一次
|
||||
|
@ -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
|
||||
|
||||
|
||||
########################################################################
|
||||
|
@ -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
|
||||
|
||||
|
||||
########################################################################
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -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)
|
||||
self.algoEngine.addAlgo(setting)
|
||||
|
@ -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('')
|
||||
|
@ -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]))
|
||||
|
||||
|
||||
########################################################################
|
||||
|
@ -3,5 +3,5 @@
|
||||
"port": 11111,
|
||||
"market": "HK",
|
||||
"password": "123123",
|
||||
"env": 1
|
||||
"env": "REAL"
|
||||
}
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user