通达信数据 - 使用通达信API

Published

通达信官方提供了API接口,可以直接通过API获取实时数据。通达信API提供了丰富的接口,包括获取股票、基金、期货等各种金融产品的实时数据。以下是使用通达信API获取实时数据的步骤:

注册并获取API Key:首先,您需要在通达信官网注册并获取API Key,这是访问通达信API的凭证。
安装Python请求库:使用pip install requests安装requests库,用于发送HTTP请求。
编写Python代码:使用requests库发送HTTP请求,获取实时数据。

import requests
def get_realtime_data(stock_code):


    url = f"http://api.tdx.com/realtime?code={stock_code}&apikey=YOUR_API_KEY"


    response = requests.get(url)


    data = response.json()


    return data


stock_code = "000001"


data = get_realtime_data(stock_code)


print(data)