def calc_price_for_depth(quote: Level, liq_behind): quote_liq = quote.size while quote_liq < liq_behind: quote = quote.next_level quote_liq += quote.size return quote.price + Side.side(quote.side) * Decimal('0.0001')
def take_pnl(self): if self.pos.position() == 0: return Decimal('0') exit_side = Side.opposite_side(self.position()) take_price = self.nbbo.side(Side.side(self.position())) take_order = Position(pos=self.pos.abs_position(), price=take_price, side=exit_side) take_pos = self.pos + take_order + take_order.fee_pos(self.fee) return take_pos.balance
def test_with_params(pos, enter_price): pnl = PNL('0.3') book = Book() book.quote_subscribers.append(pnl) config = MMParams({ "min_levels": "5", "liq_behind_exit": "0.02", "liq_behind_entry": { "BID": "0.41", "ASK": "0.41" }, "order_sizes": { "BID": "0.07", "ASK": "0.07" }, "min_profit": "0.01", "min_order_size": "0.01", "buried_volume": "10", "taker_exit_profit": "0.1", "price_tolerance": "0.0005" }) pnl.execution(Side.side(pos), abs(pos), abs(enter_price)) median = 1000 for i in range(0, 5): book.increment_level(Side.ASK, Decimal(median + i), Decimal(i / 100)) book.increment_level(Side.BID, Decimal(median - i), Decimal(i / 100)) book.quote_changed(Side.BID) book.quote_changed(Side.ASK) print_book_and_orders(book, Broker(OrderManager())) exit_price = hold_exit_price_strategy(book, pnl, config) pnl.execution(Side.opposite(pnl.position_side()), abs(pos), exit_price) return pnl.closed_pnl
def position_side(self): return Side.side(self.position())
def adjusted_size(order_size, order_side, pos): pos_side = Side.side(pos) if pos_side == order_side: return order_size - abs(pos) else: return order_size + abs(pos)
def side(self): return Side.side(self.pos)