|  | @@ -84,26 +84,26 @@ def ma_judge(data, stock_list, results):
 | 
											
												
													
														|  |      print('RRRRRRR,', results)
 |  |      print('RRRRRRR,', results)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -def sell_trader(data, positions_list):
 |  | 
 | 
											
												
													
														|  | 
 |  | +def sell_trader(data, positions_dict):
 | 
											
												
													
														|  |      # for m in data:
 |  |      # for m in data:
 | 
											
												
													
														|  |      #     print(m, data[m]['lastPrice'])
 |  |      #     print(m, data[m]['lastPrice'])
 | 
											
												
													
														|  |      print('卖出函数:', dt.now())
 |  |      print('卖出函数:', dt.now())
 | 
											
												
													
														|  |      # positions = xt_trader.query_stock_positions(acc)
 |  |      # positions = xt_trader.query_stock_positions(acc)
 | 
											
												
													
														|  |      # print('持仓总数:', len(positions_list))
 |  |      # print('持仓总数:', len(positions_list))
 | 
											
												
													
														|  | -    for stock in data:
 |  | 
 | 
											
												
													
														|  | -        if stock in positions_list:
 |  | 
 | 
											
												
													
														|  | -            print('持仓', stock, data[stock])
 |  | 
 | 
											
												
													
														|  | -            current_price = data[stock]['lastPrice']
 |  | 
 | 
											
												
													
														|  | -            open_price = data[stock]['open']
 |  | 
 | 
											
												
													
														|  | -            MA5 = ma(stock, 5, data)
 |  | 
 | 
											
												
													
														|  | -            MA5_1 = ma_1(stock, 5)
 |  | 
 | 
											
												
													
														|  | -            print('价格:', current_price, open_price, MA5, MA5_1)
 |  | 
 | 
											
												
													
														|  | -            if current_price < MA5 or MA5 < MA5_1 or current_price > MA5 * 1.07:
 |  | 
 | 
											
												
													
														|  | -                print('卖出信号!!!!!!', stock, current_price)
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            #     order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_SELL,
 |  | 
 | 
											
												
													
														|  | -            #                                     i.volume, xtconstant.LATEST_PRICE, 0, 'strategy1', 'order_test')
 |  | 
 | 
											
												
													
														|  | -            # print(order_id, i)
 |  | 
 | 
											
												
													
														|  | 
 |  | +    for stock, volume in positions_dict.items():
 | 
											
												
													
														|  | 
 |  | +        print('持仓', stock, volume)
 | 
											
												
													
														|  | 
 |  | +        current_price = data[stock]['lastPrice']
 | 
											
												
													
														|  | 
 |  | +        open_price = data[stock]['open']
 | 
											
												
													
														|  | 
 |  | +        MA5 = ma(stock, 5, data)
 | 
											
												
													
														|  | 
 |  | +        MA5_1 = ma_1(stock, 5)
 | 
											
												
													
														|  | 
 |  | +        print('价格:', current_price, open_price, MA5, MA5_1)
 | 
											
												
													
														|  | 
 |  | +        if current_price < MA5 or MA5 < MA5_1 or current_price > MA5 * 1.07:
 | 
											
												
													
														|  | 
 |  | +            print('卖出信号!!!!!!', stock, current_price)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            order_id = xt_trader.order_stock(acc, stock, xtconstant.STOCK_SELL, volume,
 | 
											
												
													
														|  | 
 |  | +                                             xtconstant.LATEST_PRICE, 0, 'strategy1', 'order_test')
 | 
											
												
													
														|  | 
 |  | +        print(order_id, stock, volume)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  def buy_trader(data):
 |  |  def buy_trader(data):
 | 
											
										
											
												
													
														|  | @@ -203,10 +203,13 @@ def trader(data):
 | 
											
												
													
														|  |      print(type(positions))
 |  |      print(type(positions))
 | 
											
												
													
														|  |      print('持仓数量', len(positions))
 |  |      print('持仓数量', len(positions))
 | 
											
												
													
														|  |      if len(positions) != 0:
 |  |      if len(positions) != 0:
 | 
											
												
													
														|  | -        positions_list = [positions[x].stock_code for x in range(0, len(positions))]
 |  | 
 | 
											
												
													
														|  | -        print(positions_list)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        positions_dict = {positions[x].stock_code:positions[x].volume for x in range(0, len(positions))}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        print(positions_dict)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        sell_trader(data, positions_list)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        sell_trader(data, positions_dict)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      # 买入条件
 |  |      # 买入条件
 | 
											
												
													
														|  |      buy_trader(data)
 |  |      buy_trader(data)
 |