老田的東京上野淺草在地游
東京上野・淺草三天兩夜美食自由行:河豚與馬肉刺身的極致饗宴
從成田機場出發,搭乘 Skyliner 直抵京城上野,開啟一場充滿歷史韻味與美食誘惑的三天兩夜旅程。在上野公園漫步、於淺草寺祈福,再到隱藏版美食河豚料理與馬肉刺身大快朵頤,這是一場結合文化、風景與味蕾的東京深度探索。
 

烽志 發表在 痞客邦 留言(0) 人氣()


文/田烽志

烽志 發表在 痞客邦 留言(0) 人氣()

文/田烽志
在當今數位轉型浪潮之下,企業不斷尋求更靈活、更具彈性的運算架構,以應對激增的資料流量與即時應變需求。雲端運算雖然提供了強大的資源,但在延遲敏感與地端反應要求高的情境中,邊緣運算(Edge Computing)漸漸成為關鍵角色。

烽志 發表在 痞客邦 留言(0) 人氣()

前言:Google URL Shortener 的終章
曾經風靡全球的 Google URL Shortener(goo.gl),自 2018 年開始逐步退場,到 2025 年完全終止所有跳轉服務,宣告短網址界進入一個新的轉型期。這不僅對長期依賴 goo.gl 的使用者造成影響,也讓市場重新思考短網址服務的定位與價值。本文將深入探討短網址的應用趨勢,同時介紹兩個強而有力的新選擇:17rl.cc 與 18rl.cc,並說明它們在數位時代的應用場景、功能優勢與商業潛能。

烽志 發表在 痞客邦 留言(0) 人氣()

作為一名長期專注於 AI 與邊緣運算的工程師與技術觀察者,我——田烽志——認為,NVIDIA 所扮演的角色遠超過單一硬體供應商,它已是推動全世界 AI 與高效運算基礎架構發展的「心臟」。從自駕車、機器人、數據中心,到生成式 AI、數位孿生和醫療影像處理,每一項尖端應用的背後,幾乎都可以看到 NVIDIA GPU 的影子。

烽志 發表在 痞客邦 留言(0) 人氣()

文/田烽志
引言:三大技術全面融合驅動未來產業革新
2025 年,IoT、邊緣運算與 AI 已不再是獨立技術,而是進入緊密融合階段,形成一股協同效應,推動工業、自動化、智慧城市、醫療等領域加速轉型。企業與政府正積極投資 AIoT 架構、邊緣智慧基礎設施,這股趨勢在 NVIDIAQualcommAMD 等科技龍頭的全球戰略佈局中可見端倪。

烽志 發表在 痞客邦 留言(0) 人氣()

作者:田烽志(AI 系統開發工程師)
在一個看似平凡的城市中,有一位沉迷技術的年輕工程師叫阿志。他的世界不只存在於電路與資料,而是穿梭於『邊緣』與『雲端』之間的未知維度。

烽志 發表在 痞客邦 留言(0) 人氣()

 
作者:田烽志(AI 系統開發工程師)

烽志 發表在 痞客邦 留言(0) 人氣()

作者:田烽志(AI 系統開發工程師)
前言:斷網不是藉口,而是創新觸發點

烽志 發表在 痞客邦 留言(0) 人氣()

作者:田烽志(AI 系統開發工程師)
前言:不是所有地方都有雲端

烽志 發表在 痞客邦 留言(0) 人氣()

作者:田烽志(AI 系統開發工程師)


前言:機器人不是未來,是現在正在發生的革命

烽志 發表在 痞客邦 留言(0) 人氣()


//歡迎加入MAX交易所 https://max.maicoin.com/signup?r=6d8216c0
 
const MAX = require('max-exchange-api-node');
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
 
const max = new MAX({
  accessKey: "",
  secretKey: "",
});
const rest = max.rest();
const market = 'dogetwd';
const MIN_VOLUME = 47;
 
// 建立 SQLite DB
const db = new sqlite3.Database('aaa.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, err => {
  if (err) return console.error(err);
  // 切換到 Write-Ahead Logging,減少寫鎖衝突
  db.run("PRAGMA journal_mode = WAL;");
  // 當遇到 busy(忙碌)狀態時,最多等待 5 秒再失敗
  db.configure("busyTimeout", 5000);
  // 把後續所有操作都排成序列執行,避免平行化寫入
  db.serialize();
});
db.run(`CREATE TABLE IF NOT EXISTS trade_log (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  side TEXT,
  volume REAL,
  price REAL,
  amount_twd REAL,
  balance_before REAL,
  balance_after REAL,
  profit REAL,
  timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)`);
 
