You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a market buy order, py-clob-client first computes a marketable limit buy price.
The marketable limit price is the price level, at which the cumulative sum of open asks amount is greater equal to the requested amount. The open asks are sorted in descending order, but should rather be sorted in ascending order (fill cheapest asks first).
defcalculate_market_price(self, token_id: str, side: str, amount: float) ->float:
""" Calculates the matching price considering an amount and the current orderbook """book=self.get_order_book(token_id) # HAS ASKS IN DESCENDING ORDERifbookisNone:
raiseException("no orderbook")
ifside=="BUY":
ifbook.asksisNone:
raiseException("no match")
returnself.builder.calculate_market_price(book.asks, amount)
else:
ifbook.bidsisNone:
raiseException("no match")
returnself.builder.calculate_market_price(book.bids, amount)
In book = self.get_order_book, asks are sorted in descending order (REST response).
Impact
When sorted in descending order, the returned price level does not guarantee, that there is enough open ask volume below the computed price level to fill the order (cheapest asks will be filled first).
Suggestion
Not sure, but sort asks in ascending order before passing self.builder.calculate_market_price(...)
The text was updated successfully, but these errors were encountered:
Overview
When creating a market buy order, py-clob-client first computes a marketable limit buy price.
The marketable limit price is the price level, at which the cumulative sum of open asks amount is greater equal to the requested amount.
The open asks are sorted in descending order, but should rather be sorted in ascending order (fill cheapest asks first).
Description
https://github.com/Polymarket/py-clob-client/blob/main/py_clob_client/client.py#L725
In
book = self.get_order_book
, asks are sorted in descending order (REST response).Impact
When sorted in descending order, the returned price level does not guarantee, that there is enough open ask volume below the computed price level to fill the order (cheapest asks will be filled first).
Suggestion
Not sure, but sort asks in ascending order before passing
self.builder.calculate_market_price(...)
The text was updated successfully, but these errors were encountered: