Пример #1
0
def test_exchange_feed():

    btc_price = Stream.source([7000, 7500, 8300],
                              dtype="float").rename("USD-BTC")
    eth_price = Stream.source([200, 212, 400], dtype="float").rename("USD-ETH")

    exchange = Exchange("bitfinex", service=execute_order)(btc_price,
                                                           eth_price)

    feed = DataFeed(exchange.streams())

    assert feed.next() == {"bitfinex:/USD-BTC": 7000, "bitfinex:/USD-ETH": 200}
Пример #2
0
def test_exchange_with_wallets_feed():

    ex1 = Exchange("bitfinex", service=execute_order)(
        Stream.source([7000, 7500, 8300], dtype="float").rename("USD-BTC"),
        Stream.source([200, 212, 400], dtype="float").rename("USD-ETH"))

    ex2 = Exchange("binance", service=execute_order)(
        Stream.source([7005, 7600, 8200], dtype="float").rename("USD-BTC"),
        Stream.source([201, 208, 402], dtype="float").rename("USD-ETH"),
        Stream.source([56, 52, 60], dtype="float").rename("USD-LTC"))

    wallet_btc = Wallet(ex1, 10 * BTC)
    wallet_btc_ds = _create_wallet_source(wallet_btc)

    wallet_usd = Wallet(ex2, 1000 * USD)
    wallet_usd.withdraw(quantity=400 * USD, reason="test")
    wallet_usd.deposit(quantity=Quantity(USD, 400, path_id="fake_id"),
                       reason="test")
    wallet_usd_ds = _create_wallet_source(wallet_usd, include_worth=False)

    streams = ex1.streams() + ex2.streams() + wallet_btc_ds + wallet_usd_ds
    feed = DataFeed(streams)

    assert feed.next() == {
        "bitfinex:/USD-BTC": 7000,
        "bitfinex:/USD-ETH": 200,
        "bitfinex:/BTC:/free": 10,
        "bitfinex:/BTC:/locked": 0,
        "bitfinex:/BTC:/total": 10,
        "bitfinex:/BTC:/worth": 70000,
        "binance:/USD-BTC": 7005,
        "binance:/USD-ETH": 201,
        "binance:/USD-LTC": 56,
        "binance:/USD:/free": 600,
        "binance:/USD:/locked": 400,
        "binance:/USD:/total": 1000
    }