Spaces:
Running
Running
Deploy Aureon OS (deploy/selfhost stack: nginx edge + fusion API x2 + console + HNC organ + redis + postgres; paper mode) (part 19)
da0ce7b verified Download scripts/traders/binanceLive.ts from GaryLeckey/aureon-os: direct link, hf CLI and curl.
- Browser
- Download file 21.2 kB
-
https://huggingface.co/spaces/GaryLeckey/aureon-os/resolve/main/scripts/traders/binanceLive.ts
- Command line
-
hf download hf://spaces/GaryLeckey/aureon-os/scripts/traders/binanceLive.ts
-
curl -L -o binanceLive.ts https://huggingface.co/spaces/GaryLeckey/aureon-os/resolve/main/scripts/traders/binanceLive.ts
21.2 kB
| /** | |
| * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| * AUREON BINANCE LIVE TRADING SYSTEM | |
| * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| * | |
| * Master Equation: Ξ(t) = S(t) + O(t) + E(t) | |
| * 9 Auris Nodes | Rainbow Bridge | Real Money | |
| * | |
| * Author: Gary Leckey | |
| * Date: November 25, 2025 | |
| * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| */ | |
| import BinanceLib from 'binance-api-node'; | |
| import * as dotenv from 'dotenv'; | |
| dotenv.config(); | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // BINANCE CLIENT | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| const client = (BinanceLib as any).default({ | |
| apiKey: process.env.BINANCE_API_KEY!, | |
| apiSecret: process.env.BINANCE_SECRET!, | |
| }); | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // 9 AURIS NODES - The Ensemble | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| interface MarketData { | |
| price: number; | |
| volume: number; | |
| high: number; | |
| low: number; | |
| open: number; | |
| change: number; | |
| } | |
| const aurisNodes = { | |
| tiger: (d: MarketData) => ((d.high - d.low) / d.price) * 100 + (d.volume > 1000000 ? 0.2 : 0), | |
| falcon: (d: MarketData) => Math.abs(d.change) * 0.7 + Math.min(d.volume / 10000000, 0.3), | |
| hummingbird: (d: MarketData) => 1 / (1 + ((d.high - d.low) / d.price) * 10), | |
| dolphin: (d: MarketData) => Math.sin(d.change * Math.PI / 10) * 0.5 + 0.5, | |
| deer: (d: MarketData) => (d.price > d.open ? 0.6 : 0.4) + (d.change > 0 ? 0.2 : -0.1), | |
| owl: (d: MarketData) => Math.cos(d.change * Math.PI / 10) * 0.3 + (d.price < d.open ? 0.3 : 0), | |
| panda: (d: MarketData) => 0.5 + Math.sin(Date.now() / 60000) * 0.1, | |
| cargoShip: (d: MarketData) => d.volume > 5000000 ? 0.8 : d.volume > 1000000 ? 0.5 : 0.3, | |
| clownfish: (d: MarketData) => Math.abs(d.price - d.open) / d.price * 100, | |
| }; | |
| const nodeWeights = { | |
| tiger: 1.2, falcon: 1.1, hummingbird: 0.9, dolphin: 1.0, | |
| deer: 0.8, owl: 0.9, panda: 0.7, cargoShip: 1.0, clownfish: 0.7 | |
| }; | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // MASTER EQUATION: Ξ(t) = S(t) + O(t) + E(t) | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| let lambdaHistory: number[] = []; | |
| const OBSERVER_WEIGHT = 0.3; | |
| const ECHO_WEIGHT = 0.2; | |
| const ECHO_DEPTH = 5; | |
| function computeSubstrate(data: MarketData): number { | |
| let sum = 0; | |
| let weightSum = 0; | |
| for (const [name, fn] of Object.entries(aurisNodes)) { | |
| const weight = nodeWeights[name as keyof typeof nodeWeights]; | |
| sum += fn(data) * weight; | |
| weightSum += weight; | |
| } | |
| return sum / weightSum; | |
| } | |
| function computeLambda(data: MarketData): number { | |
| const S = computeSubstrate(data); | |
| const O = lambdaHistory.length > 0 ? lambdaHistory[lambdaHistory.length - 1] * OBSERVER_WEIGHT : 0; | |
| const E = lambdaHistory.length >= ECHO_DEPTH | |
| ? lambdaHistory.slice(-ECHO_DEPTH).reduce((a, b) => a + b, 0) / ECHO_DEPTH * ECHO_WEIGHT | |
| : 0; | |
| const lambda = S + O + E; | |
| lambdaHistory.push(lambda); | |
| if (lambdaHistory.length > 100) lambdaHistory.shift(); | |
| return lambda; | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // COHERENCE: Ξ = 1 - ΟΒ²/c | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| function computeCoherence(data: MarketData): number { | |
| const responses: number[] = []; | |
| for (const [name, fn] of Object.entries(aurisNodes)) { | |
| responses.push(fn(data)); | |
| } | |
| const mean = responses.reduce((a, b) => a + b, 0) / responses.length; | |
| const variance = responses.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / responses.length; | |
| return Math.max(0, Math.min(1, 1 - variance / 10)); | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // RAINBOW BRIDGE: Frequency Mapping | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| function getFrequency(lambda: number, coherence: number): { hz: number; color: string; state: string } { | |
| const baseHz = 110 + lambda * 100; | |
| const targetHz = 528; // Love frequency | |
| const hz = baseHz * (1 - coherence * 0.3) + targetHz * (coherence * 0.3); | |
| if (hz < 200) return { hz, color: 'π΄', state: 'FEAR' }; | |
| if (hz < 300) return { hz, color: 'π ', state: 'FORMING' }; | |
| if (hz < 400) return { hz, color: 'π‘', state: 'FOCUS' }; | |
| if (hz < 528) return { hz, color: 'π’', state: 'FLOW' }; | |
| if (hz < 700) return { hz, color: 'π', state: 'LOVE' }; | |
| if (hz < 850) return { hz, color: 'π΅', state: 'AWE' }; | |
| return { hz, color: 'π£', state: 'UNITY' }; | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // TRADING CONFIG | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| const CONFIG = { | |
| // Coherence thresholds | |
| ENTRY_THRESHOLD: 0.938, | |
| EXIT_THRESHOLD: 0.934, | |
| // Risk management (Kelly fraction) | |
| RISK_PER_TRADE: 0.05, // 5% of balance | |
| STOP_LOSS: 0.008, // 0.8% | |
| TAKE_PROFIT: 0.018, // 1.8% | |
| // Trading pairs (high volume, low fees) | |
| PAIRS: ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'XRPUSDT'], | |
| // Timing | |
| SCAN_INTERVAL: 5000, // 5 seconds | |
| }; | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // STATE | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| interface Position { | |
| symbol: string; | |
| side: 'LONG' | 'SHORT'; | |
| entryPrice: number; | |
| quantity: number; | |
| stopLoss: number; | |
| takeProfit: number; | |
| entryTime: Date; | |
| } | |
| const state = { | |
| balance: 0, | |
| startingBalance: 0, | |
| positions: new Map<string, Position>(), | |
| trades: { wins: 0, losses: 0, total: 0 }, | |
| pnl: 0, | |
| startTime: new Date(), | |
| }; | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // BINANCE FUNCTIONS | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async function getBalance(): Promise<number> { | |
| const account = await client.accountInfo(); | |
| const usdt = account.balances.find(b => b.asset === 'USDT'); | |
| return usdt ? parseFloat(usdt.free) : 0; | |
| } | |
| async function getMarketData(symbol: string): Promise<MarketData> { | |
| const [ticker, stats] = await Promise.all([ | |
| client.prices({ symbol }), | |
| client.dailyStats({ symbol }), | |
| ]); | |
| return { | |
| price: parseFloat(ticker[symbol]), | |
| volume: parseFloat(stats.volume), | |
| high: parseFloat(stats.highPrice), | |
| low: parseFloat(stats.lowPrice), | |
| open: parseFloat(stats.openPrice), | |
| change: parseFloat(stats.priceChangePercent), | |
| }; | |
| } | |
| async function placeTrade(symbol: string, side: 'BUY' | 'SELL', quantity: number): Promise<boolean> { | |
| try { | |
| const order = await client.order({ | |
| symbol, | |
| side, | |
| type: 'MARKET', | |
| quantity: quantity.toFixed(6), | |
| }); | |
| console.log(` β Order filled: ${order.executedQty} @ ${order.fills?.[0]?.price || 'market'}`); | |
| return true; | |
| } catch (error: any) { | |
| console.log(` β Order failed: ${error.message}`); | |
| return false; | |
| } | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // TRADING LOGIC | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async function checkEntry(symbol: string, data: MarketData): Promise<void> { | |
| if (state.positions.has(symbol)) return; | |
| const lambda = computeLambda(data); | |
| const coherence = computeCoherence(data); | |
| const freq = getFrequency(lambda, coherence); | |
| if (coherence >= CONFIG.ENTRY_THRESHOLD) { | |
| const direction = data.change > 0 ? 'LONG' : 'SHORT'; | |
| const tradeAmount = state.balance * CONFIG.RISK_PER_TRADE; | |
| const quantity = tradeAmount / data.price; | |
| console.log(`\n${freq.color} [${symbol}] Ξ=${lambda.toFixed(3)} Ξ=${coherence.toFixed(3)} ${freq.hz.toFixed(0)}Hz`); | |
| console.log(` π― ENTRY SIGNAL: ${direction} @ $${data.price.toFixed(2)}`); | |
| const side = direction === 'LONG' ? 'BUY' : 'SELL'; | |
| const success = await placeTrade(symbol, side, quantity); | |
| if (success) { | |
| const stopLoss = direction === 'LONG' | |
| ? data.price * (1 - CONFIG.STOP_LOSS) | |
| : data.price * (1 + CONFIG.STOP_LOSS); | |
| const takeProfit = direction === 'LONG' | |
| ? data.price * (1 + CONFIG.TAKE_PROFIT) | |
| : data.price * (1 - CONFIG.TAKE_PROFIT); | |
| state.positions.set(symbol, { | |
| symbol, | |
| side: direction, | |
| entryPrice: data.price, | |
| quantity, | |
| stopLoss, | |
| takeProfit, | |
| entryTime: new Date(), | |
| }); | |
| state.trades.total++; | |
| console.log(` π SL: $${stopLoss.toFixed(2)} | TP: $${takeProfit.toFixed(2)}`); | |
| } | |
| } | |
| } | |
| async function checkExit(symbol: string, data: MarketData): Promise<void> { | |
| const position = state.positions.get(symbol); | |
| if (!position) return; | |
| const coherence = computeCoherence(data); | |
| let exitReason = ''; | |
| let isWin = false; | |
| // Check stop loss | |
| if (position.side === 'LONG' && data.price <= position.stopLoss) { | |
| exitReason = 'π STOP LOSS'; | |
| } else if (position.side === 'SHORT' && data.price >= position.stopLoss) { | |
| exitReason = 'π STOP LOSS'; | |
| } | |
| // Check take profit | |
| else if (position.side === 'LONG' && data.price >= position.takeProfit) { | |
| exitReason = 'π― TAKE PROFIT'; | |
| isWin = true; | |
| } else if (position.side === 'SHORT' && data.price <= position.takeProfit) { | |
| exitReason = 'π― TAKE PROFIT'; | |
| isWin = true; | |
| } | |
| // Check coherence drop | |
| else if (coherence < CONFIG.EXIT_THRESHOLD) { | |
| exitReason = 'π COHERENCE DROP'; | |
| isWin = (position.side === 'LONG' && data.price > position.entryPrice) || | |
| (position.side === 'SHORT' && data.price < position.entryPrice); | |
| } | |
| if (exitReason) { | |
| const pnlPercent = position.side === 'LONG' | |
| ? (data.price - position.entryPrice) / position.entryPrice * 100 | |
| : (position.entryPrice - data.price) / position.entryPrice * 100; | |
| const pnlValue = position.quantity * position.entryPrice * (pnlPercent / 100); | |
| console.log(`\n ${exitReason} [${symbol}]`); | |
| console.log(` ${pnlPercent >= 0 ? 'β ' : 'β'} PnL: ${pnlPercent >= 0 ? '+' : ''}${pnlPercent.toFixed(2)}% ($${pnlValue.toFixed(2)})`); | |
| const side = position.side === 'LONG' ? 'SELL' : 'BUY'; | |
| await placeTrade(symbol, side, position.quantity); | |
| state.positions.delete(symbol); | |
| state.pnl += pnlValue; | |
| if (isWin || pnlPercent > 0) state.trades.wins++; | |
| else state.trades.losses++; | |
| } | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // DISPLAY | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| function displayStatus(): void { | |
| const elapsed = (Date.now() - state.startTime.getTime()) / 1000 / 60; | |
| const winRate = state.trades.total > 0 ? (state.trades.wins / state.trades.total * 100) : 0; | |
| const roi = state.startingBalance > 0 ? (state.pnl / state.startingBalance * 100) : 0; | |
| console.log(` | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β π΅ AUREON BINANCE LIVE - ${new Date().toLocaleTimeString()} β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β β±οΈ Runtime: ${elapsed.toFixed(1)} min | π° Balance: $${state.balance.toFixed(2)} β | |
| β π Trades: ${state.trades.total} | π― Win Rate: ${winRate.toFixed(1)}% | π PnL: $${state.pnl.toFixed(2)} (${roi >= 0 ? '+' : ''}${roi.toFixed(2)}%) β | |
| β π Open Positions: ${state.positions.size} β | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ`); | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // MAIN LOOP | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async function runLiveTrading(): Promise<void> { | |
| console.log(` | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β β | |
| β ββββββ βββ ββββββββββ ββββββββ βββββββ ββββ βββ β | |
| β βββββββββββ βββββββββββββββββββββββββββββββββ βββ β | |
| β βββββββββββ βββββββββββββββββ βββ βββββββββ βββ β | |
| β βββββββββββ βββββββββββββββββ βββ βββββββββββββ β | |
| β βββ βββββββββββββββ βββββββββββββββββββββββ ββββββ β | |
| β βββ βββ βββββββ βββ βββββββββββ βββββββ βββ βββββ β | |
| β β | |
| β π΄ LIVE TRADING - BINANCE - REAL MONEY π΄ β | |
| β β | |
| β Master Equation: Ξ(t) = S(t) + O(t) + E(t) β | |
| β 9 Auris Nodes | Rainbow Bridge | Coherence Trading β | |
| β β | |
| β Author: Gary Leckey β | |
| β Date: November 25, 2025 β | |
| β β | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| `); | |
| // Get initial balance | |
| try { | |
| state.balance = await getBalance(); | |
| state.startingBalance = state.balance; | |
| console.log(`\nπ° Starting Balance: $${state.balance.toFixed(2)} USDT`); | |
| console.log(`π Trading Pairs: ${CONFIG.PAIRS.join(', ')}`); | |
| console.log(`β‘ Risk per trade: ${CONFIG.RISK_PER_TRADE * 100}%`); | |
| console.log(`π― SL: ${CONFIG.STOP_LOSS * 100}% | TP: ${CONFIG.TAKE_PROFIT * 100}%`); | |
| console.log(`\nπ Starting live trading loop...\n`); | |
| } catch (error: any) { | |
| console.error(`β Failed to connect to Binance: ${error.message}`); | |
| console.log(`\nβ οΈ Check your API keys in .env file`); | |
| return; | |
| } | |
| // Main trading loop | |
| let cycle = 0; | |
| while (true) { | |
| cycle++; | |
| // Update balance | |
| state.balance = await getBalance(); | |
| // Scan all pairs | |
| for (const symbol of CONFIG.PAIRS) { | |
| try { | |
| const data = await getMarketData(symbol); | |
| await checkExit(symbol, data); | |
| await checkEntry(symbol, data); | |
| } catch (error: any) { | |
| console.log(` β οΈ ${symbol}: ${error.message}`); | |
| } | |
| } | |
| // Display status every 5 cycles | |
| if (cycle % 5 === 0) { | |
| displayStatus(); | |
| } | |
| // Wait before next scan | |
| await new Promise(resolve => setTimeout(resolve, CONFIG.SCAN_INTERVAL)); | |
| } | |
| } | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // START | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| runLiveTrading().catch(console.error); | |