def updateStoploss(self, pid, price): return Positions.updatePosition( token=self.token, pid=pid, type_='stoploss', value=price, )
def updateProfit(self, pid, price): return Positions.updatePosition( token=self.token, pid=pid, type_='takeprofit', value=price, )
def buy(self, strategy, leverage, quantity=None, margin=None, stoploss=None, takeprofit=None, limit=None): assert(margin is not None or quantity is not None) if limit is None: positionData = Positions.buy( token=self.token, leverage=leverage, quantity=quantity, margin=margin, stoploss=stoploss, takeprofit=takeprofit, ) else: positionData = Positions.limitBuy( token=self.token, leverage=leverage, price=limit, quantity=quantity, stoploss=stoploss, takeprofit=takeprofit, ) strategy.notifyOrder(Order( Type='buy', Quantity=positionData['position']['quantity'], Leverage=leverage, Stoploss=stoploss, Takeprofit=takeprofit, Limit=limit, Parent=None, Strategy=strategy, ), positionData['position']['price']) self.orderBook = self.orderBook.append({ 'Pid': positionData['position']['pid'], 'Type': 'buy', 'Limit': limit, 'Quantity': positionData['position']['quantity'], 'Leverage': leverage, 'Stoploss': stoploss, 'Takeprofit': takeprofit, 'StopExecuted': False, 'ProfitExecuted': False, }, ignore_index=True) return positionData
def closedPositions(self): return Positions.getPositions(self.token, "closed")
def openPositions(self): return Positions.getPositions(self.token, "open")
def isOpen(self, pid): return Positions.isOpen(self.token, pid)
def cashin(self, pid, amount): return Positions.cashin(self.token, pid, amount)
def addMargin(self, pid, amount): return Positions.addMargin(self.token, pid, amount)
def cancelPosition(self, pid): return Positions.cancelPosition(self.token, pid)
def closeAllShorts(self): return Positions.closeAllShorts(self.token)
def closeAllLongs(self): return Positions.closeAllLongs(self.token)
def closePosition(self, pid): return Positions.closePosition(self.token, pid)
def test_createPosition(token): buyinfo = Positions.buy(token, leverage=1, quantity=1) assert 'position' in buyinfo assert 'pid' in buyinfo['position'] assert Positions.closePosition(token, buyinfo['position']['pid'])['closed']
def test_getPositions(token): assert 'open' in Positions.getPositions(token, 'open')