src/tradingview

https://TradingView.com client.

Example: cmd: -d:ssl -d:nimDisableCertificateValidation

import src/tradingview
const indicators: set[Indicators] = { low(Indicators) .. high(Indicators) }
doAssert indicators.len == 180
let trading = newTradingView(symbol = "BTCUSDT", timeout = 999.Positive, indicators = indicators)
echo "BTCUSDT\n", trading.getAnalysis()
(
  summary: (recommendation: NEUTRAL, buy: 2, sell: 1, neutral: 8, compute: {"MACD": SELL, "CCI": NEUTRAL, "RSI": NEUTRAL, "BBP": NEUTRAL, "STOCH.RSI": NEUTRAL, "ADX": NEUTRAL, "STOCH.K": NEUTRAL, "AO": BUY, "UO": NEUTRAL, "W%R": NEUTRAL, "MOM": BUY}),
  moving_average: (recommendation: NEUTRAL, buy: 13, sell: 1, neutral: 2, compute: {"HullMA": NEUTRAL, "Ichimoku": NEUTRAL, "VMA": SELL, "EMA10": BUY}),
  oscillators: (recommendation: NEUTRAL, buy: 15, sell: 2, neutral: 10, compute: {:})
)

Types

Analysis = tuple[summary: Summary, moving_average: MovingAverage,
                 oscillators: Oscillators]
Technical analysis.
Exchange {.pure.} = enum
  Binance = "BINANCE",      ## Crypto currencies.
  Coinbase = "COINBASE",    ## Crypto currencies (untested, use Binance).
  BITTREX = "BITTREX",      ## Crypto currencies (untested, use Binance).
  Fx_Idc = "FX_IDC",        ## FX_IDC for Forex (untested).
  Tvc = "TVC",              ## TVC for Contract For Differences (untested).
  NASDAQ = "NASDAQ",        ## NASDAQ for USA Market (untested).
  NYSE = "NYSE"              ## NYSE for USA Market (untested).
