Browse Source

修改判断持仓数量判断:
positions_dict = {positions[x].stock_code: positions[x].volume for x in range(0, len(positions)) if
positions[x].volume > 0}

Daniel 2 years ago
parent
commit
0928531153
1 changed files with 3 additions and 1 deletions
  1. 3 1
      QMT/real_time.py

+ 3 - 1
QMT/real_time.py

@@ -199,9 +199,11 @@ def buy_trader(data, positions):
         for stock in new_keep_stock:
             asset = xt_trader.query_stock_asset(acc)
             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']
-                if cash > 5000 and len(positions) < max_pos and current_price > 9:
+                if cash > 5000 and len(positions_dict) < max_pos and current_price > 9:
                     volume = int((cash / 2 / current_price) // 100 * 100)
                     print('买入信号!!!!!!', stock, volume, current_price)
                     order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_BUY, volume, xtconstant.LATEST_PRICE,