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