Esempio n. 1
0
def exchange_fees_coin():
    """'Exchange fees by cryptocurrency' page.
    """
    # If 'calc_currency' exists in cookie, use it
    currency = request.cookies.get('calc_currency')
    if currency:
        curr = currency
    else:
        curr = Params.DEFAULT_CURRENCY
    curr = get_coin(curr)
    feedback_form = FeedbackForm()
    # Get exchanges
    coins = get_coins(pos_limit=Params.BROWSE_FEE_COINS, status="Active")
    # Get Meta tags
    title = get_meta_tags('Exchanges|Fees|Coin',
                          'Title')
    description = get_meta_tags('Exchanges|Fees|Coin',
                                'Description')
    # Actions if Feedback Form was filled
    if feedback_form.feedback_submit.data:
        if feedback_form.validate():
            manage_feedback_form(feedback_form, request.path)
    # Load page
    return render_template('exchange_fees_coin.html',
                           curr=curr,
                           title=title,
                           description=description,
                           feedback_form=feedback_form,
                           coins=coins)
Esempio n. 2
0
 def validate_orig_loc(self, orig_loc):
     coin = get_coin_by_longname(self.orig_coin.data)
     if coin:
         valid_coins = get_coins(status='Active', return_ids=True)
         # Only raise error is 'orig_coin' exist
         if coin.id in valid_coins:
             # If valid coin but no exchange, set default exchange
             if not orig_loc.data or orig_loc.data in ['(Default)',
                                                       'Wallet',
                                                       'Bank']:
                 self.orig_loc.data = set_default_exch(coin.id)
                 return
             valid_exchs = get_exch_by_coin(coin.id)
             exch_id = get_exch_by_name(orig_loc.data)
             if exch_id:
                 exch_id = exch_id.id
             else:
                 # Check if extra characters where added
                 for valid_exch in valid_exchs:
                     exch_desc = get_exchange(valid_exch).name
                     if orig_loc.data.find(exch_desc) >= 0:
                         self.orig_loc.data = exch_desc
                         return
                 # raise ValidationError("'{}' is not a valid exchange name"
                 #                       .format(orig_loc.data))
             # Check that exchange is valid
             if exch_id not in valid_exchs:
                 # If not valid, use default exchange
                 self.orig_loc.data = set_default_exch(coin.id)
Esempio n. 3
0
 def validate_orig_coin(self, orig_coin):
     if not orig_coin.data:
         raise ValidationError("Please, fill 'Coin'")
     else:
         coin = get_coin_by_longname(orig_coin.data)
         if coin:
             coin = coin.id
         coins = get_coins(status='Active', return_ids=True)
         if coin not in coins:
             raise ValidationError("Unknown coin")
Esempio n. 4
0
 def validate_dest_coin(self, dest_coin):
     if not dest_coin.data:
         raise ValidationError("Please, fill 'Coin'")
     else:
         coin = get_coin_by_longname(dest_coin.data)
         if coin:
             coin = coin.id
         coins = get_coins(status='Active', return_ids=True)
         if coin not in coins:
             raise ValidationError("Unknown coin")
         elif (dest_coin.data == self.orig_coin.data):
             raise ValidationError("Same origin and destination coin")
Esempio n. 5
0
def exchange_fees_coin():
    """'Exchange fees by cryptocurrency' page.
    """
    # If 'calc_currency' exists in cookie, use it
    currency = request.cookies.get('calc_currency')
    if currency:
        curr = currency
    else:
        curr = Params.DEFAULT_CURRENCY
    feedback_form = FeedbackForm()
    # Get exchanges
    coins = get_coins(Params.BROWSE_FEE_COINS)
    # Get Meta tags
    title = get_meta_tags('Exchanges|Fees|Coin',
                          'Title')
    description = get_meta_tags('Exchanges|Fees|Coin',
                                'Description')
    # Load page
    return render_template('exchange_fees_coin.html',
                           curr=curr,
                           title=title,
                           description=description,
                           feedback_form=feedback_form,
                           coins=coins)
def update_coins_info(logger):
    """Gets the coin info from Coinpaprika.
    """
    # Get coins
    coins = get_coins(type="Crypto")
    print("update_coins_info: Processing '{}' coins. Starting...")
    # Create return dictionary
    coins_dict = {}
    # Loop for each coin
    for index, coin in enumerate(coins):
        print("update_coins_info: Processing coin '{}' --> {}"
              "".format(index + 1, coin))
        # Fetch JSON file from site
        try:
            coin_id = coin.paprika_id
            if not coin_id:
                continue
            with urlopen("https://api.coinpaprika.com/v1/coins/{}"
                         "".format(coin_id)) as response:
                source = response.read()
            coin_data = json.loads(source)
        except Exception as e:
            error_desc = ("update_coins_info: Could not fetch json for"
                          " {} [{}]".format(coin.symbol, coin.paprika_id))
            print(error_desc)
            logger.error(error_desc)
            error_notifier(
                type(e).__name__, traceback.format_exc(), mail, logger)
            return traceback.format_exc()
        # Check if JSON is a list. Throw error otherwise
        if not isinstance(coin_data, dict):
            error_desc = ("update_coins_info: The JSON for coin '{} [{}]'"
                          " is not a list".format(coin.symbol,
                                                  coin.paprika_id))
            print(error_desc)
            logger.error(error_desc)
            error_notifier("update_coins_info", error_desc, mail, logger)
            return error_desc
        # Read JSON file
        try:
            id = coin_data["id"]
        except KeyError as e:
            error_desc = ("update_coins_info: No key found for {}"
                          "".format(coin.symbol))
            print(error_desc)
            logger.warning(error_desc)
            break
        except Exception as e:
            error_desc = ("update_coins_info: Error reading '{}': {}"
                          "".format(coin.id, coin_data))
            print(error_desc)
            logger.error(error_desc)
            error_notifier(
                type(e).__name__, traceback.format_exc(), mail, logger)
            return traceback.format_exc()
        coins_dict[id] = coin_data
        logger.debug("New coin added: {} ({})".format(coin.symbol, index + 1))
        print("New coin added: {} ({})".format(coin.symbol, index + 1))
    # Repleace data in JSON with merged data and save to file:
    file = Params.COIN_INFO_FILE
    with open(file, "w") as f:
        json.dump(coins_dict, f)
    logger.debug("update_coins_info: Tags updated")
    print("update_coins_info: Tags updated")
    return "ok"