Example #1
0
def test_bitfinex_has_pairs_on_start(event_loop):
    # start app with full functionality.
    # And with real bitfinex exchange.
    # After app.exchanges.schedule() finishing
    # exchanges.pairs should contain all bitfinex's from config.

    # 1. construct bitfinex's real config for app
    bitfinex_config_str = """
bitfinex:
  fee: 0.01
  limit: 0
  interval: 1.0
  fetch_balances_interval: 0.5
  transport:
    websocket_base_url: 'wss://api.bitfinex.com/ws/2'
    http_base_url: https://api.bitfinex.com/v1
    key: dummy-key
    secret: dummy-key
"""
    bitfinex_config = yaml.load(bitfinex_config_str)

    # 2. start app with this real config
    app = get_app(event_loop, config={'exchanges': bitfinex_config})
    event_loop.run_until_complete(app.exchanges.schedule())  # type: ignore
    pair_offer_map = app.exchanges.get_pair_offer_map()  # type: ignore
    event_loop.run_until_complete(app.exchanges.stop())  # type: ignore
    event_loop.run_until_complete(app.stop())

    # 3. exchanges.pair_offers_map should contain all pairs from config.
    for pair in ['BTCUSD', 'LTCUSD']:
        assert pair in pair_offer_map
        assert (o.pair == pair and o.exchange.name == 'bitfinex'
                for o in pair_offer_map['BTCUSD'])
Example #2
0
def test_get_pair_offer_map(event_loop, input, expected):
    app = get_app(event_loop)

    async def run():
        async with app.context():
            pair_offers_map = app.exchanges.get_pair_offer_map(  # type: ignore
                pair_names=input)
            assert set(pair_offers_map) == set(expected)

    event_loop.run_until_complete(run())
Example #3
0
def test_default_config(event_loop):
    """Exchange should correctly inherit default config."""
    custom_fee = 1.0
    app = get_app(
        event_loop,
        config={'exchanges': {
            'left': {
                'fee': custom_fee,
                'transport': {}
            }
        }})

    async def run():
        async with app.context():
            exchange = app.exchanges.get('left')  # type: ignore
            assert exchange.fee == custom_fee

    event_loop.run_until_complete(run())
Example #4
0
def test_currency_limits(event_loop, pair_limits, pairs, expected):
    """`currency_limits` should be generated from `pair_limits` in correct way."""
    app = get_app(event_loop,
                  config={
                      'exchanges': {
                          'left': {
                              'pair_limits': pair_limits,
                              'transport': {}
                          }
                      }
                  })

    async def run():
        async with app.context():
            exchange = app.exchanges.get('left')  # type: ignore
            exchange.pairs = defaultdict(lambda: defaultdict(float), pairs)
            assert exchange.get_currency_limits() == expected

    event_loop.run_until_complete(run())
Example #5
0
def test_default_limit(event_loop):
    """Exchange inherit default limit of pair."""
    exchange = get_app(event_loop).exchanges.get('left')  # type: ignore
    assert exchange.get_pair_limit('does not exist') == 1.0