Skip to content

Commit

Permalink
add query_order to cta_engine & tv_engine
Browse files Browse the repository at this point in the history
  • Loading branch information
51bitquant committed Jul 12, 2022
1 parent 90dfd8b commit cf7c771
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions howtrader/app/cta_strategy/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from howtrader.trader.engine import BaseEngine, MainEngine
from howtrader.trader.object import (
OrderRequest,
OrderQueryRequest,
SubscribeRequest,
HistoryRequest,
CancelRequest,
Expand Down Expand Up @@ -526,6 +527,12 @@ def get_pricetick(self, strategy: CtaTemplate) -> Optional[Decimal]:
else:
return None

def query_order(self, vt_orderid: str) -> None:
order: Optional[OrderData] = self.main_engine.get_order(vt_orderid)
if order:
req: OrderQueryRequest = order.create_query_request()
self.main_engine.query_order(req, order.gateway_name)

def load_bar(
self,
vt_symbol: str,
Expand Down
4 changes: 4 additions & 0 deletions howtrader/app/cta_strategy/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def cancel_order(self, vt_orderid: str) -> None:
if self.trading:
self.cta_engine.cancel_order(self, vt_orderid)

def query_order(self, vt_orderid: str) -> None:
"""query order"""
self.cta_engine.query_order(vt_orderid)

def cancel_all(self) -> None:
"""
Cancel all orders sent by strategy.
Expand Down
7 changes: 7 additions & 0 deletions howtrader/app/tradingview/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from howtrader.trader.engine import BaseEngine, MainEngine
from howtrader.trader.object import (
OrderRequest,
OrderQueryRequest,
SubscribeRequest,
CancelRequest,
LogData,
Expand Down Expand Up @@ -247,6 +248,12 @@ def cancel_order(self, strategy: TVTemplate, vt_orderid: str) -> None:
req: CancelRequest = order.create_cancel_request()
self.main_engine.cancel_order(req, order.gateway_name)

def query_order(self, vt_orderid: str) -> None:
order: Optional[OrderData] = self.main_engine.get_order(vt_orderid)
if order:
req: OrderQueryRequest = order.create_query_request()
self.main_engine.query_order(req, order.gateway_name)

def cancel_all(self, strategy: TVTemplate) -> None:
"""
Cancel all active orders of a strategy.
Expand Down
3 changes: 3 additions & 0 deletions howtrader/app/tradingview/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def cancel_order(self, vt_orderid: str) -> None:
if self.trading:
self.tv_engine.cancel_order(self, vt_orderid)

def query_order(self, vt_orderid: str) -> None:
self.tv_engine.query_order(vt_orderid)

def cancel_all(self) -> None:
"""
Cancel all orders sent by strategy.
Expand Down

0 comments on commit cf7c771

Please sign in to comment.