示例#1
0
def asset_from_bitfinex(
    bitfinex_name: str,
    currency_map: Dict[str, str],
    is_currency_map_updated: bool = True,
) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset

    Currency map coming from `<Bitfinex>._query_currency_map()` is already
    updated with BITFINEX_TO_WORLD (prevent updating it on each call)
    """
    if not isinstance(bitfinex_name, str):
        raise DeserializationError(
            f'Got non-string type {type(bitfinex_name)} for bitfinex asset')

    if bitfinex_name in UNSUPPORTED_BITFINEX_ASSETS:
        raise UnsupportedAsset(bitfinex_name)

    if is_currency_map_updated is False:
        currency_map.update(BITFINEX_TO_WORLD)

    symbol = currency_map.get(bitfinex_name, bitfinex_name)
    return symbol_to_asset_or_token(symbol)
示例#2
0
def asset_from_binance(binance_name: str) -> Asset:
    if binance_name in UNSUPPORTED_BINANCE_ASSETS:
        raise UnsupportedAsset(binance_name)

    if binance_name in RENAMED_BINANCE_ASSETS:
        return Asset(RENAMED_BINANCE_ASSETS[binance_name])

    name = BINANCE_TO_WORLD.get(binance_name, binance_name)
    return Asset(name)
示例#3
0
def asset_from_poloniex(poloniex_name: str) -> Asset:
    if not isinstance(poloniex_name, str):
        raise DeserializationError(f'Got non-string type {type(poloniex_name)} for poloniex asset')

    if poloniex_name in UNSUPPORTED_POLONIEX_ASSETS:
        raise UnsupportedAsset(poloniex_name)

    our_name = POLONIEX_TO_WORLD.get(poloniex_name, poloniex_name)
    return Asset(our_name)
示例#4
0
def asset_from_bittrex(bittrex_name: str) -> Asset:
    if not isinstance(bittrex_name, str):
        raise DeserializationError(f'Got non-string type {type(bittrex_name)} for bittrex asset')

    if bittrex_name in UNSUPPORTED_BITTREX_ASSETS:
        raise UnsupportedAsset(bittrex_name)

    name = BITTREX_TO_WORLD.get(bittrex_name, bittrex_name)
    return Asset(name)
示例#5
0
    def to_coingecko(self) -> str:
        """Returns the symbol with which to query coingecko for the asset

        May raise:
            - UnsupportedAsset() if the asset is not supported by coingecko
        """
        coingecko_str = '' if self.coingecko is None else self.coingecko
        # This asset has no coingecko mapping
        if coingecko_str == '':
            raise UnsupportedAsset(f'{self.identifier} is not supported by coingecko')
        return coingecko_str
示例#6
0
文件: asset.py 项目: rizoraz/rotki
    def to_coingecko(self) -> str:
        """Returns the symbol with which to query coingecko for the asset

        May raise:
            - UnsupportedAsset() if the asset is not supported by coingecko
        """
        coingecko_str = self.identifier if self.coingecko is None else self.coingecko
        # There is an asset which should not be queried in cryptocompare
        if coingecko_str == '':
            raise UnsupportedAsset(f'{self.identifier} is not supported by coingecko')
        return coingecko_str
示例#7
0
def asset_from_eth_token_symbol(token_symbol: str) -> Asset:
    """Takes an eth token symbol from the eth_tokens.json file and turns it
    into an Asset.

    If the token is not supported the functions throws UnsupportedAsset
    """
    if token_symbol in UNSUPPORTED_ETH_TOKENS_JSON:
        raise UnsupportedAsset(token_symbol)

    token_symbol = ETH_TOKENS_JSON_TO_WORLD.get(token_symbol, token_symbol)

    return Asset(token_symbol)
示例#8
0
def asset_from_binance(binance_name: str) -> Asset:
    if not isinstance(binance_name, str):
        raise DeserializationError(f'Got non-string type {type(binance_name)} for binance asset')

    if binance_name in UNSUPPORTED_BINANCE_ASSETS:
        raise UnsupportedAsset(binance_name)

    if binance_name in RENAMED_BINANCE_ASSETS:
        return Asset(RENAMED_BINANCE_ASSETS[binance_name])

    name = BINANCE_TO_WORLD.get(binance_name, binance_name)
    return Asset(name)
示例#9
0
def asset_from_iconomi(symbol: str) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset
    """
    if not isinstance(symbol, str):
        raise DeserializationError(f'Got non-string type {type(symbol)} for iconomi asset')
    symbol = symbol.upper()
    if symbol in UNSUPPORTED_ICONOMI_ASSETS:
        raise UnsupportedAsset(symbol)
    name = ICONOMI_TO_WORLD.get(symbol, symbol)
    return symbol_to_asset_or_token(name)
示例#10
0
文件: asset.py 项目: rizoraz/rotki
    def to_cryptocompare(self) -> str:
        """Returns the symbol with which to query cryptocompare for the asset

        May raise:
            - UnsupportedAsset() if the asset is not supported by cryptocompare
        """
        cryptocompare_str = self.identifier if self.cryptocompare is None else self.cryptocompare
        # There is an asset which should not be queried in cryptocompare
        if cryptocompare_str == '':
            raise UnsupportedAsset(f'{self.identifier} is not supported by cryptocompare')

        # Seems cryptocompare capitalizes everything. So cDAI -> CDAI
        return cryptocompare_str.upper()
示例#11
0
def asset_from_ftx(ftx_name: str) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset
    """
    if not isinstance(ftx_name, str):
        raise DeserializationError(f'Got non-string type {type(ftx_name)} for ftx asset')

    if ftx_name in UNSUPPORTED_FTX_ASSETS:
        raise UnsupportedAsset(ftx_name)

    name = FTX_TO_WORLD.get(ftx_name, ftx_name)
    return symbol_to_asset_or_token(name)
示例#12
0
def asset_from_poloniex(poloniex_name: str) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset
    """
    if not isinstance(poloniex_name, str):
        raise DeserializationError(f'Got non-string type {type(poloniex_name)} for poloniex asset')

    if poloniex_name in UNSUPPORTED_POLONIEX_ASSETS:
        raise UnsupportedAsset(poloniex_name)

    our_name = POLONIEX_TO_WORLD.get(poloniex_name, poloniex_name)
    return symbol_to_asset_or_token(our_name)
示例#13
0
def asset_normalized_value(amount: int, asset: Asset) -> FVal:
    """Takes in an amount and an asset and returns its normalized value

    May raise:
    - UnsupportedAsset if the given asset is not ETH or an ethereum token
    """
    if asset.identifier == 'ETH':
        decimals = 18
    else:
        if not asset.is_eth_token():
            raise UnsupportedAsset(asset.identifier)
        decimals = EthereumToken(asset.identifier).decimals

    return token_normalized_value_decimals(amount, decimals)
示例#14
0
def asset_normalized_value(amount: int, asset: Asset) -> FVal:
    """Takes in an amount and an asset and returns its normalized value

    May raise:
    - UnsupportedAsset if the given asset is not ETH or an ethereum token
    """
    if asset.identifier == 'ETH':
        decimals = 18
    else:
        if asset.asset_type != AssetType.ETH_TOKEN:
            raise UnsupportedAsset(asset.identifier)
        decimals = asset.decimals  # type: ignore

    return token_normalized_value_decimals(amount, decimals)
示例#15
0
def asset_from_kucoin(kucoin_name: str) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset
    """
    if not isinstance(kucoin_name, str):
        raise DeserializationError(f'Got non-string type {type(kucoin_name)} for kucoin asset')

    if kucoin_name in UNSUPPORTED_KUCOIN_ASSETS:
        raise UnsupportedAsset(kucoin_name)

    name = KUCOIN_TO_WORLD.get(kucoin_name, kucoin_name)
    return Asset(name)
示例#16
0
def asset_from_gemini(symbol: str) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset
    """
    if not isinstance(symbol, str):
        raise DeserializationError(
            f'Got non-string type {type(symbol)} for gemini asset')

    if symbol in UNSUPPORTED_GEMINI_ASSETS:
        raise UnsupportedAsset(symbol)

    name = GEMINI_TO_WORLD.get(symbol, symbol)
    return symbol_to_asset_or_token(name)
