Spaces:
Paused
Paused
File size: 21,329 Bytes
da0ce7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | /**
* π΅ COHERENCE-BASED TRADER π΅
*
* THE REAL AUREON SYSTEM
*
* Based on README methodology:
* - Entry: Coherence Ξ¦(t) > 0.938
* - Exit: Coherence Ξ¦(t) < 0.934
* - Win Rate: 85.3%
* - Expected Value: +1.42% per trade (before fees)
*
* Core Formula:
* Ξ(t) = S(t) + O(t) + E(t)
*
* Where:
* Ξ(t) = Lambda - The unified field state
* S(t) = Substrate - 9 Auris nodes respond to market
* O(t) = Observer - Self-referential field awareness (Ξ(t-1) Γ 0.3)
* E(t) = Echo - Memory and momentum (avg(Ξ[t-5:t]) Γ 0.2)
* Ξ = Coherence = 1 - (variance / 10)
*
* Run: npx tsx scripts/coherenceTrader.ts
*/
import * as https from 'https';
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// CONFIGURATION
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const CONFIG = {
BALANCE_PER_BROKER: 20,
POSITION_SIZE_PCT: 0.20, // 20% of account per trade
STOP_LOSS_PCT: 0.008, // 0.8% stop loss
TAKE_PROFIT_PCT: 0.018, // 1.8% take profit
// Coherence thresholds (from README)
ENTRY_COHERENCE: 0.938, // Enter when Ξ¦(t) > 0.938
EXIT_COHERENCE: 0.934, // Exit when Ξ¦(t) < 0.934
// Scan interval
SCAN_INTERVAL_MS: 3000,
};
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// THE 9 AURIS NODES (From README)
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
interface AurisNode {
name: string;
emoji: string;
weight: number;
compute: (snapshot: MarketSnapshot) => number;
}
interface MarketSnapshot {
price: number;
volume: number; // 0-1 normalized
volatility: number; // Realized vol
momentum: number; // Price momentum
spread: number; // Bid-ask spread (normalized 0-1)
timestamp: number;
}
// The 9 Auris Nodes from README
const AURIS_NODES: Record<string, AurisNode> = {
tiger: {
name: 'π― Tiger',
emoji: 'π―',
weight: 1.2,
compute: (snap: MarketSnapshot) => snap.volatility * 0.8 + snap.spread * 0.5,
},
falcon: {
name: 'π¦
Falcon',
emoji: 'π¦
',
weight: 1.1,
compute: (snap: MarketSnapshot) => Math.abs(snap.momentum) * 0.7 + snap.volume * 0.3,
},
hummingbird: {
name: 'π¦ Hummingbird',
emoji: 'π¦',
weight: 0.8,
compute: (snap: MarketSnapshot) => 1 / (snap.volatility + 0.01) * 0.6,
},
dolphin: {
name: 'π¬ Dolphin',
emoji: 'π¬',
weight: 1.0,
compute: (snap: MarketSnapshot) => Math.sin(snap.momentum) * 0.5,
},
deer: {
name: 'π¦ Deer',
emoji: 'π¦',
weight: 0.9,
compute: (snap: MarketSnapshot) =>
snap.volume * 0.2 + snap.volatility * 0.3 + snap.spread * 0.2,
},
owl: {
name: 'π¦ Owl',
emoji: 'π¦',
weight: 1.0,
compute: (snap: MarketSnapshot) =>
Math.cos(snap.momentum) * 0.6 + (snap.momentum < 0 ? 0.3 : 0),
},
panda: {
name: 'πΌ Panda',
emoji: 'πΌ',
weight: 0.95,
compute: (snap: MarketSnapshot) =>
snap.volume > 0.7 ? snap.volume * 0.8 : 0.2,
},
cargoship: {
name: 'π’ CargoShip',
emoji: 'π’',
weight: 1.3,
compute: (snap: MarketSnapshot) =>
snap.volume > 0.8 ? snap.volume * 1.2 : 0,
},
clownfish: {
name: 'π Clownfish',
emoji: 'π ',
weight: 0.7,
compute: (snap: MarketSnapshot) =>
Math.abs(snap.price - snap.price * 0.999) * 100,
},
};
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// MASTER EQUATION & COHERENCE CALCULATION
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
class CoherenceCalculator {
private lambdaHistory: number[] = []; // Last 5 Lambda values for Echo
private maxHistorySize: number = 5;
/**
* Calculate Substrate: S(t) = Ξ£(node.compute(snapshot) Γ node.weight) / 9
*/
private calculateSubstrate(snapshot: MarketSnapshot): number {
let sum = 0;
let totalWeight = 0;
Object.values(AURIS_NODES).forEach((node) => {
const nodeResponse = node.compute(snapshot) * node.weight;
sum += nodeResponse;
totalWeight += node.weight;
});
return (sum / totalWeight) * 0.25; // Scale to 0-1 range
}
/**
* Calculate Observer: O(t) = Ξ(t-1) Γ 0.3
*/
private calculateObserver(): number {
if (this.lambdaHistory.length === 0) return 0;
return this.lambdaHistory[this.lambdaHistory.length - 1] * 0.3;
}
/**
* Calculate Echo: E(t) = average(Ξ[t-5:t]) Γ 0.2
*/
private calculateEcho(): number {
if (this.lambdaHistory.length < 2) return 0;
const avg =
this.lambdaHistory.reduce((a, b) => a + b, 0) /
this.lambdaHistory.length;
return avg * 0.2;
}
/**
* Master Equation: Ξ(t) = S(t) + O(t) + E(t)
*/
private calculateLambda(snapshot: MarketSnapshot): number {
const substrate = this.calculateSubstrate(snapshot);
const observer = this.calculateObserver();
const echo = this.calculateEcho();
const lambda = Math.max(0, Math.min(1, substrate + observer + echo));
// Store in history for next iteration
this.lambdaHistory.push(lambda);
if (this.lambdaHistory.length > this.maxHistorySize) {
this.lambdaHistory.shift();
}
return lambda;
}
/**
* Coherence: Ξ = 1 - (variance / 10)
* Where variance is calculated from recent prices
*/
private calculateCoherence(lambda: number): number {
// Use lambda variance + market microstructure variance
const variance =
Math.abs(lambda - 0.5) + Math.random() * 0.05; // Add market noise
const coherence = Math.max(0, Math.min(1, 1 - variance / 10));
return coherence;
}
/**
* Main: Calculate full coherence state
*/
public calculate(snapshot: MarketSnapshot): {
lambda: number;
coherence: number;
signal: 'BUY' | 'SELL' | 'HOLD';
confidence: number;
} {
const lambda = this.calculateLambda(snapshot);
const coherence = this.calculateCoherence(lambda);
let signal: 'BUY' | 'SELL' | 'HOLD' = 'HOLD';
let confidence = 0;
if (coherence > CONFIG.ENTRY_COHERENCE) {
// Strong buy signal when coherence peaks
if (lambda > 0.6) {
signal = 'BUY';
confidence = Math.min(1, coherence * 1.2);
} else {
signal = 'SELL';
confidence = Math.min(1, coherence * 1.2);
}
}
return { lambda, coherence, signal, confidence };
}
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// BROKER CONFIGURATION
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
interface Broker {
name: string;
emoji: string;
exchange?: string;
assets: string[];
}
const BROKERS: Broker[] = [
{
name: 'Binance',
emoji: 'πͺ',
exchange: 'binance',
assets: ['BTCUSDT', 'ETHUSDT', 'ADAUSDT', 'BNBUSDT'],
},
{
name: 'OKX',
emoji: 'β',
exchange: 'okx',
assets: ['BTC-USDT', 'ETH-USDT', 'ADA-USDT'],
},
{
name: 'Kraken',
emoji: 'π¦',
exchange: 'kraken',
assets: ['XBTUSDT', 'ETHUSDT', 'ADAUSDT'],
},
{
name: 'OANDA',
emoji: 'π±',
exchange: 'oanda',
assets: ['EUR_USD', 'GBP_USD', 'USD_JPY'],
},
{
name: 'IG Markets',
emoji: 'π',
exchange: 'ig',
assets: ['BTC/USD', 'ES', 'FTSE'],
},
{
name: 'CMC Markets',
emoji: 'π',
exchange: 'cmc',
assets: ['BTC/USD', 'ES', 'FTSE'],
},
{
name: 'Capital.com',
emoji: 'π',
exchange: 'capital',
assets: ['BTCUSD', 'ETHUSD', 'ES_F'],
},
{
name: 'Coinbase',
emoji: 'π ',
exchange: 'coinbase',
assets: ['BTC-USD', 'ETH-USD', 'ADA-USD'],
},
];
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// MARKET DATA FETCHER
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
async function fetchBinancePrice(symbol: string): Promise<number | null> {
return new Promise((resolve) => {
https
.get(
`https://api.binance.com/api/v3/ticker/price?symbol=${symbol}`,
(res) => {
let data = '';
res.on('data', (chunk) => (data += chunk));
res.on('end', () => {
try {
const json = JSON.parse(data);
resolve(parseFloat(json.price));
} catch {
resolve(null);
}
});
}
)
.on('error', () => resolve(null));
});
}
async function fetchPrice(
broker: Broker,
asset: string
): Promise<MarketSnapshot | null> {
let price: number | null = null;
if (broker.exchange === 'binance') {
price = await fetchBinancePrice(asset);
} else {
// Simulate other brokers with binance data
const baseAsset = asset.replace(/[^\w]/g, '');
price = await fetchBinancePrice(baseAsset + 'USDT');
}
if (!price) return null;
// Create realistic market snapshot
return {
price,
volume: 0.6 + Math.random() * 0.3, // 60-90% normalized
volatility: 0.015 + Math.random() * 0.02, // 1.5-3.5%
momentum: (Math.random() - 0.5) * 0.05, // -2.5% to +2.5%
spread: 0.0001 + Math.random() * 0.0003, // Realistic spread
timestamp: Date.now(),
};
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// POSITION TRACKING
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
interface Position {
broker: string;
asset: string;
direction: 'LONG' | 'SHORT';
entryPrice: number;
entryTime: number;
size: number;
coherenceAtEntry: number;
pnlGross: number;
pnlNet: number;
fees: number;
}
interface BrokerState {
balance: number;
positions: Position[];
wins: number;
losses: number;
totalFees: number;
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// MAIN TRADER ENGINE
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
class CoherenceTrader {
private coherenceCalc = new CoherenceCalculator();
private brokerStates: Map<string, BrokerState> = new Map();
private scanCount = 0;
constructor() {
// Initialize brokers
BROKERS.forEach((broker) => {
this.brokerStates.set(broker.emoji + broker.name, {
balance: CONFIG.BALANCE_PER_BROKER,
positions: [],
wins: 0,
losses: 0,
totalFees: 0,
});
});
}
async scan(): Promise<void> {
this.scanCount++;
const timestamp = new Date().toLocaleTimeString();
console.log(`\nπ SCAN #${this.scanCount} | ${timestamp}`);
console.log('β'.repeat(80));
let totalSignals = 0;
let buySignals = 0;
let sellSignals = 0;
let totalCoherence = 0;
let signalCount = 0;
// Process each broker
for (const broker of BROKERS) {
const key = broker.emoji + broker.name;
const state = this.brokerStates.get(key);
if (!state) continue;
// Get random asset from broker
const asset = broker.assets[Math.floor(Math.random() * broker.assets.length)];
// Fetch market data
const snapshot = await fetchPrice(broker, asset);
if (!snapshot) {
console.log(`${broker.emoji} ${broker.name}: β οΈ No price data`);
continue;
}
// Calculate coherence
const result = this.coherenceCalc.calculate(snapshot);
totalCoherence += result.coherence;
signalCount++;
// Display coherence state
const coherenceBar = this.drawCoherenceBar(result.coherence);
const status =
result.coherence > CONFIG.ENTRY_COHERENCE
? 'π’ ENTRY'
: result.coherence > CONFIG.EXIT_COHERENCE
? 'π‘ HOLD'
: 'π΄ EXIT';
console.log(
`${broker.emoji} ${broker.name.padEnd(15)} | Ξ¦=${result.coherence.toFixed(4)} ${coherenceBar} ${status} | ${asset}`
);
if (result.signal === 'BUY') {
buySignals++;
totalSignals++;
} else if (result.signal === 'SELL') {
sellSignals++;
totalSignals++;
}
// Execute trade if signal strong enough
if (result.coherence > CONFIG.ENTRY_COHERENCE) {
this.enterPosition(broker, key, state, asset, snapshot, result);
}
// Update existing positions
this.updatePositions(key, state, snapshot);
}
console.log('β'.repeat(80));
const avgCoherence =
signalCount > 0 ? (totalCoherence / signalCount).toFixed(4) : '0.0000';
console.log(
`π Signals: ${buySignals} BUY | ${sellSignals} SELL | Avg Ξ¦: ${avgCoherence}`
);
// Print broker summary
this.printBrokerSummary();
}
private enterPosition(
broker: Broker,
key: string,
state: BrokerState,
asset: string,
snapshot: MarketSnapshot,
result: { lambda: number; coherence: number; signal: 'BUY' | 'SELL' | 'HOLD'; confidence: number }
): void {
if (state.positions.length >= 3) return; // Max 3 positions per broker
const size = (state.balance * CONFIG.POSITION_SIZE_PCT) / snapshot.price;
if (size <= 0) return;
const position: Position = {
broker: broker.name,
asset,
direction: result.signal === 'BUY' ? 'LONG' : 'SHORT',
entryPrice: snapshot.price,
entryTime: Date.now(),
size,
coherenceAtEntry: result.coherence,
pnlGross: 0,
pnlNet: 0,
fees: snapshot.price * size * 0.002, // Estimate 0.2% round-trip fee
};
state.positions.push(position);
console.log(
` β
ENTRY ${position.direction} ${asset} @ ${snapshot.price.toFixed(2)} (Ξ¦=${result.coherence.toFixed(4)})`
);
}
private updatePositions(
key: string,
state: BrokerState,
currentPrice: MarketSnapshot
): void {
for (let i = state.positions.length - 1; i >= 0; i--) {
const pos = state.positions[i];
// Calculate P&L
const priceDiff =
pos.direction === 'LONG'
? currentPrice.price - pos.entryPrice
: pos.entryPrice - currentPrice.price;
pos.pnlGross = priceDiff * pos.size;
pos.pnlNet = pos.pnlGross - pos.fees;
// Exit conditions
if (pos.pnlNet >= pos.entryPrice * pos.size * CONFIG.TAKE_PROFIT_PCT) {
console.log(
` β
EXIT (TP) ${pos.asset} | P&L: +Β£${pos.pnlNet.toFixed(4)}`
);
state.balance += pos.pnlNet;
state.wins++;
state.totalFees += pos.fees;
state.positions.splice(i, 1);
} else if (pos.pnlNet <= -(pos.entryPrice * pos.size * CONFIG.STOP_LOSS_PCT)) {
console.log(
` β EXIT (SL) ${pos.asset} | P&L: -Β£${Math.abs(pos.pnlNet).toFixed(4)}`
);
state.balance += pos.pnlNet;
state.losses++;
state.totalFees += pos.fees;
state.positions.splice(i, 1);
}
}
}
private printBrokerSummary(): void {
console.log('\nπΌ BROKER SUMMARY:');
console.log('β'.repeat(80));
let totalBalance = 0;
let totalWins = 0;
let totalLosses = 0;
let totalPnL = 0;
let totalFees = 0;
this.brokerStates.forEach((state, key) => {
totalBalance += state.balance;
totalWins += state.wins;
totalLosses += state.losses;
totalFees += state.totalFees;
const winRate =
totalWins + totalLosses > 0
? ((totalWins / (totalWins + totalLosses)) * 100).toFixed(1)
: '0.0';
console.log(
`${key.padEnd(25)} | Balance: Β£${state.balance.toFixed(2).padStart(8)} | W: ${totalWins} | L: ${totalLosses} | WR: ${winRate}%`
);
});
console.log('β'.repeat(80));
console.log(
`π° TOTAL CAPITAL: Β£${totalBalance.toFixed(2)} | WIN RATE: ${
totalWins + totalLosses > 0
? ((totalWins / (totalWins + totalLosses)) * 100).toFixed(1)
: '0.0'
}% | FEES: Β£${totalFees.toFixed(2)}`
);
}
private drawCoherenceBar(coherence: number): string {
const width = 20;
const filled = Math.round(coherence * width);
const bar = 'β'.repeat(filled) + 'β'.repeat(width - filled);
return `[${bar}]`;
}
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// MAIN ENTRY POINT
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
async function main(): Promise<void> {
console.log(`
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π΅ COHERENCE-BASED TRADER π΅ β
β β
β Entry Threshold: Ξ¦(t) > 0.938 β
β Exit Threshold: Ξ¦(t) < 0.934 β
β Expected Win Rate: 85.3% β
β Expected Value: +1.42% per trade (before fees) β
β β
β Formula: Ξ(t) = S(t) + O(t) + E(t) β
β - S(t) = Substrate (9 Auris nodes) β
β - O(t) = Observer (self-aware field) β
β - E(t) = Echo (momentum & memory) β
β β
β Brokers: 8 deployed across crypto, forex, stocks, and CFDs β
β Capital: Β£160 total (Β£20 per broker Γ 8) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
`);
const trader = new CoherenceTrader();
// Continuous scanning
while (true) {
await trader.scan();
await new Promise((resolve) => setTimeout(resolve, CONFIG.SCAN_INTERVAL_MS));
}
}
main().catch(console.error);
|