slippage
Slippage estimation, optimization, and protection for trade execution
What this skill does
# Slippage - Complete API Reference
Estimate, minimize, and protect against slippage across all trading platforms.
---
## Chat Commands
### Estimate Slippage
```
/slippage estimate "Trump" YES 5000 Estimate for $5000 order
/slippage BTCUSDT 1.5 BTC Estimate for futures
/slippage ETH 50 --dex uniswap Estimate DEX slippage
```
### Analyze Orderbook
```
/slippage depth "Trump" Show orderbook depth
/slippage impact 10000 Price impact for size
/slippage levels "Trump" Show slippage at sizes
```
### Optimize Execution
```
/slippage optimize "Trump" YES 10000 Find best execution
/slippage split 50000 Optimal order splitting
/slippage timing "Trump" Best times for low slippage
```
### Protection Settings
```
/slippage max 1% Set max slippage tolerance
/slippage protect on Enable slippage protection
/slippage revert-threshold 2% Cancel if slippage exceeds
```
---
## TypeScript API Reference
### Create Slippage Manager
```typescript
import { createSlippageManager } from 'clodds/slippage';
const slippage = createSlippageManager({
// Default tolerance
defaultMaxSlippage: 0.01, // 1%
// Protection
enableProtection: true,
revertThreshold: 0.02, // Cancel if > 2%
// Data sources
orderbookDepth: 20, // Levels to analyze
refreshInterval: 1000, // ms
});
```
### Estimate Slippage
```typescript
const estimate = await slippage.estimate({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
size: 5000,
});
console.log(`Expected slippage: ${estimate.slippage}%`);
console.log(`Price impact: ${estimate.priceImpact}%`);
console.log(`Effective price: ${estimate.effectivePrice}`);
console.log(`Best price: ${estimate.bestPrice}`);
console.log(`Worst price: ${estimate.worstPrice}`);
console.log(`Confidence: ${estimate.confidence}%`);
```
### Analyze Orderbook Depth
```typescript
const depth = await slippage.analyzeDepth({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
});
console.log('Orderbook Depth:');
console.log(` Liquidity at 0.5%: $${depth.liquidityAt05Pct}`);
console.log(` Liquidity at 1%: $${depth.liquidityAt1Pct}`);
console.log(` Liquidity at 2%: $${depth.liquidityAt2Pct}`);
console.log(` Total depth: $${depth.totalDepth}`);
console.log('\nSlippage by Size:');
for (const level of depth.slippageLevels) {
console.log(` $${level.size}: ${level.slippage}% slippage`);
}
```
### Price Impact Analysis
```typescript
const impact = await slippage.priceImpact({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
sizes: [1000, 5000, 10000, 25000, 50000],
});
console.log('Price Impact Analysis:');
for (const level of impact.levels) {
console.log(` $${level.size}:`);
console.log(` Slippage: ${level.slippage}%`);
console.log(` Impact: ${level.impact}%`);
console.log(` Effective: ${level.effectivePrice}`);
}
```
### Optimize Execution
```typescript
const optimized = await slippage.optimize({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
size: 25000,
maxSlippage: 0.01,
});
console.log('Optimized Execution:');
console.log(` Strategy: ${optimized.strategy}`); // 'single' | 'split' | 'twap'
console.log(` Expected slippage: ${optimized.expectedSlippage}%`);
console.log(` vs naive: ${optimized.naiveSlippage}%`);
console.log(` Savings: $${optimized.savings}`);
if (optimized.strategy === 'split') {
console.log('\nOrder Split:');
for (const order of optimized.orders) {
console.log(` ${order.size} @ ${order.limitPrice} (${order.delay}s delay)`);
}
}
```
### Order Splitting
```typescript
const split = await slippage.splitOrder({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
totalSize: 50000,
maxSlippagePerOrder: 0.005, // 0.5% max per order
minOrderSize: 1000,
});
console.log(`Split into ${split.orders.length} orders:`);
for (const order of split.orders) {
console.log(` $${order.size} - expected ${order.expectedSlippage}%`);
}
console.log(`Total expected slippage: ${split.totalSlippage}%`);
console.log(`Execution time: ${split.estimatedTime}s`);
```
### TWAP Execution
```typescript
const twap = await slippage.twapSchedule({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
totalSize: 100000,
duration: 3600, // 1 hour
intervals: 12, // 12 orders
});
console.log('TWAP Schedule:');
for (const order of twap.orders) {
console.log(` ${order.time}: $${order.size}`);
}
console.log(`Expected avg slippage: ${twap.expectedSlippage}%`);
```
### Best Timing Analysis
```typescript
const timing = await slippage.analyzeTiming({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
size: 10000,
});
console.log('Best Times for Low Slippage:');
for (const window of timing.bestWindows) {
console.log(` ${window.time}: avg ${window.avgSlippage}% slippage`);
console.log(` Liquidity: $${window.avgLiquidity}`);
}
console.log('\nWorst Times:');
for (const window of timing.worstWindows) {
console.log(` ${window.time}: avg ${window.avgSlippage}% slippage`);
}
```
### Slippage Protection
```typescript
// Set protection parameters
slippage.setProtection({
maxSlippage: 0.01, // 1% max
revertThreshold: 0.02, // Cancel if > 2%
notifyThreshold: 0.005, // Alert at 0.5%
retryOnRevert: true, // Retry with lower size
retryReductionPct: 50, // Reduce size by 50%
});
// Execute with protection
const result = await slippage.executeProtected({
platform: 'polymarket',
market: 'trump-win-2028',
side: 'YES',
size: 10000,
});
console.log(`Executed: ${result.executed}`);
console.log(`Actual slippage: ${result.actualSlippage}%`);
console.log(`Protected: ${result.protected}`);
if (result.reverted) {
console.log(`Reverted: ${result.revertReason}`);
}
```
### DEX Slippage (Crypto)
```typescript
const dexSlippage = await slippage.estimateDex({
chain: 'ethereum',
dex: 'uniswap',
tokenIn: 'USDC',
tokenOut: 'ETH',
amountIn: 50000,
});
console.log('DEX Slippage Estimate:');
console.log(` Expected out: ${dexSlippage.expectedOut}`);
console.log(` Min out (1% slip): ${dexSlippage.minOut1Pct}`);
console.log(` Price impact: ${dexSlippage.priceImpact}%`);
console.log(` Route: ${dexSlippage.route.join(' → ')}`);
```
### Historical Slippage
```typescript
const history = await slippage.getHistory({
platform: 'polymarket',
period: '30d',
});
console.log('Historical Slippage:');
console.log(` Avg slippage: ${history.avgSlippage}%`);
console.log(` Max slippage: ${history.maxSlippage}%`);
console.log(` Trades with > 1%: ${history.tradesOver1Pct}`);
console.log(` Total slippage cost: $${history.totalCost}`);
```
---
## Slippage Factors
| Factor | Impact | Mitigation |
|--------|--------|------------|
| **Order size** | Larger = more slip | Split orders |
| **Liquidity** | Thin = more slip | Check depth first |
| **Volatility** | High = more slip | Use limit orders |
| **Time of day** | Off-hours = more slip | Trade peak hours |
| **Market type** | New = more slip | Avoid illiquid markets |
---
## Protection Modes
| Mode | Behavior |
|------|----------|
| `warn` | Alert but execute |
| `confirm` | Require confirmation |
| `block` | Cancel if exceeds |
| `retry` | Retry with smaller size |
---
## Best Practices
1. **Always estimate first** — Check slippage before trading
2. **Split large orders** — Reduce impact on thin orderbooks
3. **Use limit orders** — Protect against unexpected slippage
4. **Trade liquid markets** — Higher volume = lower slippage
5. **Monitor execution** — Track actual vs expected slippage
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.