[Add] Complete futu gateway test
This commit is contained in:
parent
80193f6ebb
commit
33aff65e60
@ -77,6 +77,7 @@ DIRECTION_FUTU2VT = {v: k for k, v in DIRECTION_VT2FUTU.items()}
|
||||
|
||||
STATUS_FUTU2VT = {
|
||||
OrderStatus.NONE: STATUS_SUBMITTING,
|
||||
OrderStatus.SUBMITTING: STATUS_SUBMITTING,
|
||||
OrderStatus.SUBMITTED: STATUS_NOTTRADED,
|
||||
OrderStatus.FILLED_PART: STATUS_PARTTRADED,
|
||||
OrderStatus.FILLED_ALL: STATUS_ALLTRADED,
|
||||
@ -449,10 +450,10 @@ class FutuGateway(BaseGateway):
|
||||
ask_data = data["Ask"][i]
|
||||
n = i + 1
|
||||
|
||||
d["bid_price%s" % n] = bid_data[0]
|
||||
d["bid_volume%s" % n] = bid_data[1]
|
||||
d["ask_price%s" % n] = ask_data[0]
|
||||
d["ask_volume%s" % n] = ask_data[1]
|
||||
d["bid_price_%s" % n] = bid_data[0]
|
||||
d["bid_volume_%s" % n] = bid_data[1]
|
||||
d["ask_price_%s" % n] = ask_data[0]
|
||||
d["ask_volume_%s" % n] = ask_data[1]
|
||||
|
||||
if tick.datetime:
|
||||
self.on_tick(copy(tick))
|
||||
@ -490,7 +491,7 @@ class FutuGateway(BaseGateway):
|
||||
tradeid = str(row["deal_id"])
|
||||
if tradeid in self.trades:
|
||||
continue
|
||||
self.trades.add(tradeID)
|
||||
self.trades.add(tradeid)
|
||||
|
||||
symbol, exchange = convert_symbol_futu2vt(row["code"])
|
||||
trade = TradeData(
|
||||
|
@ -140,14 +140,15 @@ class MainEngine:
|
||||
Make sure every gateway and app is closed properly before
|
||||
programme exit.
|
||||
"""
|
||||
# Stop event engine first to prevent new timer event.
|
||||
self.event_engine.stop()
|
||||
|
||||
for engine in self.engines.values():
|
||||
engine.close()
|
||||
|
||||
for gateway in self.gateways.values():
|
||||
gateway.close()
|
||||
|
||||
self.event_engine.stop()
|
||||
|
||||
|
||||
class BaseEngine(ABC):
|
||||
"""
|
||||
|
@ -281,8 +281,9 @@ class BaseMonitor(QtWidgets.QTableWidget):
|
||||
if not path:
|
||||
return
|
||||
|
||||
with open(path, "wb") as f:
|
||||
writer = csv.writer(f)
|
||||
with open(path, "w") as f:
|
||||
writer = csv.writer(f, lineterminator='\n')
|
||||
|
||||
writer.writerow(self.headers.keys())
|
||||
|
||||
for row in range(self.rowCount()):
|
||||
@ -290,11 +291,17 @@ class BaseMonitor(QtWidgets.QTableWidget):
|
||||
for column in range(self.columnCount()):
|
||||
item = self.item(row, column)
|
||||
if item:
|
||||
row_data.append(text_type(item.text()))
|
||||
row_data.append(str(item.text()))
|
||||
else:
|
||||
row_data.append("")
|
||||
writer.writerow(row_data)
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
"""
|
||||
Show menu with right click.
|
||||
"""
|
||||
self.menu.popup(QtGui.QCursor.pos())
|
||||
|
||||
|
||||
class TickMonitor(BaseMonitor):
|
||||
"""
|
||||
@ -936,8 +943,14 @@ class TradingWidget(QtWidgets.QWidget):
|
||||
contract = self.main_engine.get_contract(vt_symbol)
|
||||
if not contract:
|
||||
self.name_line.setText("")
|
||||
gateway_name = (self.gateway_combo.currentText())
|
||||
else:
|
||||
self.name_line.setText(contract.name)
|
||||
gateway_name = contract.gateway_name
|
||||
|
||||
# Update gateway combo box.
|
||||
ix = self.gateway_combo.findText(gateway_name)
|
||||
self.gateway_combo.setCurrentIndex(ix)
|
||||
|
||||
self.clear_label_text()
|
||||
|
||||
@ -946,7 +959,6 @@ class TradingWidget(QtWidgets.QWidget):
|
||||
symbol=symbol,
|
||||
exchange=exchange
|
||||
)
|
||||
gateway_name = (self.gateway_combo.currentText())
|
||||
|
||||
self.main_engine.subscribe(req, gateway_name)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user