def tokenFee(self):
        txService = TransactionService()

        tokenID = self.params.get('token_id', '')

        tokenServie = TokenService()
        tokens = tokenServie.listTokens()

        tokenName = tokens.get(tokenID).get('name')

        pdexService = PdexService()
        pdexTokens = pdexService.getTokens()

        data = txService.sumTokenFee(tokenID=tokenID)
        result = {
            'name': tokenName,
            'fee': data[tokenID] / float(pdexTokens.get(tokenID).get('exchange_rate')),
            'id': tokenID,
            'rate': pdexTokens.get(tokenID).get('exchange_rate'),
        }
        return result
Example #2
0
    def listContributeLiquidityTx(self):

        page = self.params.get('page', 0)
        limit = self.params.get('limit', 0)
        group = self.params.get('group', 0)
        order_trend = self.params.get('order_trend', 'ASC')

        service = TransactionService()
        txs = service.listTxByMetadataType(metadataType=90,
                                           page=int(page),
                                           limit=int(limit),
                                           order_trend=order_trend)

        pDexService = PdexService()
        data = pDexService.getTokens()

        for tx in txs:
            metadata = tx.get('metadata')
            tokenIDStr = metadata.get('TokenIDStr')
            token = data.get(tokenIDStr)
            if token is not None:
                tokeName = token.get('name')
                metadata['TokenNameStr'] = tokeName
            else:
                metadata['TokenNameStr'] = tokenIDStr
            tx['metadata'] = metadata

        if int(group) == 1:
            result = {}
            for tx in txs:
                PDEContributionPairID = tx['metadata']['PDEContributionPairID']
                if PDEContributionPairID not in result:
                    result[PDEContributionPairID] = []
                result[PDEContributionPairID].append(tx)
            return result
        else:
            result = []
            for tx in txs:
                result.append(tx)
            return result
    def dailytokenFee(self):
        txService = TransactionService()

        tokenID = self.params.get('token_id', '')
        fromDate = self.params.get('from_date', '')
        toDate = self.params.get('to_date', '')
        limit = self.params.get('limit', 0)
        page = self.params.get('page', 0)

        tokenServie = TokenService()
        tokens = tokenServie.listTokens()

        tokenName = tokens.get(tokenID).get('name')

        pdexService = PdexService()
        pdexTokens = pdexService.getTokens()

        data = txService.dailyTokenFee(tokenID=tokenID, fromDate=fromDate, toDate=toDate, page=int(page),
                                       limit=int(limit))

        for i in data:
            i['fee'] = i['fee'] / float(pdexTokens.get(tokenID).get('exchange_rate'))
        return data
    def lastHoursVolumeFunc(self, token1, token2, hours, direction):
        if token1 == '' and token2 == '':
            return {}
        else:
            service = PdexService()
            tokenService = TokenService()

            data = service.lastTradingTxInHours(token1, token2, hours)
            if len(data) == 0:
                return {}

            result = {}
            tokens = tokenService.listTokens()
            pdeToken = service.getTokens()
            if not direction:
                for tx in data:
                    metadata = tx['metadata']
                    if metadata[
                            'TokenIDToSellStr'] == '0000000000000000000000000000000000000000000000000000000000000004':
                        sellToken = 'PRV'
                        sellTokenId = '0000000000000000000000000000000000000000000000000000000000000004'
                    else:
                        sellToken = tokens[
                            metadata['TokenIDToSellStr']]['name']
                        sellTokenId = metadata['TokenIDToSellStr']
                    if metadata[
                            'TokenIDToBuyStr'] == '0000000000000000000000000000000000000000000000000000000000000004':
                        buyToken = 'PRV'
                        buyTokenId = '0000000000000000000000000000000000000000000000000000000000000004'
                    else:
                        buyToken = tokens[metadata['TokenIDToBuyStr']]['name']
                        buyTokenId = metadata['TokenIDToBuyStr']
                    sellAmount = metadata['SellAmount']
                    buyAmount = tx['receive_amount']

                    if sellToken not in result:
                        result[sellToken] = Decimal(0)
                    sellExchangeRate = pdeToken.get(sellTokenId).get(
                        'exchange_rate')
                    sellAmount = Decimal(sellAmount /
                                         Decimal(sellExchangeRate))
                    result[sellToken] += sellAmount

                    if buyToken not in result:
                        result[buyToken] = Decimal(0)
                    buyExchangeRate = pdeToken.get(buyTokenId).get(
                        'exchange_rate')
                    buyAmount = Decimal(buyAmount / Decimal(buyExchangeRate))
                    result[buyToken] += buyAmount

                for i in result.keys():
                    result[i] = float(result[i])
            else:
                for tx in data:
                    metadata = tx['metadata']
                    if metadata[
                            'TokenIDToSellStr'] == '0000000000000000000000000000000000000000000000000000000000000004':
                        sellToken = 'PRV'
                        sellTokenId = '0000000000000000000000000000000000000000000000000000000000000004'
                    else:
                        sellToken = tokens[
                            metadata['TokenIDToSellStr']]['name']
                        sellTokenId = metadata['TokenIDToSellStr']
                    if metadata[
                            'TokenIDToBuyStr'] == '0000000000000000000000000000000000000000000000000000000000000004':
                        buyToken = 'PRV'
                        buyTokenId = '0000000000000000000000000000000000000000000000000000000000000004'
                    else:
                        buyToken = tokens[metadata['TokenIDToBuyStr']]['name']
                        buyTokenId = metadata['TokenIDToBuyStr']
                    sellAmount = metadata['SellAmount']
                    buyAmount = tx['receive_amount']

                    if sellToken not in result:
                        result[sellToken] = {'sell': 0, 'buy': 0}
                    if buyToken not in result:
                        result[buyToken] = {'sell': 0, 'buy': 0}

                    sellExchangeRate = pdeToken.get(sellTokenId).get(
                        'exchange_rate')
                    result[sellToken]['sell'] += Decimal(
                        sellAmount / Decimal(sellExchangeRate))
                    result[sellToken]['tokenId'] = sellTokenId

                    buyExchangeRate = pdeToken.get(buyTokenId).get(
                        'exchange_rate')
                    result[buyToken]['buy'] += Decimal(
                        buyAmount / Decimal(buyExchangeRate))
                    result[buyToken]['tokenId'] = buyTokenId

                for i in result.keys():
                    result[i]['buy'] = float(result[i]['buy'])
                    result[i]['sell'] = float(result[i]['sell'])
            return result
 def getTokens(self):
     service = PdexService()
     data = service.getTokens()
     return data