Browse Source

修改自动启动方法

daniel-ali 2 years ago
parent
commit
36857a8520
2 changed files with 15 additions and 17 deletions
  1. 2 4
      QMT/qmt_real_hlfx.py
  2. 13 13
      QMT/real_time.py

+ 2 - 4
QMT/qmt_real_hlfx.py

@@ -269,12 +269,10 @@ def hlfx(data):
     engine_hlfx_pool.dispose()
 
 
-def trader(data):
-    print(dt.now(), len(data.keys()), data.keys())
 
 def bridge(list):
     print(f'MyPid is {os.getpid()}, now is {dt.now()},我需要负责{len(list)}个个股数据')
-    seq = xtdata.subscribe_whole_quote(list, callback=trader)
+    seq = xtdata.subscribe_whole_quote(list, callback=hlfx)
     run(seq)
 
 
@@ -320,7 +318,7 @@ if __name__ == '__main__':
     print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
 
     scheduler = BlockingScheduler()
-    scheduler.add_job(func=prepare, trigger='cron', day_of_week='0-4', hour='9', minute='25',
+    scheduler.add_job(func=prepare, trigger='cron', day_of_week='0-4', hour='10', minute='25',
                       timezone="Asia/Shanghai")
     try:
         scheduler.start()

+ 13 - 13
QMT/real_time.py

@@ -217,18 +217,18 @@ def buy_trader(data, positions):
             cash = asset.cash
             positions_dict = {positions[x].stock_code: positions[x].volume for x in range(0, len(positions)) if
                               positions[x].volume > 0}
-            if stock in new_keep_stock:
-                current_price = data[stock]['lastPrice']
-                current_high = data[stock]['high']
-                if cash > 5000 and len(positions_dict) < max_pos and current_price > 9 \
-                        and current_price > (current_high*0.98):
-                    volume = int((cash / 5 / current_price) // 100 * 100)
-                    print('买入信号!!!!!!', stock, volume, current_price)
-                    order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_BUY, volume, xtconstant.LATEST_PRICE,
-                                                     current_price, 'strategy1', 'order_test')
-                    print(order_id)
-                else:
-                    print(f'Cash只有:{cash} 或者 现有持仓{len(positions)} 超过了{max_pos}')
+            print(f'判断{stock}:cash={cash},持仓数量为{len(positions_dict)}')
+            current_price = data[stock]['lastPrice']
+            current_high = data[stock]['high']
+            if cash > 5000 and len(positions_dict) < max_pos and current_price > 9 \
+                    and current_price > (current_high*0.98):
+                volume = int((cash / 5 / current_price) // 100 * 100)
+                print('买入信号!!!!!!', stock, volume, current_price)
+                order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_BUY, volume, xtconstant.LATEST_PRICE,
+                                                 current_price, 'strategy1', 'order_test')
+                print(order_id)
+            else:
+                print(f'Cash只有:{cash} 或者 现有持仓{len(positions)} 超过了{max_pos}')
     engine_hlfx_pool.dispose()
     print('一轮结束了,现在时间是:', dt.now())
 
@@ -347,7 +347,7 @@ if __name__ == '__main__':
     print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
 
     scheduler = BlockingScheduler()
-    scheduler.add_job(func=bridge, trigger='cron', day_of_week='0-4', hour='9', minute='40',
+    scheduler.add_job(func=bridge, trigger='cron', day_of_week='0-4', hour='10', minute='55',
                       timezone="Asia/Shanghai")
     try:
         scheduler.start()