fix: skip market-sell for expensive side in ghost fill recovery
When expensive side (e.g. YES at 83c) is filled but cheap side (NO at 15c) is ghost, do NOT market-sell the YES tokens — the cost basis is too high and a market dump guarantees a loss. Only CL (market-sell) the cheap side remainder, where the cost basis is low enough to absorb the slippage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
9a5073dd20
commit
3d2a6e7c4a
@@ -218,11 +218,24 @@ async function recoverFromGhostFill(pos, yesShares, noShares, tag) {
|
||||
const yesRemainder = parseFloat(Math.max(0, yesShares - mergeable).toFixed(6));
|
||||
const noRemainder = parseFloat(Math.max(0, noShares - mergeable).toFixed(6));
|
||||
|
||||
// Only market-sell the CHEAP side remainder — expensive side is too costly to dump at market.
|
||||
// e.g. YES=83c filled, NO=15c ghost → hold YES (high cost basis, market sell = guaranteed loss).
|
||||
// NO=15c filled, YES=83c ghost → sell NO (cheap, small loss acceptable).
|
||||
const expSide = pos.yes.buyPrice >= pos.no.buyPrice ? 'yes' : 'no';
|
||||
|
||||
if (yesRemainder >= 1) {
|
||||
await marketSellToken(pos.yes.tokenId, yesRemainder, pos.tickSize, pos.negRisk, tag);
|
||||
if (expSide === 'yes') {
|
||||
logger.warn(`MakerMM${tag}: ghost recovery — holding YES remainder ${yesRemainder.toFixed(4)} (expensive $${pos.yes.buyPrice}, not market-selling)`);
|
||||
} else {
|
||||
await marketSellToken(pos.yes.tokenId, yesRemainder, pos.tickSize, pos.negRisk, tag);
|
||||
}
|
||||
}
|
||||
if (noRemainder >= 1) {
|
||||
await marketSellToken(pos.no.tokenId, noRemainder, pos.tickSize, pos.negRisk, tag);
|
||||
if (expSide === 'no') {
|
||||
logger.warn(`MakerMM${tag}: ghost recovery — holding NO remainder ${noRemainder.toFixed(4)} (expensive $${pos.no.buyPrice}, not market-selling)`);
|
||||
} else {
|
||||
await marketSellToken(pos.no.tokenId, noRemainder, pos.tickSize, pos.negRisk, tag);
|
||||
}
|
||||
}
|
||||
|
||||
pos.totalProfit = mergeRecovered - (pos.yes.cost + pos.no.cost);
|
||||
|
||||
Reference in New Issue
Block a user