def test_new_sell_orders_maker_amount_success_case(tmpdir):
    bands_file = BandConfig.sample_config_dif_margins(tmpdir)
    bands_config = ReloadableConfig(str(bands_file))
    airswap_bands = AirswapBands.read(bands_config, EmptyFeed(), FixedFeed({'canBuy': True, 'canSell': True}), History())

    # maker_amount -> denominated in WETH
    maker_amount = Wad(106200000000000000000)
    taker_amount = Wad(0)
    our_sell_balance = Wad(1562000000000000000000)
    sell_limit = Wad(1562000000000000000000)
    target_price = WebSocketPriceFeed(FakeFeed({"buyPrice": "120", "sellPrice": "130"})).get_price()

    new_order = airswap_bands._new_side_orders('sell',
                                               maker_amount,
                                               taker_amount,
                                               our_sell_balance,
                                               sell_limit,
                                               airswap_bands.sell_bands[0],
                                               target_price.sell_price)

    # -- pricing logic --
    # sellPrice = 130 * maxMargin = 0.08 = 10.4
    # 130 + 10.4 = 140.4
    # taker_amount = 106.2000 / 140.4 = 0.7564102564102564102564

    assert new_order['maker_amount'].__float__() == 106.2000
    assert new_order['taker_amount'].__float__() == 14910.48
def test_new_buy_orders_maker_amount_exceed_buy_balance_fail_case(tmpdir):
    bands_file = BandConfig.sample_config(tmpdir)
    bands_config = ReloadableConfig(str(bands_file))
    airswap_bands = AirswapBands.read(bands_config, EmptyFeed(), FixedFeed({'canBuy': True, 'canSell': True}), History())


    # maker_amount -> denominated in DAI
    maker_amount = Wad(156200000000000000)
    taker_amount = Wad(0)
    our_buy_balance = Wad(50000000000000000)
    buy_limit = Wad(1562000000000000000000)
    target_price = WebSocketPriceFeed(FakeFeed({"buyPrice": "120", "sellPrice": "130"})).get_price()

    new_order = airswap_bands._new_side_orders('buy',
                                               maker_amount,
                                               taker_amount,
                                               our_buy_balance,
                                               buy_limit,
                                               airswap_bands.buy_bands[0],
                                               target_price.buy_price)

    # -- pricing logic --
    # buyPrice = 120 * minMargin = 0.02 = 117.6
    # maker_amount = .1562000 * 117.6 = 18.36912000
    # our_buy_balance = 0.050000000000000000 !!BREAK!!

    assert new_order == {}
Exemple #3
0
    def test_should_handle_no_price(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({}))

        # then
        assert (price_feed.get_price().buy_price is None)
        assert (price_feed.get_price().sell_price is None)
Exemple #4
0
    def test_should_use_individual_buy_and_sell_prices_if_both_available(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"buyPrice": "120.75", "sellPrice": "130.75"}))

        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(120.75))
        assert(price_feed.get_price().sell_price == Wad.from_number(130.75))
Exemple #5
0
    def test_should_use_same_buy_and_sell_price_if_only_one_price_available(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"price": "125.75"}))

        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(125.75))
        assert(price_feed.get_price().sell_price == Wad.from_number(125.75))
Exemple #6
0
    def test_should_default_to_price_if_no_buy_price_or_no_sell_price(self):
        # when
        price_feed = WebSocketPriceFeed(
            FakeFeed({
                "price": "125.0",
                "buyPrice": "120.75"
            }))
        # then
        assert (price_feed.get_price().buy_price == Wad.from_number(120.75))
        assert (price_feed.get_price().sell_price == Wad.from_number(125.0))

        # when
        price_feed = WebSocketPriceFeed(
            FakeFeed({
                "price": "125.0",
                "sellPrice": "130.75"
            }))
        # then
        assert (price_feed.get_price().buy_price == Wad.from_number(125.0))
        assert (price_feed.get_price().sell_price == Wad.from_number(130.75))
def test_new_sell_orders_maker_amount_fail_case(tmpdir):
    bands_file = BandConfig.sample_config_dif_margins(tmpdir)
    bands_config = ReloadableConfig(str(bands_file))
    airswap_bands = AirswapBands.read(bands_config, EmptyFeed(), FixedFeed({'canBuy': True, 'canSell': True}), History())

    maker_amount = Wad(106200000000000000000)
    taker_amount = Wad(0)
    our_sell_balance = Wad(1562000000000000000)
    sell_limit = Wad(1562000000000000000000)
    target_price = WebSocketPriceFeed(FakeFeed({"buyPrice": "120", "sellPrice": "130"})).get_price()

    new_order = airswap_bands._new_side_orders('sell',
                                               maker_amount,
                                               taker_amount,
                                               our_sell_balance,
                                               sell_limit,
                                               airswap_bands.sell_bands[0],
                                               target_price.sell_price)

    assert new_order == {}