コード例 #1
0
ファイル: coinbase.py プロジェクト: super3/bifocal
    def _parse_tx(tx):
        # Making all returns lists so we can use flatten.
        stamp = Coinbase._parse_time(tx)
        quantity = int(round(float(tx['Amount']) * 100000000))

        # Coinbase Signup Gift
        if '@' in tx['To']:
            return [models.Transaction(
                        timestamp=stamp,
                        quantity=quantity,
                        asset='BTC',
                        id=tx['Notes'],
                        source='Coinbase',
                        destination='Coinbase',
                        datestring=tx['Timestamp'])]

        # Buy or Sell on Coinbase with USD
        if tx['Transfer Total'] != '':
            price = float(tx['Transfer Total']) / float(tx['Amount'])
            return [models.Transaction(
                        timestamp=stamp,
                        quantity=quantity,
                        asset='BTC',
                        price=price,
                        id=tx['To'],
                        source='Coinbase',
                        destination='Coinbase',
                        datestring=tx['Timestamp'])]

        return txns
コード例 #2
0
ファイル: celery.py プロジェクト: super3/bifocal
    def get_transactions(file_path):
        data = Celery._get_data(file_path)
        txns = []
        for tx in data:
            dollars = Celery._parse_dollars(tx)
            stamp = utils.date_to_timestamp(tx['Date'], '%b %d %Y')
            price = round(dollars / float(tx['Amount']), 2)
            tx['Amount'] = int(round(float(tx['Amount']) * 100000000))

            if tx['Type'] == 'Buy':
                txns.append(
                    models.Transaction(timestamp=stamp,
                                       quantity=tx['Amount'],
                                       price=price,
                                       asset='BTC',
                                       id=tx['TXID'],
                                       source='Celery',
                                       destination='Celery'))

            elif tx['Type'] == 'Sell':
                txns.append(
                    models.Transaction(timestamp=stamp,
                                       quantity=tx['Amount'],
                                       price=price,
                                       asset='BTC',
                                       id=tx['TXID'],
                                       source='Celery',
                                       destination='Celery'))

        return txns
コード例 #3
0
    def _parse_tx(tx, address):
        inputs, outputs = Blockchain._clean_tx(tx)

        transactions = []

        tx_map = utils.distribute(inputs, outputs)

        chart = Coindesk.get_chart()
        stamp = int(tx['time'])
        date = utils.timestamp_to_date(stamp, '%Y-%m-%d')

        if date in chart:
            price = chart[date]
        else:
            price = Coindesk.get_price_by_timestamp(stamp)

        for input_addr in inputs:
            transactions.append(
                models.Transaction(
                    timestamp=stamp,
                    quantity=tx_map[input_addr]['fee'],
                    asset='BTC',
                    price=price,
                    id=tx['hash'],
                    source=input_addr,
                    destination='fee',
                ))

            for output_addr in outputs:
                if address not in [input_addr, output_addr]:
                    continue
                transactions.append(
                    models.Transaction(
                        timestamp=stamp,
                        quantity=tx_map[input_addr][output_addr],
                        asset='BTC',
                        price=price,
                        id=tx['hash'],
                        source=input_addr,
                        destination=output_addr))

        return transactions
コード例 #4
0
    def _parse_tx(self, tx, address):
        inputs, outputs = self._clean_tx(tx)
        tx_map = utils.distribute(inputs, outputs)

        transactions = []

        fee = int(tx['total_fee'])
        stamp = utils.date_to_timestamp(tx['time'].split('+')[0],
                                        '%Y-%m-%dT%H:%M:%S')
        date = utils.timestamp_to_date(stamp, '%Y-%m-%d')

        if date in self._chart:
            price = self._chart[date]
        else:
            price = Coindesk.get_price_by_timestamp(stamp)

        for in_addr in inputs:
            if in_addr == address:
                transactions.append(models.Transaction(
                    timestamp=stamp,
                    quantity=tx_map[in_addr]['fee'],
                    asset='BTC',
                    price=price,
                    id=tx['hash'],
                    source=in_addr,
                    destination='fee',))

            for out_addr in outputs:
                if address not in [in_addr, out_addr]:
                    continue
                transactions.append(models.Transaction(
                    timestamp=stamp,
                    quantity=tx_map[in_addr][out_addr],
                    asset='BTC',
                    price=price,
                    id=tx['hash'],
                    source=in_addr,
                    destination=out_addr))

        return transactions
