From e4e8dcd77e3c13182d045bc196a61c7f2155e9ea Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Mar 2026 00:53:01 +0000 Subject: [PATCH] Fix buy price limit: cap at maxProbability to prevent slippage exceeding limit The maxProbability filter (0.90) only checked the trader's signal price, but the slippage tolerance (10%) could push the actual execution price above the limit. Now the buy price limit is hard-capped at maxProbability so the bot never pays more than the configured maximum. https://claude.ai/code/session_01XwJtbiAM1zP68HogpG66Gz --- src/bot.ts | 1 + src/index.ts | 1 + src/services/trader.ts | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 6f435dc..b7d7b2c 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -147,6 +147,7 @@ export class CopyTradingBot { dryRun: this.config.dryRun, signatureType: this.config.signatureType, orderSlippagePercent: this.config.orderSlippagePercent, + maxBuyPrice: this.config.maxProbability, apiCredentials, }); diff --git a/src/index.ts b/src/index.ts index 215acfd..4e27d88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,7 @@ async function main() { privateKey: config.privateKey, funderAddress: config.funderAddress, dryRun: config.dryRun, + maxBuyPrice: config.maxProbability, apiCredentials, }); diff --git a/src/services/trader.ts b/src/services/trader.ts index 100c950..de12b4a 100644 --- a/src/services/trader.ts +++ b/src/services/trader.ts @@ -13,6 +13,7 @@ export interface TraderConfig { dryRun?: boolean; // If true, don't actually execute trades signatureType?: number; // 0=EOA, 1=POLY_PROXY, 2=GNOSIS_SAFE orderSlippagePercent?: number; // Slippage tolerance for market orders + maxBuyPrice?: number; // Hard cap on buy price (e.g. maxProbability) - slippage cannot exceed this apiCredentials?: { key: string; secret: string; @@ -337,8 +338,12 @@ export class Trader { // IMPORTANT: Add slippage tolerance to the price limit! The trader's execution price // is often stale by the time we copy. Without tolerance, orders won't fill if // the market moved even 1 cent above the trader's price. - const buyPriceLimit = Math.min(0.99, price * (1 + this.slippage)); - console.log(`[Trader] BUY price limit: $${buyPriceLimit.toFixed(4)} (trader: $${price.toFixed(4)}, +${(this.slippage * 100).toFixed(0)}% slippage)`); + let buyPriceLimit = Math.min(0.99, price * (1 + this.slippage)); + // Hard cap: never pay more than maxBuyPrice (e.g. maxProbability config) + if (this.config.maxBuyPrice && this.config.maxBuyPrice > 0) { + buyPriceLimit = Math.min(buyPriceLimit, this.config.maxBuyPrice); + } + console.log(`[Trader] BUY price limit: $${buyPriceLimit.toFixed(4)} (trader: $${price.toFixed(4)}, +${(this.slippage * 100).toFixed(0)}% slippage${this.config.maxBuyPrice ? `, cap: $${this.config.maxBuyPrice}` : ''})`); const result = await this.client.createAndPostMarketOrder( {