fix: use 2-tick ask buffer to prevent bid crossing ask (taker race)

Between fetching the best ask and placing the GTC order, the ask can
move down 1 tick — turning our bid into a marketable (taker) order,
which hits Polymarket's $1 minimum notional error. Cap bid to
ask - 2*tickSize instead of ask - 1*tickSize to absorb the timing race.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
direkturcrypto
2026-04-01 10:55:19 +07:00
co-authored by Claude Sonnet 4.6
parent f2f2d48ada
commit ececad8574
+5 -2
View File
@@ -634,7 +634,10 @@ export async function executeMakerRebateStrategy(market) {
const cheapAsk = cheapSide === 'yes' ? yesAsk : noAsk;
let cheapBid = roundToTick(cheapBestBid + ts, tickSize);
if (cheapAsk && cheapBid >= cheapAsk) cheapBid = roundToTick(cheapAsk - ts, tickSize);
// Cap to ask - 2 ticks (not 1) to absorb timing race between fetch and place.
// A 1-tick buffer still lets the ask move 1 tick before our order is submitted,
// turning it into a marketable (taker) order and hitting the $1 minimum.
if (cheapAsk && cheapBid >= cheapAsk - ts) cheapBid = roundToTick(cheapAsk - 2 * ts, tickSize);
// Range check on cheap side
if (cheapBid < MIN_PRICE || cheapBid > MAX_PRICE) {
@@ -647,7 +650,7 @@ export async function executeMakerRebateStrategy(market) {
const expensiveBid = roundToTick(config.makerMmMaxCombined - cheapBid, tickSize);
const expensiveAsk = cheapSide === 'yes' ? noAsk : yesAsk;
let expBid = expensiveBid;
if (expensiveAsk && expBid >= expensiveAsk) expBid = roundToTick(expensiveAsk - ts, tickSize);
if (expensiveAsk && expBid >= expensiveAsk - ts) expBid = roundToTick(expensiveAsk - 2 * ts, tickSize);
if (expBid <= 0 || expBid >= 1) {
logger.info(`MakerMM${tag}: waiting — ${cheapSide === 'yes' ? 'NO' : 'YES'} bid $${expBid.toFixed(3)} out of bounds`);