Exemple #1
0
def test_initializing_exchanges(uninitialized_rotkehlchen):
    """Test that initializing exchanges for which credentials exist in the DB works

    This also tests db.get_exchange_credentials() since we also pretend to have
    a premium subscription credentials and that function should not return it.
    """
    rotki = uninitialized_rotkehlchen
    username = '******'
    db_password = '******'
    rotki.data.unlock(username, db_password, create_new=True)
    database = rotki.data.db
    # Mock having user_credentials for all exchanges and for premium
    cmd = 'INSERT OR REPLACE INTO user_credentials(name, api_key, api_secret) VALUES (?, ?, ?)'

    credentials = []
    for name in SUPPORTED_EXCHANGES:
        credentials.append((name, make_api_key(), make_api_secret()))
    credentials.append(('rotkehlchen', make_api_key(), make_api_secret()))
    cursor = rotki.data.db.conn.cursor()
    for entry in credentials:
        cursor.execute(cmd, entry)
        rotki.data.db.conn.commit()

    exchange_credentials = rotki.data.db.get_exchange_credentials()
    rotki.exchange_manager.initialize_exchanges(
        exchange_credentials=exchange_credentials,
        database=database,
    )

    assert all(name in rotki.exchange_manager.connected_exchanges
               for name in SUPPORTED_EXCHANGES)
Exemple #2
0
def test_exchanges_filtering(database, exchange_manager,
                             function_scope_messages_aggregator):
    kraken1 = MockKraken(
        name='mockkraken_1',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
    )
    kraken2 = MockKraken(
        name='mockkraken_2',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
    )
    ftx1 = Ftx(
        name='mockftx_1',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
        ftx_subaccount=None,
    )
    ftx2 = Ftx(
        name='mockftx_2',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
        ftx_subaccount=None,
    )

    exchange_manager.initialize_exchanges({}, database)
    exchange_manager.connected_exchanges[Location.KRAKEN].append(kraken1)
    exchange_manager.connected_exchanges[Location.KRAKEN].append(kraken2)
    exchange_manager.connected_exchanges[Location.FTX].append(ftx1)
    exchange_manager.connected_exchanges[Location.FTX].append(ftx2)
    assert set(exchange_manager.iterate_exchanges()) == {
        kraken1, kraken2, ftx1, ftx2
    }

    database.set_settings(
        ModifiableDBSettings(non_syncing_exchanges=[
            kraken1.location_id(),
            kraken2.location_id()
        ], ))
    assert set(exchange_manager.iterate_exchanges()) == {ftx1, ftx2}

    database.set_settings(
        ModifiableDBSettings(non_syncing_exchanges=[ftx1.location_id()], ))
    assert set(
        exchange_manager.iterate_exchanges()) == {ftx2, kraken1, kraken2}
Exemple #3
0
def test_iconomi_assets_are_known(
        database,
        inquirer,  # pylint: disable=unused-argument
):
    unsupported_assets = set(UNSUPPORTED_ICONOMI_ASSETS)
    common_items = unsupported_assets.intersection(
        set(WORLD_TO_ICONOMI.values()))
    assert not common_items, f'Iconomi assets {common_items} should not be unsupported'
    # use a real Iconomi instance so that we always get the latest data
    iconomi = Iconomi(
        name='iconomi1',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=MessagesAggregator(),
    )

    supported_tickers = iconomi.query_supported_tickers()
    for ticker in supported_tickers:
        try:
            _ = asset_from_iconomi(ticker)
        except UnknownAsset as e:
            test_warnings.warn(
                UserWarning(
                    f'Found unknown asset {e.asset_name} in ICONOMI. '
                    f'Support for it has to be added', ))
Exemple #4
0
def create_test_binance(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
    location: Location = Location.BINANCE,
    name: str = 'binance',
) -> Binance:
    if location == Location.BINANCE:
        uri = BINANCE_BASE_URL
    elif location == Location.BINANCEUS:
        uri = BINANCEUS_BASE_URL
    else:
        raise AssertionError(
            f'Tried to create binance exchange with location {location}')
    binance = Binance(
        name=name,
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
        uri=uri,
    )
    this_dir = os.path.dirname(os.path.abspath(__file__))
    json_path = Path(this_dir) / 'data' / 'binance_exchange_info.json'
    with json_path.open('r') as f:
        json_data = json.loads(f.read())

    binance._symbols_to_pair = create_binance_symbols_to_pair(
        json_data, location)
    binance.first_connection_made = True
    return binance
