def compute_hedge(self): self.current_back = self.prices[self.selection_id]["back"] self.current_lay = self.prices[self.selection_id]["lay"] self.unhedged_position = self.pricer.compute_unhedged_position() if self.current_back is None: self.current_back = MIN_PRICE if self.current_lay is None: self.current_lay = MAX_PRICE td = ticks_difference(self.current_back, self.current_lay) if td <= 2: get_logger().debug( "very tight market, sitting at the current odds", market_id=self.market_id, tick_difference=td, lay=self.current_lay, back=self.current_back) mk_back = self.current_lay mk_lay = self.current_back else: mk_back = price_ticks_away(self.current_lay, -1) mk_lay = price_ticks_away(self.current_back, 1) self.hedge_order_lay["side"] = "lay" self.hedge_order_lay["size"] = min( max(round(STARTING_STAKE + (self.unhedged_position / mk_lay), 2), MIN_STAKE), MAX_STAKE) self.hedge_order_lay["size"] += self.pricer.position_lay self.hedge_order_lay["price"] = mk_lay get_logger().debug("order hedging by lay", market_id=self.market_id, lay=self.current_lay, size=self.hedge_order_lay["size"]) self.hedge_order_back["side"] = "back" self.hedge_order_back["size"] = min( max(round(STARTING_STAKE - (self.unhedged_position / mk_back), 2), MIN_STAKE), MAX_STAKE) self.hedge_order_back["size"] += self.pricer.position_back self.hedge_order_back["price"] = mk_back get_logger().debug("order hedging by back", market_id=self.market_id, back=self.current_back, size=self.hedge_order_back["size"])
def place_passif_bet(self): selection_id = self.list_runner[self.active]["selection_id"] market_id = self.list_runner[self.active]["market_id"] size = self.stake if self.current_lay is None: price = nearest_price(max(self.current_back * 10, 200)) else: price = price_ticks_away(self.current_lay, -1) pricer = Execution(market_id, selection_id) pricer.quote(price, size, Side.BACK)
def place_passif_bet(self): selection_id = self.list_runner[self.the_draw]["selection_id"] market_id = self.list_runner[self.the_draw]["market_id"] size = self.stake if self.current_lay is None: price = nearest_price(max(self.current_back * 10, 200)) else: price = price_ticks_away(self.current_lay, -1) price = max(self.draw_limit, price) pricer = Execution(market_id, selection_id, self.customer_ref, self.strategy_id) pricer.quote(price, size, Side.BACK)
def passif_bet(self, selection_id, stake, per_of_spread = 1.0, max_odds =200, min_odds=1.01, odds_multip_if_no_spread = 10): selection_id = self.list_runner[selection_id]["selection_id"] market_id = self.list_runner[selection_id]["market_id"] size = stake if self.current_lay is None: price = nearest_price(max(self.current_back * odds_multip_if_no_spread, max_odds)) else: price = price_ticks_away(self.current_lay, -1) * (per_of_spread) + self.current_back * (1-per_of_spread) price = nearest_price(price) price = max(min_odds, price) pricer = Execution(market_id, selection_id, self.customer_ref, self.strategy_id) pricer.quote(price, size, Side.BACK)
def test_price_ticks_away(price, n_ticks, expected): assert price_ticks_away(price, n_ticks) == expected