MULTI-AGENT // PYTHON
ORACLESWARM
OracleSwarm is two interconnected projects: a BTC derivatives trader that exploits Binance-to-Chainlink oracle latency for arbitrage, and Mirofish — a multi-agent future prediction engine for Polymarket. A swarm of AI agents (Bayesian, momentum, contrarian, sentiment, fundamental) independently form beliefs and aggregate via track-record-weighted consensus to generate trading signals.
TECH_STACK
KEY_FEATURES
Oracle Latency Arbitrage
Exploits the 3-27 second lag between Binance spot price movements and Polymarket contract repricing, with Chainlink oracle divergence as a confirmation signal.
Multi-Agent Belief System
Five agent archetypes independently analyze markets and get weighted by Brier-score track records for swarm consensus.
XGBoost Entry Prediction
XGBoost model determines the probability of a profitable entry before the bot takes a position, trained on historical edge signals and market microstructure features.
Trade Feedback Loop
Post-mortem analysis on every closed trade builds a decision tree of success/failure patterns, blocking historically losing setups.
SOURCE_CODE
def calculate_implied_probability(self, spot_price, strike, direction, volatility=0.02, time_to_expiry_hours=24.0):
t = time_to_expiry_hours / (365.25 * 24)
if t <= 0:
if direction == "above":
return 1.0 if spot_price > strike else 0.0
return 1.0 if spot_price < strike else 0.0
sigma_sqrt_t = volatility * math.sqrt(t)
d2 = math.log(spot_price / strike) / sigma_sqrt_t - 0.5 * sigma_sqrt_t
prob_above = self._norm_cdf(d2)
return prob_above if direction == "above" else 1.0 - prob_above @dataclass
class BucketPrior:
"""Beta distribution for win rate estimation."""
alpha: float = 1.0 # wins + 1 (uniform prior)
beta: float = 1.0 # losses + 1
@property
def mean(self) -> float:
return self.alpha / (self.alpha + self.beta)
def update(self, win: bool) -> None:
if win:
self.alpha += 1
else:
self.beta += 1
def confidence_scale(self, key: tuple) -> float:
"""Kelly confidence multiplier based on observation count.
<=3 obs: 0.40 (conservative), 30+: 1.0 (full confidence)"""
bucket = self._buckets.get(key)
if bucket is None:
return 0.40
n = bucket.total_obs
if n <= 3:
return 0.40
if n >= 30:
return 1.0
return 0.40 + 0.60 * (n - 3) / 27 def _retune(self) -> None:
# Rolling win rate -> Kelly fraction
recent = trades[-50:]
wins = sum(1 for t in recent if t.correct)
wr = wins / len(recent)
avg_entry = max(0.30, min(0.80, avg_entry))
b = (1.0 / avg_entry) - 1.0 # Payout ratio
raw_kelly = max(0.0, (b * wr - (1 - wr)) / b)
new_kelly = max(0.15, min(0.30, raw_kelly * 0.40))
# Stop-loss tuning from SL vs non-SL outcomes
sl_trades = [t for t in trades if t.exit_type == "stop_loss"]
non_sl_losses = [t for t in trades if t.exit_type == "resolution" and not t.correct]
if len(sl_trades) >= 3 and len(non_sl_losses) >= 3:
avg_sl_pnl = sum(t.pnl_usd for t in sl_trades) / len(sl_trades)
avg_full_loss = sum(t.pnl_usd for t in non_sl_losses) / len(non_sl_losses)
if avg_sl_pnl > avg_full_loss * 0.8:
new_sl = max(0.0003, self.thresholds.sl_underlying_pct * 0.90)
else:
new_sl = min(0.0015, self.thresholds.sl_underlying_pct * 1.15) ARCHITECTURE
Data Ingestion
- Binance WebSocket spot feeds
- Polymarket Gamma API market discovery
- Chainlink oracle reads via Polygon RPC
- Real-time price divergence detection
Agent Swarm
- Bayesian probability updater
- Momentum signal tracker
- Contrarian reversal detector
- Claude-powered sentiment agent
- Fundamental analysis agent
Execution
- Kelly Criterion position sizing
- Paper + live trading modes
- Trade post-mortem feedback loop
- FastAPI monitoring dashboard