コード例 #5
0
ファイル: blockscan.py プロジェクト: super3/bifocal
 def _parse_tx(tx):
     stamp = int(tx['block_time'])
     pair = "BTC_%s" % tx['asset']
     btc_rate = Polo.get_daily_close_price(pair, stamp)
     return models.Transaction(
         timestamp=stamp,
         quantity=int(tx['quantity']),
         asset=tx['asset'],
         id=tx['event'],
         price=btc_rate * Coindesk.get_price_by_timestamp(stamp),
         price_in_btc=btc_rate,
         source=Blockscan.get_tx_source(tx['event']),
         destination=Blockscan.get_tx_destination(tx['event'])
     )
コード例 #6
0
ファイル: polo.py プロジェクト: super3/bifocal
    def _parse_tx(self, tx):
        mod = -1 if tx['type'] == 'sell' else 1
        stamp = utils.date_to_timestamp(tx['date'], '%Y-%m-%d  %H:%M:%S')
        price_in_btc = float(tx['rate'])
        price = price_in_btc * self._get_coindesk_price_by_timestamp(stamp)

        return models.Transaction(
            quantity=int(round(float(tx['amount']) * mod * 100000000)),
            asset=None,
            price=price,
            id=tx['globalTradeID'],
            price_in_btc=price_in_btc,
            timestamp=stamp,
            source='polo',
            destination='polo',
            total=float(tx['total']),
            type=tx['type'])
コード例 #7
0
ファイル: polo.py プロジェクト: super3/bifocal
 def _parse_withdrawal(self, withdrawal):
     asset = withdrawal['currency']
     stamp = withdrawal['timestamp']
     btc_in_usd = self._get_coindesk_price_by_timestamp(stamp)
     if asset != 'BTC':
         asset_in_btc = self.get_daily_close_price('BTC_%s' % asset, stamp)
         price = asset_in_btc * btc_in_usd
     else:
         price = btc_in_usd
     return models.Transaction(
         quantity=int(float(withdrawal['amount']) * 100000000),
         asset=withdrawal['currency'],
         price=price,
         id=withdrawal['status'][10:],
         timestamp=stamp,
         source='polo',
         destination=withdrawal['address']
     )
コード例 #8
0
ファイル: polo.py プロジェクト: super3/bifocal
 def _parse_deposit(self, deposit):
     asset = deposit['currency']
     stamp = deposit['timestamp']
     btc_in_usd = self._get_coindesk_price_by_timestamp(stamp)
     if asset != 'BTC':
         asset_in_btc = self.get_daily_close_price('BTC_%s' % asset, stamp)
         price = asset_in_btc * btc_in_usd
     else:
         price = btc_in_usd
     return models.Transaction(
         quantity=int(float(deposit['amount']) * 100000000),
         asset=deposit['currency'],
         price=price,
         id=deposit['txid'],
         timestamp=stamp,
         source=deposit['address'],
         destination='polo'
     )
コード例 #9
0
ファイル: polo.py プロジェクト: super3/bifocal
    def get_trade_history(self, currency_pair):
        history = self._make_private_request(
            command='returnTradeHistory',
            currencyPair=currency_pair,
            start=0,
            end=9999999999)

        history = map(self._parse_tx, history)

        btc_trades = []
        for tx in history:
            price = self._get_coindesk_price_by_timestamp(tx.timestamp)
            tx.asset = currency_pair.split('_')[1]
            sign = -1 if tx.data['type'] == 'buy' else 1
            btc_trades.append(models.Transaction(
                quantity=int(round(tx.data['total'] * sign * 100000000)),
                asset='BTC',
                id=tx.data['id'],
                timestamp=tx.timestamp,
                source='polo',
                destination='polo',
                price=price))

        return history, btc_trades