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))
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)
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))
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)
def test_should_handle_only_buy_price_or_only_sell_price(self): # when price_feed = WebSocketPriceFeed(FakeFeed({"buyPrice": "120.75"})) # then assert(price_feed.get_price().buy_price == Wad.from_number(120.75)) assert(price_feed.get_price().sell_price is None) # when price_feed = WebSocketPriceFeed(FakeFeed({"sellPrice": "130.75"})) # then assert(price_feed.get_price().buy_price is None) assert(price_feed.get_price().sell_price == Wad.from_number(130.75))
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_buy_orders_taker_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(0) taker_amount = Wad(11360000000000000000) 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 = 11.36000 / 117.6 = 0.09659863945 # our_buy_balance = 0.050000000000000000 !!BREAK!! assert new_order == {}
def test_new_buy_orders_taker_amount_success_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(0) taker_amount = Wad(11360000000000000000) our_buy_balance = Wad(1562000000000000000000) 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.04 = 4.8 # 120 - 4.8 = 115.2 # maker_amount = 11.36000 / 115.2 = 0.09861111111111111111111 assert new_order['taker_amount'].__float__() == 11.36000 assert new_order['maker_amount'].__float__() == 0.09861111111111111111111
def test_new_sell_orders_taker_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(0) taker_amount = Wad(1770600000000000000) 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 * avgMargin = 0.05 = 6.5 # 130 + 6.5 = 136.5 # taker_amount = 1.7706 / 136.5 = 0.01297142857142857142857 assert new_order['maker_amount'].__float__() == 0.01297142857142857142857 assert new_order['taker_amount'].__float__() == 1.7706
def test_should_handle_only_buy_price_or_only_sell_price(self): # when price_feed = WebSocketPriceFeed(FakeFeed({"buyPrice": "120.75"})) # then assert (price_feed.get_price().buy_price == Wad.from_number(120.75)) assert (price_feed.get_price().sell_price is None) # when price_feed = WebSocketPriceFeed(FakeFeed({"sellPrice": "130.75"})) # then assert (price_feed.get_price().buy_price is None) 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 == {}