コード例 #1
0
 def updateStoploss(self, pid, price):
     return Positions.updatePosition(
         token=self.token,
         pid=pid,
         type_='stoploss',
         value=price,
         )
コード例 #2
0
 def updateProfit(self, pid, price):
     return Positions.updatePosition(
         token=self.token,
         pid=pid,
         type_='takeprofit',
         value=price,
         )
コード例 #3
0
    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
コード例 #4
0
 def closedPositions(self):
     return Positions.getPositions(self.token, "closed")
コード例 #5
0
 def openPositions(self):
     return Positions.getPositions(self.token, "open")
コード例 #6
0
 def isOpen(self, pid):
     return Positions.isOpen(self.token, pid)
コード例 #7
0
 def cashin(self, pid, amount):
     return Positions.cashin(self.token, pid, amount)
コード例 #8
0
 def addMargin(self, pid, amount):
     return Positions.addMargin(self.token, pid, amount)
コード例 #9
0
 def cancelPosition(self, pid):
     return Positions.cancelPosition(self.token, pid)
コード例 #10
0
 def closeAllShorts(self):
     return Positions.closeAllShorts(self.token)
コード例 #11
0
 def closeAllLongs(self):
     return Positions.closeAllLongs(self.token)
コード例 #12
0
 def closePosition(self, pid):
     return Positions.closePosition(self.token, pid)
コード例 #13
0
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']
コード例 #14
0
def test_getPositions(token):
    assert 'open' in Positions.getPositions(token, 'open')