コード例 #1
0
    def get_merchant_btc_pricing_info(self):
        " Return dict of pricing info "

        currency_code = self.currency_code
        currency_symbol = self.get_currency_symbol()
        fiat_btc = BTCTransaction.get_btc_market_price(currency_code)

        buy_markup_percent = self.get_cashin_percent_markup()
        sell_markup_percent = self.get_cashout_percent_markup()

        buy_markup_fee = fiat_btc * buy_markup_percent / 100.00
        sell_markup_fee = fiat_btc * sell_markup_percent / 100.00

        buy_price = fiat_btc + buy_markup_fee
        sell_price = fiat_btc - sell_markup_fee

        return {
            "no_markup_price": format_fiat_amount(fiat_btc, currency_symbol),
            "buy_price": format_fiat_amount(buy_price, currency_symbol),
            "sell_price": format_fiat_amount(sell_price, currency_symbol),
            "sell_price_no_format": round(sell_price, 2),
            "buy_price_no_format": round(buy_price, 2),
            "buy_markup_percent": buy_markup_percent,
            "sell_markup_percent": sell_markup_percent,
            "currency_code": currency_code,
            "currency_symbol": currency_symbol,
            "max_mbtc_purchase_formatted":
            self.get_max_mbtc_purchase_formatted(),
            "max_mbtc_sale_formatted": self.get_max_mbtc_sale_formatted(),
        }
コード例 #2
0
 def get_fiat_amount_formatted(self):
     return format_fiat_amount(
         fiat_amount=self.fiat_amount,
         currency_code=self.currency_code_when_created)
コード例 #3
0
 def get_exchange_rate_formatted(self):
     return format_fiat_amount(
         fiat_amount=self.calculate_exchange_rate(),
         currency_code=self.currency_code_when_created)
コード例 #4
0
 def get_fiat_transactions_total_formatted(self):
     ' Assumes that all deposits to a forwarding address use the same currency '
     return format_fiat_amount(
         fiat_amount=self.get_fiat_transactions_total(),
         currency_code=self.get_first_forwarding_transaction(
         ).currency_code_when_created)
コード例 #5
0
    def get_txn_group_payload(self):
        """
        Get forwarding transactions and summary data for returning to AJAX call

        Handle edge case of multiple transactions coming through
        """

        txn_list = []

        all_confirmed = True
        # loop through forwarding txns
        for fwd_txn in self.get_all_forwarding_transactions():
            is_confirmed = fwd_txn.is_confirmed()
            txn_dict = {
                'satoshis': fwd_txn.satoshis,
                'satoshis_fwu': format_satoshis_with_units(fwd_txn.satoshis),
                'txn_hash': fwd_txn.txn_hash,
                'is_confirmed': is_confirmed,
                'confirmed_by': fwd_txn.txn_confirmed_by(),
                'bc_pref': fwd_txn.blockcypher_preference,
                'conf_num': fwd_txn.conf_num,
                'fiat_amount': fwd_txn.fiat_amount,
                'currency_code': fwd_txn.currency_code_when_created,
                'confs_needed': fwd_txn.get_confs_needed(),
                'fiat_amount_formatted': fwd_txn.get_fiat_amount_formatted(),
                'fiat_amount': fwd_txn.fiat_amount,
                # DISGUSTING HACK:
                'conf_str': unicode(fwd_txn.get_status()),
                'conf_delay_str': unicode(fwd_txn.get_conf_delay_str()),
            }
            txn_list.append(txn_dict)
            if not is_confirmed:
                all_confirmed = False

        total_satoshis = sum([x['satoshis'] for x in txn_list])

        if len(txn_list) == 0:
            conf_str = ''
            conf_delay_str = ''
            confs_needed = self.merchant.minimum_confirmations
            total_fiat_amount_formatted = ''
            confirmed_by = ''
        elif len(txn_list) == 1:
            conf_str = txn_list[0]['conf_str']
            conf_delay_str = txn_list[0]['conf_delay_str']
            confs_needed = txn_list[0]['confs_needed']
            total_fiat_amount_formatted = txn_list[0]['fiat_amount_formatted']
            confirmed_by = txn_list[0]['confirmed_by']
        else:
            confs_needed = self.merchant.minimum_confirmations
            if all_confirmed:
                conf_str = _('Confirmed (Multiple Transactions Detected)')
                confirmed_by = 'CoinSafe'
            else:
                conf_str = _('Not Confirmed (Multiple Transactions Detected)')
                confirmed_by = ''
            conf_delay_str = _(
                '10-20 Minutes (Multiple Transactions Detected)')
            total_fiat_amount = [x['fiat_amount'] for x in txn_list]
            total_fiat_amount_formatted = format_fiat_amount(
                fiat_amount=total_fiat_amount,
                currency_code=txn_list[0]['currency_code'])

        return {
            'txn_list': txn_list,
            'txn_list_cnt': len(txn_list),
            'total_satoshis': total_satoshis,
            'total_sfwu': format_satoshis_with_units(total_satoshis),
            'conf_str': conf_str,
            'conf_delay_str': conf_delay_str,
            'all_confirmed': all_confirmed,
            'confs_needed': confs_needed,
            'total_fiat_amount_formatted': total_fiat_amount_formatted,
            'all_txns_confirmed_by': confirmed_by,
        }