Exemple #5
0
def test_binance_assets_are_known(
        database,
        inquirer,  # pylint: disable=unused-argument
):
    # use a real binance instance so that we always get the latest data
    binance = Binance(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=MessagesAggregator(),
    )

    mapping = binance.symbols_to_pair
    binance_assets = set()
    for _, pair in mapping.items():
        binance_assets.add(pair.binance_base_asset)
        binance_assets.add(pair.binance_quote_asset)

    sorted_assets = sorted(binance_assets)
    for binance_asset in sorted_assets:
        try:
            _ = asset_from_binance(binance_asset)
        except UnsupportedAsset:
            assert binance_asset in UNSUPPORTED_BINANCE_ASSETS
        except UnknownAsset as e:
            test_warnings.warn(
                UserWarning(
                    f'Found unknown asset {e.asset_name} in Binance. Support for it has to be added',
                ))
Exemple #6
0
def coinbasepro(session_database, session_inquirer, messages_aggregator):
    mock = MockCoinbasepro(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=session_database,
        msg_aggregator=messages_aggregator,
    )
    return mock
Exemple #7
0
def kraken(session_inquirer, messages_aggregator, session_database):
    mock = MockKraken(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=session_database,
        msg_aggregator=messages_aggregator,
    )
    return mock
Exemple #8
0
def poloniex(session_database, session_inquirer, messages_aggregator):
    mock = MockPoloniex(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=session_database,
        msg_aggregator=messages_aggregator,
    )
    return mock
Exemple #9
0
def function_scope_bittrex(database, function_scope_messages_aggregator):
    mock = MockBittrex(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
    )
    return mock
Exemple #10
0
def coinbase(session_data_dir, session_inquirer, messages_aggregator):
    mock = MockCoinbase(
        api_key=make_api_key(),
        secret=make_api_secret(),
        user_directory=session_data_dir,
        msg_aggregator=messages_aggregator,
    )
    return mock
Exemple #11
0
def function_scope_kraken(inquirer, function_scope_messages_aggregator,
                          database):
    mock = MockKraken(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
    )
    return mock
Exemple #12
0
def function_scope_poloniex(database, inquirer,
                            function_scope_messages_aggregator):
    mock = MockPoloniex(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
    )
    return mock
Exemple #13
0
def function_scope_kraken(accounting_data_dir, inquirer,
                          function_scope_messages_aggregator):
    mock = MockKraken(
        api_key=make_api_key(),
        secret=make_api_secret(),
        user_directory=accounting_data_dir,
        msg_aggregator=function_scope_messages_aggregator,
    )
    return mock
