def fetch_position_ws(self): pos = Dotdict(self.ws.position()) pos.unrealisedPnlPcnt100 = pos.unrealisedPnlPcnt * 100 self.logger.info( "POSITION: qty {currentQty} cost {avgCostPrice} pnl {unrealisedPnl}({unrealisedPnlPcnt100:.2f}%) {realisedPnl}" .format(**pos)) return pos
def fetch_position(self, symbol=None): """現在のポジションを取得""" symbol = symbol or self.settings.symbol res = self.exchange.privateGetPosition() pos = [ x for x in res if x['symbol'] == self.exchange.market(symbol)['id'] ] if len(pos): pos = Dotdict(pos[0]) pos.timestamp = pd.to_datetime(pos.timestamp) else: pos = Dotdict() pos.currentQty = 0 pos.avgCostPrice = 0 pos.unrealisedPnl = 0 pos.unrealisedPnlPcnt = 0 pos.realisedPnl = 0 pos.unrealisedPnlPcnt100 = pos.unrealisedPnlPcnt * 100 self.logger.info( "POSITION: qty {currentQty} cost {avgCostPrice} pnl {unrealisedPnl}({unrealisedPnlPcnt100:.2f}%) {realisedPnl}" .format(**pos)) return pos