startLoop();
 
async function startLoop() {
  let lastPrice = null;
 
  while (true) {
    try {
 
      const shouldBuy = await detectBuySignal();
      const shouldSell = await detectSellSignal();
      const tick = await rest.ticker({ market });
 
      const dogeBal = parseFloat((await rest.account('doge')).balance);
      const twdBal = parseFloat((await rest.account('twd')).balance);
      const price = shouldBuy ? parseFloat(tick.sell) : parseFloat(tick.buy);
      const totalTwd = price * MIN_VOLUME;
      const before = twdBal + dogeBal * price;
 
      const avgCost = await getAverageCost();
      // ✅ 買入條件 A:有訊號、資金足夠、低於平均成本
      const buyConditionA = shouldBuy && twdBal > totalTwd && (!avgCost || price <= avgCost);
 
      // ✅ 買入條件 B:與上次價格相比下跌超過
      const buyConditionB = lastPrice && price < lastPrice * 0.999 && twdBal > totalTwd;
 
      // ✅ 買入條件 C:單邊上漲超過
       
      const buyConditionC = lastPrice && price > lastPrice * 1.004 && twdBal > totalTwd;
      if (buyConditionA || buyConditionB || buyConditionC) {
        let reason = '';
        if (buyConditionA) {
          reason = `[🟢 BUY-A] 有訊號且價格 ${price.toFixed(4)} < 成本 ${avgCost?.toFixed(4) ?? 'N/A'}`;
        } else if (buyConditionB) {
          reason = `[📉 BUY-B] 價格從 ${lastPrice.toFixed(4)} 下跌超過 1% ➜ ${price.toFixed(4)}`;
        } else if (buyConditionC) {
          reason = `[📈 BUY-C] 價格從 ${lastPrice.toFixed(4)} 上漲超過 0.5% ➜ ${price.toFixed(4)}`;
        }
        console.log(`${reason},嘗試買入 ${MIN_VOLUME} DOGE`);
        await rest.placeOrder({
          market,
          volume: MIN_VOLUME.toString(),
          side: 'buy',
          ordType: 'market',
        });
        await recordTrade('buy', MIN_VOLUME, price, before);
 
      } else if (shouldSell && dogeBal >= MIN_VOLUME) {
        // 🔴 賣出條件
        if (avgCost && price >= avgCost + 0.1) {
          console.log(`[🔴 SELL] 當前價格 ${price} > 成本 ${avgCost.toFixed(4)},賣出 ${MIN_VOLUME} DOGE`);
          await rest.placeOrder({
            market,
            volume: MIN_VOLUME.toString(),
            side: 'sell',
            ordType: 'market',
          });
          await recordTrade('sell', MIN_VOLUME, price, before);
        } else {
          console.log(`[🟡 HOLD] 當前價格 ${price} <= 成本 ${avgCost?.toFixed(4) ?? 'N/A'},不賣出`);
        }
 
      } else {
        console.log('[⏸️ HOLD] 無明確訊號、價格不合條件,或資產不足');
      }
 
      lastPrice = price;
 
    } catch (err) {
      console.error('❌ 錯誤:', err.message || err);
    }
 
    showTodayStats();
    await sleep(5000);
  }
}
 
async function recordTrade(side, volume, price, balanceBefore) {
  await sleep(2000); // 等待資產更新
  const dogeBal = parseFloat((await rest.account('doge')).balance);
  const twdBal = parseFloat((await rest.account('twd')).balance);
  const after = twdBal + dogeBal * price;
  const profit = after - balanceBefore;
 
  db.run(`INSERT INTO trade_log (side, volume, price, amount_twd, balance_before, balance_after, profit)
          VALUES (?, ?, ?, ?, ?, ?, ?)`,
    [side, volume, price, price * volume, balanceBefore, after, profit],
    err => {
      if (err) {
        console.error("❌ 無法寫入交易記錄", err.message);
      } else {
        console.log(`✅ 已記錄 ${side} 成交: ${volume} DOGE @ ${price}, 盈虧: ${profit.toFixed(2)} TWD`);
        showTodayStats();
      }
    });
}
 