Exemple #14
0
def create_test_poloniex(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Poloniex:
    return Poloniex(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #15
0
def create_test_bitstamp(
        database,
        msg_aggregator,
) -> Bitstamp:
    return Bitstamp(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #16
0
def create_test_iconomi(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Iconomi:
    return Iconomi(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #17
0
def create_test_bitcoinde(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Bitcoinde:
    return Bitcoinde(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #18
0
def test_initializing_exchanges(uninitialized_rotkehlchen):
    """Test that initializing exchanges for which credentials exist in the DB works

    This also tests db.get_exchange_credentials() since we also pretend to have
    a premium subscription credentials and that function should not return it.
    """
    rotki = uninitialized_rotkehlchen
    username = '******'
    db_password = '******'
    rotki.data.unlock(username, db_password, create_new=True)
    database = rotki.data.db
    # Mock having user_credentials for all exchanges and for premium
    cmd = (
        'INSERT OR REPLACE INTO user_credentials '
        '(name, location, api_key, api_secret, passphrase) VALUES (?, ?, ?, ?, ?)'
    )

    credentials = []
    for location in SUPPORTED_EXCHANGES:
        passphrase = None
        if location in EXCHANGES_WITH_PASSPHRASE:
            passphrase = 'supersecretpassphrase'
        credentials.append(
            (str(location), location.serialize_for_db(), make_api_key(),
             make_api_secret().decode(), passphrase),  # noqa: E501  # pylint: disable=no-member
        )
    credentials.append(
        ('rotkehlchen', Location.EXTERNAL.serialize_for_db(), make_api_key(),
         make_api_secret().decode(), None),  # noqa: E501  # pylint: disable=no-member
    )
    cursor = rotki.data.db.conn.cursor()
    for entry in credentials:
        cursor.execute(cmd, entry)
        rotki.data.db.conn.commit()

    exchange_credentials = rotki.data.db.get_exchange_credentials()
    rotki.exchange_manager.initialize_exchanges(
        exchange_credentials=exchange_credentials,
        database=database,
    )

    assert all(location in rotki.exchange_manager.connected_exchanges
               for location in SUPPORTED_EXCHANGES)  # noqa: E501
Exemple #19
0
def create_test_kraken(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> MockKraken:
    return MockKraken(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #20
0
def create_test_bittrex(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Bittrex:
    bittrex = Bittrex(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
    return bittrex
Exemple #21
0
def create_test_coinbase(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Coinbase:
    mock = Coinbase(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
    return mock
Exemple #22
0
def create_test_independentreserve(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Independentreserve:
    return Independentreserve(
        name='independentreserve',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #23
0
def create_test_ftx(
        database: DBHandler,
        msg_aggregator: MessagesAggregator,
) -> Ftx:
    mock = Ftx(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
    return mock
Exemple #24
0
def function_scope_coinbase(
    database,
    inquirer,  # pylint: disable=unused-argument,
    function_scope_messages_aggregator,
):
    mock = MockCoinbase(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=function_scope_messages_aggregator,
    )
    return mock
Exemple #25
0
def function_scope_coinbase(
        accounting_data_dir,
        inquirer,  # pylint: disable=unused-argument,
        function_scope_messages_aggregator,
):
    mock = MockCoinbase(
        api_key=make_api_key(),
        secret=make_api_secret(),
        user_directory=accounting_data_dir,
        msg_aggregator=function_scope_messages_aggregator,
    )
    return mock
Exemple #26
0
def create_test_coinbasepro(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
    passphrase: str,
) -> Coinbasepro:
    coinbasepro = Coinbasepro(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
        passphrase=passphrase,
    )
    return coinbasepro
Exemple #27
0
def create_test_ftx(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Ftx:
    mock = Ftx(
        name='ftx',
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
        ftx_subaccount=None,
    )
    return mock
Exemple #28
0
def create_test_bitstamp(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
    api_key: Optional[ApiKey] = None,
    secret: Optional[ApiSecret] = None,
) -> Bitstamp:
    if api_key is None:
        api_key = make_api_key()
    if secret is None:
        secret = make_api_secret()

    return Bitstamp(
        api_key=api_key,
        secret=secret,
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #29
0
def create_test_bitstamp(
    database,
    msg_aggregator,
    api_key=None,
    secret=None,
) -> Bitstamp:
    if api_key is None:
        api_key = make_api_key()
    if secret is None:
        secret = make_api_secret()

    return Bitstamp(
        api_key=api_key,
        secret=secret,
        database=database,
        msg_aggregator=msg_aggregator,
    )
Exemple #30
0
def create_test_binance(
    database: DBHandler,
    msg_aggregator: MessagesAggregator,
) -> Binance:
    binance = Binance(
        api_key=make_api_key(),
        secret=make_api_secret(),
        database=database,
        msg_aggregator=msg_aggregator,
    )
    this_dir = os.path.dirname(os.path.abspath(__file__))
    json_path = Path(this_dir) / 'data' / 'binance_exchange_info.json'
    with json_path.open('r') as f:
        json_data = json.loads(f.read())

    binance._symbols_to_pair = create_binance_symbols_to_pair(json_data)
    binance.first_connection_made = True
    return binance