示例#17
0
    def to_cryptocompare(self) -> str:
        cryptocompare_str = WORLD_TO_CRYPTOCOMPARE.get(self.identifier,
                                                       self.identifier)
        # There is an asset which should not be queried in cryptocompare
        if cryptocompare_str is None:
            if self.identifier == 'MRS':
                raise UnsupportedAsset(
                    'Marginless is not in cryptocompare. Asking for MRS '
                    'will return MARScoin', )
            else:
                raise RuntimeError(
                    f'Got {self.identifier} as a cryptocompare query but it is '
                    f'documented as returning None and is not handled', )

        return cryptocompare_str
示例#18
0
def asset_from_binance(binance_name: str) -> Asset:
    if not isinstance(binance_name, str):
        raise DeserializationError(f'Got non-string type {type(binance_name)} for binance asset')

    if len(binance_name) >= 5 and binance_name.startswith('LD'):
        # this is a lending/savings coin. For now since we don't show lending/savings coins
        # consider it as the normal version. In the future we may perhaps
        # differentiate between them in the balances
        binance_name = binance_name[2:]

    if binance_name in UNSUPPORTED_BINANCE_ASSETS:
        raise UnsupportedAsset(binance_name)

    if binance_name in RENAMED_BINANCE_ASSETS:
        return Asset(RENAMED_BINANCE_ASSETS[binance_name])

    name = BINANCE_TO_WORLD.get(binance_name, binance_name)
    return Asset(name)
示例#19
0
def asset_from_ftx(ftx_name: str) -> Asset:
    """May raise:
    - DeserializationError
    - UnsupportedAsset
    - UnknownAsset
    """
    if not isinstance(ftx_name, str):
        raise DeserializationError(
            f'Got non-string type {type(ftx_name)} for ftx asset')

    if ftx_name in UNSUPPORTED_FTX_ASSETS:
        raise UnsupportedAsset(ftx_name)

    if ftx_name == 'SRM_LOCKED':
        name = strethaddress_to_identifier(
            '0x476c5E26a75bd202a9683ffD34359C0CC15be0fF')  # SRM
    else:
        name = FTX_TO_WORLD.get(ftx_name, ftx_name)
    return symbol_to_asset_or_token(name)
示例#20
0
 def to_cryptocompare(self) -> str:
     raise UnsupportedAsset(
         f'{self.identifier} is not supported by cryptocompare')
示例#21
0
 def to_coingecko(self) -> str:
     raise UnsupportedAsset(
         f'{self.identifier} is not supported by coingecko')
示例#22
0
def asset_from_poloniex(poloniex_name: str) -> Asset:
    if poloniex_name in UNSUPPORTED_POLONIEX_ASSETS:
        raise UnsupportedAsset(poloniex_name)

    our_name = POLONIEX_TO_WORLD.get(poloniex_name, poloniex_name)
    return Asset(our_name)
示例#23
0
def asset_from_bittrex(bittrex_name: str) -> Asset:
    if bittrex_name in UNSUPPORTED_BITTREX_ASSETS:
        raise UnsupportedAsset(bittrex_name)

    name = BITTREX_TO_WORLD.get(bittrex_name, bittrex_name)
    return Asset(name)
示例#24
0
文件: iconomi.py 项目: zalam003/rotki
def iconomi_asset(asset: str) -> Asset:
    symbol = asset.upper()
    if symbol in UNSUPPORTED_ICONOMI_ASSETS:
        raise UnsupportedAsset(symbol)
    return Asset(ICONOMI_TO_WORLD.get(symbol, symbol))