示例#1
0
def MercadoBitCoin(coinRequest=None, functionRequest=None):

    try:
        if coinRequest != None:
            reqUrl = RequestAPI.API_Selection(
                "https://www.mercadobitcoin.net/api/" + coinRequest +
                "/ticker/")

            if functionRequest == None:
                return jsonify(reqUrl)

            else:
                if functionRequest == "date":
                    return jsonify(
                        Utils.transformUnix(reqUrl['ticker'][functionRequest]))
                else:
                    return jsonify(reqUrl['ticker'][functionRequest])

        else:
            return jsonify(
                RequestAPI.API_Selection(
                    "https://www.mercadobitcoin.net/api/BTC/ticker/"),
                RequestAPI.API_Selection(
                    "https://www.mercadobitcoin.net/api/LTC/ticker/"),
                RequestAPI.API_Selection(
                    "https://www.mercadobitcoin.net/api/BCH/ticker/"))

    except Exception as e:
        print("Something went wrong: ", e)
        return Utils.showMessage(None, "0x410")
示例#2
0
def CoinDesk(functionRequest=None,
             subFunctionRequest=None,
             subFunctionRequest_2=None,
             coinRequest=None):

    try:
        if coinRequest == None:
            reqUrl = RequestAPI.API_Selection(
                "https://api.coindesk.com/v1/bpi/currentprice.json")

            if functionRequest != None and subFunctionRequest == None and subFunctionRequest_2 == None:
                return jsonify(reqUrl[functionRequest])

            elif functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 == None:
                return jsonify(reqUrl[functionRequest][subFunctionRequest])

            elif functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 != None:
                return jsonify(reqUrl[functionRequest][subFunctionRequest]
                               [subFunctionRequest_2])

            else:
                return jsonify(reqUrl)

        elif coinRequest != None:

            reqUrl = RequestAPI.API_Selection(
                "https://api.coindesk.com/v1/bpi/currentprice/" + coinRequest +
                ".json")

            if functionRequest != None and subFunctionRequest == None and subFunctionRequest_2 == None:
                return jsonify(reqUrl[functionRequest])

            elif functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 == None:
                return jsonify(reqUrl[functionRequest][subFunctionRequest])

            elif functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 != None:
                return jsonify(reqUrl[functionRequest][subFunctionRequest]
                               [subFunctionRequest_2])

            else:  #Return personalize json.
                return jsonify(country=Utils.coinDesk_infoCurrencies(
                    coinRequest, 1),
                               info=reqUrl)
        else:
            return Utils.showMessage("Dont find the requested coin.", "0x420")

    except Exception as e:
        print("Something went wrong: ", e)
        return Utils.showMessage(None, "0x421")
示例#3
0
def coinBase_infoCurrencies(infoRequest, typeReturn=None):

    try:
        reqUrl = RequestAPI.API_Selection(
            "https://api.coinbase.com/v2/currencies")
        upperLetter = infoRequest.upper()
        sizeObject = len(reqUrl['data'])

        if typeReturn == None:  # Search coin and return coin.
            for i in range(sizeObject):
                if upperLetter == reqUrl['data'][i]['id']:
                    return reqUrl['data'][i]['id']

        elif typeReturn == 1:  # Search coin and return country.
            for i in range(sizeObject):
                if upperLetter == reqUrl['data'][i]['id']:
                    return reqUrl['data'][i]['name']

        elif typeReturn == 2:  # Search country and return coin.
            for i in range(sizeObject):
                if upperLetter == reqUrl['data'][i]['name']:
                    return reqUrl['data'][i]['id']

        else:
            return showMessage(None, "0x290")

    except Exception as e:
        print("Something went wrong: ", e)
        return showMessage(None, "0x291")
