Browse Source

修订real_time购买策略
减少打印

Daniel 2 years ago
parent
commit
ae43ccaa61
2 changed files with 9 additions and 11 deletions
  1. 4 3
      QMT/qmt_real_hlfx.py
  2. 5 8
      QMT/real_time.py

+ 4 - 3
QMT/qmt_real_hlfx.py

@@ -37,6 +37,7 @@ def run(seq):
         now_date = dt.now()
         if not client.is_connected() or dt.now() > now_date.replace(hour=15, minute=0, second=0):
             xtdata.unsubscribe_quote(seq)
+            print(f'现在时间:{dt.now()},已收盘')
             raise Exception('行情服务连接断开')
             break
     return
@@ -260,12 +261,12 @@ def hlfx(data):
                               password='r6kEwqWU9!v3',
                               database='hlfx_pool')
     cursor_pool = db_pool.cursor()
-    print(set(results))
+    # print(set(results))
     results_list = ','.join(set(results))
     sql = "INSERT INTO %s (date,value) VALUES('%s','%s')" % (fre, dt.now().strftime('%Y-%m-%d %H:%M:%S'), results_list)
     cursor_pool.execute(sql)
     db_pool.commit()
-    print(f'{dt.now()}写入新的results,hlfx_pool更新')
+    print(f'{dt.now()}写入新的results{len(results_list)}个,hlfx_pool更新')
     engine_hlfx_pool.dispose()
 
 
@@ -318,7 +319,7 @@ if __name__ == '__main__':
     print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
 
     scheduler = BlockingScheduler()
-    scheduler.add_job(func=prepare, trigger='cron', day_of_week='0-4', hour='10', minute='25',
+    scheduler.add_job(func=prepare, trigger='cron', day_of_week='0-4', hour='9', minute='25',
                       timezone="Asia/Shanghai")
     try:
         scheduler.start()

+ 5 - 8
QMT/real_time.py

@@ -87,9 +87,9 @@ def his_vol(stock, num):
 
 
 def ma_judge(data, stock_list, rate, results):
-    print(f'这个ma_judge的PID为:{os.getpid()},收到的data数据为:{len(data.keys())},stock_pool长度为{len(stock_list)},now is {dt.now()}')
+    # print(f',收到的data数据为:{len(data.keys())},stock_pool长度为{len(stock_list)},now is {dt.now()}')
     list_judge = list(set(data.keys()) & set(stock_list))
-    print(f'本轮计算:{len(list_judge)}个股')
+    print(f'这个ma_judge的PID为:{os.getpid()},本轮计算:{len(list_judge)}个股')
     for stock in list_judge:
         i = stock.replace('XSHG', 'SH').replace('XSHE', 'SZ')
         current_price, open_price = data[i]['lastPrice'], data[i]['open']
@@ -102,7 +102,6 @@ def ma_judge(data, stock_list, rate, results):
                 MA20 < MA10) & (current_price > MA120 or current_price < MA120*rate):
             if his_vol(i, -1) > his_vol(i, -2):
                 results.append(i.replace('SH', 'XSHG').replace('SZ', 'XSHE'))
-    print('RRRRRRR,', results)
 
 
 def sell_trader(data, positions_dict):
@@ -178,7 +177,6 @@ def buy_trader(data, positions):
         # 基本面过滤
         results = get_fundamentals(results)
         num_industry = get_industry(results)
-        print(num_industry)
         industry_list = []
         for key in num_industry.values():
             for key2 in key.values():
@@ -191,7 +189,6 @@ def buy_trader(data, positions):
             for key2 in value.values():
                 if key2['industry_name'] in max_industry_list:
                     results_industry.append(key)
-        print('所有:', set(results_industry))
         results_industry = ','.join(set(results_industry))
         print('1d', '\n', results_industry)
 
@@ -207,7 +204,7 @@ def buy_trader(data, positions):
 
         keep_stocks = results_industry.split(",")
         new_keep_stock = [stock.replace('XSHG', 'SH').replace('XSHE', 'SZ') for stock in keep_stocks]
-        print(f'new_keep_stock is:{len(new_keep_stock)},{new_keep_stock}')
+        print(f'new_keep_stock is:{len(new_keep_stock)}')
 
 
         #进入购买程序
@@ -222,7 +219,7 @@ def buy_trader(data, positions):
             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)
+                volume = int((cash / 3 / 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')
@@ -347,7 +344,7 @@ if __name__ == '__main__':
     print('对交易回调进行订阅,订阅后可以收到交易主推,返回0表示订阅成功', subscribe_result)
 
     scheduler = BlockingScheduler()
-    scheduler.add_job(func=bridge, trigger='cron', day_of_week='0-4', hour='10', minute='55',
+    scheduler.add_job(func=bridge, trigger='cron', day_of_week='0-4', hour='9', minute='40',
                       timezone="Asia/Shanghai")
     try:
         scheduler.start()