|
@@ -90,20 +90,23 @@ def sell_trader(data, positions_dict):
|
|
|
print('卖出函数:', dt.now())
|
|
|
# positions = xt_trader.query_stock_positions(acc)
|
|
|
# print('持仓总数:', len(positions_list))
|
|
|
+ for i in data:
|
|
|
+ print(i, type(i))
|
|
|
+ break
|
|
|
|
|
|
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)
|
|
|
+ if stock in data:
|
|
|
+ print('持仓', stock, volume)
|
|
|
+ current_price = data[stock]['lastPrice']
|
|
|
+ open_price = data[stock]['open']
|
|
|
+ MA5 = ma(stock, 5, data)
|
|
|
+ MA5_1 = ma_1(stock, 5)
|
|
|
+ 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('价格:', current_price, open_price, MA5, MA5_1)
|
|
|
+ print(order_id, stock, volume)
|
|
|
|
|
|
|
|
|
def buy_trader(data):
|
|
@@ -197,15 +200,13 @@ def buy_trader(data):
|
|
|
|
|
|
def trader(data):
|
|
|
print(len(data.keys()))
|
|
|
-
|
|
|
# 先判断卖出条件
|
|
|
positions = xt_trader.query_stock_positions(acc)
|
|
|
- print(type(positions))
|
|
|
print('持仓数量', len(positions))
|
|
|
if len(positions) != 0:
|
|
|
- positions_dict = {positions[x].stock_code:positions[x].volume for x in range(0, len(positions))}
|
|
|
-
|
|
|
- print(positions_dict)
|
|
|
+ positions_dict = {positions[x].stock_code: positions[x].volume for x in range(0, len(positions))}
|
|
|
+ print(type(positions_dict.keys()))
|
|
|
+ # print(data[positions_dict.keys()[0]])
|
|
|
|
|
|
|
|
|
|