LoginSignup
2
6

TradingViewのテクニカルアナリシスデータを取得してみた

Posted at

趣旨

TradingViewのWebhookを介さずにPythonのみで取得できるデータを基に注文できるかどうか試してみたかったのでリサーチしてみました。

私がどのようにこのライブラリを使おうと思ってるかは秘密にしておきます。

GitHubの該当ページはここにあります。

環境設定からコードまで

ライブラリ1つインストールするだけで良いので簡単ですね。

pip install tradingview-ta

以下サンプルになります。どうぞご自由に改造してご使用ください。

python sample.py
from tradingview_ta import TA_Handler, Interval, Exchange
import tradingview_ta
from tradingview_ta import TradingView


btc = TA_Handler(
    symbol="BTCUSDT",
    screener="crypto",
    exchange="BINANCE",
    interval=Interval.INTERVAL_1_DAY
)

print('ta version')
print(tradingview_ta.__version__)

analysis = btc.get_analysis()
print(f'Summary: {analysis.summary}')
print(f'Oscillators: {analysis.oscillators}')
print(f'Close price: {analysis.indicators["close"]}')
print(f'Momentam: {analysis.indicators["Mom"]}')
print(f'RSI: {analysis.indicators["RSI"]}')
print(f'MACD: {analysis.indicators["MACD.macd"]}')
print(f'Indicators: {analysis.indicators}')

# assigning specific values to a new variable
bb_upper = analysis.indicators['BB.upper']
print(f'BB Upper: {bb_upper}')

結果

ta version
3.3.0
Summary: {'RECOMMENDATION': 'BUY', 'BUY': 16, 'SELL': 2, 'NEUTRAL': 8}
Oscillators: {'RECOMMENDATION': 'BUY', 'BUY': 3, 'SELL': 1, 'NEUTRAL': 7, 'COMPUTE': {'RSI': 'NEUTRAL', 'STOCH.K': 'NEUTRAL', 'CCI': 'SELL', 'ADX': 'NEUTRAL', 'AO': 'NEUTRAL', 'Mom': 'BUY', 'MACD': 'BUY', 'Stoch.RSI': 'NEUTRAL', 'W%R': 'NEUTRAL', 'BBP': 'NEUTRAL', 'UO': 'BUY'}}
Close price: 50063.94
Momentam: 7057.26
RSI: 78.86765521
MACD: 1717.23868793
Indicators: {'Recommend.Other': 0.18181818, 'Recommend.All': 0.49090909, 'Recommend.MA': 0.8, 'RSI': 78.86765521, 'RSI[1]': 78.59355363, 'Stoch.K': 95.74497457, 'Stoch.D': 93.81009686, 'Stoch.K[1]': 94.66767345, 'Stoch.D[1]': 92.10321574, 'CCI20': 177.27666473, 'CCI20[1]': 199.18975039, 'ADX': 23.45907788, 'ADX+DI': 36.8188587, 'ADX-DI': 11.33700201, 'ADX+DI[1]': 37.83882705, 'ADX-DI[1]': 11.70323035, 'AO': 4974.93879412, 'AO[1]': 4079.25317647, 'Mom': 7057.26, 'Mom[1]': 6735, 'MACD.macd': 1717.23868793, 'MACD.signal': 911.81314021, 'Rec.Stoch.RSI': 0, 'Stoch.RSI.K': 100, 'Rec.WR': 0, 'W.R': -3.59097301, 'Rec.BBPower': 0, 'BBPower': 7594.45104515, 'Rec.UO': 1, 'UO': 70.03623266, 'close': 50063.94, 'EMA5': 48553.32691135, 'SMA5': 48634.782, 'EMA10': 46917.04520261, 'SMA10': 46118.784, 'EMA20': 45248.22751324, 'SMA20': 44262.2375, 'EMA30': 44476.87994418, 'SMA30': 43316.11, 'EMA50': 43487.00110529, 'SMA50': 43521.163, 'EMA100': 41034.96114425, 'SMA100': 41621.9042, 'EMA200': 37080.92714512, 'SMA200': 35002.5266, 'Rec.Ichimoku': 0, 'Ichimoku.BLine': 44461.805, 'Rec.VWMA': 1, 'VWMA': 44574.50186189, 'Rec.HullMA9': -1, 'HullMA9': 50542.23807407, 'Pivot.M.Classic.S3': 22541.6, 'Pivot.M.Classic.S2': 32956.08, 'Pivot.M.Classic.S1': 37771.64, 'Pivot.M.Classic.Middle': 43370.56, 'Pivot.M.Classic.R1': 48186.12, 'Pivot.M.Classic.R2': 53785.04, 'Pivot.M.Classic.R3': 64199.52, 'Pivot.M.Fibonacci.S3': 32956.08, 'Pivot.M.Fibonacci.S2': 36934.41136, 'Pivot.M.Fibonacci.S1': 39392.22864, 'Pivot.M.Fibonacci.Middle': 43370.56, 'Pivot.M.Fibonacci.R1': 47348.89136, 'Pivot.M.Fibonacci.R2': 49806.70864, 'Pivot.M.Fibonacci.R3': 53785.04, 'Pivot.M.Camarilla.S3': 39723.218, 'Pivot.M.Camarilla.S2': 40677.87866667, 'Pivot.M.Camarilla.S1': 41632.53933333, 'Pivot.M.Camarilla.Middle': 43370.56, 'Pivot.M.Camarilla.R1': 43541.86066667, 'Pivot.M.Camarilla.R2': 44496.52133333, 'Pivot.M.Camarilla.R3': 45451.182, 'Pivot.M.Woodie.S3': 26958.28, 'Pivot.M.Woodie.S2': 32756.64, 'Pivot.M.Woodie.S1': 37372.76, 'Pivot.M.Woodie.Middle': 43171.12, 'Pivot.M.Woodie.R1': 47787.24, 'Pivot.M.Woodie.R2': 53585.6, 'Pivot.M.Woodie.R3': 58201.72, 'Pivot.M.Demark.S1': 40571.1, 'Pivot.M.Demark.Middle': 44770.29, 'Pivot.M.Demark.R1': 50985.58, 'open': 49917.28, 'P.SAR': 43994.18633888, 'BB.lower': 38717.33698888, 'BB.upper': 49807.13801112, 'AO[2]': 3071.51664706, 'volume': 15064.84727, 'change': 0.25823576, 'low': 49724.33, 'high': 50368.61}
BB Upper: 49807.13801112

以下のページを参考にいろいろ改造するの楽しそうです。

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6