示例#4
0
def coinDesk_infoCurrencies(infoRequest, typeReturn=None):

    try:
        reqUrl = RequestAPI.API_Selection(
            "https://api.coindesk.com/v1/bpi/supported-currencies.json")
        upperLetter = infoRequest.upper()
        sizeObject = len(reqUrl)

        if typeReturn == None:  # Search coin and return coin.
            for i in range(sizeObject):
                if upperLetter == reqUrl[i]['currency']:
                    return reqUrl[i]['currency']

        elif typeReturn == 1:  # Search coin and return country.
            for i in range(sizeObject):
                if upperLetter == reqUrl[i]['currency']:
                    return reqUrl[i]['country']

        elif typeReturn == 2:  # Search country and return coin.
            for i in range(sizeObject):
                if upperLetter == reqUrl[i]['country']:
                    return reqUrl[i]['currency']

        else:
            return showMessage(None, "0x280")

    except Exception as e:
        print("Something went wrong: ", e)
        return showMessage(None, "0x281")
示例#5
0
def BlinkTrade(functionRequest=None, currencyRequest=None):

    try:
        if functionRequest == None and currencyRequest != None:
            reqUrl = RequestAPI.API_Selection(
                "https://api.blinktrade.com/api/v1/" + currencyRequest +
                "/ticker")

            return jsonify(reqUrl)

        elif functionRequest != None and currencyRequest != None:
            reqUrl = RequestAPI.API_Selection(
                "https://api.blinktrade.com/api/v1/" + currencyRequest +
                "/ticker")

            return jsonify(reqUrl[functionRequest])

        else:
            return jsonify(
                RequestAPI.API_Selection(
                    "https://api.blinktrade.com/api/v1/VEF/ticker"),
                RequestAPI.API_Selection(
                    "https://api.blinktrade.com/api/v1/VND/ticker"),
                RequestAPI.API_Selection(
                    "https://api.blinktrade.com/api/v1/BRL/ticker"),
                RequestAPI.API_Selection(
                    "https://api.blinktrade.com/api/v1/PKR/ticker"),
                RequestAPI.API_Selection(
                    "https://api.blinktrade.com/api/v1/CLP/ticker"))

    except Exception as e:
        print("Something went wrong: ", e)
        return Utils.showMessage(None, "0x400")
示例#6
0
def converterToBTC(coinRequest="USD", value=1):

    try:
        reqUrl = RequestAPI.API_Selection(
            "https://blockchain.info/tobtc?currency=" + coinRequest + "&value=" + str(value))
        return reqUrl

    except Exception as e:
        print("Something went wrong: ", e)
        return showMessage(None, "0x220")
示例#7
0
def nicehash_GetLength(wallet_address, functionRequest, subFunctionRequest, subFunctionRequest_2):

    try:
        reqUrl = RequestAPI.API_Selection(
            "https://api.nicehash.com/api?method=" + functionRequest + "&addr=" + wallet_address)
        return len(reqUrl[subFunctionRequest][subFunctionRequest_2])

    except Exception as e:
        print("Something went wrong: ", e)
        return showMessage(None, "0x240")
示例#8
0
def BlockChain(coinRequest=None,
               functionRequest=None,
               subFunctionRequest=None):

    if coinRequest == None:
        if functionRequest == None:
            return jsonify(stats=RequestAPI.API_Selection(
                "https://api.blockchain.info/stats"),
                           exchange_rate=RequestAPI.API_Selection(
                               "https://blockchain.info/pt/ticker"))
        elif functionRequest != None:
            if functionRequest == "stats":
                if subFunctionRequest == None:
                    return jsonify(
                        RequestAPI.API_Selection(
                            "https://api.blockchain.info/stats"))
                else:
                    return jsonify(
                        RequestAPI.API_Selection(
                            "https://api.blockchain.info/stats")
                        [subFunctionRequest])
            elif functionRequest == "exchange_rate":
                return jsonify(
                    RequestAPI.API_Selection(
                        "https://blockchain.info/pt/ticker"))
            else:
                return Utils.showMessage(None, "0x450")
        else:
            return Utils.showMessage(None, "0x451")

    elif coinRequest != None:
        if functionRequest == None:
            return jsonify(
                RequestAPI.API_Selection("https://blockchain.info/pt/ticker")
                [coinRequest])
        elif functionRequest != None:
            return jsonify(
                RequestAPI.API_Selection("https://blockchain.info/pt/ticker")
                [coinRequest][functionRequest])
        else:
            return Utils.showMessage(None, "0x452")
    else:
        return Utils.showMessage(None, "0x453")
