From 198cbd5d62360fe9d02c664c36610f0b742cfae2 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 7 May 2018 19:25:06 +0200 Subject: [PATCH] Modernize beta --- beta/api/coincheck/__init__.py | 3 +- beta/api/coincheck/test.py | 3 +- beta/api/coincheck/test2.py | 3 +- beta/api/coincheck/test3.py | 8 +-- beta/api/coincheck/test4.py | 3 +- beta/api/coincheck/vncoincheck.py | 51 ++++++++++--------- beta/api/korbit/__init__.py | 3 +- .../korbit/private_api.py | 6 ++- .../korbit-python-master/korbit/public_api.py | 9 ++-- .../korbit-python-master/korbit/test.py | 6 ++- beta/api/korbit/test.py | 3 +- beta/api/korbit/vnkorbit.py | 37 +++++++------- beta/api/okex/__init__.py | 3 +- beta/api/okex/test.py | 3 +- beta/api/okex/vnokex.py | 11 ++-- beta/api/zaif/__init__.py | 3 +- beta/api/zaif/test.py | 3 +- beta/api/zaif/vnzaif.py | 37 +++++++------- beta/api/zb/__init__.py | 3 +- beta/api/zb/test.py | 3 +- beta/api/zb/vnzb.py | 25 ++++----- beta/gateway/coincheckGateway/__init__.py | 3 +- .../coincheckGateway/coincheckGateway.py | 25 ++++----- beta/gateway/korbitGateway/__init__.py | 3 +- beta/gateway/korbitGateway/korbitGateway.py | 11 ++-- beta/gateway/okexGateway/__init__.py | 3 +- beta/gateway/okexGateway/okexGateway.py | 15 +++--- beta/gateway/zbGateway/__init__.py | 3 +- beta/gateway/zbGateway/zbGateway.py | 15 +++--- beta/spreadtrading/stBase.py | 4 +- 30 files changed, 170 insertions(+), 138 deletions(-) diff --git a/beta/api/coincheck/__init__.py b/beta/api/coincheck/__init__.py index f08065df..88a1aa53 100644 --- a/beta/api/coincheck/__init__.py +++ b/beta/api/coincheck/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vncoincheck import TradeApi, DataApi \ No newline at end of file +from __future__ import absolute_import +from .vncoincheck import TradeApi, DataApi \ No newline at end of file diff --git a/beta/api/coincheck/test.py b/beta/api/coincheck/test.py index dac1e7c9..fd016f3a 100644 --- a/beta/api/coincheck/test.py +++ b/beta/api/coincheck/test.py @@ -1,6 +1,7 @@ # encoding: utf-8 -from vncoincheck import * +from __future__ import absolute_import +from .vncoincheck import * def testTrade(): """测试交易""" diff --git a/beta/api/coincheck/test2.py b/beta/api/coincheck/test2.py index db4d59a6..d9d46f56 100644 --- a/beta/api/coincheck/test2.py +++ b/beta/api/coincheck/test2.py @@ -1,6 +1,7 @@ # encoding: utf-8 +from __future__ import print_function from coincheck import order,market,account ok = order.Order(access_key="你的accessKey", secret_key="你的secretKey") -print ok.buy_btc_jpy(amount=0.01,rate=200) \ No newline at end of file +print(ok.buy_btc_jpy(amount=0.01,rate=200)) \ No newline at end of file diff --git a/beta/api/coincheck/test3.py b/beta/api/coincheck/test3.py index b0a85827..e0945a2c 100644 --- a/beta/api/coincheck/test3.py +++ b/beta/api/coincheck/test3.py @@ -1,6 +1,8 @@ # encoding: utf-8 -from vncoincheck import * +from __future__ import print_function +from __future__ import absolute_import +from .vncoincheck import * import socket import json @@ -10,7 +12,7 @@ from websocket import create_connection ws = None def open(): global ws - print "open" + print("open") ws.send( json.dumps({"type": "subscribe", "channel": "btc_jpy-trades"})) def testWebsocket(): @@ -20,7 +22,7 @@ def testWebsocket(): ws = create_connection("wss://ws-api.coincheck.com/", on_open=open) if ws.connected: - print ws.recv() + print(ws.recv()) sleep(5) diff --git a/beta/api/coincheck/test4.py b/beta/api/coincheck/test4.py index 0995e9c9..ae4b7487 100644 --- a/beta/api/coincheck/test4.py +++ b/beta/api/coincheck/test4.py @@ -1,6 +1,7 @@ # encoding: utf-8 -from vncoincheck import * +from __future__ import absolute_import +from .vncoincheck import * def test(): diff --git a/beta/api/coincheck/vncoincheck.py b/beta/api/coincheck/vncoincheck.py index 018c92b9..a1920380 100644 --- a/beta/api/coincheck/vncoincheck.py +++ b/beta/api/coincheck/vncoincheck.py @@ -1,5 +1,6 @@ # encoding: utf-8 +from __future__ import print_function import urllib import hashlib @@ -108,7 +109,7 @@ class TradeApi(object): if r != None and r.status_code == 200: data = r.json() if data['success'] == 0: - print "error in coincheck %s" % method + print("error in coincheck %s" % method) return data else: return data @@ -116,7 +117,7 @@ class TradeApi(object): try: data = json.loads(r.text) return data - except Exception,ex: + except Exception as ex: return None #---------------------------------------------------------------------- @@ -138,12 +139,12 @@ class TradeApi(object): # 请求成功 if data != None : if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data, req, reqID) self.reqQueue.pop(0) sleep(0.1) - except Exception,ex: + except Exception as ex: pass #---------------------------------------------------------------------- @@ -205,11 +206,11 @@ class TradeApi(object): return self.sendRequest( self.API_balance , FUNCTIONCODE_GET_BALANCE_COINCHECK , self.onGet_balance , None) def buy_btc_jpy(self , **kwargs): - print "buy_btc_jpy" + print("buy_btc_jpy") return self.sendRequest( self.API_trade , FUNCTIONCODE_BUY_ORDER_COINCHECK , self.onBuy_btc , kwargs = kwargs, optional = None) def sell_btc_jpy(self, **kwargs): - print "sell_btc_jpy" + print("sell_btc_jpy") return self.sendRequest( self.API_trade , FUNCTIONCODE_SELL_ORDER_COINCHECK , self.onSell_btc , kwargs = kwargs, optional = None) def list_orders(self): @@ -225,19 +226,19 @@ class TradeApi(object): ## 回调函数 #################################################### def onGet_info(self, data, req, reqID): - print data + print(data) def onGet_balance(self, data, req, reqID): - print data + print(data) def onBuy_btc(self, data, req, reqID): - print data + print(data) def onSell_btc(self, data, req, reqID): - print data + print(data) def onList_order(self, data, req, reqID): - print data + print(data) def onCancel_orders(self, data, req, reqID): - print data + print(data) def onHistory_orders(self, data, req, reqID): - print data + print(data) class DataApiSocket(object): """基于websocket的API对象""" @@ -257,24 +258,24 @@ class DataApiSocket(object): #---------------------------------------------------------------------- def onMessage(self, ws, evt): """信息推送""" - print 'onMessage' - print evt + print('onMessage') + print(evt) #---------------------------------------------------------------------- def onError(self, ws, evt): """错误推送""" - print 'onError' - print evt + print('onError') + print(evt) #---------------------------------------------------------------------- def onClose(self, ws): """接口断开""" - print 'onClose' + print('onClose') #---------------------------------------------------------------------- def onOpen(self, ws): """接口打开""" - print "onOpen" + print("onOpen") self.sendOrderbookRequest() self.sendTradesRequest() @@ -415,10 +416,10 @@ class DataApi(object): if r.status_code == 200: data = r.json() if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data) - except Exception, e: - print e + except Exception as e: + print(e) sleep(self.taskInterval) #---------------------------------------------------------------------- @@ -445,16 +446,16 @@ class DataApi(object): #---------------------------------------------------------------------- def onTick(self, data): """实时成交推送""" - print data + print(data) #---------------------------------------------------------------------- def onTrades(self, data): """实时成交推送""" - print data + print(data) #---------------------------------------------------------------------- def onOrderbooks(self, data): """实时成交推送""" - print data + print(data) if __name__ == '__main__': pass diff --git a/beta/api/korbit/__init__.py b/beta/api/korbit/__init__.py index a35bb985..d7ac34df 100644 --- a/beta/api/korbit/__init__.py +++ b/beta/api/korbit/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnkorbit import Korbit_TradeApi, Korbit_DataApi , KORBIT_ALL_SYMBOL_PAIR , KORBIT_ALL_SYMBOLS \ No newline at end of file +from __future__ import absolute_import +from .vnkorbit import Korbit_TradeApi, Korbit_DataApi , KORBIT_ALL_SYMBOL_PAIR , KORBIT_ALL_SYMBOLS \ No newline at end of file diff --git a/beta/api/korbit/korbit-python-master/korbit/private_api.py b/beta/api/korbit/korbit-python-master/korbit/private_api.py index da724922..b8d6b6fc 100644 --- a/beta/api/korbit/korbit-python-master/korbit/private_api.py +++ b/beta/api/korbit/korbit-python-master/korbit/private_api.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import absolute_import import time -from public_api import PublicAPI +from .public_api import PublicAPI class PrivateAPI(PublicAPI): @@ -105,7 +107,7 @@ class PrivateAPI(PublicAPI): 'offset': offset, 'limit': limit } - print "user/orders" , self.headers , params + print("user/orders" , self.headers , params) return self.request_get("user/orders", headers=self.headers, params=params) def view_transfers(self, offset=0, limit=10, currency="btc"): diff --git a/beta/api/korbit/korbit-python-master/korbit/public_api.py b/beta/api/korbit/korbit-python-master/korbit/public_api.py index 36fd3d08..cc3faaff 100644 --- a/beta/api/korbit/korbit-python-master/korbit/public_api.py +++ b/beta/api/korbit/korbit-python-master/korbit/public_api.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import print_function import requests import json import logging @@ -53,9 +54,9 @@ class PublicAPI: return self.request_get("constants") def request_get(self, path, headers=None, params=None): - print urljoin(self.host, path) + print(urljoin(self.host, path)) response = requests.get(urljoin(self.host, path), headers=headers, params=params, timeout=self.__timeout) - print response + print(response) try: return response.json() except json.decoder.JSONDecodeError as e: @@ -63,9 +64,9 @@ class PublicAPI: return response.text def request_post(self, path, headers=None, data=None): - print urljoin(self.host, path) , headers , data + print(urljoin(self.host, path) , headers , data) response = requests.post(urljoin(self.host, path), headers=headers, data=data, timeout=self.__timeout) - print response + print(response) try: return response.json() except json.decoder.JSONDecodeError as e: diff --git a/beta/api/korbit/korbit-python-master/korbit/test.py b/beta/api/korbit/korbit-python-master/korbit/test.py index 718bf972..275aeb6a 100644 --- a/beta/api/korbit/korbit-python-master/korbit/test.py +++ b/beta/api/korbit/korbit-python-master/korbit/test.py @@ -1,10 +1,12 @@ # encoding: utf-8 -from private_api import * +from __future__ import print_function +from __future__ import absolute_import +from .private_api import * api = PrivateAPI('FssV9Jw0aZVCOYbu9YlqVNc2Rhgmh1QpruNgSVhvVmFP1iw1aPfc3APbfz0ZM', 'lSMc1TT2AZYX5pyEm01SFqx7PgMjNB18eXWpi8DQKHf0rcYhLiaiRVzJwaVZR') -print api.create_token_directly('xiaoshuang8921@naver.com', 'Wxiaoshuang8921') +print(api.create_token_directly('xiaoshuang8921@naver.com', 'Wxiaoshuang8921')) # print api.view_exchange_orders( 0 , 10 , "btc_krw") #api.limit_bid_order(coin_amount = 0.01 , price = 1000 , currency_pair="btc_krw") diff --git a/beta/api/korbit/test.py b/beta/api/korbit/test.py index af0aeb20..1d13f3d2 100644 --- a/beta/api/korbit/test.py +++ b/beta/api/korbit/test.py @@ -1,6 +1,7 @@ # encoding: UTF-8 -from vnkorbit import Korbit_TradeApi , Korbit_DataApi +from __future__ import absolute_import +from .vnkorbit import Korbit_TradeApi , Korbit_DataApi apiKey = 'FssV9Jw0aZVCOYbu9YlqVNc2Rhgmh1QpruNgSVhvVmFP1iw1aPfc3APbfz0ZM' secretKey = 'lSMc1TT2AZYX5pyEm01SFqx7PgMjNB18eXWpi8DQKHf0rcYhLiaiRVzJwaVZR' diff --git a/beta/api/korbit/vnkorbit.py b/beta/api/korbit/vnkorbit.py index ff123ed6..41d83c24 100644 --- a/beta/api/korbit/vnkorbit.py +++ b/beta/api/korbit/vnkorbit.py @@ -1,5 +1,6 @@ # encoding: utf-8 +from __future__ import print_function import urllib import hashlib @@ -63,7 +64,7 @@ class Korbit_TradeApi(object): try: return response.json() except json.decoder.JSONDecodeError as e: - print "exception: {}, response_text: {}".format(e, response.text) + print("exception: {}, response_text: {}".format(e, response.text)) return response.text ''' @@ -170,10 +171,10 @@ class Korbit_TradeApi(object): else: try: data = json.loads(r.text) - print "Error in r , " , data + print("Error in r , " , data) return data - except Exception,ex: - print ex + except Exception as ex: + print(ex) return None #---------------------------------------------------------------------- @@ -194,13 +195,13 @@ class Korbit_TradeApi(object): # 请求成功 if data != None : if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data, req, reqID) sleep(0.1) - except Exception,ex: - print ex + except Exception as ex: + print(ex) #---------------------------------------------------------------------- def sendRequest(self, url , method, callback, kwargs = None,optional=None): @@ -277,19 +278,19 @@ class Korbit_TradeApi(object): ## 回调函数 #################################################### def on_buy_currency(self, data , req, reqID): - print data + print(data) #---------------------------------------------------------------------- def on_sell_currency(self, data , req, reqID): - print data + print(data) #---------------------------------------------------------------------- def on_list_exchange_orders(self, data , req, reqID): - print data + print(data) #---------------------------------------------------------------------- def onCancelOrders(self, data , req, reqID): - print data + print(data) #---------------------------------------------------------------------- def onBalances(self, data , req, reqID): - print data + print(data) class Korbit_DataApi(object): @@ -334,10 +335,10 @@ class Korbit_DataApi(object): data = r.json() data["symbol"] = symbol if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data) - except Exception, e: - print "Korbit_DataApi" , e + except Exception as e: + print("Korbit_DataApi" , e) sleep(self.taskInterval) #---------------------------------------------------------------------- @@ -365,13 +366,13 @@ class Korbit_DataApi(object): #---------------------------------------------------------------------- def onTick(self, data): """实时成交推送""" - print data + print(data) #---------------------------------------------------------------------- def onTrades(self, data): """实时成交推送""" - print data + print(data) #---------------------------------------------------------------------- def onOrderbooks(self, data): """实时成交推送""" - print data + print(data) diff --git a/beta/api/okex/__init__.py b/beta/api/okex/__init__.py index a55eb22f..a0b1b632 100644 --- a/beta/api/okex/__init__.py +++ b/beta/api/okex/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnokex import OkexSpotApi, OkexFuturesApi, CONTRACT_SYMBOL, SPOT_CURRENCY \ No newline at end of file +from __future__ import absolute_import +from .vnokex import OkexSpotApi, OkexFuturesApi, CONTRACT_SYMBOL, SPOT_CURRENCY \ No newline at end of file diff --git a/beta/api/okex/test.py b/beta/api/okex/test.py index c85a365d..2e20cb82 100644 --- a/beta/api/okex/test.py +++ b/beta/api/okex/test.py @@ -1,6 +1,7 @@ # encoding: UTF-8 -from vnokex import * +from __future__ import absolute_import +from .vnokex import * # 在OkCoin网站申请这两个Key,分别对应用户名和密码 apiKey = '你的accessKey' diff --git a/beta/api/okex/vnokex.py b/beta/api/okex/vnokex.py index cb565ecc..18267b97 100644 --- a/beta/api/okex/vnokex.py +++ b/beta/api/okex/vnokex.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import hashlib import zlib import json @@ -129,23 +130,23 @@ class OkexApi(object): #---------------------------------------------------------------------- def onMessage(self, ws, evt): """信息推送""" - print evt + print(evt) #---------------------------------------------------------------------- def onError(self, ws, evt): """错误推送""" - print 'onError' - print evt + print('onError') + print(evt) #---------------------------------------------------------------------- def onClose(self, ws): """接口断开""" - print 'onClose' + print('onClose') #---------------------------------------------------------------------- def onOpen(self, ws): """接口打开""" - print 'onOpen' + print('onOpen') #---------------------------------------------------------------------- def generateSign(self, params): diff --git a/beta/api/zaif/__init__.py b/beta/api/zaif/__init__.py index 210d0e4a..d7541141 100644 --- a/beta/api/zaif/__init__.py +++ b/beta/api/zaif/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnzaif import TradeApi, DataApi \ No newline at end of file +from __future__ import absolute_import +from .vnzaif import TradeApi, DataApi \ No newline at end of file diff --git a/beta/api/zaif/test.py b/beta/api/zaif/test.py index ed41d65b..094bbcb8 100644 --- a/beta/api/zaif/test.py +++ b/beta/api/zaif/test.py @@ -1,6 +1,7 @@ # encoding: utf-8 -from vnzaif import * +from __future__ import absolute_import +from .vnzaif import * def testTrade(): """测试交易""" diff --git a/beta/api/zaif/vnzaif.py b/beta/api/zaif/vnzaif.py index 5f46ea36..ffd46980 100644 --- a/beta/api/zaif/vnzaif.py +++ b/beta/api/zaif/vnzaif.py @@ -1,5 +1,6 @@ # encoding: utf-8 +from __future__ import print_function import urllib import hashlib @@ -175,11 +176,11 @@ class TradeApi(object): try: data = r.json() if data['success'] == 0: - print "error in vnzaif %s" % method + print("error in vnzaif %s" % method) return data else: return data - except Exception,ex: + except Exception as ex: return None else: return None @@ -218,7 +219,7 @@ class TradeApi(object): # 请求成功 else: if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data, req, reqID) except Empty: @@ -344,29 +345,29 @@ class TradeApi(object): print data ''' def onTrade(self, data, req, reqID): - print data + print(data) def onCancelOrder(self, data, req, reqID): - print data + print(data) def onWithdraw(self, data, req, reqID): - print data + print(data) def onDepositHistory(self, data, req, reqID): - print data + print(data) def onWithdrawHistory(self, data, req, reqID): - print data + print(data) def onTradeHistory(self, data, req, reqID): - print data + print(data) def onActiveOrders(self, data, req, reqID): - print data + print(data) def onGet_info2(self, data, req, reqID): """用户信息""" - print data + print(data) @@ -435,13 +436,13 @@ class DataApi(object): if r.status_code == 200: data = r.json() if self.DEBUG: - print callback.__name__ + print(callback.__name__) data = {"return_symbol": (url.split('/'))[-1].split('_')[0] , "data":data} #data["return_symbol"] = callback(data) - except Exception, e: - print e + except Exception as e: + print(e) sleep(self.taskInterval) @@ -483,18 +484,18 @@ class DataApi(object): #---------------------------------------------------------------------- def onTick(self, data): """实时成交推送""" - print data + print(data) #---------------------------------------------------------------------- def onLast(self, data): """实时深度推送""" - print data + print(data) #---------------------------------------------------------------------- def onTrades(self, data): """实时深度推送""" - print data + print(data) #---------------------------------------------------------------------- def onDepth(self, data): """实时深度推送""" - print data + print(data) diff --git a/beta/api/zb/__init__.py b/beta/api/zb/__init__.py index 835d9d9a..d1a5b42e 100644 --- a/beta/api/zb/__init__.py +++ b/beta/api/zb/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnzb import ZB_Sub_Spot_Api , zb_all_symbol_pairs , zb_all_symbols , zb_all_real_pair \ No newline at end of file +from __future__ import absolute_import +from .vnzb import ZB_Sub_Spot_Api , zb_all_symbol_pairs , zb_all_symbols , zb_all_real_pair \ No newline at end of file diff --git a/beta/api/zb/test.py b/beta/api/zb/test.py index cb1fabed..b0060ab0 100644 --- a/beta/api/zb/test.py +++ b/beta/api/zb/test.py @@ -1,6 +1,7 @@ # encoding: UTF-8 -from vnzb import * +from __future__ import absolute_import +from .vnzb import * # 在OkCoin网站申请这两个Key,分别对应用户名和密码 apiKey = '你的apiKey' diff --git a/beta/api/zb/vnzb.py b/beta/api/zb/vnzb.py index 0e700fa3..2f7faf33 100644 --- a/beta/api/zb/vnzb.py +++ b/beta/api/zb/vnzb.py @@ -1,15 +1,16 @@ # encoding: UTF-8 +from __future__ import print_function + import hashlib -import zlib import json -from time import sleep +import sha +import struct from threading import Thread -import websocket -import urllib2, hashlib,struct,sha,time - +from six import xrange +import websocket # OKEX网站 zb_usd_url = "wss://api.zb.com:9999/websocket" @@ -88,23 +89,23 @@ class ZB_Sub_Spot_Api(object): #---------------------------------------------------------------------- def onMessage(self, ws, evt): """信息推送""" - print evt + print(evt) #---------------------------------------------------------------------- def onError(self, ws, evt): """错误推送""" - print 'onError' - print evt + print('onError') + print(evt) #---------------------------------------------------------------------- def onClose(self, ws): """接口断开""" - print 'onClose' + print('onClose') #---------------------------------------------------------------------- def onOpen(self, ws): """接口打开""" - print 'onOpen' + print('onOpen') #---------------------------------------------------------------------- def subscribeSpotTicker(self, symbol_pair): @@ -210,7 +211,7 @@ class ZB_Sub_Spot_Api(object): channel = symbol_pair.lower() + "_order" - print channel , str(type_) , str(price) , str(amount) + print(channel , str(type_) , str(price) , str(amount)) self.sendTradingRequest(channel, params) #---------------------------------------------------------------------- @@ -265,4 +266,4 @@ class ZB_Sub_Spot_Api(object): channel = symbol_pair.lower() + "_getordersignoretradetype" - self.sendTradingRequest(channel, params) \ No newline at end of file + self.sendTradingRequest(channel, params) diff --git a/beta/gateway/coincheckGateway/__init__.py b/beta/gateway/coincheckGateway/__init__.py index 5cb64a33..34333254 100644 --- a/beta/gateway/coincheckGateway/__init__.py +++ b/beta/gateway/coincheckGateway/__init__.py @@ -1,7 +1,8 @@ # encoding: UTF-8 +from __future__ import absolute_import from vnpy.trader import vtConstant -from coincheckGateway import CoincheckGateway, CoincheckTradeApi , CoincheckSocketDataApi +from .coincheckGateway import CoincheckGateway, CoincheckTradeApi , CoincheckSocketDataApi gatewayClass = CoincheckGateway gatewayName = 'COINCHECK' diff --git a/beta/gateway/coincheckGateway/coincheckGateway.py b/beta/gateway/coincheckGateway/coincheckGateway.py index fe32c887..96ce0b67 100644 --- a/beta/gateway/coincheckGateway/coincheckGateway.py +++ b/beta/gateway/coincheckGateway/coincheckGateway.py @@ -3,6 +3,7 @@ ''' vn.coincheck的gateway接入 ''' +from __future__ import print_function import os import json from datetime import datetime @@ -146,7 +147,7 @@ class CoincheckGateway(VtGateway): #---------------------------------------------------------------------- def onListOrder(self, data): - print data + print(data) #---------------------------------------------------------------------- def setQryEnabled(self, qryEnabled): @@ -181,7 +182,7 @@ class CoincheckTradeApi(vncoincheck.TradeApi): #---------------------------------------------------------------------- def onError(self, method ,data): - print method , data + print(method , data) # ''' "return" : @@ -191,7 +192,7 @@ ty_status': u'identity_verified', u'id': 1007549} ''' def onGet_info(self, data, req, reqID): """用户信息""" - print data + print(data) ''' {u'zec': u'0', u'rep_debt': u'0.0', u'xem': u'0', u'lsk': u'0', u'rep_lend_in_use': u'0.0', u'ltc_de bt': u'0.0', u'xmr_reserved': u'0.0', u'cny': u'0', u'btc_reserved': u'0.0', u'dao_reserved': u'0.0' @@ -215,8 +216,8 @@ u'dash': u'0', u'cny_debt': u'0.0', u'xrp_lend_in_use': u'0.0', u'xem_reserved': ''' def onGet_balance(self, data, req, reqID): if data["success"] == 0: - print "Error in onGet_balance" - print data + print("Error in onGet_balance") + print(data) else: account = VtAccountData() account.gatewayName = self.gatewayName @@ -308,8 +309,8 @@ u'id': 324141928} # print "onBuy_btc" # print data if data["success"] == 0: - print "Error in onBuy_btc" - print data + print("Error in onBuy_btc") + print(data) else: localID = self.reqLocalDict[reqID] systemID = data['id'] @@ -335,7 +336,7 @@ u'id': 324141928} # print data """卖出回调""" if data["success"] == 0: - print "Error in onSell_btc" + print("Error in onSell_btc") else: localID = self.reqLocalDict[reqID] systemID = data['id'] @@ -513,7 +514,7 @@ pending_market_buy_amount': None, u'rate': u'100.0', u'pair': u'btc_jpy', u'stop self.gateway.onOrder(order) def onHistory_orders(self, data, req, reqID): - print data + print(data) def cancel(self, req): localID = req.orderID @@ -594,7 +595,7 @@ class CoincheckSocketDataApi(vncoincheck.DataApiSocket): tick.bidPrice3, tick.bidVolume3 = bids[2] tick.bidPrice4, tick.bidVolume4 = bids[3] tick.bidPrice5, tick.bidVolume5 = bids[4] - except Exception,ex: + except Exception as ex: pass try: @@ -603,7 +604,7 @@ class CoincheckSocketDataApi(vncoincheck.DataApiSocket): tick.askPrice3, tick.askVolume3 = asks[2] tick.askPrice4, tick.askVolume4 = asks[3] tick.askPrice5, tick.askVolume5 = asks[4] - except Exception,ex: + except Exception as ex: pass now = datetime.now() @@ -716,7 +717,7 @@ class CoincheckDataApi(vncoincheck.DataApi): #---------------------------------------------------------------------- def onTrades(self, data): """实时成交推送""" - print data + print(data) #---------------------------------------------------------------------- def onOrderbooks(self, data): diff --git a/beta/gateway/korbitGateway/__init__.py b/beta/gateway/korbitGateway/__init__.py index e4fc53b6..42636a74 100644 --- a/beta/gateway/korbitGateway/__init__.py +++ b/beta/gateway/korbitGateway/__init__.py @@ -1,7 +1,8 @@ # encoding: UTF-8 +from __future__ import absolute_import from vnpy.trader import vtConstant -from korbitGateway import korbitGateway +from .korbitGateway import korbitGateway gatewayClass = korbitGateway gatewayName = 'KORBIT' diff --git a/beta/gateway/korbitGateway/korbitGateway.py b/beta/gateway/korbitGateway/korbitGateway.py index 32a4d352..07928757 100644 --- a/beta/gateway/korbitGateway/korbitGateway.py +++ b/beta/gateway/korbitGateway/korbitGateway.py @@ -3,6 +3,7 @@ ''' vn.coincheck的gateway接入 ''' +from __future__ import print_function import os import json from datetime import datetime @@ -255,13 +256,13 @@ class KorbitTradeApi(vnkorbit.Korbit_TradeApi): #-------------------------------------------------------------------- def onError(self, method ,data): - print method , data + print(method , data) #-------------------------------------------------------------------- def on_buy_currency(self, data , req, reqID): if data["status"] != "success": - print "Error in on_buy_currency" - print data + print("Error in on_buy_currency") + print(data) else: localID = self.reqLocalDict[reqID] systemID = str(data['orderId']) @@ -286,7 +287,7 @@ class KorbitTradeApi(vnkorbit.Korbit_TradeApi): def on_sell_currency(self, data , req, reqID): """卖出回调""" if data["status"] != "success": - print "Error in on_sell_currency" + print("Error in on_sell_currency") else: localID = self.reqLocalDict[reqID] systemID = str(data['orderId']) @@ -306,7 +307,7 @@ class KorbitTradeApi(vnkorbit.Korbit_TradeApi): self.tradedVolumeDict[localID] = 0.0 self.gateway.onOrder(order) - print "what" + print("what") #-------------------------------------------------------------------- def on_list_exchange_orders(self, data , req, reqID): diff --git a/beta/gateway/okexGateway/__init__.py b/beta/gateway/okexGateway/__init__.py index d22d522a..bafb2366 100644 --- a/beta/gateway/okexGateway/__init__.py +++ b/beta/gateway/okexGateway/__init__.py @@ -1,7 +1,8 @@ # encoding: UTF-8 +from __future__ import absolute_import from vnpy.trader import vtConstant -from okexGateway import okexGateway +from .okexGateway import okexGateway gatewayClass = okexGateway gatewayName = 'OKEX' diff --git a/beta/gateway/okexGateway/okexGateway.py b/beta/gateway/okexGateway/okexGateway.py index 102670ba..ba8deb48 100644 --- a/beta/gateway/okexGateway/okexGateway.py +++ b/beta/gateway/okexGateway/okexGateway.py @@ -6,6 +6,7 @@ vnpy.api.okex的gateway接入 注意: 1. 目前仅支持USD现货交易 ''' +from __future__ import print_function import os import json @@ -232,7 +233,7 @@ class SpotApi(OkexSpotApi): data = self.readData(evt)[0] try: channel = data['channel'] - except Exception,ex: + except Exception as ex: channel = None if channel == None: return @@ -310,7 +311,7 @@ class SpotApi(OkexSpotApi): #---------------------------------------------------------------------- def spotAllOrders(self): - print spotAllOrders + print(spotAllOrders) for symbol in registerSymbolPairArray: if symbol in okex_all_symbol_pairs: self.spotOrderInfo(symbol, '-1') @@ -453,8 +454,8 @@ class SpotApi(OkexSpotApi): # print "ticker", tick.date, tick.time # newtick = copy(tick) # self.gateway.onTick(newtick) - except Exception,ex: - print "Error in onTicker ", channel + except Exception as ex: + print("Error in onTicker ", channel) #---------------------------------------------------------------------- def onDepth(self, data): @@ -464,7 +465,7 @@ class SpotApi(OkexSpotApi): try: channel = data['channel'] symbol = self.channelSymbolMap[channel] - except Exception,ex: + except Exception as ex: symbol = None if symbol == None: @@ -789,7 +790,7 @@ nel': u'ok_sub_spot_etc_usdt_order'} def onSpotOrderInfo(self, data): """委托信息查询回调""" if "error_code" in data.keys(): - print data + print(data) return rawData = data['data'] for d in rawData['orders']: @@ -839,7 +840,7 @@ nel': u'ok_sub_spot_etc_usdt_order'} def onSpotOrder(self, data): rawData = data['data'] if 'error_code' in rawData.keys(): - print data + print(data) return orderId = str(rawData['order_id']) diff --git a/beta/gateway/zbGateway/__init__.py b/beta/gateway/zbGateway/__init__.py index 9b25efff..526aaebd 100644 --- a/beta/gateway/zbGateway/__init__.py +++ b/beta/gateway/zbGateway/__init__.py @@ -1,7 +1,8 @@ # encoding: UTF-8 +from __future__ import absolute_import from vnpy.trader import vtConstant -from zbGateway import zbGateway +from .zbGateway import zbGateway gatewayClass = zbGateway gatewayName = 'ZB' diff --git a/beta/gateway/zbGateway/zbGateway.py b/beta/gateway/zbGateway/zbGateway.py index db7f7f16..839cea06 100644 --- a/beta/gateway/zbGateway/zbGateway.py +++ b/beta/gateway/zbGateway/zbGateway.py @@ -3,6 +3,7 @@ ''' vn.zb的gateway接入 ''' +from __future__ import print_function import os import json from datetime import datetime @@ -224,7 +225,7 @@ class ZB_API_Spot(ZB_Sub_Spot_Api): data = self.readData(evt) try: channel = data['channel'] - except Exception,ex: + except Exception as ex: channel = None if channel == None: return @@ -379,8 +380,8 @@ class ZB_API_Spot(ZB_Sub_Spot_Api): # print "ticker", tick.date , tick.time # newtick = copy(tick) # self.gateway.onTick(newtick) - except Exception,ex: - print "Error in onTicker " , channel + except Exception as ex: + print("Error in onTicker " , channel) #---------------------------------------------------------------------- def onDepth(self, data): @@ -388,7 +389,7 @@ class ZB_API_Spot(ZB_Sub_Spot_Api): try: channel = data['channel'] symbol = self.channelSymbolMap[channel] - except Exception,ex: + except Exception as ex: symbol = None if symbol == None: @@ -605,7 +606,7 @@ class ZB_API_Spot(ZB_Sub_Spot_Api): # 现在的处理方式是, 先缓存这里的信息,等到出现了 localID,再来处理这一段 localNo = self.orderIdDict.get(orderId , None) if localNo == None: - print "Error , localNo is none !" + str(localNo) + print("Error , localNo is none !" + str(localNo)) return # 委托信息 @@ -812,8 +813,8 @@ class ZB_API_Spot(ZB_Sub_Spot_Api): rawData = json.loads(rawData) coins = rawData["coins"] - except Exception,ex: - print ex + except Exception as ex: + print(ex) for coin in coins: symbol = coin["cnName"].lower() diff --git a/beta/spreadtrading/stBase.py b/beta/spreadtrading/stBase.py index 3a8094bf..ab31be10 100644 --- a/beta/spreadtrading/stBase.py +++ b/beta/spreadtrading/stBase.py @@ -184,8 +184,8 @@ class StSpread(object): askok = True for k in self.code.co_names : - bidok = bidok and legbidglobal.has_key(k) - askok = askok and legaskglobal.has_key(k) + bidok = bidok and k in legbidglobal + askok = askok and k in legaskglobal if bidok and askok : self.bidPrice = eval(self.code,legbidglobal)