def get_day_skvol(tdapi, instrumentID): tdapi.qryPosition(instrumentID) while not q_positions.empty(): posi = q_positions.get(timeout=1) # print posi if posi.InstrumentID == instrumentID and posi.PosiDirection == '3' and posi.PositionDate == '1': return int(posi.Position)
def getPos(tradespi, inst=strategy_inst): if tradespi is None or inst is None: return 0 tradespi.qryPosition(InstrumentID=inst) all_buyorder = 0 all_sellorder = 0 while not q_positions.empty(): pos = q_positions.get() if pos.PosiDirection == '2': # 多头 if pos.PositionDate == '1': # 日内开平仓情况 print('今天多单情况:', '当前持仓:', pos.Position, '今天开仓数量: ', pos.OpenVolume, '今日平仓数量: ', pos.CloseVolume, '平仓盈利: ', pos.CloseProfit, '平仓手续费:', pos.Commission) all_buyorder += pos.Position # print 'today buy order: ', pos.YdPosition+pos.Position # print pos.YdPosition # print pos.Position elif pos.PositionDate == '2': # history order print() '历史多单情况:', '当前持仓:', pos.Position, '今天开仓数量: ', pos.OpenVolume, '今日平仓数量: ', pos.CloseVolume, '平仓盈利: ', pos.CloseProfit, '平仓手续费:', pos.Commission all_buyorder += pos.Position # print 'history buy order: ', pos.YdPosition + pos.Position print() pos.YdPosition print() pos.Position if pos.PosiDirection == '3': # 空头持仓 if pos.PositionDate == '1': # 今日仓位 print() '今天空单情况:', '当前持仓:', pos.Position, '今天开仓数量: ', pos.OpenVolume, '今日平仓数量: ', pos.CloseVolume, '平仓盈利: ', pos.CloseProfit, '平仓手续费:', pos.Commission all_sellorder += pos.Position # print pos.YdPosition # print pos.Position elif pos.PositionDate == '2': # history order print('历史空单情况:', '当前持仓:', pos.Position, '今天开仓数量: ', pos.OpenVolume, '今日平仓数量: ', pos.CloseVolume, '平仓盈利: ', pos.CloseProfit, '平仓手续费:', pos.Commission) # print 'history sell order: ', pos.YdPosition + pos.Position all_sellorder += pos.Position # print pos.YdPosition # print pos.Position print(strategy_inst, '多单合计:', all_buyorder) print(strategy_inst, '空单合计:', all_sellorder) return (all_buyorder, all_sellorder)