function getAverageCost() {
  return new Promise((resolve, reject) => {
    db.all(`SELECT volume, amount_twd FROM trade_log WHERE side = 'buy'`, (err, rows) => {
      if (err) {
        console.error("❌ 無法計算平均成本", err.message);
        return reject(err);
      }
 
      const totalVolume = rows.reduce((sum, r) => sum + r.volume, 0);
      const totalAmount = rows.reduce((sum, r) => sum + r.amount_twd, 0);
      const avgCost = totalVolume > 0 ? totalAmount / totalVolume : null;
 
      resolve(avgCost);
    });
  });
}
 
function showTodayStats() {
  db.all(
    `SELECT side, volume, amount_twd, profit FROM trade_log`,
    [],
    (err, rows) => {
      if (err) {
        return console.error("❌ 統計失敗", err.message);
      }
 
      const totalTrades = rows.length;
      const profitTrades = rows.filter(r => r.profit > 0).length;
      const lossTrades = rows.filter(r => r.profit <= 0).length;
      const totalProfit = rows.reduce((sum, r) => sum + r.profit, 0);
      const winRate = totalTrades > 0
        ? (profitTrades / totalTrades * 100).toFixed(2) + '%'
        : '0.00%';
 
      // 計算所有買入的平均成本
      const buyTrades = rows.filter(r => r.side === 'buy');
      const totalBuyVolume = buyTrades.reduce((sum, r) => sum + r.volume, 0);
      const totalBuyAmount = buyTrades.reduce((sum, r) => sum + r.amount_twd, 0);
      const avgCost = totalBuyVolume > 0
        ? (totalBuyAmount / totalBuyVolume).toFixed(4)
        : 'N/A';
 
    }
  );
}
 
async function detectBuySignal() {
  const candles = await rest.k({ market, period: 1, limit: 30 });
  const closes = candles.map(c => parseFloat(c[4])); // close
  const rsi = calcRSI(closes, 14);
  const { lower } = calcBollinger(closes, 20);
  const last = closes.at(-1);
  return rsi < 25 && last < lower;
}
 
async function detectSellSignal() {
  const candles = await rest.k({ market, period: 1, limit: 30 });
  const closes = candles.map(c => parseFloat(c[4])); // close
  const rsi = calcRSI(closes, 14);
  const { upper } = calcBollinger(closes, 20);
  const last = closes.at(-1);
  return rsi > 75 && last > upper;
}
 
function calcRSI(closes, period) {
  if (closes.length < period + 1) return 50; // return neutral if not enough data
 
  let gainSum = 0, lossSum = 0;
  for (let i = closes.length - period - 1; i < closes.length - 1; i++) {
    const change = closes[i + 1] - closes[i];
    if (change > 0) gainSum += change;
    else lossSum -= change;
  }
 
  const avgGain = gainSum / period;
  const avgLoss = lossSum / period || 1;
 
  const rs = avgGain / avgLoss;
  const rsi = 100 - (100 / (1 + rs));
 
  // 自動調整閾值範圍:根據波動性偏移 RSI 評分
  const recentVolatility = Math.max(...closes.slice(-5)) - Math.min(...closes.slice(-5));
  const baselineVolatility = Math.max(...closes.slice(-period)) - Math.min(...closes.slice(-period));
 
  const volatilityFactor = recentVolatility / (baselineVolatility || 1);
 
  // 假如波動大,代表趨勢強,允許 RSI 更極端
  if (volatilityFactor > 1.3 && rsi < 50) {
    return rsi - 5;
  } else if (volatilityFactor > 1.3 && rsi > 50) {
    return rsi + 5;
  }
 
  return rsi;
}
 
function calcBollinger(closes, period) {
  const slice = closes.slice(-period);
  const avg = slice.reduce((a, b) => a + b, 0) / slice.length;
  const std = Math.sqrt(slice.reduce((sum, val) => sum + (val - avg) ** 2, 0) / period);
  return { lower: avg - 2 * std, upper: avg + 2 * std };
}
 
function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

烽志 發表在 痞客邦 留言(0) 人氣()

1 2 3
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。