示例#9
0
def BitStamp(typeRequest=None, coinRequest=None, functionRequest=None):

    if typeRequest == None and coinRequest == None and functionRequest == None:
        return Utils.showMessage("Welcome to BitStamp API.", None)

    elif typeRequest != None and coinRequest == None and functionRequest == None:

        if typeRequest == "ticker":
            return jsonify(
                RequestAPI.API_Selection(
                    "https://www.bitstamp.net/api/v2/ticker/btcusd/"))
        elif typeRequest == "ticker_hour":
            return jsonify(
                RequestAPI.API_Selection(
                    "https://www.bitstamp.net/api/v2/ticker_hour/btcusd/"))
        elif typeRequest == "eur_usd":
            return jsonify(
                RequestAPI.API_Selection(
                    "https://www.bitstamp.net/api/eur_usd/"))
        else:
            return Utils.showMessage(None, "0x460")

    elif typeRequest != None and coinRequest != None and functionRequest == None:

        if typeRequest == "ticker":
            return jsonify(
                RequestAPI.API_Selection(
                    "https://www.bitstamp.net/api/v2/ticker/" + coinRequest +
                    "/"))
        elif typeRequest == "ticker_hour":
            return jsonify(
                RequestAPI.API_Selection(
                    "https://www.bitstamp.net/api/v2/ticker_hour/" +
                    coinRequest + "/"))
        else:
            return Utils.showMessage(None, "0x461")

    elif typeRequest != None and coinRequest != None and functionRequest != None:

        if typeRequest == "ticker":
            reqUrl = RequestAPI.API_Selection(
                "https://www.bitstamp.net/api/v2/ticker/" + coinRequest + "/")

            if functionRequest == "timestamp":
                return jsonify(
                    Utils.transformUnix(int(reqUrl[functionRequest])))
            else:
                return jsonify(reqUrl[[functionRequest]])
        elif typeRequest == "ticker_hour":
            reqUrl = RequestAPI.API_Selection(
                "https://www.bitstamp.net/api/v2/ticker_hour/" + coinRequest +
                "/")

            if functionRequest == "timestamp":
                return jsonify(
                    Utils.transformUnix(int(reqUrl[functionRequest])))
            else:
                return jsonify(reqUrl[functionRequest])
        else:
            return Utils.showMessage(None, "0x462")
    else:
        return Utils.showMessage(None, "0x463")
示例#10
0
def CoinBase(coinRequest=None, functionRequest=None, subFunctionRequest=None):

    try:
        if coinRequest == None:
            if functionRequest == None and subFunctionRequest == None:
                return jsonify(
                    buy=RequestAPI.API_Selection(
                        "https://api.coinbase.com/v2/prices/BTC-USD/buy")
                    ['data'],
                    sell=RequestAPI.API_Selection(
                        "https://api.coinbase.com/v2/prices/BTC-USD/sell")
                    ['data'])
            elif functionRequest != None and subFunctionRequest == None:
                return jsonify(
                    RequestAPI.API_Selection(
                        "https://api.coinbase.com/v2/prices/BTC-USD/" +
                        functionRequest)['data'])
            elif functionRequest != None and subFunctionRequest != None:
                return jsonify(
                    RequestAPI.API_Selection(
                        "https://api.coinbase.com/v2/prices/BTC-USD/" +
                        functionRequest)['data'][subFunctionRequest])

            else:
                return Utils.showMessage(None, "0x440")

        elif coinRequest != None:

            verifyCoin = Utils.coinBase_infoCurrencies(coinRequest)

            if verifyCoin != None:
                if functionRequest == None and subFunctionRequest == None:
                    return jsonify(
                        buy=RequestAPI.API_Selection(
                            "https://api.coinbase.com/v2/prices/BTC-" +
                            verifyCoin + "/buy")['data'],
                        sell=RequestAPI.API_Selection(
                            "https://api.coinbase.com/v2/prices/BTC-" +
                            verifyCoin + "/sell")['data'])
                elif functionRequest != None and subFunctionRequest == None:
                    return jsonify(
                        RequestAPI.API_Selection(
                            "https://api.coinbase.com/v2/prices/BTC-" +
                            verifyCoin + "/" + functionRequest)['data'])
                elif functionRequest != None and subFunctionRequest != None:
                    return jsonify(
                        RequestAPI.API_Selection(
                            "https://api.coinbase.com/v2/prices/BTC-" +
                            verifyCoin + "/" +
                            functionRequest)['data'][subFunctionRequest])
                else:
                    return Utils.showMessage(None, "0x441")
            else:
                return Utils.showMessage(None, "0x442")

        else:
            return Utils.showMessage(None, "0x443")

    except Exception as e:
        print("Something went wrong: ", e)
        return Utils.showMessage(None, "0x444")
