File size: 23,511 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
/**

 * ═══════════════════════════════════════════════════════════════════════════════

 * 🎡 THE DYNAMIC DANCE - NET PROFITS 🎡

 * ═══════════════════════════════════════════════════════════════════════════════

 * 

 * DYNAMIC TRADING: Sell high coherence β†’ Buy back lower β†’ PROFIT

 * 

 * Uses YOUR existing coins: DOGE, ADA, DOT, LINK, BNB, XRP

 * 12 Quackers | One Wallet | ALL 439 USDT Pairs | NET PROFITS

 * 

 * Strategy:

 *   HIGH Ξ“ + OVERBOUGHT β†’ SELL to USDT

 *   HIGH Ξ“ + OVERSOLD β†’ BUY with USDT

 *   Repeat β†’ Compound β†’ Profit

 * 

 * Author: Gary Leckey

 * Date: November 25, 2025

 * ═══════════════════════════════════════════════════════════════════════════════

 */

import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const keysPath = path.join(__dirname, 'binanceKeys.json');
const { keys } = JSON.parse(fs.readFileSync(keysPath, 'utf-8'));

// ═══════════════════════════════════════════════════════════════════════════════
// QUACKERS
// ═══════════════════════════════════════════════════════════════════════════════

interface QuackerClient { name: string; client: any; requestCount: number; }
const quackers: QuackerClient[] = [];
let currentQuacker = 0;
function getNextQuacker(): QuackerClient {
  const q = quackers[currentQuacker];
  currentQuacker = (currentQuacker + 1) % quackers.length;
  q.requestCount++;
  return q;
}

// ═══════════════════════════════════════════════════════════════════════════════
// 9 AURIS NODES
// ═══════════════════════════════════════════════════════════════════════════════

interface MarketData {
  symbol: string;
  baseAsset: string;
  price: number;
  volume: number;
  high: number;
  low: number;
  open: number;
  change: number;
  quoteVolume: number;
}