Exchanges, currently only Binance.
Indicators {.pure.} = enum
  RecommendOther = "Recommend.Other", RecommendAll = "Recommend.All",
  RecommendMA = "Recommend.MA", RSI = "RSI", RSI1 = "RSI[1]",
  StochK = "Stoch.K", StochD = "Stoch.D", StochK1 = "Stoch.K[1]",
  StochD1 = "Stoch.D[1]", CCI20 = "CCI20", CCI201 = "CCI20[1]", ADX = "ADX",
  ADXplusDI = "ADX+DI", ADXminusDI = "ADX-DI", ADXplusDI1 = "ADX+DI[1]",
  ADXminusDI1 = "ADX-DI[1]", AO = "AO", AO1 = "AO[1]", Mom = "Mom",
  Mom1 = "Mom[1]", MACDmacd = "MACD.macd", MACDsignal = "MACD.signal",
  RecStochRSI = "Rec.Stoch.RSI", StochRSIK = "Stoch.RSI.K", RecWR = "Rec.WR",
  WR = "W.R", RecBBPower = "Rec.BBPower", BBPower = "BBPower", RecUO = "Rec.UO",
  UO = "UO", close = "close", EMA5 = "EMA5", SMA5 = "SMA5", EMA10 = "EMA10",
  SMA10 = "SMA10", EMA20 = "EMA20", SMA20 = "SMA20", EMA30 = "EMA30",
  SMA30 = "SMA30", EMA50 = "EMA50", SMA50 = "SMA50", EMA100 = "EMA100",
  SMA100 = "SMA100", EMA200 = "EMA200", SMA200 = "SMA200",
  RecIchimoku = "Rec.Ichimoku", IchimokuBLine = "Ichimoku.BLine",
  RecVWMA = "Rec.VWMA", VWMA = "VWMA", RecHullMA9 = "Rec.HullMA9",
  HullMA9 = "HullMA9", PivotMClassicS3 = "Pivot.M.Classic.S3",
  PivotMClassicS2 = "Pivot.M.Classic.S2",
  PivotMClassicS1 = "Pivot.M.Classic.S1",
  PivotMClassicMiddle = "Pivot.M.Classic.Middle",
  PivotMClassicR1 = "Pivot.M.Classic.R1",
  PivotMClassicR2 = "Pivot.M.Classic.R2",
  PivotMClassicR3 = "Pivot.M.Classic.R3",
  PivotMFibonacciS3 = "Pivot.M.Fibonacci.S3",
  PivotMFibonacciS2 = "Pivot.M.Fibonacci.S2",
  PivotMFibonacciS1 = "Pivot.M.Fibonacci.S1",
  PivotMFibonacciMiddle = "Pivot.M.Fibonacci.Middle",
  PivotMFibonacciR1 = "Pivot.M.Fibonacci.R1",
  PivotMFibonacciR2 = "Pivot.M.Fibonacci.R2",
  PivotMFibonacciR3 = "Pivot.M.Fibonacci.R3",
  PivotMCamarillaS3 = "Pivot.M.Camarilla.S3",
  PivotMCamarillaS2 = "Pivot.M.Camarilla.S2",
  PivotMCamarillaS1 = "Pivot.M.Camarilla.S1",
  PivotMCamarillaMiddle = "Pivot.M.Camarilla.Middle",
  PivotMCamarillaR1 = "Pivot.M.Camarilla.R1",
  PivotMCamarillaR2 = "Pivot.M.Camarilla.R2",
  PivotMCamarillaR3 = "Pivot.M.Camarilla.R3",
  PivotMWoodieS3 = "Pivot.M.Woodie.S3", PivotMWoodieS2 = "Pivot.M.Woodie.S2",
  PivotMWoodieS1 = "Pivot.M.Woodie.S1",
  PivotMWoodieMiddle = "Pivot.M.Woodie.Middle",
  PivotMWoodieR1 = "Pivot.M.Woodie.R1", PivotMWoodieR2 = "Pivot.M.Woodie.R2",
  PivotMWoodieR3 = "Pivot.M.Woodie.R3", PivotMDemarkS1 = "Pivot.M.Demark.S1",
  PivotMDemarkMiddle = "Pivot.M.Demark.Middle",
  PivotMDemarkR1 = "Pivot.M.Demark.R1", open = "open", PSAR = "P.SAR",
  BBlower = "BB.lower", BBupper = "BB.upper", AO2 = "AO[2]", volume = "volume",
  change = "change", name = "name", changeabs = "change_abs",
  exchange = "exchange", High1M = "High.1M", Low1M = "Low.1M",
  High3M = "High.3M", Low3M = "Low.3M", Perf3M = "Perf.3M",
  price52weekhigh = "price_52_week_high", price52weeklow = "price_52_week_low",
  High6M = "High.6M", Low6M = "Low.6M", Perf6M = "Perf.6M",
  HighAll = "High.All", LowAll = "Low.All", AroonDown = "Aroon.Down",
  AroonUp = "Aroon.Up", ADR = "ADR", ATR = "ATR",
  averagevolume10dcalc = "average_volume_10d_calc", PerfY = "Perf.Y",
  PerfYTD = "Perf.YTD", averagevolume30dcalc = "average_volume_30d_calc",
  averagevolume60dcalc = "average_volume_60d_calc",
  averagevolume90dcalc = "average_volume_90d_calc",
  changeabs15 = "change_abs|15", change15 = "change|15",
  changeabs60 = "change_abs|60", change60 = "change|60",
  changeabs1 = "change_abs|1", change1 = "change|1",
  changeabs240 = "change_abs|240", change240 = "change|240",
  changeabs5 = "change_abs|5", change5 = "change|5",
  changefromopenabs = "change_from_open_abs",
  changefromopen = "change_from_open", DonchCh20Lower = "DonchCh20.Lower",
  DonchCh20Upper = "DonchCh20.Upper", gap = "gap",
  IchimokuCLine = "Ichimoku.CLine", IchimokuLead1 = "Ichimoku.Lead1",
  IchimokuLead2 = "Ichimoku.Lead2", KltChnllower = "KltChnl.lower",
  KltChnlupper = "KltChnl.upper", marketcapcalc = "market_cap_calc",
  Perf1M = "Perf.1M", ROC = "ROC", RSI7 = "RSI7",
  relativevolume10dcalc = "relative_volume_10d_calc", StochRSID = "Stoch.RSI.D",
  VolatilityD = "Volatility.D", VolatilityM = "Volatility.M",
  VolatilityW = "Volatility.W", VWAP = "VWAP", PerfW = "Perf.W",
  description = "description", subtype = "subtype", updatemode = "update_mode",
  pricescale = "pricescale", minmov = "minmov", fractional = "fractional",
  minmove2 = "minmove2", ADXDI = "ADX-DI[1]",
  CandleAbandonedBabyBearish = "Candle.AbandonedBaby.Bearish",
  CandleAbandonedBabyBullish = "Candle.AbandonedBaby.Bullish",
  CandleEngulfingBearish = "Candle.Engulfing.Bearish",
  CandleHaramiBearish = "Candle.Harami.Bearish",
  CandleEngulfingBullish = "Candle.Engulfing.Bullish",
  CandleHaramiBullish = "Candle.Harami.Bullish", CandleDoji = "Candle.Doji",
  CandleDojiDragonfly = "Candle.Doji.Dragonfly",
  CandleEveningStar = "Candle.EveningStar",
  CandleDojiGravestone = "Candle.Doji.Gravestone",
  CandleHammer = "Candle.Hammer", CandleHangingMan = "Candle.HangingMan",
  CandleInvertedHammer = "Candle.InvertedHammer",
  CandleKickingBearish = "Candle.Kicking.Bearish",
  CandleKickingBullish = "Candle.Kicking.Bullish",
  CandleLongShadowLower = "Candle.LongShadow.Lower",
  CandleLongShadowUpper = "Candle.LongShadow.Upper",
  CandleMarubozuBlack = "Candle.Marubozu.Black",
  CandleMarubozuWhite = "Candle.Marubozu.White",
  CandleMorningStar = "Candle.MorningStar",
  CandleShootingStar = "Candle.ShootingStar",
  CandleSpinningTopBlack = "Candle.SpinningTop.Black",
  CandleSpinningTopWhite = "Candle.SpinningTop.White",
  Candle3BlackCrows = "Candle.3BlackCrows",
  Candle3WhiteSoldiers = "Candle.3WhiteSoldiers",
  CandleTriStarBearish = "Candle.TriStar.Bearish",
  CandleTriStarBullish = "Candle.TriStar.Bullish"
