Example #1
0
def test_exchange_with_wallets_feed():

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

    ex2 = Exchange("binance",
                   service=execute_order)(Stream([7005, 7600,
                                                  8200]).rename("USD-BTC"),
                                          Stream([201, 208,
                                                  402]).rename("USD-ETH"),
                                          Stream([56, 52,
                                                  60]).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)

    feed = DataFeed([ex1, ex2, wallet_btc_ds, wallet_usd_ds])

    assert feed.next() == {
        "coinbase:/USD-BTC": 7000,
        "coinbase:/USD-ETH": 200,
        "coinbase:/BTC:/free": 10,
        "coinbase:/BTC:/locked": 0,
        "coinbase:/BTC:/total": 10,
        "coinbase:/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
    }
Example #2
0
def test_invalid_isub():

    # Add to balance with locked path_id
    wallet = Wallet(exchange, 10000 * USD)
    wallet.deposit(quantity=Quantity(USD, 500, path_id=path_id), reason="test")
    wallet.deposit(quantity=Quantity(USD, 700, path_id=other_id),
                   reason="test")

    with pytest.raises(InsufficientFunds):
        wallet.withdraw(quantity=11000 * USD, reason="test")

    with pytest.raises(InsufficientFunds):
        wallet.withdraw(quantity=Quantity(USD, 750, path_id), reason="test")

    with pytest.raises(InsufficientFunds):
        wallet.withdraw(quantity=Quantity(USD, 750, path_id), reason="test")

    with pytest.raises(IncompatibleInstrumentOperation):
        wallet.withdraw(quantity=500 * BTC, reason="test")
Example #3
0
def test_valid_isub():

    # Add to remove from unlocked balance
    wallet = Wallet(exchange, 10000 * USD)
    wallet.withdraw(quantity=500 * USD, reason="test")
    assert wallet.balance == 9500 * USD
    assert len(wallet.locked) == 0

    # Add to balance with locked path_id
    wallet = Wallet(exchange, 10000 * USD)
    wallet.deposit(quantity=Quantity(USD, 750, path_id=path_id), reason="test")
    wallet.deposit(quantity=Quantity(USD, 1000, path_id=other_id),
                   reason="test")

    wallet.withdraw(quantity=Quantity(USD, 500, path_id=path_id),
                    reason="test")
    assert wallet.balance == 10000 * USD
    assert wallet.locked[path_id] == 250 * USD

    wallet.withdraw(quantity=Quantity(USD, 500, path_id=other_id),
                    reason="test")
    assert wallet.balance == 10000 * USD
    assert wallet.locked[other_id] == 500 * USD