Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class CopyTradingBot {
dryRun: this.config.dryRun,
signatureType: this.config.signatureType,
orderSlippagePercent: this.config.orderSlippagePercent,
maxBuyPrice: this.config.maxProbability,
apiCredentials,
});

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function main() {
privateKey: config.privateKey,
funderAddress: config.funderAddress,
dryRun: config.dryRun,
maxBuyPrice: config.maxProbability,
apiCredentials,
});

Expand Down
9 changes: 7 additions & 2 deletions src/services/trader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
{
Expand Down
Loading