Technical analysis indicators.
Interval {.pure.} = enum
  INTERVAL1MINUTE = "1m", INTERVAL5MINUTES = "5m", INTERVAL15MINUTES = "15m",
  INTERVAL30MINUTES = "30m", INTERVAL1HOUR = "1h", INTERVAL2HOURS = "2h",
  INTERVAL4HOURS = "4h", INTERVAL1DAY = "1d", INTERVAL1WEEK = "1W",
  INTERVAL1MONTH = "1M"
Time intervals.
Recommendation {.pure.} = enum
  buy = "BUY", strongBuy = "STRONG_BUY", sell = "SELL",
  strongSell = "STRONG_SELL", neutral = "NEUTRAL"
Buy or Sell ?.
Screener {.pure.} = enum
  Crypto = "CRYPTO",        ## Crypto currencies.
  Forex = "FOREX",          ## Forex (untested).
  America = "AMERICA",      ## USA Market (untested).
  Cfd = "CFD"                ## Contract For Differences (untested).
Screeners, currently only Crypto.
TradingView = object
  screener: Screener         ## Screener, currently only Crypto.
  exchange: Exchange         ## Exchange to use, currently only Binance.
  symbol: string             ## Symbol (e.g. "BTCUSDT", "ETHBUSD", "DOGEDAI", etc).
  interval: Interval         ## Time interval to use (e.g. "1m", "5m", "15m", "30m", "1h", "2h", "4h", "1d", "1W", "1M").
  timeout: Positive          ## Timeout.
  indicators: set[Indicators] ## Indicators to be used in the chart (e.g. "SMA", "EMA", "MACD", etc).
  
TradingView client.

Procs

func awesomeOscillator(ao, ao1, ao2: float): Recommendation {....raises: [],
    tags: [].}
proc calculate(self: TradingView): Analysis {....raises: [KeyError, ValueError,
    HttpRequestError, Exception, LibraryError, SslError, OSError, IOError,
    TimeoutError, ProtocolError, JsonParsingError],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect].}
proc getAnalysis(self: TradingView): Analysis {....raises: [KeyError, ValueError,
    HttpRequestError, Exception, LibraryError, SslError, OSError, IOError,
    TimeoutError, ProtocolError, JsonParsingError],
    tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect].}
func newTradingView(symbol: string; timeout: Positive; interval = INTERVAL1DAY;
                    indicators: set[Indicators]): TradingView {.inline,
    ...raises: [], tags: [].}
Constructor for TradingView.
func recommend(value: float): Recommendation {....raises: [], tags: [].}
Generic basic recommendation.
func tradingViewData(exchangeSymbols: seq[string]; indicators: set[Indicators];
                     interval: Interval): JsonNode {....raises: [], tags: [].}
Format TradingView Scanner Post Data.
  • exchangeSymbols example @["BINANCE:BTCUSDT", "BINANCE:ETHBUSD"], indicators must be all uppercase.