def test_should_not_cancel_anything_if_no_orders_to_cancel_regardless_of_price_availability( self, tmpdir): # given config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) # when price = Price(buy_price=Wad.from_number(100), sell_price=Wad.from_number(200)) orders_to_cancel = bands.cancellable_orders([], [], price) # then assert (orders_to_cancel == []) # when price = Price(buy_price=Wad.from_number(100), sell_price=None) orders_to_cancel = bands.cancellable_orders([], [], price) # then assert (orders_to_cancel == []) # when price = Price(buy_price=None, sell_price=Wad.from_number(200)) orders_to_cancel = bands.cancellable_orders([], [], price) # then assert (orders_to_cancel == []) # when price = Price(buy_price=None, sell_price=None) orders_to_cancel = bands.cancellable_orders([], [], price) # then assert (orders_to_cancel == [])
def test_should_cancel_orders_if_price_disappears(self, tmpdir): # given config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) # and buy_order = FakeOrder(Wad.from_number(75), Wad.from_number(96)) sell_order = FakeOrder(Wad.from_number(7.5), Wad.from_number(208)) # when price = Price(buy_price=Wad.from_number(100), sell_price=Wad.from_number(200)) orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price) # then assert(orders_to_cancel == []) # when price = Price(buy_price=Wad.from_number(100), sell_price=None) orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price) # then assert(orders_to_cancel == [sell_order]) # when price = Price(buy_price=None, sell_price=Wad.from_number(200)) orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price) # then assert(orders_to_cancel == [buy_order]) # when price = Price(buy_price=None, sell_price=None) orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price) # then assert(orders_to_cancel == [buy_order, sell_order])
def test_should_create_both_buy_and_sell_orders_and_modifie_it_according_rules(self, tmpdir): config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) buy_price_to_round_up = Wad.from_number(100.009) sell_price_to_round_up = Wad.from_number(200.039) price = Price(buy_price=buy_price_to_round_up, sell_price=sell_price_to_round_up) new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price) assert(len(new_orders) == 2) assert(new_orders[0].is_sell is False) assert(new_orders[0].price == Wad.from_number(96.01)) assert(new_orders[0].amount == Wad.from_number(0.78117)) assert(new_orders[1].is_sell is True) assert(new_orders[1].price == Wad.from_number(208.04)) assert(new_orders[1].amount == Wad.from_number(7.5)) buy_price_to_round_down = Wad.from_number(100.022) sell_price_to_round_down = Wad.from_number(200.014) price = Price(buy_price=buy_price_to_round_down, sell_price=sell_price_to_round_down) new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price) assert(len(new_orders) == 2) assert(new_orders[0].is_sell is False) assert(new_orders[0].price == Wad.from_number(96.02)) assert(new_orders[0].amount == Wad.from_number(0.78109)) assert(new_orders[1].is_sell is True) assert(new_orders[1].price == Wad.from_number(208.01)) assert(new_orders[1].amount == Wad.from_number(7.5))
def test_should_not_create_orders_if_neither_buy_nor_sell_price_available(self, tmpdir): # given config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) # when price = Price(buy_price=None, sell_price=None) new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price) # then assert(new_orders == [])
def test_should_create_only_sell_orders_if_only_sell_price_is_available(self, tmpdir): # given config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) # when price = Price(buy_price=None, sell_price=Wad.from_number(200)) new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price) # then assert(len(new_orders) == 1) assert(new_orders[0].is_sell is True) assert(new_orders[0].price == Wad.from_number(208))
def test_should_create_both_buy_and_sell_orders_when_rules_allows_it(self, tmpdir): config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) price = Price(buy_price=Wad.from_number(100.01), sell_price=Wad.from_number(200.03)) new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price) assert(len(new_orders) == 2) assert(new_orders[0].is_sell is False) assert(new_orders[0].amount == Wad.from_number(0.78117)) assert(new_orders[0].price == Wad.from_number(96.01)) assert(new_orders[1].is_sell is True) assert(new_orders[1].price == Wad.from_number(208.03)) assert(new_orders[1].amount == Wad.from_number(7.5))
def test_should_create_both_buy_and_sell_orders_if_both_prices_are_available( self, tmpdir): # given config = BandConfig.sample_config(tmpdir) bands = self.create_bands(config) # when price = Price(buy_price=Wad.from_number(100), sell_price=Wad.from_number(200)) new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price) # then assert (len(new_orders) == 2) assert (new_orders[0].is_sell is False) assert (new_orders[0].price == Wad.from_number(96)) assert (new_orders[0].amount == Wad.from_number(0.78125)) assert (new_orders[1].is_sell is True) assert (new_orders[1].price == Wad.from_number(208)) assert (new_orders[1].amount == Wad.from_number(7.5))
def get_price(self) -> Price: return Price(buy_price=self.price, sell_price=self.price)