如何从Alpha Vantage API中提取数据?

问题描述 投票:0回答:1

我想对股票发出RSI警报。

这是Alpha Vantage API响应我的请求的数据。每当我运行代码时,我都想提取最新的RSI。

在这种情况下为77.0835。由于日期和时间(即2020-01-24 14:30)不断变化,请问有什么方法可以获取最新的RSI?

摘自Alpha Vantage的回复:

{
    "Meta Data": {
        "1: Symbol": "tlt",
        "2: Indicator": "Relative Strength Index (RSI)",
        "3: Last Refreshed": "2020-01-24 14:30:46",
        "4: Interval": "60min",
        "5: Time Period": 14,
        "6: Series Type": "close",
        "7: Time Zone": "US/Eastern Time"
    },
    "Technical Analysis: RSI": {
        "2020-01-24 14:30": {
            "RSI": "77.0835"
        },
        "2020-01-24 13:30": {
            "RSI": "78.0121"
        },
        "2020-01-24 12:30": {
            "RSI": "75.8201"
        },
        "2020-01-24 11:30": {
            "RSI": "75.7447"
        },
        "2020-01-24 10:30": {
            "RSI": "73.9965"
        },
        "2020-01-24 09:30": {
            "RSI": "73.8768"
        }

python json extract
1个回答
0
投票

怎么样?

data = {
    "Meta Data": {
        "1: Symbol": "tlt",
        "2: Indicator": "Relative Strength Index (RSI)",
        "3: Last Refreshed": "2020-01-24 14:30:46",
        "4: Interval": "60min",
        "5: Time Period": 14,
        "6: Series Type": "close",
        "7: Time Zone": "US/Eastern Time"
    },
    "Technical Analysis: RSI": {
        "2020-01-24 14:30": {
            "RSI": "77.0835"
        },
        "2020-01-24 13:30": {
            "RSI": "78.0121"
        },
        "2020-01-24 12:30": {
            "RSI": "75.8201"
        },
        "2020-01-24 11:30": {
            "RSI": "75.7447"
        },
        "2020-01-24 10:30": {
            "RSI": "73.9965"
        },
        "2020-01-24 09:30": {
            "RSI": "73.8768"
        }
    }
}

most_recent_rsi = data['Technical Analysis: RSI'][sorted(data['Technical Analysis: RSI'])[-1]]
© www.soinside.com 2019 - 2024. All rights reserved.