def renew_all_market_position(self): # positions = utils.get_trader(common_pb2.FULL_INFO).positions ress = utils.get_trader(common_pb2.FULL_INFO) positions=ress.positions rorders=[] # if hasattr(utils.get_trader(common_pb2.FULL_INFO),"orders"): # orderrr=utils.get_trader(common_pb2.FULL_INFO).orders # # rorders=list(orderrr.orders.values()) if hasattr(ress,"orders"): orderrr=ress.orders rorders=list(orderrr.orders.values()) #todo self.remaining_orders=rorders for symbol in SYMBOLS: market_position = 0 avg_entry_price = 0 unrealized_pnl = 0 if hasattr(positions, 'long_positions') and positions.long_positions[symbol] is not None: if hasattr(positions.long_positions[symbol], 'volume'): if positions.long_positions[symbol].volume > 0: market_position = positions.long_positions[symbol].volume avg_entry_price = positions.long_positions[symbol].avg_price unrealized_pnl = positions.long_positions[symbol].unrealized_pnl if hasattr(positions, 'short_positions') and positions.short_positions[symbol] is not None: if hasattr(positions.short_positions[symbol], 'volume'): if positions.short_positions[symbol].volume > 0: market_position = - positions.short_positions[symbol].volume avg_entry_price = positions.short_positions[symbol].avg_price unrealized_pnl = positions.short_positions[symbol].unrealized_pnl self.marketPosition[symbol] = market_position self.averageEntryPrice[symbol] = avg_entry_price self.unrealizedPnl[symbol] = unrealized_pnl for symbol in UNDERLYING: market_position = 0 avg_entry_price = 0 unrealized_pnl = 0 if hasattr(positions, 'long_positions') and positions.long_positions[symbol] is not None: if hasattr(positions.long_positions[symbol], 'volume'): if positions.long_positions[symbol].volume > 0: market_position = positions.long_positions[symbol].volume avg_entry_price = positions.long_positions[symbol].avg_price unrealized_pnl = positions.long_positions[symbol].unrealized_pnl if hasattr(positions, 'short_positions') and positions.short_positions[symbol] is not None: if hasattr(positions.short_positions[symbol], 'volume'): if positions.short_positions[symbol].volume > 0: market_position = - positions.short_positions[symbol].volume avg_entry_price = positions.short_positions[symbol].avg_price unrealized_pnl = positions.short_positions[symbol].unrealized_pnl self.marketPosition[symbol] = market_position self.averageEntryPrice[symbol] = avg_entry_price self.unrealizedPnl[symbol] = unrealized_pnl return self.marketPosition
def renew_market_positionandorder(self,symbol,thisorder): ress=utils.get_trader(common_pb2.FULL_INFO) rorders = [] if hasattr(ress, "orders"): orderrr = ress.orders.orders for id in thisorder.outgoingorder: if not id is None: if not orderrr[id].symbol=='': rorders.append(orderrr[id]) self.remaining_orders = rorders market_position = 0 avg_entry_price = 0 unrealized_pnl = 0 positions=ress.positions if hasattr(positions, 'long_positions') and positions.long_positions[symbol] is not None: if hasattr(positions.long_positions[symbol], 'volume'): if positions.long_positions[symbol].volume > 0: self.marketLongPosition[symbol]=positions.long_positions[symbol].volume market_position = positions.long_positions[symbol].volume avg_entry_price = positions.long_positions[symbol].avg_price unrealized_pnl = positions.long_positions[symbol].unrealized_pnl if hasattr(positions, 'short_positions') and positions.short_positions[symbol] is not None: if hasattr(positions.short_positions[symbol], 'volume'): if positions.short_positions[symbol].volume > 0: self.marketShortPosition[symbol]=positions.short_positions[symbol].volume market_position = - positions.short_positions[symbol].volume avg_entry_price = positions.short_positions[symbol].avg_price unrealized_pnl = positions.short_positions[symbol].unrealized_pnl self.marketPosition[symbol] = market_position self.averageEntryPrice[symbol] = avg_entry_price self.unrealizedPnl[symbol] = unrealized_pnl
def renew_all_market_position(self): positions = utils.get_trader(common_pb2.FULL_INFO).positions for symbol in SYMBOLS: market_position = 0 avg_entry_price = 0 unrealized_pnl = 0 if hasattr(positions, 'long_positions' ) and positions.long_positions[symbol] is not None: if hasattr(positions.long_positions[symbol], 'volume'): if positions.long_positions[symbol].volume > 0: market_position = positions.long_positions[ symbol].volume avg_entry_price = positions.long_positions[ symbol].avg_price unrealized_pnl = positions.long_positions[ symbol].unrealized_pnl if hasattr(positions, 'short_positions' ) and positions.short_positions[symbol] is not None: if hasattr(positions.short_positions[symbol], 'volume'): if positions.short_positions[symbol].volume > 0: market_position = -positions.short_positions[ symbol].volume avg_entry_price = positions.short_positions[ symbol].avg_price unrealized_pnl = positions.short_positions[ symbol].unrealized_pnl self.marketPosition[symbol] = market_position self.averageEntryPrice[symbol] = avg_entry_price self.unrealizedPnl[symbol] = unrealized_pnl return self.marketPosition
def renew_market_position(self, symbol): ress = utils.get_trader(common_pb2.FULL_INFO) market_position = 0 avg_entry_price = 0 unrealized_pnl = 0 positions = ress.positions if hasattr(positions, 'long_positions' ) and positions.long_positions[symbol] is not None: if hasattr(positions.long_positions[symbol], 'volume'): if positions.long_positions[symbol].volume > 0: market_position = positions.long_positions[symbol].volume avg_entry_price = positions.long_positions[ symbol].avg_price self.unrealizedPnllong[symbol] = positions.long_positions[ symbol].unrealized_pnl self.occupiedcashlong[symbol] = positions.long_positions[ symbol].occupied_cash if hasattr(positions, 'short_positions' ) and positions.short_positions[symbol] is not None: if hasattr(positions.short_positions[symbol], 'volume'): if positions.short_positions[symbol].volume > 0: market_position = -positions.short_positions[symbol].volume avg_entry_price = positions.short_positions[ symbol].avg_price self.unrealizedPnlshort[ symbol] = positions.short_positions[ symbol].unrealized_pnl self.occupiedcashshort[symbol] = positions.short_positions[ symbol].occupied_cash self.marketPosition[symbol] = market_position self.averageEntryPrice[symbol] = avg_entry_price
def renew_allfast(self, orders): ress = utils.get_trader(common_pb2.FULL_INFO) # print(ress.positions) # 正式比赛时考虑注释这一行 # print(ress.market_records[2]) # print(ress.pnl) # print(ress.market_records) rorders = [] for symbol in SYMBOLS: if hasattr(ress, "orders"): orderrr = ress.orders.orders for id in orders[symbol].outgoingorder: if not id is None: if not orderrr[id].symbol == '': rorders.append(orderrr[id]) self.orderdict[symbol] = rorders market_position = 0 avg_entry_price = 0 unrealized_pnl = 0 positions = ress.positions if hasattr(positions, 'long_positions' ) and positions.long_positions[symbol] is not None: if hasattr(positions.long_positions[symbol], 'volume'): if positions.long_positions[symbol].volume > 0: self.marketLongPosition[ symbol] = positions.long_positions[symbol].volume market_position = positions.long_positions[ symbol].volume avg_entry_price = positions.long_positions[ symbol].avg_price # unrealized_pnl = positions.long_positions[symbol].unrealized_pnl self.unrealizedPnllong[ symbol] = positions.long_positions[ symbol].unrealized_pnl self.occupiedcashlong[ symbol] = positions.long_positions[ symbol].occupied_cash if hasattr(positions, 'short_positions' ) and positions.short_positions[symbol] is not None: if hasattr(positions.short_positions[symbol], 'volume'): if positions.short_positions[symbol].volume > 0: self.marketShortPosition[ symbol] = positions.short_positions[symbol].volume market_position = -positions.short_positions[ symbol].volume avg_entry_price = positions.short_positions[ symbol].avg_price # unrealized_pnl = positions.short_positions[symbol].unrealized_pnl self.unrealizedPnlshort[ symbol] = positions.short_positions[ symbol].unrealized_pnl self.occupiedcashshort[ symbol] = positions.short_positions[ symbol].occupied_cash self.marketPosition[symbol] = market_position self.averageEntryPrice[symbol] = avg_entry_price
def insert_closePosition(self, symbol): positions = utils.get_trader(common_pb2.FULL_INFO).positions if hasattr(positions, 'long_positions'): long_positions = positions.long_positions if long_positions[symbol] is not None: self.buf.append( (common_pb2.ASK, symbol, long_positions[symbol].volume, None, True, common_pb2.LONG)) if hasattr(positions, 'short_positions'): short_positions = positions.short_positions if short_positions[symbol] is not None: self.buf.append( (common_pb2.BID, symbol, short_positions[symbol].volume, None, True, common_pb2.SHORT))
def renew_market_position(self): positions=utils.get_trader(common_pb2.FULL_INFO) if hasattr(positions, 'long_positions') and positions.long_positions[self.symbol] is not None: if hasattr(positions.long_positions[self.symbol],'volume'): if positions.long_positions[self.symbol].volume>0: self.longpositions = positions.long_positions[self.symbol].volume self.avgentry_long = positions.long_positions[self.symbol].avg_price self.longpnl= positions.long_positions[self.symbol].unrealized_pnl if hasattr(positions, 'short_positions') and positions.short_positions[self.symbol] is not None: if hasattr(positions.short_positions[self.symbol], 'volume'): if positions.short_positions[self.symbol].volume > 0: self.shortpositions = - positions.short_positions[self.symbol].volume self.avgentry_long = positions.short_positions[self.symbol].avg_price self.shortpnl = positions.short_positions[self.symbol].unrealized_pnl