[Merge] pull request #1345 from nanoric/ci

ci
This commit is contained in:
vn.py 2019-01-18 14:13:07 +08:00 committed by GitHub
commit d8dae9e680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 116 additions and 77 deletions

View File

@ -121,7 +121,7 @@ never-returning-functions=sys.exit
# Regular expression matching correct argument names. Overrides argument-
# naming-style.
argument-rgx=[a-z][a-z0-9_]*
argument-rgx=^[a-z][a-z0-9_]*$
# Naming style matching correct attribute names.
attr-naming-style=snake_case

View File

@ -262,7 +262,7 @@ class FutuGateway(BaseGateway):
orderid = str(row["order_id"])
order = req.create_order_data(orderid, self.gateway_name)
self.gateway.on_order(order)
self.on_order(order)
return order.vt_orderid
def cancel_order(self, req):

View File

@ -182,21 +182,21 @@ class IbApi(EWrapper):
self.client = IbClient(self)
self.thread = Thread(target=self.client.run)
def connectAck(self):
def connectAck(self): # pylint: disable=invalid-name
"""
Callback when connection is established.
"""
self.status = True
self.gateway.write_log("IB TWS连接成功")
def connectionClosed(self):
def connectionClosed(self): # pylint: disable=invalid-name
"""
Callback when connection is closed.
"""
self.status = False
self.gateway.write_log("IB TWS连接断开")
def nextValidId(self, orderId: int):
def nextValidId(self, orderId: int): # pylint: disable=invalid-name
"""
Callback of next valid orderid.
"""
@ -204,7 +204,7 @@ class IbApi(EWrapper):
self.orderid = orderId
def currentTime(self, time: int):
def currentTime(self, time: int): # pylint: disable=invalid-name
"""
Callback of current server time of IB.
"""
@ -216,7 +216,7 @@ class IbApi(EWrapper):
msg = f"服务器时间: {time_string}"
self.gateway.write_log(msg)
def error(self, reqId: TickerId, errorCode: int, errorString: str):
def error(self, reqId: TickerId, errorCode: int, errorString: str): # pylint: disable=invalid-name
"""
Callback of error caused by specific request.
"""
@ -225,7 +225,7 @@ class IbApi(EWrapper):
msg = f"信息通知,代码:{errorCode},内容: {errorString}"
self.gateway.write_log(msg)
def tickPrice(
def tickPrice( # pylint: disable=invalid-name
self,
reqId: TickerId,
tickType: TickType,
@ -257,7 +257,7 @@ class IbApi(EWrapper):
tick.datetime = datetime.now()
self.gateway.on_tick(copy(tick))
def tickSize(self, reqId: TickerId, tickType: TickType, size: int):
def tickSize(self, reqId: TickerId, tickType: TickType, size: int): # pylint: disable=invalid-name
"""
Callback of tick volume update.
"""
@ -272,7 +272,7 @@ class IbApi(EWrapper):
self.gateway.on_tick(copy(tick))
def tickString(self, reqId: TickerId, tickType: TickType, value: str):
def tickString(self, reqId: TickerId, tickType: TickType, value: str): # pylint: disable=invalid-name
"""
Callback of tick string update.
"""
@ -286,7 +286,7 @@ class IbApi(EWrapper):
self.gateway.on_tick(copy(tick))
def orderStatus(
def orderStatus( # pylint: disable=invalid-name
self,
orderId: OrderId,
status: str,
@ -325,7 +325,7 @@ class IbApi(EWrapper):
self.gateway.on_order(copy(order))
def openOrder(
def openOrder( # pylint: disable=invalid-name
self,
orderId: OrderId,
ib_contract: Contract,
@ -354,7 +354,7 @@ class IbApi(EWrapper):
self.orders[orderid] = order
self.gateway.on_order(copy(order))
def updateAccountValue(
def updateAccountValue( # pylint: disable=invalid-name
self,
key: str,
val: str,
@ -381,7 +381,7 @@ class IbApi(EWrapper):
name = ACCOUNTFIELD_IB2VT[key]
setattr(account, name, float(val))
def updatePortfolio(
def updatePortfolio( # pylint: disable=invalid-name
self,
contract: Contract,
position: float,
@ -419,7 +419,7 @@ class IbApi(EWrapper):
)
self.gateway.on_position(pos)
def updateAccountTime(self, timeStamp: str):
def updateAccountTime(self, timeStamp: str): # pylint: disable=invalid-name
"""
Callback of account update time.
"""
@ -427,7 +427,7 @@ class IbApi(EWrapper):
for account in self.accounts.values():
self.gateway.on_account(copy(account))
def contractDetails(self, reqId: int, contractDetails: ContractDetails):
def contractDetails(self, reqId: int, contractDetails: ContractDetails): # pylint: disable=invalid-name
"""
Callback of contract data update.
"""
@ -456,7 +456,7 @@ class IbApi(EWrapper):
self.contracts[contract.vt_symbol] = contract
def execDetails(self, reqId: int, contract: Contract, execution: Execution):
def execDetails(self, reqId: int, contract: Contract, execution: Execution): # pylint: disable=invalid-name
"""
Callback of trade data update.
"""
@ -479,7 +479,7 @@ class IbApi(EWrapper):
self.gateway.on_trade(trade)
def managedAccounts(self, accountsList: str):
def managedAccounts(self, accountsList: str): # pylint: disable=invalid-name
"""
Callback of all sub accountid.
"""

View File

@ -11,8 +11,15 @@ from PyQt5 import QtWidgets, QtGui, QtCore
from vnpy.event import EventEngine, Event
from ..constant import Direction, Offset, PriceType, Exchange
from ..engine import MainEngine
from ..event import (EVENT_TICK, EVENT_ORDER, EVENT_TRADE, EVENT_ACCOUNT,
EVENT_POSITION, EVENT_CONTRACT, EVENT_LOG)
from ..event import (
EVENT_TICK,
EVENT_ORDER,
EVENT_TRADE,
EVENT_ACCOUNT,
EVENT_POSITION,
EVENT_CONTRACT,
EVENT_LOG
)
from ..object import SubscribeRequest, OrderRequest, CancelRequest
from ..utility import load_setting, save_setting
@ -282,7 +289,8 @@ class BaseMonitor(QtWidgets.QTableWidget):
Resize all columns according to contents.
"""
self.horizontalHeader().resizeSections(
QtWidgets.QHeaderView.ResizeToContents)
QtWidgets.QHeaderView.ResizeToContents
)
def save_csv(self):
"""
@ -682,7 +690,9 @@ class ConnectDialog(QtWidgets.QDialog):
self.setWindowTitle(f"连接{self.gateway_name}")
# Default setting provides field name, field data type and field default value.
default_setting = self.main_engine.get_default_setting(self.gateway_name)
default_setting = self.main_engine.get_default_setting(
self.gateway_name
)
# Saved setting provides field data used last time.
loaded_setting = load_setting(self.file_name)
@ -737,7 +747,6 @@ class ConnectDialog(QtWidgets.QDialog):
self.accept()
class TradingWidget(QtWidgets.QWidget):
"""
General manual trading widget.
@ -772,16 +781,18 @@ class TradingWidget(QtWidgets.QWidget):
self.name_line.setReadOnly(True)
self.direction_combo = QtWidgets.QComboBox()
self.direction_combo.addItems([
Direction.LONG.value,
Direction.SHORT.value
])
self.direction_combo.addItems(
[Direction.LONG.value,
Direction.SHORT.value]
)
self.offset_combo = QtWidgets.QComboBox()
self.offset_combo.addItems([offset.value for offset in Offset])
self.price_type_combo = QtWidgets.QComboBox()
self.price_type_combo.addItems([price_type.value for price_type in PriceType])
self.price_type_combo.addItems(
[price_type.value for price_type in PriceType]
)
double_validator = QtGui.QDoubleValidator()
double_validator.setBottom(0)
@ -824,11 +835,26 @@ class TradingWidget(QtWidgets.QWidget):
self.bp4_label = self.create_label(bid_color)
self.bp5_label = self.create_label(bid_color)
self.bv1_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight)
self.bv2_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight)
self.bv3_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight)
self.bv4_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight)
self.bv5_label = self.create_label(bid_color, alignment=QtCore.Qt.AlignRight)
self.bv1_label = self.create_label(
bid_color,
alignment=QtCore.Qt.AlignRight
)
self.bv2_label = self.create_label(
bid_color,
alignment=QtCore.Qt.AlignRight
)
self.bv3_label = self.create_label(
bid_color,
alignment=QtCore.Qt.AlignRight
)
self.bv4_label = self.create_label(
bid_color,
alignment=QtCore.Qt.AlignRight
)
self.bv5_label = self.create_label(
bid_color,
alignment=QtCore.Qt.AlignRight
)
self.ap1_label = self.create_label(ask_color)
self.ap2_label = self.create_label(ask_color)
@ -836,11 +862,26 @@ class TradingWidget(QtWidgets.QWidget):
self.ap4_label = self.create_label(ask_color)
self.ap5_label = self.create_label(ask_color)
self.av1_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight)
self.av2_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight)
self.av3_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight)
self.av4_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight)
self.av5_label = self.create_label(ask_color, alignment=QtCore.Qt.AlignRight)
self.av1_label = self.create_label(
ask_color,
alignment=QtCore.Qt.AlignRight
)
self.av2_label = self.create_label(
ask_color,
alignment=QtCore.Qt.AlignRight
)
self.av3_label = self.create_label(
ask_color,
alignment=QtCore.Qt.AlignRight
)
self.av4_label = self.create_label(
ask_color,
alignment=QtCore.Qt.AlignRight
)
self.av5_label = self.create_label(
ask_color,
alignment=QtCore.Qt.AlignRight
)
self.lp_label = self.create_label()
self.return_label = self.create_label(alignment=QtCore.Qt.AlignRight)
@ -864,7 +905,11 @@ class TradingWidget(QtWidgets.QWidget):
vbox.addLayout(form2)
self.setLayout(vbox)
def create_label(self, color: str = "", alignment: int = QtCore.Qt.AlignLeft):
def create_label(
self,
color: str = "",
alignment: int = QtCore.Qt.AlignLeft
):
"""
Create label with certain font color.
"""
@ -948,10 +993,7 @@ class TradingWidget(QtWidgets.QWidget):
self.clear_label_text()
# Subscribe tick data
req = SubscribeRequest(
symbol=symbol,
exchange=Exchange(exchange_value)
)
req = SubscribeRequest(symbol=symbol, exchange=Exchange(exchange_value))
self.main_engine.subscribe(req, gateway_name)
@ -992,18 +1034,12 @@ class TradingWidget(QtWidgets.QWidget):
"""
symbol = str(self.symbol_line.text())
if not symbol:
QtWidgets.QMessageBox.critical(
"委托失败",
"请输入合约代码"
)
QtWidgets.QMessageBox.critical("委托失败", "请输入合约代码")
return
volume_text = str(self.volume_line.text())
if not volume_text:
QtWidgets.QMessageBox.critical(
"委托失败",
"请输入委托数量"
)
QtWidgets.QMessageBox.critical("委托失败", "请输入委托数量")
return
volume = float(volume_text)
@ -1123,7 +1159,10 @@ class ContractManager(QtWidgets.QWidget):
all_contracts = self.main_engine.get_all_contracts()
if flt:
contracts = [contract for contract in all_contracts if flt in contract.vt_symbol]
contracts = [
contract for contract in all_contracts
if flt in contract.vt_symbol
]
else:
contracts = all_contracts