Skip to content

Commit

Permalink
V2.1.7.7
Browse files Browse the repository at this point in the history
  • Loading branch information
lin committed Dec 13, 2020
1 parent 343b8a4 commit 1a43283
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ folder by using the multi-threads for speeding.

4. V2.1.7.6 : update the position. 对订阅的交易对,都会推送其头寸的更新.

5. V2.1.7.7 : add the position_update_interval and
order_update_interval, 添加对订单和仓位信息的更新频率.

## 联系方式
微信: bitquant51

Expand Down
2 changes: 1 addition & 1 deletion howtrader/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.7.6"
__version__ = "2.1.7.7"
15 changes: 10 additions & 5 deletions howtrader/trader/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ def __init__(self, main_engine: MainEngine, event_engine: EventEngine):
self.add_function()
self.register_event()

self.timer_count = 0 # for counting the timer.
self.order_update_interval = 0 # for counting the timer.
self.position_update_interval = 0

def add_function(self) -> None:
"""Add query function to main engine."""
Expand Down Expand Up @@ -434,17 +435,21 @@ def process_timer(self, event: Event) -> None:
"""
update the orders, positions by timer, for we may be disconnected from server update push.
"""
if self.timer_count >= SETTINGS.get('order_update_timer', 120):
self.timer_count = 0

self.order_update_interval += 1
self.position_update_interval += 1

if self.order_update_interval >= SETTINGS.get('order_update_interval', 120):
self.order_update_interval = 0
orders = self.get_all_active_orders()
for order in orders:
if order.datetime and (datetime.now(order.datetime.tzinfo) - order.datetime).seconds > SETTINGS.get('order_update_timer', 120):
req = order.create_query_request()
self.main_engine.query_order(req, order.gateway_name)

if self.position_update_interval >= SETTINGS.get('position_update_interval', 120):
self.main_engine.query_position()
else:
self.timer_count += 1
self.position_update_interval = 0

def get_tick(self, vt_symbol: str) -> Optional[TickData]:
"""
Expand Down
3 changes: 2 additions & 1 deletion howtrader/trader/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
SETTINGS: Dict[str, Any] = {
"font.family": "Arial",
"font.size": 12,
"order_update_timer": 120,
"order_update_interval": 120,
"position_update_interval": 120,
"log.active": True,
"log.level": CRITICAL,
"log.console": True,
Expand Down

0 comments on commit 1a43283

Please sign in to comment.