diff --git a/.gitignore b/.gitignore index 2c73ccf..8e77a12 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ rec/* */__pycache__/* __pycache__ agent-py-bot/scrape/raw/summary_log.txt -agent-py-bot/scrape/raw/* \ No newline at end of file +agent-py-bot/scrape/raw/* +.aider* +tts/*.m4a +agent-mobile/jdk/* diff --git a/Niki/new.pine b/Niki/new.pine new file mode 100644 index 0000000..5c04adc --- /dev/null +++ b/Niki/new.pine @@ -0,0 +1,125 @@ +//@version=5 +indicator("DrNiki's Market Nuker", shorttitle="DrNiki's Market Nuker", overlay=true) + + + +// /* +// create a calculator in pinescript that uses all of this data at the same time: +// here are the pairs: +// -US30 +// -GOLD +// -DXY (for this pair inverse the results, each long point goes to a short point and vice versa) +// -BTCUSDT.P +// -syminfo.ticker +// (e.g.:pairs = ["US30", "GOLD", "DXY", "BTCUSDT.P", syminfo.ticker]) + +// use these 4 timeframes: +// 1 hour +// 2 hour +// 3 hour +// 4 hour + +// Use these 4 indicators: + +// Wavetrend with crosses [LazyBear] and use wt1 only - when it goes higher than the previous candle from the timeframe specified (we specified 4 timeframes) give it 1 point for longs. When it goes lower than the previous candle from the current timeframe specified (we specified 4 timeframes) give it 1 point for shorts + +// for rsi do the same + +// for stoch rsi K line do the same + +// for OBV do the same + +// DO it on all pairs and on all timeframes at the same time, the maximum odds should be 100% total. write the results in a text with the odds per pair for a long and short based on each timeframe and pair and based on each pair and timeframe. +// Then have a total when you have the most efficient way of combining them calculated + + +// */ + + + +// [Input for Indicators] +rsiLength = input(14, title="RSI Length") +stochRsiLength = input(14, title="Stochastic RSI Length") +n1 = input(10, title="WT Channel Length") +n2 = input(21, title="WT Average Length") + +// Wavetrend Indicator Calculation +ap = hlc3 +esa = ta.ema(ap, n1) +d = ta.ema(math.abs(ap - esa), n1) +ci = (ap - esa) / (0.015 * d) +tci = ta.ema(ci, n2) + +wt1 = tci +wt2 = ta.sma(wt1, 4) + +// Custom implementation of On Balance Volume (OBV) +var float obv = na +obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv + +// Money Flow Index (MFI) +mfiLength = input(7, title="MFI Length") +mfiValue = ta.mfi(close, mfiLength) + + +// RSI and Stochastic RSI Calculation +rsiValue = ta.rsi(close, rsiLength) +stochRsiValue = ta.stoch(rsiValue, rsiValue, rsiValue, stochRsiLength) + + +// [Function to calculate points for a given indicator and pair] + +// Function to calculate points for a given indicator and pair +calcPoints(currentValue, previousValue, isInverse) => + value = 0 + if isInverse + value := currentValue < previousValue ? 1 : currentValue > previousValue ? -1 : 0 + else + value := currentValue > previousValue ? 1 : currentValue < previousValue ? -1 : 0 + value + +// Calculate points for each currency pair +longPoints(pair, isInverse) => + rsiP = calcPoints(rsiValue, rsiValue[1], isInverse) + stochRsiP = calcPoints(stochRsiValue, stochRsiValue[1], isInverse) + wavetrendP = calcPoints(wt1, wt1[1], isInverse) + rsiP + stochRsiP + wavetrendP + +shortPoints(pair, isInverse) => -longPoints(pair, isInverse) + + +// Hardcoded pairs and their corresponding inverse flags +pairs = array.new_string(5) +array.set(pairs, 0, "US30") +array.set(pairs, 1, "GOLD") +array.set(pairs, 2, "DXY") +array.set(pairs, 3, "BTCUSDT.P") +array.set(pairs, 4, syminfo.tickerid) + +isInverse = array.new_bool(5, false) +array.set(isInverse, 2, true) // Inverse for DXY + +// Initialize variables for storing points +var float totalLongPoints = 0 +var float totalShortPoints = 0 + +// Calculate points for each pair +longPointsArray = array.new_float(5) +shortPointsArray = array.new_float(5) +for i = 0 to 4 + pair = array.get(pairs, i) + inverseFlag = array.get(isInverse, i) + array.set(longPointsArray, i, longPoints(pair, inverseFlag)) + array.set(shortPointsArray, i, shortPoints(pair, inverseFlag)) + +// Update total points +for i = 0 to 4 + totalLongPoints := totalLongPoints + array.get(longPointsArray, i) + totalShortPoints := totalShortPoints + array.get(shortPointsArray, i) + +// Display the results +plot(totalLongPoints, title="Total Long Points", color=color.blue) +plot(totalShortPoints, title="Total Short Points", color=color.orange) + + +// Display \ No newline at end of file diff --git a/Niki/niki-refactored.pine b/Niki/niki-refactored.pine new file mode 100644 index 0000000..646c2c2 --- /dev/null +++ b/Niki/niki-refactored.pine @@ -0,0 +1,129 @@ +//@version=5 +indicator("DrNiki's Market Nuker", shorttitle="DrNiki's Market Nuker", overlay=true) + +// Function to calculate RSI +rsiLength = input(14, title="RSI Length") +stochRsiLength = input(14, title="Stochastic RSI Length") +n1 = input(10, "Channel Length") +n2 = input(21, "Average Length") +mfiLength = input(7, title="MFI Length") + + +// calcRSI() => ta.rsi(close, rsiLength) +// // Function to calculate Stochastic RSI +// calcStochRSI() => ta.stoch(close, close, close, stochRsiLength) +// // Function to calculate Wavetrend +// calcWavetrend() => +// ap = hlc3 +// esa = ta.ema(ap, n1) +// d = ta.ema(math.abs(ap - esa), n1) +// ci = (ap - esa) / (0.015 * d) +// tci = ta.ema(ci, n2) +// wt1 = tci +// wt2 = ta.sma(wt1, 4) +// [wt1, wt2] + +// // Function to calculate On Balance Volume (OBV) +// calcOBV() => +// var float obv = na +// obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv +// obv + +// // Function to calculate MFI +// calcMFI() => ta.mfi(close, mfiLength) + + +calcRSI(source) => ta.rsi(source, rsiLength) +calcStochRSI(source) => ta.stoch(source, source, source, stochRsiLength) +calcWavetrend(source) => + ap = source + esa = ta.ema(ap, n1) + d = ta.ema(math.abs(ap - esa), n1) + ci = (ap - esa) / (0.015 * d) + tci = ta.ema(ci, n2) + wt1 = tci + wt2 = ta.sma(wt1, 4) + [wt1, wt2] + +calcOBV(source, volumeSource) => + var float obv = na + obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv + obv + +calcMFI(source) => ta.mfi(source, mfiLength) + +// Function to calculate points for a symbol +calcPoints(symbol) => + rsiValue = request.security(symbol, timeframe.period, calcRSI(close), barmerge.gaps_off, barmerge.lookahead_on) + stochRsiValue = request.security(symbol, timeframe.period, calcStochRSI(close), barmerge.gaps_off, barmerge.lookahead_on) + [wt1, wt2] = request.security(symbol, timeframe.period, calcWavetrend(close), barmerge.gaps_off, barmerge.lookahead_on) + obv = request.security(symbol, timeframe.period, calcOBV(close, volume), barmerge.gaps_off, barmerge.lookahead_on) + mfiValue = request.security(symbol, timeframe.period, calcMFI(close), barmerge.gaps_off, barmerge.lookahead_on) + + longPoints = 0 + shortPoints = 0 + longPoints := rsiValue > rsiValue[1] ? longPoints + 1 : longPoints + shortPoints := rsiValue < rsiValue[1] ? shortPoints + 1 : shortPoints + longPoints := stochRsiValue > stochRsiValue[1] ? longPoints + 1 : longPoints + shortPoints := stochRsiValue < stochRsiValue[1] ? shortPoints + 1 : shortPoints + longPoints := wt1 > wt1[1] ? longPoints + 1 : longPoints + shortPoints := wt1 < wt1[1] ? shortPoints + 1 : shortPoints + longPoints := obv > obv[1] ? longPoints + 1 : longPoints + shortPoints := obv < obv[1] ? shortPoints + 1 : shortPoints + longPoints := mfiValue > 50 ? longPoints + 1 : longPoints + shortPoints := mfiValue < 50 ? shortPoints + 1 : shortPoints + var logMessage = "Symbol: " + symbol + ", Long: " + str.tostring(longPoints) + ", Short: " + str.tostring(shortPoints) + log.info(logMessage) + [longPoints, shortPoints] + +// Symbols array +symbols = array.new_string(5) +array.set(symbols, 0, syminfo.ticker) // Replace with the symbol of your chart +array.set(symbols, 1, "GOLD") +array.set(symbols, 2, "DXY") +array.set(symbols, 3, "BTCUSDT.P") +array.set(symbols, 4, "US30") + + +var string[] list = array.from(syminfo.ticker, "GOLD", "DXY", "BTCUSDT.P", "US30") +var string sym = "" + +for i in list + log.info(i) + [longPoints, shortPoints] = calcPoints(i) + sym := i + " " + var logMessage = "| sym: " + sym + " " + i + barTimeStr = str.format_time(time, "yyyy-MM-dd HH:mm:ss", "Europe/Sofia") + log.info(logMessage) + +log.info("-------------------------") + +// Calculate points for each symbol +var symbolPoints = array.new_int(size=array.size(symbols) * 2, initial_value=0) +for i in list + var sm = i +" " + barTimeStr = str.format_time(time, "yyyy-MM-dd HH:mm:ss", "Europe/Sofia") + var logMessage = barTimeStr + "| Symbol: " + i + "sm: " + sm + log.info(logMessage) + //rsiValue = request.security(symbol, timeframe.period, calcRSI(close), barmerge.gaps_off, barmerge.lookahead_on) + + // Change symbol context using security() function + // [longPoints, shortPoints] = calcPoints(symbol.symbol) + // array.set(symbolPoints, 0, array.get(symbolPoints, 0) + longPoints) + // array.set(symbolPoints, 1, array.get(symbolPoints, 1) + shortPoints) + +// Calculate total long and short probabilities +totalLongPoints = array.get(symbolPoints, 0) +totalShortPoints = array.get(symbolPoints, 1) +combinedProbabilityLong = totalLongPoints / (array.size(symbols) * 3) * 100 +combinedProbabilityShort = totalShortPoints / (array.size(symbols) * 3) * 100 + +// Display combined probabilities +var labelBox = label.new(na, na, "") +label.set_xy(labelBox, bar_index, high) +label.set_text(labelBox, "Combined Probabilities\nLong: " + str.tostring(combinedProbabilityLong) + "%\nShort: " + str.tostring(combinedProbabilityShort) + "%") +label.set_color(labelBox, color.new(color.blue, 0)) +label.set_style(labelBox, label.style_label_left) + + + diff --git a/Niki/niki.pine b/Niki/niki.pine new file mode 100644 index 0000000..47f74f5 --- /dev/null +++ b/Niki/niki.pine @@ -0,0 +1,111 @@ +//@version=5 +indicator("Divergence Odds Calculator", shorttitle="DrNiki DivOdds", overlay=true) + +// Function to detect bullish divergence +bullishDivergence(src, refSrc, rsiSrc, overboughtLevel, oversoldLevel) => + priceHigh = ta.highest(src, 5) + rsiHigh = ta.highest(rsiSrc, 5) + priceLow = ta.lowest(src, 5) + rsiLow = ta.lowest(rsiSrc, 5) + + priceDiv = (src > priceHigh[1] and rsiSrc > rsiHigh[1]) ? true : false + rsiDiv = (rsiSrc > rsiHigh[1] and src > priceHigh[1]) ? true : false + + priceDiv or rsiDiv + +// Function to detect bearish divergence +bearishDivergence(src, refSrc, rsiSrc, overboughtLevel, oversoldLevel) => + priceHigh = ta.highest(src, 5) + rsiHigh = ta.highest(rsiSrc, 5) + priceLow = ta.lowest(src, 5) + rsiLow = ta.lowest(rsiSrc, 5) + + priceDiv = (src < priceLow[1] and rsiSrc < rsiLow[1]) ? true : false + rsiDiv = (rsiSrc < rsiLow[1] and src < priceLow[1]) ? true : false + + priceDiv or rsiDiv + +// RSI settings +rsiLength = input(14, title="RSI Length") +rsiOverbought = input(70, title="RSI Overbought Level") +rsiOversold = input(30, title="RSI Oversold Level") +rsiSrc = ta.rsi(close, rsiLength) + +// Calculate the number of occurrences of bullish and bearish divergences for different periods +bullishCount1 = ta.barssince(bullishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[1] + 1 +bearishCount1 = ta.barssince(bearishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[1] + 1 + +bullishCount2 = ta.barssince(bullishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[2] + 1 +bearishCount2 = ta.barssince(bearishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[2] + 1 + +bullishCount3 = ta.barssince(bullishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[3] + 1 +bearishCount3 = ta.barssince(bearishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[3] + 1 + +bullishCount5 = ta.barssince(bullishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[5] + 1 +bearishCount5 = ta.barssince(bearishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[5] + 1 + +bullishCount10 = ta.barssince(bullishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[10] + 1 +bearishCount10 = ta.barssince(bearishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[10] + 1 + +bullishCount20 = ta.barssince(bullishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[20] + 1 +bearishCount20 = ta.barssince(bearishDivergence(close, close[1], rsiSrc, rsiOverbought, rsiOversold))[20] + 1 + +// Calculate odds based on the occurrences of divergences +calcOdds(count, candles) => + odds = (count / candles) * 100 + odds + +// Normalize probabilities so they add up to 100% +normalizeProbabilities(bullish, bearish) => + total = bullish + bearish + bullishProb = (bullish / total) * 100 + bearishProb = (bearish / total) * 100 + [bullishProb, bearishProb] + +// Calculate odds for different candle periods +[bullishOdds1, bearishOdds1] = normalizeProbabilities(calcOdds(bullishCount1, 1), calcOdds(bearishCount1, 1)) +[bullishOdds2, bearishOdds2] = normalizeProbabilities(calcOdds(bullishCount2, 2), calcOdds(bearishCount2, 2)) +[bullishOdds3, bearishOdds3] = normalizeProbabilities(calcOdds(bullishCount3, 3), calcOdds(bearishCount3, 3)) +[bullishOdds5, bearishOdds5] = normalizeProbabilities(calcOdds(bullishCount5, 5), calcOdds(bearishCount5, 5)) +[bullishOdds10, bearishOdds10] = normalizeProbabilities(calcOdds(bullishCount10, 10), calcOdds(bearishCount10, 10)) +[bullishOdds20, bearishOdds20] = normalizeProbabilities(calcOdds(bullishCount20, 20), calcOdds(bearishCount20, 20)) + +// Calculate total odds for the selected candle periods +totalBullishOdds = bullishOdds1 + bullishOdds2 + bullishOdds3 + bullishOdds5 + bullishOdds10 + bullishOdds20 +totalBearishOdds = bearishOdds1 + bearishOdds2 + bearishOdds3 + bearishOdds5 + bearishOdds10 + bearishOdds20 + +// New totals +totalBullishOdds1_2 = bullishOdds1 + bullishOdds2 +totalBullishOdds1_2_3 = totalBullishOdds1_2 + bullishOdds3 +totalBullishOdds1_2_3_5 = totalBullishOdds1_2_3 + bullishOdds5 + +totalBearishOdds1_2 = bearishOdds1 + bearishOdds2 +totalBearishOdds1_2_3 = totalBearishOdds1_2 + bearishOdds3 +totalBearishOdds1_2_3_5 = totalBearishOdds1_2_3 + bearishOdds5 + +// Display odds information in a label +var labelOdds = label.new(na, na, "") +label.set_xy(labelOdds, bar_index, high) +label.set_text(labelOdds, "Odds:\nLast 1 Candle: Bullish " + str.tostring(bullishOdds1) + "%, Bearish " + str.tostring(bearishOdds1) + "%\nLast 2 Candles: Bullish " + str.tostring(bullishOdds2) + "%, Bearish " + str.tostring(bearishOdds2) + "%\nLast 3 Candles: Bullish " + str.tostring(bullishOdds3) + "%, Bearish " + str.tostring(bearishOdds3) + "%\nLast 5 Candles: Bullish " + str.tostring(bullishOdds5) + "%, Bearish " + str.tostring(bearishOdds5) + "%\nLast 10 Candles: Bullish " + str.tostring(bullishOdds10) + "%, Bearish " + str.tostring(bearishOdds10) + "%\nLast 20 Candles: Bullish " + str.tostring(bullishOdds20) + "%, Bearish " + str.tostring(bearishOdds20) + "%\nTotal: Bullish " + str.tostring(totalBullishOdds) + "%, Bearish " + str.tostring(totalBearishOdds) + "%\n\nNew Totals:\nTotal 1-2: Bullish " + str.tostring(totalBullishOdds1_2) + "%, Bearish " + str.tostring(totalBearishOdds1_2) + "%\nTotal 1-2-3: Bullish " + str.tostring(totalBullishOdds1_2_3) + "%, Bearish " + str.tostring(totalBearishOdds1_2_3) + "%\nTotal 1-2-3-5: Bullish " + str.tostring(totalBullishOdds1_2_3_5) + "%, Bearish " + str.tostring(totalBearishOdds1_2_3_5) + "%") +label.set_color(labelOdds, totalBullishOdds > totalBearishOdds ? color.new(color.green, 0) : color.new(color.red, 0)) +label.set_style(labelOdds, label.style_label_left) + +// Plotting +plot(rsiSrc, title="RSI", color=color.new(color.blue, 0), linewidth=2) + +// Plot green flag if total bullish odds are 5 times higher than bearish odds +plotshape(totalBullishOdds > 5 * totalBearishOdds, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.small) + +// Plot red flag if total bearish odds are 5 times higher than bullish odds +plotshape(totalBearishOdds > 5 * totalBullishOdds, style=shape.triangledown, location=location.belowbar, color=color.new(color.red, 0), size=size.small) + +// Plot diamond if total bullish odds are 6 times higher than bearish odds +plotshape(totalBullishOdds > 6 * totalBearishOdds, style=shape.diamond, location=location.belowbar, color=color.new(color.blue, 0), size=size.small) + +// Plot diamond if total bearish odds are 6 times higher than bullish odds +plotshape(totalBearishOdds > 6 * totalBullishOdds, style=shape.diamond, location=location.belowbar, color=color.new(color.purple, 0), size=size.small) + +// Plot green flag for previous occurrences if total bullish odds are 5 times higher than bearish odds +plotshape(totalBullishOdds[1] > 5 * totalBearishOdds[1], style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.small) + +// Plot red \ No newline at end of file diff --git a/Niki/niki2.pine b/Niki/niki2.pine new file mode 100644 index 0000000..6e68f3c --- /dev/null +++ b/Niki/niki2.pine @@ -0,0 +1,80 @@ +//@version=5 +indicator("DrNiki's Market Nuker", shorttitle="DrNiki's Market Nuker", overlay=true) + +// Function to calculate RSI +rsiLength = input(14, title="RSI Length") +rsiValue = ta.rsi(close, rsiLength) + +// Stochastic RSI +stochRsiLength = input(14, title="Stochastic RSI Length") +stochRsiValue = ta.stoch(close, close, close, stochRsiLength) + +// Wavetrend Indicator +n1 = input(10, "Channel Length") +n2 = input(21, "Average Length") +obLevel1 = input(60, "Over Bought Level 1") +obLevel2 = input(53, "Over Bought Level 2") +osLevel1 = input(-60, "Over Sold Level 1") +osLevel2 = input(-53, "Over Sold Level 2") + +ap = hlc3 +esa = ta.ema(ap, n1) +d = ta.ema(math.abs(ap - esa), n1) +ci = (ap - esa) / (0.015 * d) +tci = ta.ema(ci, n2) + +wt1 = tci +wt2 = ta.sma(wt1, 4) + +// Custom implementation of On Balance Volume (OBV) +var float obv = na +obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv + +// Money Flow Index (MFI) +mfiLength = input(7, title="MFI Length") +mfiValue = ta.mfi(close, mfiLength) + +// Initialize points for each timeframe +longPointsRSI = close > close[1] ? 1 : 0 +shortPointsRSI = close < close[1] ? 1 : 0 +longPointsStochRSI = stochRsiValue > stochRsiValue[1] ? 1 : 0 +shortPointsStochRSI = stochRsiValue < stochRsiValue[1] ? 1 : 0 +longPointsWavetrend = wt1 > wt1[1] ? 1 : 0 +shortPointsWavetrend = wt1 < wt1[1] ? 1 : 0 +longPointsOBV = obv > obv[1] ? 1 : 0 +shortPointsOBV = obv < obv[1] ? 1 : 0 +longPointsMFI = mfiValue > 50 ? 1 : 0 +shortPointsMFI = mfiValue < 50 ? 1 : 0 + +// Calculate total points for each timeframe +totalLongPoints = longPointsRSI + longPointsStochRSI + longPointsWavetrend + longPointsOBV + longPointsMFI +totalShortPoints = shortPointsRSI + shortPointsStochRSI + shortPointsWavetrend + shortPointsOBV + shortPointsMFI + +// Calculate combined probabilities for each timeframe +combinedProbabilityLong = totalLongPoints / 5 * 100 +combinedProbabilityShort = totalShortPoints / 5 * 100 + +// Display combined probabilities in a box at the top right corner +var labelBox = label.new(na, na, "") +label.set_xy(labelBox, bar_index, high) +label.set_text(labelBox, "Long: " + str.tostring(combinedProbabilityLong) + "%\nShort: " + str.tostring(combinedProbabilityShort) + "%") +label.set_color(labelBox, color.new(color.blue, 0)) +label.set_style(labelBox, label.style_label_left) + +// Display on different timeframes +rsiValue1H = ta.rsi(close, 14) +rsiValue2H = ta.rsi(close, 28) +rsiValue3H = ta.rsi(close, 42) +rsiValue4H = ta.rsi(close, 56) + +// Odds calculation for each timeframe +odds1H = (longPointsRSI + longPointsStochRSI + longPointsWavetrend + longPointsOBV + longPointsMFI) / 5 * 100 +odds2H = (shortPointsRSI + shortPointsStochRSI + shortPointsWavetrend + shortPointsOBV + shortPointsMFI) / 5 * 100 +odds3H = (longPointsRSI + longPointsStochRSI + longPointsWavetrend + longPointsOBV + longPointsMFI) / 5 * 100 +odds4H = (shortPointsRSI + shortPointsStochRSI + shortPointsWavetrend + shortPointsOBV + shortPointsMFI) / 5 * 100 + +// Plotting +plot(rsiValue1H, title="RSI 1H", color=color.new(color.red, 0), linewidth=2) +plot(rsiValue2H, title="RSI 2H", color=color.new(color.blue, 0), linewidth=2) +plot(rsiValue3H, title="RSI 3H", color=color.new(color.green, 0), linewidth=2) +plot(rsiValue4H, title="RSI 4H", color=color.new(color.purple, 0), linewidth=2) \ No newline at end of file diff --git a/Niki/old/new.pine b/Niki/old/new.pine new file mode 100644 index 0000000..8fc01b7 --- /dev/null +++ b/Niki/old/new.pine @@ -0,0 +1,93 @@ +//@version=5 +indicator("DrNiki's Market Nuker", shorttitle="DrNiki's Market Nuker", overlay=true) + +// Function to calculate RSI +rsiLength = input(14, title="RSI Length") +calcRSI() => ta.rsi(close, rsiLength) + +// Function to calculate Stochastic RSI +stochRsiLength = input(14, title="Stochastic RSI Length") +calcStochRSI() => ta.stoch(close, close, close, stochRsiLength) + +// Function to calculate Wavetrend +n1 = input(10, "Channel Length") +n2 = input(21, "Average Length") +calcWavetrend() => + ap = hlc3 + esa = ta.ema(ap, n1) + d = ta.ema(math.abs(ap - esa), n1) + ci = (ap - esa) / (0.015 * d) + tci = ta.ema(ci, n2) + wt1 = tci + wt2 = ta.sma(wt1, 4) + [wt1, wt2] + +// Function to calculate On Balance Volume (OBV) +calcOBV() => + var float obv = na + obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv + obv + +// Function to calculate MFI +mfiLength = input(7, title="MFI Length") +calcMFI() => ta.mfi(close, mfiLength) + +// Function to calculate points for a symbol +calcPoints(symbol) => + rsiValue = calcRSI() + stochRsiValue = calcStochRSI() + [wt1, wt2] = calcWavetrend() + obv = calcOBV() + mfiValue = calcMFI() + + longPoints = 0 + shortPoints = 0 + longPoints := rsiValue > rsiValue[1] ? longPoints + 1 : longPoints + shortPoints := rsiValue < rsiValue[1] ? shortPoints + 1 : shortPoints + longPoints := stochRsiValue > stochRsiValue[1] ? longPoints + 1 : longPoints + shortPoints := stochRsiValue < stochRsiValue[1] ? shortPoints + 1 : shortPoints + longPoints := wt1 > wt1[1] ? longPoints + 1 : longPoints + shortPoints := wt1 < wt1[1] ? shortPoints + 1 : shortPoints + longPoints := obv > obv[1] ? longPoints + 1 : longPoints + shortPoints := obv < obv[1] ? shortPoints + 1 : shortPoints + longPoints := mfiValue > 50 ? longPoints + 1 : longPoints + shortPoints := mfiValue < 50 ? shortPoints + 1 : shortPoints + var logMessage = "Symbol: " + symbol + ", RSI: " + str.tostring(rsiValue) + + ", StochRSI: " + str.tostring(stochRsiValue) + + ", WT1: " + str.tostring(wt1) + + ", OBV: " + str.tostring(obv) + + ", MFI: " + str.tostring(mfiValue) + + ", Long: " + str.tostring(longPoints) + ", Short: " + str.tostring(shortPoints) + log.info(logMessage) + [longPoints, shortPoints] + +// Symbols array +symbols = array.new_string(5) +array.set(symbols, 0, syminfo.tickerid) +array.set(symbols, 1, "GOLD") +array.set(symbols, 2, "DXY") +array.set(symbols, 3, "BTCUSDT.P") +array.set(symbols, 4, "US30" ) + +// Calculate points for each symbol +var symbolPoints = array.new_int(2, 0) +for symbol in symbols + // Change symbol context using security() function + [longPoints, shortPoints] = calcPoints(symbol) + var logMessage = "Symbol: " + symbol + ", Long: " + str.tostring(longPoints) + ", Short: " + str.tostring(shortPoints) + log.info(logMessage) + array.set(symbolPoints, 0, array.get(symbolPoints, 0) + longPoints) + array.set(symbolPoints, 1, array.get(symbolPoints, 1) + shortPoints) + +// Calculate total long and short probabilities +totalLongPoints = array.get(symbolPoints, 0) +totalShortPoints = array.get(symbolPoints, 1) +combinedProbabilityLong = totalLongPoints / (array.size(symbols) * 3) * 100 +combinedProbabilityShort = totalShortPoints / (array.size(symbols) * 3) * 100 + +// Display combined probabilities +var labelBox = label.new(na, na, "") +label.set_xy(labelBox, bar_index, high) +label.set_text(labelBox, "Combined Probabilities\nLong: " + str.tostring(combinedProbabilityLong) + "%\nShort: " + str.tostring(combinedProbabilityShort) + "%") +label.set_color(labelBox, color.new(color.blue, 0)) +label.set_style(labelBox, label.style_label_left) diff --git a/Niki/old/niki.pine b/Niki/old/niki.pine new file mode 100644 index 0000000..e9c0a91 --- /dev/null +++ b/Niki/old/niki.pine @@ -0,0 +1,151 @@ +//@version=5 +indicator("DrNiki's Market Nuker", shorttitle="DrNiki's Market Nuker", overlay=true) + +// Relative Strength Index (RSI) +rsiLength = input(14, title="RSI Length") +rsiValue = ta.rsi(close, rsiLength) + +// Stochastic RSI +stochRsiLength = input(14, title="Stochastic RSI Length") +stochRsiValue = ta.stoch(close, close, close, stochRsiLength) + +// Wavetrend Indicator +n1 = input(10, "Channel Length") +n2 = input(21, "Average Length") +obLevel1 = input(60, "Over Bought Level 1") +obLevel2 = input(53, "Over Bought Level 2") +osLevel1 = input(-60, "Over Sold Level 1") +osLevel2 = input(-53, "Over Sold Level 2") + +ap = hlc3 +esa = ta.ema(ap, n1) +d = ta.ema(math.abs(ap - esa), n1) +ci = (ap - esa) / (0.015 * d) +tci = ta.ema(ci, n2) + +wt1 = tci +wt2 = ta.sma(wt1, 4) + +// Custom implementation of On Balance Volume (OBV) +var float obv = na +obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv + +// Money Flow Index (MFI) +mfiLength = input(7, title="MFI Length") +mfiValue = ta.mfi(close, mfiLength) + + + +// Initialize points for BTCUSDT.P +longPointsRSIBTC = close > close[1] ? 1 : 0 +shortPointsRSIBTC = close < close[1] ? 1 : 0 +longPointsStochRSIBTC = stochRsiValue > stochRsiValue[1] ? 1 : 0 +shortPointsStochRSIBTC = stochRsiValue < stochRsiValue[1] ? 1 : 0 +longPointsWavetrendBTC = wt1 > wt1[1] ? 1 : 0 +shortPointsWavetrendBTC = wt1 < wt1[1] ? 1 : 0 +longPointsOBVBTC = obv > obv[1] ? 1 : 0 +shortPointsOBVBTC = obv < obv[1] ? 1 : 0 +longPointsMFIBTC = mfiValue > 50 ? 1 : 0 +shortPointsMFIBTC = mfiValue < 50 ? 1 : 0 +//log time and close +//log.info("close: " + str.tostring(close)) +// get time formatted +timeStr = time(timeframe.period, "YYYY-MM-DD HH:mm:ss") +log.info("time: " + str.tostring(time) + " close: " + str.tostring(close) + " longPointsRSIBTC: " + str.tostring(longPointsRSIBTC) + " shortPointsRSIBTC: " + str.tostring(shortPointsRSIBTC) + " longPointsStochRSIBTC: " + str.tostring(longPointsStochRSIBTC) + " shortPointsStochRSIBTC: " + str.tostring(shortPointsStochRSIBTC) + " longPointsWavetrendBTC: " + str.tostring(longPointsWavetrendBTC) + " shortPointsWavetrendBTC: " + str.tostring(shortPointsWavetrendBTC) + " longPointsOBVBTC: " + str.tostring(longPointsOBVBTC) + " shortPointsOBVBTC: " + str.tostring(shortPointsOBVBTC) + " longPointsMFIBTC: " + str.tostring(longPointsMFIBTC) + " shortPointsMFIBTC: " + str.tostring(shortPointsMFIBTC)) + +// Initialize points for DXY +longPointsRSIDXY = close > close[1] ? 0 : 1 +shortPointsRSIDXY = close < close[1] ? 0 : 1 +longPointsStochRSIDXY = stochRsiValue > stochRsiValue[1] ? 0 : 1 +shortPointsStochRSIDXY = stochRsiValue < stochRsiValue[1] ? 0 : 1 +longPointsWavetrendDXY = wt1 < wt1[1] ? 0 : 1 +shortPointsWavetrendDXY = wt1 > wt1[1] ? 0 : 1 +longPointsOBVDXY = obv > obv[1] ? 0 : 1 +shortPointsOBVDXY = obv < obv[1] ? 0 : 1 +longPointsMFIDXY = mfiValue > 50 ? 0 : 1 +shortPointsMFIDXY = mfiValue < 50 ? 0 : 1 + +// Initialize points for GOLD +longPointsRSIGOLD = close > close[1] ? 1 : 0 +shortPointsRSIGOLD = close < close[1] ? 1 : 0 +longPointsStochRSIGOLD = stochRsiValue > stochRsiValue[1] ? 1 : 0 +shortPointsStochRSIGOLD = stochRsiValue < stochRsiValue[1] ? 1 : 0 +longPointsWavetrendGOLD = wt1 > wt1[1] ? 1 : 0 +shortPointsWavetrendGOLD = wt1 < wt1[1] ? 1 : 0 +longPointsOBVGOLD = obv > obv[1] ? 1 : 0 +shortPointsOBVGOLD = obv < obv[1] ? 1 : 0 +longPointsMFIGOLD = mfiValue > 50 ? 1 : 0 +shortPointsMFIGOLD = mfiValue < 50 ? 1 : 0 + + +// Initialize points for US30 +longPointsRSIUS30 = close > close[1] ? 1 : 0 +shortPointsRSIUS30 = close < close[1] ? 1 : 0 +longPointsStochRSIUS30 = stochRsiValue > stochRsiValue[1] ? 1 : 0 +shortPointsStochRSIUS30 = stochRsiValue < stochRsiValue[1] ? 1 : 0 +longPointsWavetrendUS30 = wt1 > wt1[1] ? 1 : 0 +shortPointsWavetrendUS30 = wt1 < wt1[1] ? 1 : 0 +longPointsOBVUS30 = obv > obv[1] ? 1 : 0 +shortPointsOBVUS30 = obv < obv[1] ? 1 : 0 +longPointsMFIUS30 = mfiValue > 50 ? 1 : 0 +shortPointsMFIUS30 = mfiValue < 50 ? 1 : 0 + +// Initialize points for the current trading pair (syminfo.ticker) +longPointsRSIPAIR = close > close[1] ? 1 : 0 +shortPointsRSIPAIR = close < close[1] ? 1 : 0 +longPointsStochRSIPAIR = stochRsiValue > stochRsiValue[1] ? 1 : 0 +shortPointsStochRSIPAIR = stochRsiValue < stochRsiValue[1] ? 1 : 0 +longPointsWavetrendPAIR = wt1 > wt1[1] ? 1 : 0 +shortPointsWavetrendPAIR = wt1 < wt1[1] ? 1 : 0 +longPointsOBVPAIR = obv > obv[1] ? 1 : 0 +shortPointsOBVPAIR = obv < obv[1] ? 1 : 0 +longPointsMFIPAIR = mfiValue > 50 ? 1 : 0 +shortPointsMFIPAIR = mfiValue < 50 ? 1 : 0 + +// Calculate total points for each symbol +totalLongPointsBTC = longPointsRSIBTC + longPointsStochRSIBTC + longPointsWavetrendBTC +totalShortPointsBTC = shortPointsRSIBTC + shortPointsStochRSIBTC + shortPointsWavetrendBTC + +totalLongPointsGOLD = longPointsRSIGOLD + longPointsStochRSIGOLD + longPointsWavetrendGOLD +totalShortPointsGOLD = shortPointsRSIGOLD + shortPointsStochRSIGOLD + shortPointsWavetrendGOLD + +totalLongPointsDXY = longPointsRSIDXY + longPointsStochRSIDXY + longPointsWavetrendDXY +totalShortPointsDXY = shortPointsRSIDXY + shortPointsStochRSIDXY + shortPointsWavetrendDXY + +totalLongPointsUS30 = longPointsRSIUS30 + longPointsStochRSIUS30 + longPointsWavetrendUS30 +totalShortPointsUS30 = shortPointsRSIUS30 + shortPointsStochRSIUS30 + shortPointsWavetrendUS30 + +totalLongPointsPAIR = longPointsRSIPAIR + longPointsStochRSIPAIR + longPointsWavetrendPAIR +totalShortPointsPAIR = shortPointsRSIPAIR + shortPointsStochRSIPAIR + shortPointsWavetrendPAIR + +// Calculate total long and short probabilities for all symbols +totalLongPoints = totalLongPointsBTC + totalLongPointsDXY + totalLongPointsGOLD + totalLongPointsUS30 + totalLongPointsPAIR +totalShortPoints = totalShortPointsBTC + totalShortPointsDXY + totalShortPointsGOLD + totalShortPointsUS30 + totalShortPointsPAIR + +// Calculate combined probabilities for each symbol +combinedProbabilityLongBTC = totalLongPointsBTC / 3 * 100 +combinedProbabilityShortBTC = totalShortPointsBTC / 3 * 100 + +combinedProbabilityLongDXY = totalLongPointsDXY / 3 * 100 +combinedProbabilityShortDXY = totalShortPointsDXY / 3 * 100 + +combinedProbabilityLongGOLD = totalLongPointsGOLD / 3 * 100 +combinedProbabilityShortGOLD = totalShortPointsGOLD / 3 * 100 + +combinedProbabilityLongUS30 = totalLongPointsUS30 / 3 * 100 +combinedProbabilityShortUS30 = totalShortPointsUS30 / 3 * 100 + +combinedProbabilityLongPAIR = totalLongPointsPAIR / 3 * 100 +combinedProbabilityShortPAIR = totalShortPointsPAIR / 3 * 100 + +// Calculate combined probabilities for all symbols +combinedProbabilityLong = totalLongPoints / 15 * 100 +combinedProbabilityShort = totalShortPoints / 15 * 100 + +// Display combined probabilities in a box at the top right corner +var labelBox = label.new(na, na, "") +label.set_xy(labelBox, bar_index, high) +label.set_text(labelBox, "Long: BTC " + str.tostring(combinedProbabilityLongBTC) + "%, DXY " + str.tostring(combinedProbabilityLongDXY) + "%, GOLD " + str.tostring(combinedProbabilityLongGOLD) + "%, US30 " + str.tostring(combinedProbabilityLongUS30) + "%, syminfo.ticker " + str.tostring(combinedProbabilityLongPAIR) + "%\nShort: BTC " + str.tostring(combinedProbabilityShortBTC) + "%, DXY " + str.tostring(combinedProbabilityShortDXY) + "%, GOLD " + str.tostring(combinedProbabilityShortGOLD) + "%, US30 " + str.tostring(combinedProbabilityShortUS30) + "%, syminfo.ticker " + str.tostring(combinedProbabilityShortPAIR) + "%\n\nTotal: Long " + str.tostring(combinedProbabilityLong) + "%, Short " + str.tostring(combinedProbabilityShort) + "%") +label.set_color(labelBox, color.new(color.blue, 0)) +label.set_style(labelBox, label.style_label_left) + diff --git a/agent-mobile/artimobile/.bundle/config b/agent-mobile/artimobile/.bundle/config new file mode 100644 index 0000000..848943b --- /dev/null +++ b/agent-mobile/artimobile/.bundle/config @@ -0,0 +1,2 @@ +BUNDLE_PATH: "vendor/bundle" +BUNDLE_FORCE_RUBY_PLATFORM: 1 diff --git a/agent-mobile/artimobile/.env b/agent-mobile/artimobile/.env new file mode 100644 index 0000000..dc8dba7 --- /dev/null +++ b/agent-mobile/artimobile/.env @@ -0,0 +1 @@ +TTS_BACKEND_URL=http://192.168.0.10:9008/asr diff --git a/agent-mobile/artimobile/.eslintrc.js b/agent-mobile/artimobile/.eslintrc.js new file mode 100644 index 0000000..187894b --- /dev/null +++ b/agent-mobile/artimobile/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: '@react-native', +}; diff --git a/agent-mobile/artimobile/.gitignore b/agent-mobile/artimobile/.gitignore new file mode 100644 index 0000000..0cab2ac --- /dev/null +++ b/agent-mobile/artimobile/.gitignore @@ -0,0 +1,66 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +ios/.xcode.env.local + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml +*.hprof +.cxx/ +*.keystore +!debug.keystore + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +**/fastlane/report.xml +**/fastlane/Preview.html +**/fastlane/screenshots +**/fastlane/test_output + +# Bundle artifact +*.jsbundle + +# Ruby / CocoaPods +/ios/Pods/ +/vendor/bundle/ + +# Temporary files created by Metro to check the health of the file watcher +.metro-health-check* + +# testing +/coverage diff --git a/agent-mobile/artimobile/.prettierrc.js b/agent-mobile/artimobile/.prettierrc.js new file mode 100644 index 0000000..2b54074 --- /dev/null +++ b/agent-mobile/artimobile/.prettierrc.js @@ -0,0 +1,7 @@ +module.exports = { + arrowParens: 'avoid', + bracketSameLine: true, + bracketSpacing: false, + singleQuote: true, + trailingComma: 'all', +}; diff --git a/agent-mobile/artimobile/.watchmanconfig b/agent-mobile/artimobile/.watchmanconfig new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/agent-mobile/artimobile/.watchmanconfig @@ -0,0 +1 @@ +{} diff --git a/agent-mobile/artimobile/App.tsx b/agent-mobile/artimobile/App.tsx new file mode 100644 index 0000000..125fe1b --- /dev/null +++ b/agent-mobile/artimobile/App.tsx @@ -0,0 +1,118 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + * + * @format + */ + +import React from 'react'; +import type {PropsWithChildren} from 'react'; +import { + SafeAreaView, + ScrollView, + StatusBar, + StyleSheet, + Text, + useColorScheme, + View, +} from 'react-native'; + +import { + Colors, + DebugInstructions, + Header, + LearnMoreLinks, + ReloadInstructions, +} from 'react-native/Libraries/NewAppScreen'; + +type SectionProps = PropsWithChildren<{ + title: string; +}>; + +function Section({children, title}: SectionProps): React.JSX.Element { + const isDarkMode = useColorScheme() === 'dark'; + return ( + + + {title} + + + {children} + + + ); +} + +function App(): React.JSX.Element { + const isDarkMode = useColorScheme() === 'dark'; + + const backgroundStyle = { + backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, + }; + + return ( + + + +
+ +
+ Edit App.tsx to change this + screen and then come back to see your edits. +
+
+ +
+
+ +
+
+ Read the docs to discover what to do next: +
+ +
+ + + ); +} + +const styles = StyleSheet.create({ + sectionContainer: { + marginTop: 32, + paddingHorizontal: 24, + }, + sectionTitle: { + fontSize: 24, + fontWeight: '600', + }, + sectionDescription: { + marginTop: 8, + fontSize: 18, + fontWeight: '400', + }, + highlight: { + fontWeight: '700', + }, +}); + +export default App; diff --git a/agent-mobile/artimobile/Gemfile b/agent-mobile/artimobile/Gemfile new file mode 100644 index 0000000..8d72c37 --- /dev/null +++ b/agent-mobile/artimobile/Gemfile @@ -0,0 +1,9 @@ +source 'https://rubygems.org' + +# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version +ruby ">= 2.6.10" + +# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper +# bound in the template on Cocoapods with next React Native release. +gem 'cocoapods', '>= 1.13', '< 1.15' +gem 'activesupport', '>= 6.1.7.5', '< 7.1.0' diff --git a/agent-mobile/artimobile/README.md b/agent-mobile/artimobile/README.md new file mode 100644 index 0000000..12470c3 --- /dev/null +++ b/agent-mobile/artimobile/README.md @@ -0,0 +1,79 @@ +This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). + +# Getting Started + +>**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. + +## Step 1: Start the Metro Server + +First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. + +To start Metro, run the following command from the _root_ of your React Native project: + +```bash +# using npm +npm start + +# OR using Yarn +yarn start +``` + +## Step 2: Start your Application + +Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: + +### For Android + +```bash +# using npm +npm run android + +# OR using Yarn +yarn android +``` + +### For iOS + +```bash +# using npm +npm run ios + +# OR using Yarn +yarn ios +``` + +If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. + +This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. + +## Step 3: Modifying your App + +Now that you have successfully run the app, let's modify it. + +1. Open `App.tsx` in your text editor of choice and edit some lines. +2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! + + For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! + +## Congratulations! :tada: + +You've successfully run and modified your React Native App. :partying_face: + +### Now what? + +- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). +- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). + +# Troubleshooting + +If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. + +# Learn More + +To learn more about React Native, take a look at the following resources: + +- [React Native Website](https://reactnative.dev) - learn more about React Native. +- [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. +- [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. +- [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. +- [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. diff --git a/agent-mobile/artimobile/Task b/agent-mobile/artimobile/Task new file mode 100644 index 0000000..e69de29 diff --git a/agent-mobile/artimobile/VoiceHandler.js b/agent-mobile/artimobile/VoiceHandler.js new file mode 100644 index 0000000..fb278a1 --- /dev/null +++ b/agent-mobile/artimobile/VoiceHandler.js @@ -0,0 +1,191 @@ +// VoiceHandler.js +import React, { Component } from 'react'; +import { View, Text, Button } from 'react-native'; +import Voice from '@react-native-voice/voice'; + +// import Config from 'react-native-config'; +// process.env.TTS_BACKEND_URL = Config.TTS_BACKEND_URL; +// process.env.TTS_BACKEND_URL = "http://192.168.0.10:9008/asr" +process.env.TTS_BACKEND_URL = "https://tts.d-popov.com/asr" + +const LLM_ENDPOINT = "https://ws.ai.d-popov.com/api/chat"; +// const LLM_ENDPOINT = "http://192.168.0.11:11434/api/chat"; + +const LOG_ENDPOINT = "ws://192.168.0.11:9999"; + +class VoiceHandler extends Component { + constructor(props) { + super(props); + this.state = { + status: '', + recognized: '', + started: '', + results: [], + isRecording: false, + isProcessing: false, + }; + + Voice.onSpeechStart = this.onSpeechStart.bind(this); + Voice.onSpeechRecognized = this.onSpeechRecognized.bind(this); + Voice.onSpeechResults = this.onSpeechResults.bind(this); + } + + componentWillUnmount() { + Voice.destroy().then(Voice.removeAllListeners); + } + + onSpeechStart(e) { + this.setState({ + started: '√', + status: "listening..." + }); + } + + onSpeechRecognized(e) { + this.setState({ + status: "Recognized" + }); + console.log("onSpeechRecognized()"); + } + + onSpeechResults(e) { + this.setState({ + recognized: [...recognized, e.value], + status: this.state.status+ "\nonSpeechResults():" + e.value + }); + console.log("onSpeechResults():" + e.value); + } + + async _startRecognizing(e) { + this.setState({ + recognized: '', + started: '', + results: [], + status: "Starting...", + isRecording: true, + }); + + try { + await Voice.start('en-US'); // Start the voice recognition + } catch (error) { + console.error('There was an error starting voice recognition:', error); + this.setState({ + isRecording: false, + }); + } + } + async _stopRecognizing() { + try { + await Voice.stop(); + this.setState({ + isRecording: false, + isProcessing:true, + status: this.state.status+ "\nstopRecognizing()" + this.state.recognized + }); + // Assuming you have the audio data, send it to your backend + this._sendTranscribedTextToLLM("who is the president of thr USA"); + //this._sendTranscribedTextToLLM(this.state.recognized); + } catch (e) { + console.error(e); + } + } + async _sendTranscribedTextToLLM(transcribedText) { + + const model = "openhermes:latest"; + const prompt = "I have a question. Answer briefly and precise as an expert: \n" + transcribedText ; + const data = { + model: model, + messages: [{ role: "user", content: `${prompt}`}], + stream: false, + }; + this.setState({ + status: this.state.status + "\nsending to LLM:\n" + prompt + }) + + try { + console.log('sending text to LLM at ', LLM_ENDPOINT, ": '", transcribedText, "'"); + const response = await fetch(LLM_ENDPOINT, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); + + if (response.ok) { + const responseJson = await response.json(); + if (responseJson.error) { + console.error("LLM Error:", responseJson.error); + // Handle error appropriately in your app + } else { + // Handle successful response + console.log('LLM Response:', responseJson.message); + // Update your app state or UI based on LLM response + this.setState(prevState => ({ + status: "LLM responded", + results: [...prevState.results, responseJson.message.content], // Append the response to the existing results + })); + } + } else { + // Handle HTTP errors + console.error("HTTP Error:", response.status); + } + } catch (error) { + console.error('Request failed:', error); + // Handle request error + } + + finally{ + this.setState({ + isProcessing:false + }); + } + + } + _sendAudioToBackend(results) { + // Placeholder: Convert `results` or actual audio data to a format acceptable by your backend + const formData = new FormData(); + //formData.append('audio', {uri: 'path_to_audio_file', type: 'audio/x-m4a', name: 'audio.m4a'}); + + fetch(process.env.TTS_BACKEND_URL, { + method: 'POST', + body: formData, + headers: { + 'Content-Type': 'multipart/form-data', + }, + }) + .then(response => response.text()) + .then(body => { + console.log('Audio sent to backend, response:', body); + this.setState(prevState => ({ + results: [...prevState.results, body], // Append the response to the existing results + })); + }) + .catch(error => { + console.error('Failed to send audio:', error); + }); + } + render() { + return ( + + Press the button and start speaking. +