示例#11
0
def NiceHash(wallet_address=None,
             functionRequest=None,
             subFunctionRequest=None,
             subFunctionRequest_2=None,
             subFunctionRequest_3=None,
             subFunctionRequest_4=None,
             subFunctionRequest_5=None):

    try:

        if wallet_address == None and functionRequest == None and subFunctionRequest == None and subFunctionRequest_2 == None and subFunctionRequest_3 == None and subFunctionRequest_4 == None and subFunctionRequest_5 == None:
            return Utils.showMessage("Welcome to NiceHash API.", None)

        elif wallet_address != None and functionRequest == None and subFunctionRequest == None and subFunctionRequest_2 == None and subFunctionRequest_3 == None and subFunctionRequest_4 == None and subFunctionRequest_5 == None:
            #return Utils.showMessage("Your wallet address: " + "[" + wallet_address + "]," + " is valid.")
            return jsonify(message="Your wallet address: " + "[" +
                           wallet_address + "]," + " is valid.",
                           code=True)

        #The reqUrl here dont make any error in API.
        reqUrl = RequestAPI.API_Selection(
            "https://api.nicehash.com/api?method=" + functionRequest +
            "&addr=" + wallet_address)

        if wallet_address != None and functionRequest != None and subFunctionRequest == None and subFunctionRequest_2 == None and subFunctionRequest_3 == None and subFunctionRequest_4 == None and subFunctionRequest_5 == None:
            return jsonify(reqUrl)

        elif wallet_address != None and functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 == None and subFunctionRequest_3 == None and subFunctionRequest_4 == None and subFunctionRequest_5 == None:
            return jsonify(reqUrl[subFunctionRequest])

        elif wallet_address != None and functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 != None and subFunctionRequest_3 == None and subFunctionRequest_4 == None and subFunctionRequest_5 == None:
            return jsonify(reqUrl[subFunctionRequest][subFunctionRequest_2])

        elif wallet_address != None and functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 != None and subFunctionRequest_3 != None and subFunctionRequest_4 == None and subFunctionRequest_5 == None:

            if subFunctionRequest_3 == "total_accepted_speed" or subFunctionRequest_3 == "total_rejected_speed" or subFunctionRequest_3 == "total_balance" or subFunctionRequest_3 == "last_payment":
                return Utils.nicehash_selectAndDo(subFunctionRequest_3, reqUrl,
                                                  subFunctionRequest,
                                                  subFunctionRequest_2)

            elif subFunctionRequest_2 == "payments":
                if type(subFunctionRequest_3) == int:
                    return jsonify(  #subFunctionRequest_3 here is a number os json list.
                        reqUrl[subFunctionRequest][subFunctionRequest_2]
                        [subFunctionRequest_3])
                else:
                    return Utils.showMessage(None, "0x430")

            elif subFunctionRequest_2 == "stats":
                return jsonify(reqUrl[subFunctionRequest][subFunctionRequest_2]
                               [int(subFunctionRequest_3)])
            else:
                return jsonify(reqUrl[subFunctionRequest][subFunctionRequest_2]
                               [subFunctionRequest_3])

        elif wallet_address != None and functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 != None and subFunctionRequest_3 != None and subFunctionRequest_4 != None and subFunctionRequest_5 == None:
            return Utils.nicehash_selectAndDo(subFunctionRequest_3, reqUrl,
                                              subFunctionRequest,
                                              subFunctionRequest_2,
                                              subFunctionRequest_4)

        elif wallet_address != None and functionRequest != None and subFunctionRequest != None and subFunctionRequest_2 != None and subFunctionRequest_3 != None and subFunctionRequest_4 != None and subFunctionRequest_5 != None:
            # subFunctionRequest_5 could be anything, except nothing.

            if subFunctionRequest_5 == 1:
                return jsonify(  # In this case, subFunctionRequest_3 is a integer witch select a list of stats.
                    reqUrl[subFunctionRequest][subFunctionRequest_2][int(
                        subFunctionRequest_3)][subFunctionRequest_4])
            elif subFunctionRequest_5 == 2:
                return jsonify(
                    reqUrl[subFunctionRequest][subFunctionRequest_2][int(
                        subFunctionRequest_3)][subFunctionRequest_4])
            else:
                return Utils.showMessage(None, "0x431")

        else:
            return Utils.showMessage(None, "0x432")

    except Exception as e:
        print("Something went wrong: ", e)
        return Utils.showMessage(None, "0x433")
