Ejemplo n.º 1
0
    def convert(cls, row, header):
        """
        Converts the given `row` into a `Transaction`

        Args:
            row (list):     The row as a list of values
            header (list):  Description of each row entry

        Notes:
            The list lengths of row and header have to equal.

        Returns:
            CryptoTransaction:  The row converted into a CryptoTransaction

        """
        assert len(row) == len(
            header), 'Each column must have an entry in the header!'
        assert isinstance(row, list), 'The row should be a list'
        assert isinstance(header, list), 'The header should be list'

        row_ = TradeHistoryParser.Row(row=row, header=header)

        return Deposit(
            timestamp=datetime.datetime.utcfromtimestamp(
                row_[cls._COLUMN_APPLY_TIME] / 1E3),
            address=row_[cls._COLUMN_ADDRESS],
            txid=row_[cls._COLUMN_TXID],
            coin=row_[cls._COLUMN_COIN],
            amount=row_[cls._COLUMN_AMOUNT_TRANSFER],
            fee=Fee(amount=0, currency=""),
            status=row_[cls._COLUMN_STATUS],
            exchange="Binance",
        )
Ejemplo n.º 2
0
    def convert(cls, row, header):
        """
        Converts the given `row` into a `Transaction`

        Args:
            row (list):     The row as a list of values
            header (list):  Description of each row entry

        Notes:
            The list lengths of row and header have to equal.

        Returns:
            CryptoTransaction:  The row converted into a CryptoTransaction

        """
        assert len(row) == len(header), 'Each column must have an entry in the header!'
        assert isinstance(row, list), 'The row should be a list'
        assert isinstance(header, list), 'The header should be list'

        row_ = TradeHistoryParser.Row(row=row, header=header)

        base, quota = row_[cls._COLUMN_BASE_ASSET], row_[cls._COLUMN_QUOTE_ASSET]

        return CryptoTransaction(
            datetime=datetime.datetime.utcfromtimestamp(row_[BinanceCrawlerParser._COLUMN_TIME] / 1000),
            trading_pair=(Position(amount=row_[BinanceCrawlerParser._COLUMN_TOTAL_QUOTA], currency=quota),
                          Position(amount=row_[BinanceCrawlerParser._COLUMN_QUANTITY], currency=base)),
            trading_type=row_[BinanceCrawlerParser._COLUMN_SIDE],
            price=row_[BinanceCrawlerParser._COLUMN_PRICE],
            fee=Fee(row_[BinanceCrawlerParser._COLUMN_FEE], row_[BinanceCrawlerParser._COLUMN_FEE_COIN]),
            exchange="Binance"
        )
Ejemplo n.º 3
0
    def parse(self, csv_file):

        csv_content = self._read_file(csv_file)

        # the first line is a disclaimer and the second line is the title with the account email address
        del csv_content[0:2]

        # the third line is the header
        header = csv_content[0]
        del csv_content[0]

        # check if each entry in the header is in our list
        for c in header:
            if c not in self._COLUMNS:
                # otherwise, rise an exception that the parser is out of date
                raise ParserOutdatedError(
                    'The column {} is unknown. The parser has to be updated!'.
                    format(c))

        transactions = []

        # parse all other rows
        for row in csv_content:
            row_ = TradeHistoryParser.Row(row=row, header=header)

            if row_[self._COLUMN_TYPE] in ['buy', 'sell']:
                # only process buy and sells

                transactions.append(
                    CryptoTransaction(
                        datetime=row_[self._COLUMN_DATE],
                        trading_pair=(
                            Position(amount=row_[self._COLUMN_FIAT_AMOUNT],
                                     currency=row_[self._COLUMN_FIAT]),
                            Position(amount=row_[self._COLUMN_CRYPTO_AMOUNT],
                                     currency=row_[self._COLUMN_CRYPTO])),
                        trading_type=row_[self._COLUMN_TYPE],

                        # calculate the price based on the amount of fiat used to buy a certain amount of cryptocoins
                        price=row_[self._COLUMN_FIAT_AMOUNT] /
                        row_[self._COLUMN_CRYPTO_AMOUNT],

                        # we actually cannot calculate the fee using the data provided by bitpanda
                        fee=Fee(0, row_[self._COLUMN_FIAT]),
                        exchange="Bitpanda"))

        return transactions
Ejemplo n.º 4
0
    def parse(self, csv_file):

        csv_content = self._read_file(csv_file)

        # the first line is the header of the csv columns
        header = csv_content[0]
        del csv_content[0]

        # check if each entry in the header is in our list
        for c in header:
            if c not in self._COLUMNS:
                # otherwise, rise an exception that the parser is out of date
                raise ParserOutdatedError(
                    'The column {} is unknown. The parser has to be updated!'.
                    format(c))

        transactions = []

        # parse all other rows
        for row in csv_content:
            row_ = TradeHistoryParser.Row(row=row, header=header)

            base, quota = _market_to_trading_pair(row_[self._COLUMN_MARKET])

            # old binance files had different way to store datetimes which will not be converted
            # by the xlsx module by default. Thus, we have to check this manually.
            if not isinstance(row_.get(self._COLUMN_DATE), datetime.datetime):
                row_[self._COLUMN_DATE] = datetime.datetime.strptime(
                    row_[self._COLUMN_DATE], "%d.%m.%y %H:%M")

            # convert the row to a transaction
            transactions.append(
                CryptoTransaction(
                    datetime=row_[self._COLUMN_DATE],
                    trading_pair=(Position(amount=row_[self._COLUMN_TOTAL],
                                           currency=quota),
                                  Position(
                                      amount=row_[self._COLUMN_COIN_AMOUNT],
                                      currency=base)),
                    trading_type=row_[self._COLUMN_TYPE],
                    price=row_[self._COLUMN_PRICE],
                    fee=Fee(row_[self._COLUMN_FEE],
                            row_[self._COLUMN_FEE_COIN]),
                    exchange="Binance"))

        return transactions
Ejemplo n.º 5
0
    def parse(self, file):

        content = self._read_file(file)

        # the first line is the header of the csv columns
        header = content[0]
        del content[0]

        # check if each entry in the header is in our list
        for c in header:
            if c not in self._COLUMNS:
                # otherwise, rise an exception that the parser is out of date
                raise ParserOutdatedError(
                    'The column {} is unknown. The parser has to be updated!'.
                    format(c))

        deposits = []

        # parse all other rows
        for row in content:
            row_ = TradeHistoryParser.Row(row=row, header=header)

            d = Deposit(
                timestamp=row_[self._COLUMN_DATE],
                address=row_[self._COLUMN_ADDRESS],
                txid=row_[self._COLUMN_TXID],
                coin=row_[self._COLUMN_COIN],
                amount=row_[self._COLUMN_AMOUNT],
                fee=Fee(amount=row_[self._COLUMN_TRANSACTIONFEE], currency=""),
                status=row_[self._COLUMN_STATUS],
                exchange="Binance",
            )

            deposits.append(d)

        return deposits