2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PythonでFXチャートを表示してみる API編

Last updated at Posted at 2022-02-12

PythonでFXチャートを表示するのをGoogle Colabでやってみます。
https://colab.research.google.com

【相場分析】移動平均線の傾きをPythonで算出する
https://qiita.com/kazama1209/items/5b558b599923283df9fa

Twelve Data 株、為替、仮想通貨といった金融商品の情報を取得できるサービス。
https://twelvedata.com

!pip install twelvedata websocket mplfinance
import datetime
import pandas as pd
import mplfinance as mpf
from twelvedata import TDClient

TWELVE_DATA_API_KEY = '****************************' # Twelve Data のAPIキー

# ヒストリカルデータを取得
def get_historical_data(symbol, interval, outputsize, start_date, end_date, timezone):
    td = TDClient(apikey = TWELVE_DATA_API_KEY)

    res = td.time_series(
              symbol = symbol,
              interval = interval,
              outputsize = outputsize,
              start_date = start_date,
              end_date = end_date,
              timezone = timezone
          ).as_json()

    df = pd.DataFrame(res).iloc[::-1].set_index('datetime').astype(float)
    df = df[df.index >= start_date]
    df.index = pd.to_datetime(df.index)

    return df
# 銘柄
symbol = 'USD/JPY'

# 時間軸
#interval = '15min'
interval = '1h'

# 取得件数
#outputsize = 1000
outputsize = 20

# 取得開始日
start_date = '2022-01-03'

# 取得終了日
#end_date = datetime.datetime.now().strftime('%Y-%m-%d')
end_date = '2022-01-04'

# タイムゾーン
timezone = 'Asia/Tokyo'

# ヒストリカルデータを取得
df = get_historical_data(symbol, interval, outputsize, start_date, end_date, timezone)

df

スクリーンショット 2022-02-12 10.49.25.png

# 2022/1/3 5:00 - 23:00
mpf.plot(df[0:19], figratio=(12,4), type='candle', style="yahoo")

スクリーンショット 2022-02-12 10.49.42.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?