示例#12
0
def getHighestValue(typeValue=None):

    try:
        reqUrl = [
            RequestAPI.API_Selection(
                "https://api.blinktrade.com/api/v1/BRL/ticker"),
            RequestAPI.API_Selection(
                "https://api.coindesk.com/v1/bpi/currentprice/BRL.json"),
            RequestAPI.API_Selection(
                "https://www.mercadobitcoin.net/api/BTC/ticker/"),
            RequestAPI.API_Selection(
                "https://api.coinbase.com/v2/prices/spot?currency=BRL")
        ]

        prices_default = {
            'blinktrade': float(reqUrl[0]['last']),
            'coindesk': float(reqUrl[1]['bpi']['BRL']['rate_float']),
            'mercadobitcoin': float(reqUrl[2]['ticker']['last']),
            'coinbase': float(reqUrl[3]['data']['amount'])
        }

        prices_high = {
            'blinktrade': float(reqUrl[0]['high']),
            'coindesk': float(reqUrl[1]['bpi']['BRL']['rate_float']),
            'mercadobitcoin': float(reqUrl[2]['ticker']['high']),
            'coinbase': float(reqUrl[3]['data']['amount'])
        }

        if typeValue == None:

            getMax_Default = max(prices_default.items(), key=lambda x: x[1])

            return jsonify(
                highest_last=getMax_Default[1],
                local=getMax_Default[0],
                currency="BRL"
            )

        elif typeValue != None:
            if typeValue == "all":

                getMaxLast = max(prices_default.items(), key=lambda x: x[1])
                getMinLast = min(prices_default.items(), key=lambda x: x[1])

                getMaxHigh = max(prices_high.items(), key=lambda x: x[1])
                getMinHigh = min(prices_high.items(), key=lambda x: x[1])

                return jsonify(
                    typeValue=typeValue,

                    last=[{
                        "highest": [{
                            "value": getMaxLast[1],
                            "local": getMaxLast[0]
                        }],

                        "lowest": [{
                            "value": getMinLast[1],
                            "local": getMinLast[0]
                        }]
                    }],

                    high=[{
                        "highest": [{
                            "value": getMaxHigh[1],
                            "local": getMaxHigh[0]
                        }],

                        "lowest": [{
                            "value": getMinHigh[1],
                            "local": getMinHigh[0]
                        }]
                    }]

                )

            else:
                prices_custom = {
                    'blinktrade': float(reqUrl[0][typeValue]),
                    'coindesk': float(reqUrl[1]['bpi']['BRL']['rate_float']),
                    'mercadobitcoin': float(reqUrl[2]['ticker'][typeValue])
                }

                getMax_Custom = max(prices_custom.items(), key=lambda x: x[1])

                return jsonify(
                    typeValue=typeValue,
                    value=getMax_Custom[1],
                    local=getMax_Custom[0],
                    currency="BRL"
                )

        else:
            return showMessage(None, "0x270")

    except Exception as e:
        print("Something went wrong: ", e)
        return showMessage(None, "0x271")