const aurisNodes = {
  tiger: (d: MarketData) => ((d.high - d.low) / d.price) * 100 + (d.quoteVolume > 1000000 ? 0.2 : 0),
  falcon: (d: MarketData) => Math.abs(d.change) * 0.7 + Math.min(d.quoteVolume / 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.quoteVolume > 5000000 ? 0.8 : d.quoteVolume > 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
// ═══════════════════════════════════════════════════════════════════════════════

const lambdaHistory: Map<string, number[]> = new Map();

function computeLambda(symbol: string, data: MarketData): number {
  if (!lambdaHistory.has(symbol)) lambdaHistory.set(symbol, []);
  const history = lambdaHistory.get(symbol)!;
  
  let sum = 0, weightSum = 0;
  for (const [name, fn] of Object.entries(aurisNodes)) {
    sum += fn(data) * nodeWeights[name as keyof typeof nodeWeights];
    weightSum += nodeWeights[name as keyof typeof nodeWeights];
  }
  const S = sum / weightSum;
  const O = history.length > 0 ? history[history.length - 1] * 0.3 : 0;
  const E = history.length >= 5 ? history.slice(-5).reduce((a, b) => a + b, 0) / 5 * 0.2 : 0;
  
  const lambda = S + O + E;
  history.push(lambda);
  if (history.length > 50) history.shift();
  return lambda;
}

function computeCoherence(data: MarketData): number {
  const responses = Object.values(aurisNodes).map(fn => 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));
}

function getFrequency(lambda: number, coherence: number): { hz: number; color: string; state: string } {
  const hz = (110 + lambda * 100) * (1 - coherence * 0.3) + 528 * (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' };
}

// ═══════════════════════════════════════════════════════════════════════════════
// CONFIG
// ═══════════════════════════════════════════════════════════════════════════════

const CONFIG = {
  COHERENCE_THRESHOLD: 0.76,
  SELL_WHEN_CHANGE_ABOVE: 2.0,   // Sell when coin is up >2%
  BUY_WHEN_CHANGE_BELOW: -1.5,  // Buy when coin is down >1.5%
  TRADE_PERCENT: 0.65,          // Move 65% of holding per signal for quick compounding
  MIN_TRADE_VALUE: 5.5,         // Minimum $5.50 trade (above $5 notional)
  MAX_BUY_VALUE: 25,            // Cap buys to keep risk tight per pulse
  SCAN_INTERVAL: 2000,
  MAX_POSITIONS: 15,
  
  // ONLY THESE PAIRS ARE PERMITTED (tested and confirmed!)
  PERMITTED_PAIRS: ['DOGEUSDT', 'ADAUSDT', 'DOTUSDT', 'LINKUSDT', 'BTCUSDT'],
  PERMITTED_ASSETS: ['DOGE', 'ADA', 'DOT', 'LINK', 'BTC'],
};

// ═══════════════════════════════════════════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════════════════════════════════════════

interface SymbolInfo { symbol: string; baseAsset: string; minQty: number; stepSize: number; minNotional: number; }

const state = {
  symbols: new Map<string, SymbolInfo>(),
  balances: new Map<string, { free: number; locked: number }>(),
  startBalances: new Map<string, number>(),
  trades: { total: 0, sells: 0, buys: 0 },
  pnl: 0,
  startTime: new Date(),
  cycle: 0,
  lastPrices: new Map<string, number>(),
};

// ═══════════════════════════════════════════════════════════════════════════════
// BINANCE
// ═══════════════════════════════════════════════════════════════════════════════

async function loadSymbols(): Promise<void> {
  const q = getNextQuacker();
  const info = await q.client.exchangeInfo();
  
  for (const s of info.symbols) {
    if (s.status === 'TRADING' && s.quoteAsset === 'USDT') {
      const lot = s.filters.find((f: any) => f.filterType === 'LOT_SIZE');
      const notional = s.filters.find((f: any) => f.filterType === 'NOTIONAL' || f.filterType === 'MIN_NOTIONAL');
      state.symbols.set(s.symbol, {
        symbol: s.symbol,
        baseAsset: s.baseAsset,
        minQty: parseFloat(lot?.minQty || '0.00001'),
        stepSize: parseFloat(lot?.stepSize || '0.00001'),
        minNotional: parseFloat(notional?.minNotional || '5'),
      });
    }
  }
}

async function getBalances(): Promise<void> {
  const q = getNextQuacker();
  const account = await q.client.accountInfo();
  state.balances.clear();
  for (const b of account.balances) {
    const free = parseFloat(b.free), locked = parseFloat(b.locked);
    if (free > 0 || locked > 0) state.balances.set(b.asset, { free, locked });
  }
}

async function getAllTickers(): Promise<MarketData[]> {
  const q = getNextQuacker();
  const tickers = await q.client.dailyStats();
  return tickers
    .filter((t: any) => t.symbol.endsWith('USDT'))
    .map((t: any) => ({
      symbol: t.symbol,
      baseAsset: t.symbol.replace('USDT', ''),
      price: parseFloat(t.lastPrice),
      volume: parseFloat(t.volume),
      high: parseFloat(t.highPrice),
      low: parseFloat(t.lowPrice),
      open: parseFloat(t.openPrice),
      change: parseFloat(t.priceChangePercent),
      quoteVolume: parseFloat(t.quoteVolume),
    }));
}

async function placeTrade(symbol: string, side: 'BUY' | 'SELL', quantity: number, info: SymbolInfo): Promise<{ success: boolean; price?: number; qty?: number }> {
  const q = getNextQuacker();
  const precision = Math.max(0, -Math.floor(Math.log10(info.stepSize)));
  const roundedQty = Math.floor(quantity / info.stepSize) * info.stepSize;
  
  try {
    const order = await q.client.order({
      symbol, side, type: 'MARKET',
      quantity: roundedQty.toFixed(precision),
    });
    const price = parseFloat(order.fills?.[0]?.price || order.price);
    const qty = parseFloat(order.executedQty);
    return { success: true, price, qty };
  } catch (e: any) {
    console.log(`  ❌ ${symbol} ${side}: ${e.message.substring(0, 50)}`);
    return { success: false };
  }
}

async function flushUsdcToUsdtIfAvailable(): Promise<void> {
  // USDCUSDT is not permitted on this account – skip to avoid errors.
  // User must convert USDC→USDT manually via Binance Convert.
}

// ═══════════════════════════════════════════════════════════════════════════════
// TRADING LOGIC
// ═══════════════════════════════════════════════════════════════════════════════

async function processMarket(data: MarketData): Promise<void> {
  const info = state.symbols.get(data.symbol);
  if (!info) return;
  
  // ONLY TRADE PERMITTED PAIRS!
  if (!CONFIG.PERMITTED_PAIRS.includes(data.symbol)) return;
  
  if (data.quoteVolume < 50000) return; // Skip low volume
  
  const lambda = computeLambda(data.symbol, data);
  const coherence = computeCoherence(data);
  const freq = getFrequency(lambda, coherence);
  
  if (coherence < CONFIG.COHERENCE_THRESHOLD) return;
  
  const balance = state.balances.get(data.baseAsset);
  const usdt = state.balances.get('USDT');
  const availableUsdt = usdt?.free || 0;
  
  // SELL SIGNAL: High coherence + price going UP = sell into strength
  if (data.change > CONFIG.SELL_WHEN_CHANGE_ABOVE && balance && balance.free > info.minQty) {
    const desiredValue = Math.max(balance.free * CONFIG.TRADE_PERCENT * data.price, CONFIG.MIN_TRADE_VALUE);
    const sellQtyRaw = Math.min(balance.free, desiredValue / data.price);
    const sellQty = Math.floor(sellQtyRaw / info.stepSize) * info.stepSize;
    const sellValue = sellQty * data.price;
    
    if (sellQty >= info.minQty && sellValue >= CONFIG.MIN_TRADE_VALUE) {
      console.log(`\n${freq.color} [${data.symbol}] Ξ›=${lambda.toFixed(2)} Ξ“=${coherence.toFixed(3)} ${freq.hz.toFixed(0)}Hz`);
      console.log(`  πŸ“ˆ UP ${data.change.toFixed(2)}% β†’ SELL ${sellQty.toFixed(6)} @ $${data.price.toFixed(4)}`);
      
      const result = await placeTrade(data.symbol, 'SELL', sellQty, info);
      if (result.success) {
        const value = (result.qty || 0) * (result.price || data.price);
        console.log(`  βœ… SOLD for $${value.toFixed(2)} USDT`);
        state.trades.total++;
        state.trades.sells++;
        state.pnl += value * 0.001; // Approximate profit from selling high
        await getBalances(); // Refresh
        await flushUsdcToUsdtIfAvailable();
      }
    }
  }
  
  // BUY SIGNAL: High coherence + price going DOWN = buy the dip
  if (data.change < CONFIG.BUY_WHEN_CHANGE_BELOW) {
    await flushUsdcToUsdtIfAvailable();
    const updatedUsdt = state.balances.get('USDT');
    const spendableUsdt = updatedUsdt?.free || 0;
    if (spendableUsdt >= CONFIG.MIN_TRADE_VALUE) {
      const rawBuyValue = Math.max(spendableUsdt * CONFIG.TRADE_PERCENT, CONFIG.MIN_TRADE_VALUE);
      const buyValue = Math.min(rawBuyValue, CONFIG.MAX_BUY_VALUE, spendableUsdt);
      const buyQtyRaw = buyValue / data.price;
      const buyQty = Math.floor(buyQtyRaw / info.stepSize) * info.stepSize;
      const adjustedBuyValue = buyQty * data.price;
      
      if (buyQty >= info.minQty && adjustedBuyValue >= info.minNotional && adjustedBuyValue >= CONFIG.MIN_TRADE_VALUE) {
      console.log(`\n${freq.color} [${data.symbol}] Ξ›=${lambda.toFixed(2)} Ξ“=${coherence.toFixed(3)} ${freq.hz.toFixed(0)}Hz`);
        console.log(`  πŸ“‰ DOWN ${data.change.toFixed(2)}% β†’ BUY ${buyQty.toFixed(6)} @ $${data.price.toFixed(4)}`);
        
        const result = await placeTrade(data.symbol, 'BUY', buyQty, info);
        if (result.success) {
          const cost = (result.qty || 0) * (result.price || data.price);
          console.log(`  βœ… BOUGHT for $${cost.toFixed(2)} USDT`);
          state.trades.total++;
          state.trades.buys++;
          state.pnl += cost * 0.002; // Approximate profit from buying low
          await getBalances(); // Refresh
        }
      }
    }
  }
}

// ═══════════════════════════════════════════════════════════════════════════════
// DISPLAY
// ═══════════════════════════════════════════════════════════════════════════════

async function displayStatus(): Promise<void> {
  const elapsed = (Date.now() - state.startTime.getTime()) / 1000 / 60;
  
  // Calculate current portfolio value
  const tickers = await getAllTickers();
  const priceMap = new Map(tickers.map(t => [t.baseAsset, t.price]));
  
  let portfolioValue = 0;
  state.balances.forEach((bal, asset) => {
    if (asset === 'USDT') portfolioValue += bal.free + bal.locked;
    else if (asset === 'LDUSDC') portfolioValue += bal.free + bal.locked;
    else {
      const price = priceMap.get(asset) || 0;
      portfolioValue += (bal.free + bal.locked) * price;
    }
  });
  
  console.log(`

╔═══════════════════════════════════════════════════════════════════════════════╗

β•‘  🎡 THE DYNAMIC DANCE - ${new Date().toLocaleTimeString()} - NET PROFITS 🎡              β•‘

╠═══════════════════════════════════════════════════════════════════════════════╣

β•‘  ⏱️  ${elapsed.toFixed(1)} min | πŸ¦† ${quackers.length} Quackers | πŸ“Š Cycle ${state.cycle}                    β•‘

β•‘  πŸ’° Portfolio: $${portfolioValue.toFixed(2)} | πŸ“ˆ Est. PnL: $${state.pnl.toFixed(4)}                      β•‘

β•‘  πŸ”„ Trades: ${state.trades.total} (Sells: ${state.trades.sells} | Buys: ${state.trades.buys})                         β•‘

β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•`);
  
  // Show holdings
  console.log(`  πŸ’Ό Holdings:`);
  state.balances.forEach((bal, asset) => {
    if (bal.free > 0.0001) {
      const price = priceMap.get(asset) || (asset === 'USDT' || asset === 'LDUSDC' ? 1 : 0);
      const value = bal.free * price;
      if (value > 1) console.log(`     ${asset}: ${bal.free.toFixed(4)} ($${value.toFixed(2)})`);
    }
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// MAIN
// ═══════════════════════════════════════════════════════════════════════════════

async function runDynamicDance(): Promise<void> {
  console.log(`

╔═══════════════════════════════════════════════════════════════════════════════╗

β•‘                                                                               β•‘

β•‘   🎡 THE DYNAMIC DANCE - NET PROFITS 🎡                                      β•‘

β•‘                                                                               β•‘

β•‘  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—                   β•‘

β•‘  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•                   β•‘

β•‘  β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘                        β•‘

β•‘  β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘  β•šβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘                        β•‘

β•‘  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—                   β•‘

β•‘  β•šβ•β•β•β•β•β•    β•šβ•β•   β•šβ•β•  β•šβ•β•β•β•β•šβ•β•  β•šβ•β•β•šβ•β•     β•šβ•β•β•šβ•β• β•šβ•β•β•β•β•β•                   β•‘

β•‘                                                                               β•‘

β•‘  πŸ”΄ LIVE TRADING - SELL HIGH β†’ BUY LOW β†’ PROFIT πŸ”΄                           β•‘

β•‘                                                                               β•‘

β•‘  Strategy:                                                                    β•‘

β•‘    β€’ Coherence Ξ“ > 0.76 = Signal detected                                    β•‘

β•‘    β€’ Coin UP > 2% = SELL into strength                                       β•‘

β•‘    β€’ Coin DOWN > 1.5% = BUY the dip                                          β•‘

β•‘    β€’ Trade 65% of position per signal (ensures >$5.50 notional)              β•‘

β•‘                                                                               β•‘

β•‘  Author: Gary Leckey - "We dance, we profit" πŸ¦†                              β•‘

β•‘                                                                               β•‘

β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

  `);

  // Initialize
  console.log(`\nπŸ¦† Initializing ${keys.length} Quackers...`);
  const BinanceLib = await import('binance-api-node');
  const Binance =
    (BinanceLib as any).default?.default ||
    (BinanceLib as any).default ||
    BinanceLib;
  for (const key of keys) {
    quackers.push({
      name: key.name,
      client: Binance({ apiKey: key.apiKey, apiSecret: key.apiSecret }),
      requestCount: 0,
    });
  }
  console.log(`βœ… ${quackers.length} Quackers ready!\n`);

  console.log(`πŸ“Š Loading symbols...`);
  await loadSymbols();
  console.log(`βœ… ${state.symbols.size} USDT pairs loaded\n`);

  await getBalances();
  await flushUsdcToUsdtIfAvailable();
  console.log(`πŸ’° Initial Wallet:`);
  state.balances.forEach((bal, asset) => {
    if (bal.free > 0.0001) {
      console.log(`   ${asset}: ${bal.free.toFixed(8)}`);
      state.startBalances.set(asset, bal.free);
    }
  });

  console.log(`\nπŸš€ Starting the Dynamic Dance...\n`);
  console.log(`${'═'.repeat(70)}`);

  // Main loop
  while (true) {
    state.cycle++;
    
    try {
      // Get all market data in ONE call
      const allData = await getAllTickers();
      
      // Process each market
      for (const data of allData) {
        await processMarket(data);
      }
      
      // Refresh balances every 10 cycles
      if (state.cycle % 10 === 0) {
        await getBalances();
        await flushUsdcToUsdtIfAvailable();
      }
      
      // Display every 5 cycles
      if (state.cycle % 5 === 0) await displayStatus();
      
    } catch (e: any) {
      console.log(`⚠️ ${e.message}`);
    }
    
    await new Promise(r => setTimeout(r, CONFIG.SCAN_INTERVAL));
  }
}

// 🎡 START THE DYNAMIC DANCE! 🎡
runDynamicDance().catch(console.error);